private List <NetworkLane> BacktrackRoute(NetworkLaneConnection end, Dictionary <string, NetworkLaneConnection> previous) { var route = new List <NetworkLane> (); route.Add(end.lane); string id = end.id; NetworkLaneConnection previousLane; while (previous.ContainsKey(id)) { previousLane = previous [id]; List <NetworkLane> viaLanes; if (previousLane.via.TryGetValue(id, out viaLanes)) { viaLanes.Reverse(); foreach (NetworkLane viaLane in viaLanes) { route.Add(viaLane); } } route.Add(previousLane.lane); id = previousLane.id; } route.Reverse(); return(route); }
private void BuildConnectivityGraph(JSONNode root) { foreach (JSONNode connectionJSON in root["connections"].AsArray.Children) { string fromLaneID = connectionJSON ["fromLane"]; string toLaneID = connectionJSON ["toLane"]; List <NetworkLane> viaLanes = new List <NetworkLane> (); foreach (string laneID in connectionJSON["via"].AsArray.Children) { NetworkLane viaLane = GetLaneByID(laneID); if (viaLane == null) { Debug.Log("viaLane does not exist!"); continue; } viaLanes.Add(viaLane); } NetworkLaneConnection connection; if (connectivityGraph.TryGetValue(fromLaneID, out connection)) { connection.AppendLane(toLaneID, viaLanes); } else { NetworkLane fromLane = GetLaneByID(fromLaneID); if (fromLane == null) { Debug.Log("Lane " + fromLaneID + " does not exist!"); continue; } connection = new NetworkLaneConnection(fromLane); connection.AppendLane(toLaneID, viaLanes); connectivityGraph.Add(fromLaneID, connection); } if (!connectivityGraph.ContainsKey(toLaneID)) { NetworkLane toLane = GetLaneByID(toLaneID); if (toLane == null) { Debug.Log("Lane " + toLaneID + " does not exist!"); continue; } connectivityGraph.Add(toLaneID, new NetworkLaneConnection(toLane)); } } }