private static Graph buildGraph ( ) { Graph g = new TinkerGraph ( ) ; //add vertices Vertex v1 = g . addVertex ( "v1" ) ; Vertex v2 = g . addVertex ( "v2" ) ; Vertex v3 = g . addVertex ( "v3" ) ; Vertex v4 = g . addVertex ( "v4" ) ; Vertex v5 = g . addVertex ( "v5" ) ; Vertex v6 = g . addVertex ( "v6" ) ; //add edges labeled with costs Edge e1 = g . addEdge ( "e1" , v1 , v2 , "(7, 1)" ) ; e1 . setProperty ( "c1" , 7 ) ; e1 . setProperty ( "c2" , 1 ) ; Edge e2 = g . addEdge ( "e2" , v1 , v3 , "(1, 4)" ) ; e2 . setProperty ( "c1" , 1 ) ; e2 . setProperty ( "c2" , 4 ) ; Edge e3 = g . addEdge ( "e3" , v1 , v4 , "(2, 1)" ) ; e3 . setProperty ( "c1" , 2 ) ; e3 . setProperty ( "c2" , 1 ) ; Edge e4 = g . addEdge ( "e4" , v2 , v4 , "(1, 1)" ) ; e4 . setProperty ( "c1" , 1 ) ; e4 . setProperty ( "c2" , 1 ) ; Edge e5 = g . addEdge ( "e5" , v2 , v6 , "(2, 1)" ) ; e5 . setProperty ( "c1" , 2 ) ; e5 . setProperty ( "c2" , 1 ) ; Edge e6 = g . addEdge ( "e6" , v3 , v4 , "(1, 1)" ) ; e6 . setProperty ( "c1" , 1 ) ; e6 . setProperty ( "c2" , 1 ) ; Edge e7 = g . addEdge ( "e7" , v4 , v5 , "(3, 2)" ) ; e7 . setProperty ( "c1" , 3 ) ; e7 . setProperty ( "c2" , 2 ) ; Edge e8 = g . addEdge ( "e8" , v4 , v6 , "(4, 8)" ) ; e8 . setProperty ( "c1" , 4 ) ; e8 . setProperty ( "c2" , 8 ) ; Edge e9 = g . addEdge ( "e9" , v5 , v6 , "(1, 1)" ) ; e9 . setProperty ( "c1" , 1 ) ; e9 . setProperty ( "c2" , 1 ) ; return g ; }
Build an example graph to execute in this example .