Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
OmidRezaei committed May 10, 2019
1 parent 35a63d8 commit 29e2cff
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 7 deletions.
Binary file added Diagrams/PathTaker.vsdx
Binary file not shown.
5 changes: 5 additions & 0 deletions Graph/src/algorithms/Dijkstra/DijkstraAlgorithm.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
package algorithms.Dijkstra;

import elements.Graph;

public class DijkstraAlgorithm {
public static void FindShortestPath(Graph graph, String sourceNodeIdentification, String targetNodeIdentification) {

}
}
20 changes: 19 additions & 1 deletion Graph/src/algorithms/Dijkstra/DijkstraAlgorithmTest.java
Original file line number Diff line number Diff line change
@@ -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"));
}
}
59 changes: 59 additions & 0 deletions Graph/src/algorithms/GraphBuilder.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
4 changes: 2 additions & 2 deletions Graph/src/elements/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/*
Expand Down Expand Up @@ -185,7 +185,7 @@ public void removeDirectionalEdge(GraphEdge edge) {
*/
detachNodes(edge.getSourceNode(), edge.getTargetNode());


}

/**
Expand Down
10 changes: 6 additions & 4 deletions Graph/src/graph/App.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 29e2cff

Please sign in to comment.