Package cu.repsystestbed.tests

Source Code of cu.repsystestbed.tests.SimpleTest

package cu.repsystestbed.tests;

import java.util.List;

import org.apache.log4j.BasicConfigurator;

import cu.repsystestbed.algorithms.ReputationAlgorithm;
import cu.repsystestbed.algorithms.TrustAlgorithm;
import cu.repsystestbed.algorithms.examples.EigenTrust;
import cu.repsystestbed.algorithms.examples.RankbasedTrustAlg;
import cu.repsystestbed.data.Feedback;
import cu.repsystestbed.graphs.FeedbackHistoryEdgeFactory;
import cu.repsystestbed.graphs.FeedbackHistoryGraph;
import cu.repsystestbed.graphs.ReputationGraph;
import cu.repsystestbed.graphs.TrustGraph;
import cu.repsystestbed.util.DefaultArffFeedbackGenerator;


public class SimpleTest
{

  public static void main(String[] args) throws Exception
  {
    BasicConfigurator.configure();
   
    EigenTrust repAlg = (EigenTrust) ReputationAlgorithm.getInstance("cu.repsystestbed.algorithms.EigenTrust");
    //initialize the eigentrust parameters
//    repAlg.setIterations(10);
//    repAlg.setThreshold2Satisfy(0.7);
   
    //create a feedback history graph
    FeedbackHistoryGraph feedbackHistoryGraph = new FeedbackHistoryGraph(new FeedbackHistoryEdgeFactory());
   
    //parse the feedbacks from the arff file
    DefaultArffFeedbackGenerator feedbackGen = new DefaultArffFeedbackGenerator();
    List<Feedback> feedbacks = feedbackGen.generateHardcoded("feedbacks.arff");
   
    //add the feedbacks to the feedback history graph
    for(Feedback f : feedbacks)
    {
      feedbackHistoryGraph.addFeedback(f);
    }
   
    //eigentrust needs to use the feedback history graph
    repAlg.setGraph2Listen(feedbackHistoryGraph);
   
    //add eigentrust as an observer to the feedback history graph
    feedbackHistoryGraph.addObserver(repAlg);
   
    //make eigentrust calculate the reputation of all the agents
    feedbackHistoryGraph.notifyObservers(false);
   
    ReputationGraph repGraph = (ReputationGraph) repAlg.getGraph2Output();
    //TODO display the reputation graph.
   
    RankbasedTrustAlg trustAlg = (RankbasedTrustAlg) TrustAlgorithm.getInstance("cu.repsystestbed.algorithms.RankbasedTrustAlg");
    trustAlg.setRatio(0.7);
    trustAlg.setGraph2Listen(repGraph);
   
    repGraph.addObserver(trustAlg);
   
    repGraph.notifyObservers(null);
   
    TrustGraph trustGraph = (TrustGraph) trustAlg.getGraph2Output();
    //TODO display the trust graph.
   

   
   
   
  }
}
TOP

Related Classes of cu.repsystestbed.tests.SimpleTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.