{
static private Logger logger = Logger.getLogger(ReputationGraphCreator.class);
public static ReputationGraph createGraph(String arffFileName) throws Exception
{
ReputationGraph repGraph = new ReputationGraph(new ReputationEdgeFactory());
Util.assertNotNull(arffFileName);
Util.assertFileExists(arffFileName);
DataSource source;
try
{
source = new DataSource(arffFileName);
Instances instances = source.getDataSet();
logger.debug("Number of instances in arff file is " + instances.numInstances());
Enumeration enu = instances.enumerateInstances();
//get all the feedback lines
while(enu.hasMoreElements())
{
Instance temp = (Instance)enu.nextElement();
logger.info("Parsing " + temp);
String[] feedbackInstance = new String[3];
//go through each feedback line
if(temp.numValues()!=3) throw new GenericTestbedException("Reputation line does not have 3 elements. This is illegal.");
for(int i=0;i<temp.numValues();i++)
{
//number of values == 3
feedbackInstance[i] = temp.stringValue(i);
}
Agent src = new Agent(new Integer(feedbackInstance[0]));
Agent sink = new Agent(new Integer(feedbackInstance[1]));
Double reputation = new Double(feedbackInstance[2]);
if(!repGraph.containsVertex(src))
{
repGraph.addVertex(src);
}
if(!repGraph.containsVertex(sink))
{
repGraph.addVertex(sink);
}
repGraph.addEdge(src, sink);
ReputationEdge repEdge = (ReputationEdge) repGraph.getEdge(src, sink);
repEdge.setReputation(reputation);
System.out.println(repGraph);
}
return repGraph;