removed duplicate
This commit is contained in:
parent
3498fe5ae3
commit
adda057b88
@ -3,7 +3,7 @@ using Logging;
|
||||
using astar;
|
||||
|
||||
Logger logger = new (LogType.CONSOLE, LogLevel.DEBUG);
|
||||
Graph.Graph graph = OpenStreetMap_Importer.Importer.Import(@"", true, logger);
|
||||
Graph.Graph graph = OpenStreetMap_Importer.Importer.Import(@"C:\Users\glax\Downloads\oberbayern-latest.osm", true, logger);
|
||||
logger.level = LogLevel.DEBUG;
|
||||
|
||||
Random r = new();
|
||||
@ -13,8 +13,8 @@ do
|
||||
{
|
||||
do
|
||||
{
|
||||
n1 = graph.GetNodeAtIndex(r.Next(0, graph.GetNodeCount() - 1));
|
||||
n2 = graph.GetNodeAtIndex(r.Next(0, graph.GetNodeCount() - 1));
|
||||
n1 = graph.NodeAtIndex(r.Next(0, graph.GetNodeCount() - 1));
|
||||
n2 = graph.NodeAtIndex(r.Next(0, graph.GetNodeCount() - 1));
|
||||
_route = new Astar().FindPath(graph, n1, n2, logger);
|
||||
} while (!_route.routeFound);
|
||||
} while (Console.ReadKey().Key.Equals(ConsoleKey.Enter));
|
@ -3,29 +3,21 @@ namespace Graph
|
||||
{
|
||||
public class Graph
|
||||
{
|
||||
private List<Node> nodes { get; }
|
||||
private Dictionary<ulong, Node> nodes { get; }
|
||||
|
||||
public Graph()
|
||||
{
|
||||
this.nodes = new();
|
||||
}
|
||||
|
||||
public bool AddNode(Node n)
|
||||
public bool AddNode(ulong id, Node n)
|
||||
{
|
||||
if (!this.ContainsNode(n.id))
|
||||
{
|
||||
this.nodes.Add(n);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this.nodes.TryAdd(id, n);
|
||||
}
|
||||
|
||||
public Node GetNodeAtIndex(int i)
|
||||
public Node NodeAtIndex(int i)
|
||||
{
|
||||
return this.nodes[i];
|
||||
return this.nodes.Values.ToArray()[i];
|
||||
}
|
||||
|
||||
public int GetNodeCount()
|
||||
@ -35,44 +27,30 @@ namespace Graph
|
||||
|
||||
public Node? GetNode(ulong id)
|
||||
{
|
||||
foreach(Node n in this.nodes)
|
||||
{
|
||||
if (n.id == id)
|
||||
if (this.nodes.TryGetValue(id, out Node? n))
|
||||
return n;
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool ContainsNode(ulong id)
|
||||
{
|
||||
return this.GetNode(id) != null;
|
||||
return this.nodes.ContainsKey(id);
|
||||
}
|
||||
|
||||
public bool ContainsNode(Node n)
|
||||
{
|
||||
return this.nodes.Values.Contains(n);
|
||||
}
|
||||
|
||||
public bool RemoveNode(ulong id)
|
||||
{
|
||||
Node? n = this.GetNode(id);
|
||||
if(n != null)
|
||||
{
|
||||
this.nodes.Remove(n);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this.nodes.Remove(id);
|
||||
}
|
||||
|
||||
public bool RemoveNode(Node n)
|
||||
{
|
||||
if (this.RemoveNode(n.id))
|
||||
{
|
||||
this.nodes.Remove(n);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Node ClosestNodeToCoordinates(float lat, float lon)
|
||||
|
@ -5,12 +5,10 @@
|
||||
public float lat { get; }
|
||||
public float lon { get; }
|
||||
|
||||
public ulong id { get; }
|
||||
public HashSet<Edge> edges { get; }
|
||||
|
||||
public Node(ulong id, float lat, float lon)
|
||||
public Node(float lat, float lon)
|
||||
{
|
||||
this.id = id;
|
||||
this.lat = lat;
|
||||
this.lon = lon;
|
||||
this.edges = new();
|
||||
|
@ -118,7 +118,7 @@ namespace OpenStreetMap_Importer
|
||||
{
|
||||
float lat = Convert.ToSingle(_reader.GetAttribute("lat").Replace('.', ','));
|
||||
float lon = Convert.ToSingle(_reader.GetAttribute("lon").Replace('.', ','));
|
||||
_graph.AddNode(new Node(id, lat, lon));
|
||||
_graph.AddNode(id, new Node(lat, lon));
|
||||
logger?.Log(LogLevel.VERBOSE, "NODE {0} {1} {2} {3}", id, lat, lon, occuranceCount[id]);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user