public void deleteEdge(Node origin, Node destiny) { bool exist = false; Adj ad = new Adj(); foreach (Adj adj in origin.AdjacencyList) { if (adj.Node == destiny) { ad = adj; exist = true; } } if (exist) { origin.AdjacencyList.Remove(ad); } }
public void addEdge(Node origin, Node destiny, int weight = 0) { Adj aux = new Adj(destiny, weight); bool exist = false; foreach (Adj adj in origin.AdjacencyList) { if (adj == aux) { exist = true; break; } } if (!exist) { origin.addAdj(aux); } }
private void drawEdge(Node node, Adj adj) { Pen penEdgeLow = new Pen(Color.LightGreen, 2); Pen penEdgeMedium = new Pen(Color.Yellow, 2); Pen penEdgeHigh = new Pen(Color.Red, 2); Brush brushLow = Brushes.LightGreen; Brush brushMedium = Brushes.Yellow; Brush brushHigh = Brushes.Red; AdjustableArrowCap arrow = new AdjustableArrowCap(5f, 5f); penEdgeLow.CustomEndCap = arrow; penEdgeMedium.CustomEndCap = arrow; penEdgeHigh.CustomEndCap = arrow; int xDestiny = circlePoint((int)node.X, (int)node.Y, (int)adj.Node.X, (int)adj.Node.Y)[0]; int yDestiny = circlePoint((int)node.X, (int)node.Y, (int)adj.Node.X, (int)adj.Node.Y)[1]; int xOrigin = circlePoint((int)adj.Node.X, (int)adj.Node.Y, (int)node.X, (int)node.Y)[0]; int yOrigin = circlePoint((int)adj.Node.X, (int)adj.Node.Y, (int)node.X, (int)node.Y)[1]; Point weight = new Point(((xOrigin + xDestiny) / 2) + 5, ((yOrigin + yDestiny) / 2) - 15); if (adj.Weight <= 850) { panel1.CreateGraphics().DrawString(adj.Weight.ToString(), this.Font, brushLow, weight); panel1.CreateGraphics().DrawLine(penEdgeLow, xOrigin, yOrigin, xDestiny, yDestiny); } else if (adj.Weight >= 1500) { panel1.CreateGraphics().DrawString(adj.Weight.ToString(), this.Font, brushHigh, weight); panel1.CreateGraphics().DrawLine(penEdgeHigh, xOrigin, yOrigin, xDestiny, yDestiny); } else { panel1.CreateGraphics().DrawString(adj.Weight.ToString(), this.Font, brushMedium, weight); panel1.CreateGraphics().DrawLine(penEdgeMedium, xOrigin, yOrigin, xDestiny, yDestiny); } }
public void addAdj(Adj adj) { AdjacencyList.Add(adj); }