public T GetWeight(int nodeAIndex, int nodeBIndex) { IWeightedGraphNode <T> nodeA = GetByIndex(nodeAIndex); IWeightedGraphNode <T> nodeB = GetByIndex(nodeBIndex); return(nodeA.GetWeight(nodeB)); }
public void SetWeightSymmetrical(IWeightedGraphNode <T> node, T weight) { int index = IndexOf((WeightedGraphNode <T>)node); if (index < 0) { throw new ArgumentException("Node is not connected"); } _weights[index] = weight; node.SetWeight(this, weight); }
public T GetWeight(IWeightedGraphNode <T> node) { int index = IndexOf((WeightedGraphNode <T>)node); if (index < 0) { return(InfinityWeight); //throw new ArgumentException("Node is not connected"); } return(_weights[index]); }
public ICollection <IWeightedGraphNode <T> > GetWeightedGraphNodes() { IWeightedGraphNode <T>[] nodes = new IWeightedGraphNode <T> [Width * Height]; for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { nodes[y * Width + x] = (IWeightedGraphNode <T>)GraphNodes[x, y]; } } return(nodes); }
public void SetWeight(IWeightedGraphNode <T> connection, T weight) { int connectionIndex = Connections.IndexOf((GraphNode)connection); if (connectionIndex == -1) { Connections.Add((GraphNode)connection); _weights.Add(weight); } else { _weights[connectionIndex] = weight; } }
public void ConnectNode(IWeightedGraphNode <double> node, NeighbourMode neighbourMode) { AStarAlgorithm aStarAlgorithm = new AStarAlgorithm(); CoordinateTransformer transformer = new CoordinateTransformer(this, LeftBottom); foreach (var transitionNode in _transitionNodes) { IList <Vector2Int> path = aStarAlgorithm.GetPath(transformer, node.Position - LeftBottom, transitionNode.Position - LeftBottom, neighbourMode); if (path != null) { node.SetWeight(transitionNode, path.Count); transitionNode.SetWeight(node, path.Count); // Other mode will not be connected } } }
public IList <Vector2Int> GetPathSingleLayer(ICellMap mapBase, Vector2Int start, Vector2Int stop, NeighbourMode neighbourMode) { if (neighbourMode == NeighbourMode.SideOnly) { GraphNode[,] graphNodes = GraphGenerator.GetGraph(mapBase, neighbourMode); IGraphNode[,] nodesInterface = new IGraphNode[mapBase.Width, mapBase.Height]; for (int i = 0; i < mapBase.Width; i++) { for (int j = 0; j < mapBase.Height; j++) { if (graphNodes[i, j] == null) { continue; } graphNodes[i, j].Data = new GraphData(); SetPosition(graphNodes[i, j], new Vector2Int(i, j)); nodesInterface[i, j] = graphNodes[i, j]; } } IGraphNode startNode = graphNodes[start.X, start.Y]; IGraphNode stopNode = graphNodes[stop.X, stop.Y]; Graph graph = new Graph(nodesInterface); var nodePath = GetPath(graph, startNode, stopNode); if (nodePath == null) { return(null); } List <Vector2Int> path = new List <Vector2Int>(nodePath.Count); foreach (var node in nodePath) { path.Add(node.Position); } return(path); } else { IWeightedGraph <double> graph = GraphGenerator.GetWeightedGraph(mapBase, NeighbourMode.SidesAndDiagonals); var nodes = graph.GetWeightedGraphNodes(); IWeightedGraphNode <double> startNode = null, stopNode = null; foreach (var node in nodes) { if (node == null) { continue; } node.Data = new GraphData(); if (node.Position == start) { startNode = node; } if (node.Position == stop) { stopNode = node; } } var nodePath = GetPath(graph, startNode, stopNode); if (nodePath == null) { return(null); } List <Vector2Int> path = new List <Vector2Int>(nodePath.Count); foreach (var node in nodePath) { path.Add(node.Position); } return(path); } }
public IList <IGraphNode> GetPath(IWeightedGraph <double> map, IWeightedGraphNode <double> start, IWeightedGraphNode <double> stop) { var nodePath = GetPath((IGraph)map, start, stop); return(nodePath); }
private double GetConnectionWeight(IWeightedGraphNode <double> weightedNodeA, IWeightedGraphNode <double> weightedNodeB) { return(weightedNodeA.GetWeight(weightedNodeB)); }
public int GetConnectionIndex(IWeightedGraphNode <T> connection) { return(Connections.IndexOf((GraphNode)connection)); }
public bool Remove(IWeightedGraphNode <T> item) { return(base.Remove(item)); }
public bool Contains(IWeightedGraphNode <T> item) { return(base.Contains(item)); }
public void Add(IWeightedGraphNode <T> item) { base.Add(item); }