private void CM_SaveArcDestination(object sender, RoutedEventArgs e) { MenuItem mi = sender as MenuItem; if (mi != null) { ContextMenu cm = mi.CommandParameter as ContextMenu; if (cm != null) { Ellipse destination = cm.PlacementTarget as Ellipse; if (destination != null) { Console.WriteLine(destination.Name); IEnumerable <Ellipse> collection = canvas.Children.OfType <Ellipse>(); Ellipse source = collection.First(x => x.Width == 100); Console.WriteLine("Add arc from: " + source.Name + " to " + destination.Name); source.Width = 50; foreach (Ellipse every_ellipse in collection) { Console.WriteLine(); MenuItem elem = (MenuItem)every_ellipse.ContextMenu.Items.GetItemAt(0); elem.IsEnabled = true; } Node <City> vn_src = cityGraph[source.Name]; Node <City> vn_dest = cityGraph[destination.Name]; vn_src.AddArc(vn_dest); } } } }
/// <summary> /// Create a new arc, connecting this Node to the Nod passed in the parameter /// Also, it creates the inversed node in the passed node /// </summary> public Node AddArc(Node child, int w) { /* Arcs.Add(new Arc * { * Parent = this, * Child = child, * Weigth = w * });*/ //ako je node već dodan u susjede if (arcsarr[child.id] != null) { return(this); } //ako nije dodan susjed arcsarr[child.id] = new Arc { Parent = this, Child = child, Weigth = w }; // Debug.Log("Sad sam na" + "Parent: "+ this.Name + " Child: " + child.Name); /*if (!child.Arcs.Exists(a => a.Parent == child && a.Child == this)) * { * child.AddArc(this, w); * // Debug.Log("dodaje se" + " Parent:" + child.Name + " Child:" + this.Name); * }*/ if (child.arcsarr[this.id] == null) { child.AddArc(this, w); } return(this); }
public void TestAddArc_correct() { testGraph["Bydgoszcz"] = new City("Bydgoszcz", "kuj-pom", "300tys."); testNode.AddArc(testGraph["Bydgoszcz"]); Assert.AreEqual(1, testNode.arcsOut.Count, "arcsOut list didn't change"); Assert.AreEqual(testGraph["Bydgoszcz"], testNode.arcsOut[0]); Assert.AreEqual(testGraph["Bydgoszcz"].name, testNode.arcsOut[0].name, "arcsOut[0].name is not the added node.name"); Assert.AreEqual(testGraph["Bydgoszcz"].properties["county"], testNode.arcsOut[0].properties["county"], "arcsOut[0].county is not the added nodecounty"); }
public Node AddArc(Node dest, int weight) { arcs.Add(new Arc { source = this, destination = dest, weight = weight }); if (!dest.arcs.Exists(x => x.source == dest && x.destination == this)) { dest.AddArc(this, weight); } return(this); }
/// <summary> /// Create a new arc, connecting this Node to the Nod passed in the parameter /// Also, it creates the inversed node in the passed node /// </summary> public Node AddArc(Node child, int w) { Arcs.Add(new Arc { Parent = this, Child = child, Weigth = w }); if (!child.Arcs.Exists(a => a.Parent == child && a.Child == this)) { child.AddArc(this, w); } return(this); }
private void CreateWorldConnections() { graph = new Graph(); Node europe = graph.CreateRoot(home, transforms.Find(x => x.name == "Europe").position); Node africa = graph.CreateNode(areas.Find(x => x.Name == "Africa"), transforms.Find(x => x.name == "Africa").position); Node asia = graph.CreateNode(areas.Find(x => x.Name == "Asia"), transforms.Find(x => x.name == "Asia").position); Node nAmerica = graph.CreateNode(areas.Find(x => x.Name == "North America"), transforms.Find(x => x.name == "North America").position); Node sAmerica = graph.CreateNode(areas.Find(x => x.Name == "South America"), transforms.Find(x => x.name == "South America").position); africa.AddArc(asia, africaAsia).AddArc(europe, africaEurope).AddArc(nAmerica, africaNorthAmerica).AddArc(sAmerica, africaSouthAmerica); asia.AddArc(europe, asiaEurope).AddArc(nAmerica, asiaNorthAmerica).AddArc(sAmerica, asiaSouthAmerica); europe.AddArc(nAmerica, europeNorthAmerica).AddArc(sAmerica, europeSouthAmerica); nAmerica.AddArc(sAmerica, americaAmerica); }