# Exports a graph with weights as GraphML.
# For a description of the format see http://en.wikipedia.org/wiki/ GraphML.
# see: http://jgrapht.org/javadoc/org/jgrapht/ext/package-summary
from jhplot import *
g=HGraph().buildWeightedPseudograph()
# add vertices
v1,v2,v3 = "v1","v2","v3"
g.addVertex(v1), g.addVertex(v2), g.addVertex(v3)
factory = g.getEdgeFactory()
e = factory.createEdge(v1,v2)
g.setEdgeWeight(e, 5)
g.addEdge(v1, v2, e)
e = factory.createEdge(v2,v3)
g.setEdgeWeight(e, 8.8)
g.addEdge(v2, v3, e)
e = factory.createEdge(v2,v1)
g.setEdgeWeight(e, 0.1)
g.addEdge(v2, v1, e)
HGraph().showGraph(g) # show the graph in GUI
from org.jgrapht.ext import GraphMLExporter
from java.io import *
file="example.ml"
writer=FileWriter(file)
f=GraphMLExporter()
f.setExportEdgeWeights(True)
f.exportGraph(g, writer)
writer.close()
print "File ",file," is created"