From: Szabolcs B. <bes...@gm...> - 2016-06-16 17:37:37
|
Hi, It is because you need to give a VertexNameProvider and an EdgeNameProvider to the constructor of the exporter. It seems you also need to define one pair of VertexNameProvider and EdgeNameProvider for each vertex/edge respectively. Here is a snippet on how to achieve such behaviour from the exporter: class GraphNode { > String name; > String label; > String type; > > public GraphNode(String name, String label, String type) { > this.name = name; > this.label = label; > this.type = type; > } > > @Override > public String toString() { > return "GraphNode{" + "name=" + name + ", label=" + label + ", > type=" + type + '}'; > } > } > > public class Main { > > public static void main(String[] args) throws IOException, > SAXException, TransformerConfigurationException { > DefaultDirectedGraph<GraphNode, DefaultEdge> g = > new DefaultDirectedGraph<>(DefaultEdge.class); > GraphNode node1 = new GraphNode("node1","label1","type1"); > GraphNode node2 = new GraphNode("node2","label2","type1"); > > g.addVertex(node1); > g.addVertex(node2); > g.addEdge(node1, node2); > > VertexNameProvider<GraphNode> vLabelNameProvider = new > StringNameProvider<>(); > VertexNameProvider<GraphNode> vIdNameProvider = new > IntegerNameProvider<>(); > > EdgeNameProvider<DefaultEdge> eLabelNameProvider = new > StringEdgeNameProvider<>(); > EdgeNameProvider<DefaultEdge> eIdNameProvider = new > IntegerEdgeNameProvider<>(); > > GraphMLExporter<GraphNode, DefaultEdge> exporter > = new GraphMLExporter<>(vIdNameProvider, > vLabelNameProvider, eIdNameProvider, eLabelNameProvider); > > FileWriter w = new FileWriter("output.txt"); > exporter.export(w, g); > } > > } > And the result: <?xml version="1.0" encoding="UTF-8"?><graphml xmlns=" > http://graphml.graphdrawing.org/xmlns" xsi:schemaLocation=" > http://graphml.graphdrawing.org/xmlns > http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd" xmlns:xsi=" > http://www.w3.org/2001/XMLSchema-instance"> > <key id="vertex_label" for="node" attr.name="Vertex Label" > attr.type="string"/> > <key id="edge_label" for="edge" attr.name="Edge Label" > attr.type="string"/> > <graph edgedefault="directed"> > <node id="1"> > <data key="vertex_label">GraphNode{name=node1, label=label1, > type=type1}</data> > </node> > <node id="2"> > <data key="vertex_label">GraphNode{name=node2, label=label2, > type=type1}</data> > </node> > <edge id="1" source="1" target="2"> > <data key="edge_label"/> > </edge> > </graph> > </graphml> > Üdvözlettel, Besenyei Szabolcs 2016-06-16 16:55 GMT+02:00 Mansour Ahmadi <man...@gm...>: > Hi, > > I am trying to save a graph with custom nodes, but the export function > doesn't save the attributes of the graph nodes (it just saves an id for > each node). > > public class GraphNode { > String name; > String label; > String type; > } > > GraphMLExporter<GraphNode, DefaultEdge> exporter = > new GraphMLExporter<GraphNode, DefaultEdge>(); > w = new FileWriter(file); > exporter.export(w, this.g); > > Would you please help me how can I save all of the attributes of nodes? > > Thanks > > > ------------------------------------------------------------------------------ > What NetFlow Analyzer can do for you? Monitors network bandwidth and > traffic > patterns at an interface-level. Reveals which users, apps, and protocols > are > consuming the most bandwidth. Provides multi-vendor support for NetFlow, > J-Flow, sFlow and other flows. Make informed decisions using capacity > planning > reports. > http://pubads.g.doubleclick.net/gampad/clk?id=1444514421&iu=/41014381 > _______________________________________________ > jgrapht-users mailing list > jgr...@li... > https://lists.sourceforge.net/lists/listinfo/jgrapht-users > > |