Changed protection of Graph.nodes to private

This commit is contained in:
C9Glax 2022-11-13 14:19:07 +01:00
parent 6d338018b5
commit 3498fe5ae3
3 changed files with 14 additions and 4 deletions

View File

@ -13,8 +13,8 @@ do
{
do
{
n1 = graph.nodes[r.Next(0, graph.nodes.Count - 1)];
n2 = graph.nodes[r.Next(0, graph.nodes.Count - 1)];
n1 = graph.GetNodeAtIndex(r.Next(0, graph.GetNodeCount() - 1));
n2 = graph.GetNodeAtIndex(r.Next(0, graph.GetNodeCount() - 1));
_route = new Astar().FindPath(graph, n1, n2, logger);
} while (!_route.routeFound);
} while (Console.ReadKey().Key.Equals(ConsoleKey.Enter));

View File

@ -3,7 +3,7 @@ namespace Graph
{
public class Graph
{
public List<Node> nodes { get; }
private List<Node> nodes { get; }
public Graph()
{
@ -23,6 +23,16 @@ namespace Graph
}
}
public Node GetNodeAtIndex(int i)
{
return this.nodes[i];
}
public int GetNodeCount()
{
return this.nodes.Count;
}
public Node? GetNode(ulong id)
{
foreach(Node n in this.nodes)

View File

@ -34,7 +34,7 @@ namespace OpenStreetMap_Importer
mapData.Position = 0;
logger?.Log(LogLevel.INFO, "Importing Graph...");
Graph.Graph _graph = CreateGraph(mapData, occuranceCount, onlyJunctions, logger);
logger?.Log(LogLevel.DEBUG, "Loaded Nodes: {0}", _graph.nodes.Count);
logger?.Log(LogLevel.DEBUG, "Loaded Nodes: {0}", _graph.GetNodeCount());
mapData.Close();
occuranceCount.Clear();