TrustGrapher
r52
A playabale simulator for modelling trust between agents
|
00001 00002 package cu.trustGrapher.graphs; 00003 00004 import cu.trustGrapher.eventplayer.TrustLogEvent; 00005 import cu.repsystestbed.algorithms.TrustAlgorithm; 00006 import cu.repsystestbed.entities.Agent; 00007 import cu.repsystestbed.graphs.TestbedEdge; 00008 import cu.repsystestbed.graphs.TrustEdgeFactory; 00009 import cu.repsystestbed.graphs.TrustGraph; 00010 import java.util.Collection; 00011 00012 import org.jgrapht.graph.SimpleDirectedGraph; 00013 00014 import aohara.utilities.ChatterBox; 00015 import cu.trustGrapher.loading.GraphConfig; 00016 00021 public class SimTrustGraph extends SimAbstractGraph { 00022 00024 00028 public SimTrustGraph(GraphConfig graphConfig) { 00029 super(graphConfig, (SimpleDirectedGraph) new TrustGraph(new TrustEdgeFactory())); 00030 } 00031 00033 00040 @Override 00041 public void graphEvent(TrustLogEvent event, boolean forward) { 00042 TrustAlgorithm alg = (TrustAlgorithm) getAlgorithm(); 00043 Collection<Agent> vertices = forward ? alg.getReputationGraph().vertexSet() : getVertices(); 00044 for (Agent src : vertices) { 00045 for (Agent sink : vertices) { 00046 try { 00047 if (!src.equals(sink)) { 00048 if (alg.trusts(src, sink)) { //Ensure an edge exists between the two agents that trust eachother 00049 ensureAgentExists(src.id, this); 00050 ensureAgentExists(sink.id, this); 00051 ensureEdgeExists(src, sink, this); 00052 } else { 00053 throw new IllegalArgumentException(); //Remove the edge 00054 } 00055 } 00056 } catch (IllegalArgumentException ex) { //If they don't trust eachother or exist in the rep graph, enusre that no edge exists between them 00057 TestbedEdge edgeToRemove = findEdge(src, sink); 00058 if (edgeToRemove != null) { 00059 removeEdge(edgeToRemove); 00060 } 00061 } catch (Exception ex) { 00062 ChatterBox.error(this, "graphEvent()", ex.getMessage()); 00063 } 00064 } 00065 } 00066 for (Object agent : getVertices().toArray()){ 00067 if (getIncidentEdges((Agent) agent).isEmpty()){ 00068 removeVertex((Agent) agent); 00069 } 00070 } 00071 } 00072 } 00074