Exports a graph with weights as GraphML
Code: "graph6_export.py". Programming language: Python DMelt Version 1.8. Last modified: 06/15/1971. License: Free
https://datamelt.org/code/cache/graph6_export_1192.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.


# 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"