How to create undirected graph using low level api?

I tried to construct a graph using the method in

            BooleanEncodedValue accessEnc = VehicleAccess.create("car");
            DecimalEncodedValue speedEnc = VehicleSpeed.create("car", 7, 2, false);
            EncodingManager em = EncodingManager.start().add(accessEnc).add(speedEnc).build();
            BaseGraph graph = new BaseGraph.Builder(em).setDir(new RAMDirectory(graphLocation, true)).create();
            // Make a weighted edge between two nodes and set average speed to 50km/h
            EdgeIteratorState edge = graph.edge(0, 1).setDistance(1234).set(speedEnc, 50);

            // Set node coordinates and build location index
            NodeAccess na = graph.getNodeAccess();
            graph.edge(0, 1).set(accessEnc, true).set(speedEnc, 10).setDistance(1530);
            na.setNode(0, 15.15, 20.20);
            na.setNode(1, 15.25, 20.21);

But I found that the edges Iā€™v created have direction and the graph is a directed graph. How could I set the graph undirected or set the edges bidirectional?

Either always call setReverse(enc, value) or use:

set(accessEnc, true, true)
set(speedEnc, 10, 10)
1 Like

Thank you so much! I used to add 2 edge instead, and it may cause some hilarious problem.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.