BufferedWriter graphWriter =
new BufferedWriter(new FileWriter(graphOutputFile));
BufferedWriter seedWriter =
new BufferedWriter(new FileWriter(graphOutputFile + ".seed_vertices"));
RyanAlphabet alpha = new RyanAlphabet();
// we would like to avoid 0 as the index
alpha.lookupIndex("", true);
Iterator<String> vIter = _vertices.keySet().iterator();
while (vIter.hasNext()) {
String vName = vIter.next();
int vIdx = alpha.lookupIndex(vName, true);
// seed node writer
if (_vertices.get(vName).IsSeedNode()) {
seedWriter.write(vIdx + "\t" + vIdx + "\t" + 1.0 + "\n");
}
Vertex2 v = _vertices.get(vName);
Object[] neighNames = v.GetNeighborNames();
int totalNeighbors = neighNames.length;
for (int ni = 0; ni < totalNeighbors; ++ni) {
int nIdx = alpha.lookupIndex(neighNames[ni], true);
// edge writer
graphWriter.write(vIdx + "\t" +
nIdx + "\t" +
v.GetNeighborWeight((String) neighNames[ni]) +
"\n");
}
}
graphWriter.close();
seedWriter.close();
// write out the alphabet file
alpha.dump(graphOutputFile + ".alpha");
} catch (IOException ioe) {
ioe.printStackTrace();
}
}