Author: batosai
Date: 2008-07-26 18:11:54 +0000 (Sat, 26 Jul 2008)
New Revision: 21426

Modified:
   trunk/apps/WoT/src/plugins/WoT/WoT.java
Log:
Added some code to stress the algorithm. It looks good enough to me for the 
moment. But there certainly is some possible optimisations.

Modified: trunk/apps/WoT/src/plugins/WoT/WoT.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoT.java     2008-07-26 18:06:49 UTC (rev 
21425)
+++ trunk/apps/WoT/src/plugins/WoT/WoT.java     2008-07-26 18:11:54 UTC (rev 
21426)
@@ -47,8 +47,6 @@
                boolean changedTrustValue = false;
                boolean changedComment = false;

-               System.out.println("*****" + newTrust);
-               
                ObjectSet<Trust> trustResult = db.queryByExample(new 
Trust(newTrust.getTruster(), newTrust.getTrustee(), 0));
                if(trustResult.size() != 0) {
                        Trust oldTrust = trustResult.next();
@@ -108,17 +106,13 @@
                while(trusters.hasNext()) {

                        Trust trusterTrust = trusters.next();
-                       
-                       System.out.println("**"+trusterTrust);
-                       
+                                       
                        Score trusterScore; 

                        ObjectSet<Score> trustersScore = db.queryByExample(new 
Score(treeOwner, trusterTrust.getTruster(), 0, 0, 0));
                        if(trustersScore.hasNext()) trusterScore = 
trustersScore.next();
                        else trusterScore = new Score(treeOwner, 
trusterTrust.getTruster(), 0, -1, 0);

-                       System.out.println("*"+trusterScore);
-                       
                        if(trusterScore.getCapacity() > 0) {
                                newScore += trusterScore.getCapacity() * 
trusterTrust.getValue() / 100;
                                if(newRank == -1 || newRank > 
trusterScore.getRank())
@@ -129,13 +123,14 @@
                if(newRank != -1) newRank++; // We don't want to give the 
trustee the same rank as the truster, right ?
                if((newScore > 0) && !hasNegativeTrust) newCapacity = 
capacities[newRank];

+               if(score.getRank() != 0) { // We don't want our own identites' 
rank to be changed either
+                       score.setRank(newRank);
+                       score.setCapacity(newCapacity);
+               }
                score.setScore(newScore);
-               score.setRank(newRank);
-               score.setCapacity(newCapacity);
+
                db.store(score);
-               
-               System.out.println(score);
-               
+       
                if(oldCapacity != newCapacity) {
                        ObjectSet<Trust> trustees = db.queryByExample(new 
Trust(identity, null, 0));
                        while(trustees.hasNext()) {
@@ -145,6 +140,32 @@
                }
        }

+       public void stressTest(int nbIdentities, int nbTrustPerIdentity) {
+               
+               ObjectSet<Identity> search;
+               
+               for(int i = 1 ; i != nbIdentities ; i++) {
+                       Identity id = new Identity(String.valueOf(i), new 
Date(), 0, true);
+                       db.store(id);
+               }
+               
+               for(int i = 0 ; i != nbIdentities ; i++) {
+                       for(int j = 0 ; j != nbTrustPerIdentity ; j++) {
+                               search = db.queryByExample(new 
Identity(String.valueOf(i), null, 0, true));
+                               Identity truster = search.next();
+                               
+                               double trusteeId = Math.random() * nbIdentities;
+                               double value =  Math.random() * 100;
+                               
+                               search = db.queryByExample(new 
Identity(String.valueOf((int) trusteeId), null, 0, true));
+                               Identity trustee = search.next();
+                               
+                               setTrust(new Trust(truster, trustee, (int) 
value)); 
+                       }
+                       System.out.println(i);
+               }
+       }
+       
        /**
         * This code will have to move in the plugin methods.
         */
@@ -156,72 +177,30 @@

                try {
                        db = Db4o.openFile("WoT.db4o");
-                       /*
-                       fcp = new FcpConnection("localhost",9481);
-                       fcp.connect();
-                       fcp.sendMessage(new ClientHello("WoT"));
-                       */
-                       //fcp = new FCPHandler(host,port);

-                       //identityInserter = new IdentityInserter(db, fcp);
-                       //identityInserter.start();
-                       
                        //Empty the database
                        ObjectSet<Object> result = db.queryByExample(new 
Object());
                        while (result.hasNext()) { db.delete(result.next()); }

-                       OwnIdentity root = new OwnIdentity("root", "root", new 
Date(), new Date(), 0, true);
+                       OwnIdentity root = new OwnIdentity("0", "0", new 
Date(), new Date(), 0, true);
                        Score initScore = new Score(root,root,100,0,100);
-                       Identity a = new Identity("a", new Date(), 0, true);
-                       Identity b = new Identity("b", new Date(), 0, true);
-                       Identity c = new Identity("c", new Date(), 0, true);
-
                        db.store(root);
                        db.store(initScore);
-                       db.store(a);
-                       db.store(b);
-                       db.store(c);

                        WoT wot = new WoT(db);
-                       wot.setTrust(new Trust(root, a, 80, "Friend of mine"));
-                       wot.setTrust(new Trust(b, c, 50, "Like him"));
-                       wot.setTrust(new Trust(a, b, 100, "He's my brother"));
-                       wot.setTrust(new Trust(root, b, 30, "Looks like a nice 
guy"));
-                       wot.setTrust(new Trust(root, b, -100, "That was a trap 
!"));
-
+                       
+                       wot.stressTest(100, 5);
+                       
                        System.out.println("\n***** Trust objects in the 
database :");
                        ObjectSet<Trust> trustList = 
db.queryByExample(Trust.class);
-                       while(trustList.hasNext()) {
-                               System.out.println(trustList.next());
-                       }
+                       System.out.println(trustList.size());

                        System.out.println("\n***** Score objects in the 
database :");
                        ObjectSet<Score> scoreList = 
db.queryByExample(Score.class);
                        while(scoreList.hasNext()) {
                                System.out.println(scoreList.next());
                        }
-                       /*
-                       

-                       Identity a = new Identity("a", new Date(), true);
-                       Identity b = new Identity("b", new Date(), true);
-                       
-                       db.store(a);
-                       db.store(b);
-                       
-                       root.addTrust(db, a, 80);
-                       root.addTrust(db, b, 30);
-                       a.addTrust(db, b, 100);
-                       */
-                       /*
-                       Identity test = new Identity("USK at 
DCOSLbqlCS-~Ly8ZBxvcI9MkrweRl0t7BLLKs2zGj38,J~GQAEk3m5eXI5KagpSXxHX2~3GPC61eJtQGIWn~5Ns,AQACAAE/",
 new Date(), 3, true);
-                       
-                       IdentityFetcher identityFetcher = new 
IdentityFetcher(db,fcp);
-                       identityFetcher.fetch(test);
-                                       
-                       //identityInserter.stop();
-                       fcp.disconnect();
-                       */
                        db.close();
                }
                catch (Exception e) {


Reply via email to