diff --git a/src/ch/zhaw/ads/RouteServer.java b/src/ch/zhaw/ads/RouteServer.java index 73ae492..6b345ab 100644 --- a/src/ch/zhaw/ads/RouteServer.java +++ b/src/ch/zhaw/ads/RouteServer.java @@ -1,15 +1,24 @@ package ch.zhaw.ads; -import java.util.LinkedList; -import java.util.List; -import java.util.Queue; -import java.util.StringTokenizer; +import java.util.*; public class RouteServer implements CommandExecutor { /** build the graph given a text file with the topology */ - public Graph createGraph(String topo) throws Exception { + public Graph createGraph(String topo) throws Exception { + Graph graph = new AdjListGraph<>(DijkstraNode.class, Edge.class); + String[] lines = topo.split("\n"); + for(String line : lines){ + String[] strings = line.split(" "); + try { + graph.addEdge(strings[0], strings[1], Double.parseDouble(strings[2])); + graph.addEdge(strings[1], strings[0], Double.parseDouble(strings[2])); + } catch (Throwable e) { + e.printStackTrace(); + } + } + return graph; // TODO implement } @@ -17,7 +26,7 @@ public class RouteServer implements CommandExecutor { /** apply the dijkstra algorithm */ - public void dijkstraRoute(Graph graph, String from, String to) { + public void dijkstraRoute(Graph graph, String from, String to) { // TODO implement }