!(m_graph2Output.getEdge(src, sink) instanceof ReputationEdge))
{
throw new GenericTestbedException("Expected edge type is ReputationEdge.");
}
ReputationEdge repEdge = (ReputationEdge) m_graph2Output.getEdge(src, sink);
//repEdge may be null. all edges in the graph this alg listens to may have been added but that is not
//reflected in the reputation graph edge. So reputationGraph.getEdge(src, sink) may return null.
if(repEdge==null)
{
if(!m_graph2Output.containsVertex(src)) m_graph2Output.addVertex(src);
if(!m_graph2Output.containsVertex(sink)) m_graph2Output.addVertex(sink);
m_graph2Output.addEdge(src, sink);
repEdge = (ReputationEdge) m_graph2Output.getEdge(src, sink);
}
repEdge.setReputation(trustScore);
m_graph2Output.setEdgeWeight(repEdge, trustScore);
edgesTobeUpdated.add(repEdge);
}
}
}
}else if(outputGraphType == OutputGraphType.TRANSITIVE_GRAPH)
{
/**
* Calculate trust scores of sink agents that are reachable from the source.
* that is determine the transitive closure of the graph that this alg listens to
* and set the weights of the edges.
*/
Graph transitiveGraph = m_graph2Listen.getTransitiveClosureGraph();
for(Agent src : agents)
{
Set<TestbedEdge> outgoingEdges = transitiveGraph.outgoingEdgesOf(src);
for(TestbedEdge e : outgoingEdges)
{
double trustScore = calculateTrustScore(src, (Agent)e.sink);
if(!assertVariablePrecondition(trustScore))
{
throw new GenericTestbedException("Failed postconditions: assertVariablePrecondition()");
}
if(!((ReputationEdge) m_graph2Output.getEdge(src, (Agent)e.sink) instanceof ReputationEdge))
{
throw new GenericTestbedException("Expected edge type is ReputationEdge.");
}
ReputationEdge repEdge = (ReputationEdge) m_graph2Output.getEdge(src, (Agent)e.sink);
//repEdge may be null. see setFeedbackHistoryGraph(). a feedback history graph edge may have been added but that is not
//reflected in the reputation graph edge. So reputationGraph.getEdge(src, sink) may return null.
if(repEdge==null)
{
if(!m_graph2Output.containsVertex(src)) m_graph2Output.addVertex(src);
if(!m_graph2Output.containsVertex((Agent)e.sink)) m_graph2Output.addVertex((Agent)e.sink);
m_graph2Output.addEdge(src, (Agent)e.sink);
repEdge = (ReputationEdge) m_graph2Output.getEdge(src, (Agent)e.sink);
repEdge.setReputation(trustScore);
}
m_graph2Output.setEdgeWeight(repEdge, trustScore);
edgesTobeUpdated.add(repEdge);
}
}
}
else
{
for(Agent src : agents)
{
Set<TestbedEdge> outgoingEdges = super.m_graph2Listen.outgoingEdgesOf(src);
for(TestbedEdge e : outgoingEdges)
{
double trustScore = calculateTrustScore(src, (Agent)e.sink);
if(!assertVariablePrecondition(trustScore))
{
throw new GenericTestbedException("Failed postconditions: assertVariablePrecondition()");
}
if(!((ReputationEdge) m_graph2Output.getEdge(src, (Agent)e.sink) instanceof ReputationEdge))
{
throw new GenericTestbedException("Expected edge type is ReputationEdge.");
}
ReputationEdge repEdge = (ReputationEdge) m_graph2Output.getEdge(src, (Agent)e.sink);
if(repEdge==null)
{
if(!m_graph2Output.containsVertex(src)) m_graph2Output.addVertex(src);
if(!m_graph2Output.containsVertex((Agent)e.sink)) m_graph2Output.addVertex((Agent)e.sink);
m_graph2Output.addEdge(src, (Agent)e.sink);
repEdge = (ReputationEdge) m_graph2Output.getEdge(src, (Agent)e.sink);
repEdge.setReputation(trustScore);
}
m_graph2Output.setEdgeWeight(repEdge, trustScore);
edgesTobeUpdated.add(repEdge);
}
}