TrustGrapher
r52
A playabale simulator for modelling trust between agents
|
00001 00002 package cu.trustGrapher.loading; 00003 00004 import cu.trustGrapher.graphs.*; 00005 import cu.repsystestbed.algorithms.ReputationAlgorithm; 00006 import cu.repsystestbed.algorithms.TrustAlgorithm; 00007 import cu.repsystestbed.graphs.FeedbackHistoryGraph; 00008 import cu.repsystestbed.graphs.ReputationGraph; 00009 00010 import java.util.List; 00011 import java.util.ArrayList; 00012 import org.jgrapht.graph.SimpleDirectedGraph; 00013 00014 import aohara.utilities.ChatterBox; 00015 00020 public class GraphLoader { 00021 00027 public static List<SimAbstractGraph> loadGraphs(List<GraphConfig> graphConfigs) { 00028 List<SimAbstractGraph> graphs = new ArrayList<SimAbstractGraph>(); 00029 ArrayList<GraphConfig> trustGraphs = new ArrayList<GraphConfig>(); 00030 for (GraphConfig graphConfig : graphConfigs) { 00031 if (graphConfig.isTrustGraph()) { //Trust Algorithms cannot be made yet since the graph that they depend on may not be created yet 00032 trustGraphs.add(graphConfig); 00033 } else if (graphConfig.isFeedbackGraph()) { // add the Feedback Graph 00034 graphs.add(new SimFeedbackGraph(graphConfig)); 00035 } else if (graphConfig.isReputationGraph()) { //Add a Reputation Graph 00036 graphs.add(new SimReputationGraph(graphConfig, (SimFeedbackGraph) graphs.get(0))); 00037 ReputationAlgorithm alg = (ReputationAlgorithm) graphConfig.getAlgorithm(); //get the algorithm and add it to the inner jGraphT graph 00038 alg.setFeedbackHistoryGraph((FeedbackHistoryGraph) getInnerGraph(graphConfig.getBaseIndex(), graphs)); 00039 } else { 00040 ChatterBox.criticalError("SimGraphPair", "<init>", "Unsupported graph type"); 00041 } 00042 } 00043 for (GraphConfig graphConfig : trustGraphs) { //Now add the Tryst Graphs 00044 graphs.add(new SimTrustGraph(graphConfig)); 00045 TrustAlgorithm alg = (TrustAlgorithm) graphConfig.getAlgorithm(); //get the algorithm and add it to the inner jGraphT graph 00046 alg.setReputationGraph((ReputationGraph) getInnerGraph(graphConfig.getBaseIndex(), graphs)); 00047 } 00048 return graphs; 00049 } 00050 00057 private static SimpleDirectedGraph getInnerGraph(int graphID, List<SimAbstractGraph> graphs) { 00058 for (SimAbstractGraph graph : graphs) { 00059 if (graph.getID() == graphID) { 00060 return graph.getInnerGraph(); 00061 } 00062 } 00063 ChatterBox.error("GraphLoader", "getBase()", "Could not find a graph with id " + graphID); 00064 return null; 00065 } 00066 } 00068