public void AddEdge(Edge edge) { AddEdge(edge.FirstVertex, edge.SecondVertex, edge.Weight); }
/// <summary> /// Removes a bi-directional edge from the network /// </summary> /// <param name="e"></param> /// <returns></returns> public bool RemoveEdgeUndirected(Edge e) { return(_edges.Remove(e) && _edges.Remove(e.Conjugate())); }
/// <summary> /// Searches the network for an edge with the same vertices as Edge e /// </summary> /// <param name="e"></param> /// <returns></returns> public Edge GetEdge(Edge e) { return(_edges.Find(x => x.Equals(e))); }
public override void AddEdges(Edge e1) { AdjacentGraph G = this; G += e1; }
/// <summary> /// Removes a directed edge from the network /// </summary> /// <param name="e"></param> /// <returns></returns> public bool RemoveEdge(Edge e) { return(_edges.Remove(e)); }
/// <summary> /// Adds an edge to this node. /// </summary> /// <param name="e">The edge to add.</param> private void addEdge(Edge e) { if (e.getNode().TerrainType == SquareType.Unwalkable || TerrainType == SquareType.Unwalkable) return; if (edgeList.Count == maxEdges) { string errmsg = "tried to add more than " + maxEdges + " edges! " + ToString() + e.getNode().ToString() + "\n"; foreach (Edge edge in edgeList) errmsg += edge.getNode().ToString(); throw new System.Exception(errmsg); } #if DEBUG_NODE_EDGES lineDraw.SetPosition(edgeList.Count * 2 + 1, e.getPos()); lineDraw.SetPosition(edgeList.Count * 2 + 2, pos); #endif // Do not move this. lineDraw will out of bounds otherwise. edgeList.Add(e); }
public static void Disconnect(Edge edge) { edge.From.edges.Remove(edge); edge.To.edges.Remove(edge); }
public void Delete(Edge edge) { Node.Disconnect(edge); }
public static Graph CreateGraph(string path) { Graph graph = new Graph(); List <Edge> edges = new List <Edge>(); List <Node> nodes = new List <Node>(); string input = File.ReadAllText(path); if (input.Any(x => x.Equals('r'))) { input = input.Replace("\r", ""); } int arrDimension = Int32.Parse(input.Split("\n").ElementAt(0)); graph.VerticesCount = arrDimension; input = input.Substring(2); int i = 0, j = 0; foreach (var row in input.Split('\n')) { j = 0; foreach (var col in row.Trim().Split(' ')) { var value = int.Parse(col.Trim()); if (value != 0) { if (!edges.Exists(x => x.Source == j && x.Destination == i)) { var edge = new Edge { Source = i, Destination = j, Weight = int.Parse(col.Trim()) }; edges.Add(edge); if (nodes.Exists(x => x.Id == i)) { nodes.First(x => x.Id == i).Rank++; } else { nodes.Add(new Node { Id = i, Rank = 1 }); } if (nodes.Exists(x => x.Id == j)) { nodes.First(x => x.Id == j).Rank++; } else { nodes.Add(new Node { Id = j, Rank = 1 }); } } } j++; } i++; } graph.EdgesCount = edges.Count; graph.Edges = edges.ToArray(); graph.Nodes = nodes.ToArray(); return(graph); }
public static Graph CreateGraph(int[,] matrix) { Graph graph = new Graph(); List <Edge> edges = new List <Edge>(); List <Node> nodes = new List <Node>(); graph.VerticesCount = matrix.GetLength(0); int i = 0, j = 0; for (int row = 0; row < matrix.GetLength(0); row++) { j = 0; for (int col = 0; col < matrix.GetLength(1); col++) { var value = matrix[row, col]; if (value != 0) { if (!edges.Exists(x => x.Source == j && x.Destination == i)) { var edge = new Edge { Source = i, Destination = j, Weight = value }; edges.Add(edge); if (nodes.Exists(x => x.Id == i)) { nodes.First(x => x.Id == i).Rank++; } else { nodes.Add(new Node { Id = i, Rank = 1 }); } if (nodes.Exists(x => x.Id == j)) { nodes.First(x => x.Id == j).Rank++; } else { nodes.Add(new Node { Id = j, Rank = 1 }); } } } j++; } i++; } graph.EdgesCount = edges.Count; graph.Edges = edges.ToArray(); graph.Nodes = nodes.ToArray(); return(graph); }