public static void main(String args[]) throws Exception { HashMap<Integer, Integer> fileToGraphVIDMap = new HashMap<Integer, Integer>(); MyGraph<Coordinate, Street> g = GraphFactory.loadGraph("./graphs/distanceedjohnDijkstra.txt", true, fileToGraphVIDMap); g.removeEdge(7); g.removeEdge(8); g.removeEdge(14); printList(doTopologicalSort(g)); MyDijkstra<Coordinate, Street> dijkstra = new MyDijkstra<Coordinate, Street>(); dijkstra.setGraph(g); dijkstra.setStart(5); dijkstra.setWeighing(new MyWeighing(g)); dijkstra.computeShortestPath(); GuiGraphDriver gui = new GuiGraphDriver(g); List<Integer> path = dijkstra.getPath(8); gui.addPath(path, Color.yellow); printList(path); g.removeEdge(dijkstra.getConnectingEID(2)); dijkstra.computeShortestPath(); path = dijkstra.getPath(8); gui.addPath(path, Color.cyan); printList(path); /* g.removeEdge(dijkstra.getConnectingEID(7)); dijkstra.computeShortestPath(); printList(dijkstra.getPath(7)); */ }
public static void main(String[] args) { test(GraphFactory.getBellmanSampleGraph(), "bellman"); test(GraphFactory.getDijkstraSampleGraph(), "dijkstra"); }
public static void main(String[] args) { Map<Character, ImmutableGraphNode<Character>> graph = GraphFactory.createSimpleGraph(); printPath( AStarPathFinder.findPath(graph.get('A'), graph.get('D'), new MyNodeExpander<Character>())); }
public void process() { // Workspace ProjectController pc = Lookup.getDefault().lookup(ProjectController.class); if (workspace == null) { workspace = pc.newWorkspace(pc.getCurrentProject()); pc.openWorkspace(workspace); } if (container.getSource() != null) { pc.setSource(workspace, container.getSource()); } // Architecture GraphModel graphModel = Lookup.getDefault().lookup(GraphController.class).getModel(workspace); HierarchicalGraph graph = null; switch (container.getEdgeDefault()) { case DIRECTED: graph = graphModel.getHierarchicalDirectedGraph(); break; case UNDIRECTED: graph = graphModel.getHierarchicalUndirectedGraph(); break; case MIXED: graph = graphModel.getHierarchicalMixedGraph(); break; default: graph = graphModel.getHierarchicalMixedGraph(); break; } GraphFactory factory = graphModel.factory(); // Attributes - Creates columns for properties attributeModel = Lookup.getDefault().lookup(AttributeController.class).getModel(workspace); attributeModel.mergeModel(container.getAttributeModel()); // Dynamic if (container.getTimeFormat() != null) { DynamicController dynamicController = Lookup.getDefault().lookup(DynamicController.class); if (dynamicController != null) { dynamicController.setTimeFormat(container.getTimeFormat()); } } int nodeCount = 0; // Create all nodes for (NodeDraftGetter draftNode : container.getNodes()) { Node n = factory.newNode(draftNode.isAutoId() ? null : draftNode.getId()); flushToNode(draftNode, n); draftNode.setNode(n); nodeCount++; } // Push nodes in data structure for (NodeDraftGetter draftNode : container.getNodes()) { Node n = draftNode.getNode(); NodeDraftGetter[] parents = draftNode.getParents(); if (parents != null) { for (int i = 0; i < parents.length; i++) { Node parent = parents[i].getNode(); graph.addNode(n, parent); } } else { graph.addNode(n); } } // Create all edges and push to data structure int edgeCount = 0; for (EdgeDraftGetter edge : container.getEdges()) { Node source = edge.getSource().getNode(); Node target = edge.getTarget().getNode(); Edge e = null; switch (container.getEdgeDefault()) { case DIRECTED: e = factory.newEdge( edge.isAutoId() ? null : edge.getId(), source, target, edge.getWeight(), true); break; case UNDIRECTED: e = factory.newEdge( edge.isAutoId() ? null : edge.getId(), source, target, edge.getWeight(), false); break; case MIXED: e = factory.newEdge( edge.isAutoId() ? null : edge.getId(), source, target, edge.getWeight(), edge.getType().equals(EdgeType.UNDIRECTED) ? false : true); break; } flushToEdge(edge, e); edgeCount++; graph.addEdge(e); } workspace = null; }