diff --git a/Diagrams/PathTaker.vsdx b/Diagrams/PathTaker.vsdx new file mode 100644 index 0000000..c7d4318 Binary files /dev/null and b/Diagrams/PathTaker.vsdx differ diff --git a/Graph/src/algorithms/Dijkstra/DijkstraAlgorithm.java b/Graph/src/algorithms/Dijkstra/DijkstraAlgorithm.java index 88e6074..2615f52 100644 --- a/Graph/src/algorithms/Dijkstra/DijkstraAlgorithm.java +++ b/Graph/src/algorithms/Dijkstra/DijkstraAlgorithm.java @@ -1,4 +1,9 @@ package algorithms.Dijkstra; +import elements.Graph; + public class DijkstraAlgorithm { + public static void FindShortestPath(Graph graph, String sourceNodeIdentification, String targetNodeIdentification) { + + } } diff --git a/Graph/src/algorithms/Dijkstra/DijkstraAlgorithmTest.java b/Graph/src/algorithms/Dijkstra/DijkstraAlgorithmTest.java index b66222b..4227371 100644 --- a/Graph/src/algorithms/Dijkstra/DijkstraAlgorithmTest.java +++ b/Graph/src/algorithms/Dijkstra/DijkstraAlgorithmTest.java @@ -1,7 +1,25 @@ package algorithms.Dijkstra; -import static org.junit.jupiter.api.Assertions.*; +import algorithms.GraphBuilder; +import elements.Graph; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; class DijkstraAlgorithmTest { + Graph graph; + + @BeforeEach + void SetUp() { + + } + + @Test + void Test1() { + graph = GraphBuilder.Build().WithNodes(0).getGraph(); + + Assertions.assertThrows(IllegalArgumentException.class, + () -> DijkstraAlgorithm.FindShortestPath(graph, "0", "0")); + } } \ No newline at end of file diff --git a/Graph/src/algorithms/GraphBuilder.java b/Graph/src/algorithms/GraphBuilder.java new file mode 100644 index 0000000..fb33ff1 --- /dev/null +++ b/Graph/src/algorithms/GraphBuilder.java @@ -0,0 +1,59 @@ +package algorithms; + +import elements.Graph; +import elements.GraphNode; + +public class GraphBuilder { + private Graph graph; + + private GraphBuilder() { + graph = new Graph(); + } + + public static GraphBuilder Build() { + return new GraphBuilder(); + } + + public GraphBuilder WithNodes(int nodeCount) { + for (int index = 0; index < nodeCount; index++) + graph.addNode(String.format("%d", nodeCount)); + + return this; + } + + public GraphBuilder AllConnected(int... weights) { + int weightIndex = 0; + for (GraphNode graphNode1 : graph.getNodes()) { + for (GraphNode graphNode2 : graph.getNodes()) { + if (graphNode1 != graphNode2) { + graph.addDirectionalEdge(weights[weightIndex], graphNode1, graphNode2); + weightIndex++; + } + } + } + + return this; + } + + public GraphBuilder SomeConnected(String[] sourceIdentifiers, String[] targetIdentifiers, int... weights) { + int identifierIndex = 0; + int weightIndex = 0; + for (GraphNode graphNode1 : graph.getNodes()) { + for (GraphNode graphNode2 : graph.getNodes()) { + if (graphNode1 != graphNode2) { + if (graphNode1.getIdentifier().equals(sourceIdentifiers[identifierIndex]) && graphNode2.getIdentifier().equals(targetIdentifiers[identifierIndex])) { + graph.addDirectionalEdge(weights[weightIndex], graphNode1, graphNode2); + weightIndex++; + identifierIndex++; + } + } + } + } + + return this; + } + + public Graph getGraph() { + return graph; + } +} diff --git a/Graph/src/elements/Graph.java b/Graph/src/elements/Graph.java index 4d6d577..866450b 100644 --- a/Graph/src/elements/Graph.java +++ b/Graph/src/elements/Graph.java @@ -61,7 +61,7 @@ public GraphNode addNode(String id) { * Instantiate new graph node and add it * to the main nodes array list */ - GraphNode newNode = new GraphNode(id, id); + GraphNode newNode = new GraphNode(id); nodes.add(newNode); /* @@ -185,7 +185,7 @@ public void removeDirectionalEdge(GraphEdge edge) { */ detachNodes(edge.getSourceNode(), edge.getTargetNode()); - + } /** diff --git a/Graph/src/graph/App.java b/Graph/src/graph/App.java index dc83f99..dcc317b 100644 --- a/Graph/src/graph/App.java +++ b/Graph/src/graph/App.java @@ -1,8 +1,10 @@ package graph; -import com.jfoenix.controls.JFXButton; import de.jensd.fx.glyphs.fontawesome.FontAwesomeIconView; -import elements.*; +import elements.GraphNode; +import elements.NodeGestures; +import elements.PannableCanvas; +import elements.SceneGestures; import javafx.geometry.Bounds; import javafx.scene.Cursor; import javafx.scene.Scene; @@ -61,7 +63,7 @@ public void set(Scene scene) { */ interactMode(); - GraphNode graphNode = new GraphNode("1", "1"); + GraphNode graphNode = new GraphNode("1"); graphNode.setTranslateX(50); graphNode.setTranslateY(50); graphNode.setPrefHeight(70); @@ -70,7 +72,7 @@ public void set(Scene scene) { graphNode.addEventFilter(MouseEvent.MOUSE_PRESSED, nodeGestures.getOnMousePressedEventHandler()); graphNode.addEventFilter(MouseEvent.MOUSE_DRAGGED, nodeGestures.getOnMouseDraggedEventHandler()); - GraphNode graphNode2 = new GraphNode("2", "2"); + GraphNode graphNode2 = new GraphNode("2"); graphNode2.setTranslateX(200); graphNode2.setTranslateY(200); graphNode2.setPrefHeight(70);