/// <summary> /// Retourne True si une sortie d'un component1 à une sortie d'un component2 ont été reliées, et si c'est le cas mettre à jour les input/output /// </summary> /// <param name="component1">Le composant qui comporte le input/output sortie</param> /// <param name="component2">Le composant qui comporte le input/output entree</param> /// <param name="sortie">La sortie à relier</param> /// <param name="entree">L'entrée à relier</param> /// <returns></returns> public bool Relate(Outils component1, Outils component2, Sortie sortie, ClasseEntree entree) { component1.circuit = this; component2.circuit = this; //On vérifie si l'entrée entree n'est pas déjà reliée, //et si sortie et entree ont le meme état booléen, //et si sortie est contenue dans la liste_sorties de component1, //et si entree est contenue dans la liste_sentrees de component2, //et si component1 et component2 sont contenus dans le circuit if (!entree.getRelated() && entree.getEtat() == sortie.getEtat() && component1.getListesorties().Contains(sortie) && component2.getListeentrees().Contains(entree) && Circuit.ContainsVertex(component2) && Circuit.ContainsVertex(component1)) //Si l'entrée de component2 n'est pas reliée { OutStruct outstruct = new OutStruct(entree, component2); //Mise à jour des liaison if (!sortie.getSortie().Contains(outstruct)) { sortie.getSortie().Add(outstruct); entree.setRelated(true);//Mise à jour de related } if (!Circuit.ContainsEdge(component1, component2)) //Si il n'y a pas un edge déja présent liant component1 et component2 { Edge <Outils> edge = new Edge <Outils>(component1, component2); Circuit.AddEdge(edge); //Ajouter edge entre component1 et component2 } entree.setEtat(sortie.getEtat()); //Mise à jour de l'état d'entree de component2 return(true); // component1 et component2 liées avec succès } else { return(false); } }
public void removeEdgeIfTest() { var graph = new BidirectionalGraph <int, IEdge <int> >(); graph.AddVertex(1); graph.AddVertex(2); graph.AddVertex(3); graph.AddEdge(new EquatableEdge <int>(1, 2)); graph.AddEdge(new EquatableEdge <int>(2, 3)); graph.AddEdge(new EquatableEdge <int>(2, 1)); graph.RemoveOutEdgeIf(2, (edge) => edge.Target == 1); Assert.IsTrue(graph.ContainsEdge(1, 2)); Assert.IsFalse(graph.ContainsEdge(2, 1)); Assert.IsTrue(graph.ContainsEdge(2, 3)); graph.RemoveInEdgeIf(2, (edge) => edge.Source == 1); Assert.IsTrue(graph.ContainsEdge(2, 3)); Assert.IsFalse(graph.ContainsEdge(1, 2)); }
private void AddEdge(object source, object target, Color edgeColor, BidirectionalGraph <object, IEdge <object> > graph) { var edge = new MyEdge(source, target) { EdgeColor = edgeColor }; if (!graph.ContainsEdge(edge)) { graph.AddEdge(edge); } }
/// <summary> /// /// </summary> /// <param name="edge"></param> protected void AddEdge(NodeEdge edge) { // Skip if it it already been added if (graph.ContainsEdge(edge)) { return; } // Add the vertex to the logic graph graph.AddEdge(edge); // Create the vertex control var control = AssociatedObject.ControlFactory.CreateEdgeControl(AssociatedObject.VertexList[edge.Source], AssociatedObject.VertexList[edge.Target], edge); control.DataContext = edge; //control.Visibility = Visibility.Hidden; // make them invisible (there is no layout positions yet calculated) // Create data binding for input slots and output slots var binding = new Binding(); binding.Path = new PropertyPath("SourceSlot"); binding.Mode = BindingMode.TwoWay; binding.Source = edge; binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; BindingOperations.SetBinding(control, NodeEdgeControl.SourceSlotProperty, binding); binding = new Binding(); binding.Path = new PropertyPath("TargetSlot"); binding.Mode = BindingMode.TwoWay; binding.Source = edge; binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; BindingOperations.SetBinding(control, NodeEdgeControl.TargetSlotProperty, binding); // Add vertex and control to the graph area AssociatedObject.AddEdge(edge, control); }
public void Add(Edge edge) { Add(edge.Subject, false); Add(edge.Obj, false); graph.AddVerticesAndEdge(edge); if (AddBiDirectionalLinks && !edge.Inverted) { Edge backlink = GetBackLink(edge); backlink.Inverted = true; if (edge.Subject != edge.Obj && !graph.ContainsEdge(backlink)) { graph.AddVerticesAndEdge(backlink); } } }
public void removeIsolatedVertices() { var graph = new BidirectionalGraph <int, IEdge <int> >(); graph.AddVertex(1); var edge = new EquatableEdge <int>(2, 3); graph.AddVerticesAndEdge(edge); var predicate = new IsolatedVertexPredicate <int, IEdge <int> >(graph); graph.RemoveVertexIf(predicate.Test); Assert.IsTrue(graph.ContainsVertex(2)); Assert.IsTrue(graph.ContainsEdge(edge)); Assert.IsFalse(graph.ContainsVertex(1)); }
public static IBidirectionalGraph <TVertex, TEdge> CreateGeneralGraph <TVertex, TEdge>( int vertexCount, int edgeCount, int maxDegree, bool parallelEdgeAllowed, [NotNull, InstantHandle] Func <int, TVertex> vertexFactory, [NotNull, InstantHandle] Func <TVertex, TVertex, TEdge> edgeFactory, [NotNull] Random random) where TEdge : IEdge <TVertex> { var graph = new BidirectionalGraph <TVertex, TEdge>(parallelEdgeAllowed, vertexCount); var verticesMap = new Dictionary <int, TVertex>(); for (int i = 0; i < vertexCount; ++i) { TVertex vertex = vertexFactory(i); verticesMap[i] = vertex; graph.AddVertex(vertex); } for (int i = 0; i < edgeCount; ++i) { int childIndex; int parentIndex; TVertex child; TVertex parent; do { childIndex = random.Next(vertexCount); parentIndex = random.Next(vertexCount); child = verticesMap[childIndex]; parent = verticesMap[parentIndex]; } while (childIndex == parentIndex || !parallelEdgeAllowed && graph.ContainsEdge(parent, child) || graph.Degree(parent) >= maxDegree || graph.Degree(child) >= maxDegree); // Create the edge between the 2 vertex graph.AddEdge(edgeFactory(parent, child)); } return(graph); }
public static IBidirectionalGraph <TVertex, TEdge> CreateDAG <TVertex, TEdge>( int vertexCount, int edgeCount, int maxParent, int maxChild, bool parallelEdgeAllowed, [NotNull, InstantHandle] Func <int, TVertex> vertexFactory, [NotNull, InstantHandle] Func <TVertex, TVertex, TEdge> edgeFactory, [NotNull] Random random) where TEdge : IEdge <TVertex> { var dagGraph = new BidirectionalGraph <TVertex, TEdge>(parallelEdgeAllowed, vertexCount); var verticesMap = new Dictionary <int, TVertex>(); for (int i = 0; i < vertexCount; ++i) { TVertex vertex = vertexFactory(i); verticesMap[i] = vertex; dagGraph.AddVertex(vertex); } for (int i = 0; i < edgeCount; ++i) { TVertex parent; TVertex child; do { int childIndex = random.Next(vertexCount - 1) + 1; int parentIndex = random.Next(childIndex); child = verticesMap[childIndex]; parent = verticesMap[parentIndex]; } while (!parallelEdgeAllowed && dagGraph.ContainsEdge(parent, child) || dagGraph.OutDegree(parent) >= maxChild || dagGraph.InDegree(child) >= maxParent); // Create the edge between the 2 vertex dagGraph.AddEdge(edgeFactory(parent, child)); } return(dagGraph); }
public static IBidirectionalGraph <TVertex, TEdge> CreateGeneralGraph <TVertex, TEdge>(int vertexCount, int edgeCount, int maxDegree, bool parallelEdgeAllowed, Func <int, TVertex> vertexFactory, Func <TVertex, TVertex, TEdge> edgeFactory) where TEdge : IEdge <TVertex> { BidirectionalGraph <TVertex, TEdge> graph = new BidirectionalGraph <TVertex, TEdge>(false, vertexCount); Dictionary <int, TVertex> vertexMap = new Dictionary <int, TVertex>(); for (int i = 0; i < vertexCount; i++) { TVertex v = vertexFactory(i); vertexMap[i] = v; graph.AddVertex(v); } Random rnd = new Random(DateTime.Now.Millisecond); int childIndex; int parentIndex; TVertex child; TVertex parent; for (int i = 0; i < edgeCount; i++) { do { childIndex = rnd.Next(vertexCount); parentIndex = rnd.Next(vertexCount); child = vertexMap[childIndex]; parent = vertexMap[parentIndex]; }while (childIndex == parentIndex || (!parallelEdgeAllowed && graph.ContainsEdge(parent, child)) || graph.Degree(parent) >= maxDegree || graph.Degree(child) >= maxDegree); //create the edge between the 2 vertex TEdge e = edgeFactory(parent, child); graph.AddEdge(e); } return(graph); }
public void ReadFromString(string metroNetworkGraphStr) { if(String.IsNullOrWhiteSpace(metroNetworkGraphStr)) throw new ArgumentException("Metro network string either null, empty or consists only of whitespaces", "metroNetworkGraphStr"); try { var edges = metroNetworkGraphStr.Split(',').Select(s => s.Trim()); foreach (var edgeStr in edges) { var stationPairAndDistance = edgeStr.Split(':'); var stationPair = stationPairAndDistance[0].Split('-'); var station1 = stationPair[0]; var station2 = stationPair[1]; var distance = Int32.Parse(stationPairAndDistance[1]); if (!_graph.ContainsVertex(station1)) { _graph.AddVertex(station1); } if (!_graph.ContainsVertex(station2)) { _graph.AddVertex(station2); } var edge = new Edge<string>(station1, station2); if (!_graph.ContainsEdge(edge)) { _graph.AddEdge(edge); _costs.Add(edge, distance); } } } catch (Exception exc) { throw new FormatException("Can't read a metro networkgraph - string is in incorrect format", exc); } }
public bool ContainsDependency(Assembly from, Assembly to) { return(_dependencyGraph.ContainsEdge(new AssemblyNode(from), new AssemblyNode(to))); }
private WordPair createNewGreenEdges(Word uWord, Word kWord, BidirectionalGraph <Word, Edge <Word> > graph) { Cache1.Clear(); List <SPath> paths = new List <SPath>(); foreach (var item in graph.OutEdges(uWord)) { SLink linkCU = new SLink(item.Target, uWord); linkCU.Exists = graph.ContainsEdge(uWord, item.Target); SLink linkCK = new SLink(item.Target, kWord); linkCK.Exists = graph.ContainsEdge(item.Target, kWord); SPath path = new SPath(linkCU, linkCK); paths.Add(path); Cache1.Add(item.Target.ID, true); } foreach (var item in graph.InEdges(kWord)) { if (Cache1.ContainsKey(item.Source.ID)) { continue; } SLink linkCK = new SLink(item.Source, kWord); linkCK.Exists = graph.ContainsEdge(item.Source, kWord); SLink linkCU = new SLink(item.Source, uWord); linkCU.Exists = graph.ContainsEdge(uWord, item.Source); SPath path = new SPath(linkCU, linkCK); paths.Add(path); } //calculate probability float pUK = 0; float pKU = 0; float probUK = 0; float probKU = 0; foreach (var item in paths) { if (!item.LinkCU.Exists || !item.LinkCK.Exists) //containing non-existance link { continue; } float PrCU = 0.0f; float PrKC = 0.0f; float PrCK = 0.0f; float PrUC = 0.0f; foreach (var downEdgeCU in graph.OutEdges(item.LinkCU.WordNonPivot)) //Loop through down-path from nonpivot1 to pivot { PrCU += 1.0f / LinkWeightCache[new SLink(downEdgeCU.Target, downEdgeCU.Source)]; //P(C|U) = P(C&U)/P(U) } foreach (var downEdgeCK in graph.OutEdges(item.LinkCK.WordPivot)) //Loop through down-path from pivot to nonpivot2 { PrKC += 1.0f / LinkWeightCache[new SLink(downEdgeCK.Source, downEdgeCK.Target)]; //P(K|C) = P(K&C)/P(C) } foreach (var upEdgeCK in graph.InEdges(item.LinkCK.WordNonPivot)) //Loop through up-path from nonpivot2 to pivot { PrCK += 1.0f / LinkWeightCache[new SLink(upEdgeCK.Source, upEdgeCK.Target)]; //P(C|K) = P(C&K)/P(K) } foreach (var upEdgeCU in graph.InEdges(item.LinkCU.WordPivot)) //Loop through up-path from pivot to nonpivot1 { PrUC += 1.0f / LinkWeightCache[new SLink(upEdgeCU.Target, upEdgeCU.Source)]; //P(U|C) = P(U&C)/P(C) } PrCU = 1.0f / PrCU; PrKC = 1.0f / PrKC; PrCK = 1.0f / PrCK; PrUC = 1.0f / PrUC; pUK += PrUC * PrCK; pKU += PrKC * PrCU; } probUK = pUK * pKU; WordPair pair = new WordPair(uWord, kWord); pair.Paths = paths; pair.Prob = (float)probUK; //set link weights foreach (var item in pair.Paths) { //CU if (!item.LinkCU.Exists) { float value = 0; if (LinkWeightCache.TryGetValue(item.LinkCU, out value)) { if (pair.Prob > value) { item.LinkCU.Pr = LinkWeightCache[item.LinkCU] = pair.Prob; } else { item.LinkCU.Pr = value; } } else { item.LinkCU.Pr = pair.Prob; LinkWeightCache.Add(item.LinkCU, pair.Prob); } } //CK if (!item.LinkCK.Exists) { float value = 0; if (LinkWeightCache.TryGetValue(item.LinkCK, out value)) { if (pair.Prob > value) { LinkWeightCache[item.LinkCK] = item.LinkCK.Pr = pair.Prob; } else { item.LinkCK.Pr = value; } } else { item.LinkCK.Pr = pair.Prob; LinkWeightCache.Add(item.LinkCK, pair.Prob); } } } return(pair); }
private WordPair createNewEdges(Word uWord, Word kWord, BidirectionalGraph <Word, Edge <Word> > semiCompleteGraph, BidirectionalGraph <Word, Edge <Word> > completeGraph)//, int uCount, int kCount) { Cache1.Clear(); List <SPath> paths = new List <SPath>(); WordPair pair = new WordPair(uWord, kWord); pair.Polysemy = 0f; foreach (var item in semiCompleteGraph.OutEdges(uWord)) // Using the updated graph with new edges { int inDegreePivot = (int)semiCompleteGraph.InDegree(item.Target); int outDegreePivot = (int)semiCompleteGraph.OutDegree(item.Target); int totalSenseEdge = (Math.Max(inDegreePivot, outDegreePivot) - 1) * (inDegreePivot + outDegreePivot); pair.Polysemy += totalSenseEdge; //Word pivot_sense = item.Target; //for (int sense = 1; sense <= totalSense; sense++) //{ //pivot_sense.Value = pivot_sense.Value + "_sense" + sense; SLink linkCU = new SLink(item.Target, uWord); linkCU.Exists = true;// semiCompleteGraph.ContainsEdge(uWord, pivot_sense); SLink linkCK = new SLink(item.Target, kWord); linkCK.Exists = semiCompleteGraph.ContainsEdge(item.Target, kWord); SPath path = new SPath(linkCU, linkCK); paths.Add(path); Cache1.Add(item.Target.ID, true); //} } foreach (var item in semiCompleteGraph.InEdges(kWord)) // Using the updated graph with new edges { if (Cache1.ContainsKey(item.Source.ID)) { continue; } int inDegreePivot = (int)semiCompleteGraph.InDegree(item.Source); int outDegreePivot = (int)semiCompleteGraph.OutDegree(item.Source); int totalSenseEdge = (Math.Max(inDegreePivot, outDegreePivot) - 1) * (inDegreePivot + outDegreePivot); pair.Polysemy += totalSenseEdge; SLink linkCK = new SLink(item.Source, kWord); linkCK.Exists = true;// semiCompleteGraph.ContainsEdge(item.Source, kWord); SLink linkCU = new SLink(item.Source, uWord); linkCU.Exists = semiCompleteGraph.ContainsEdge(uWord, item.Source); SPath path = new SPath(linkCU, linkCK); paths.Add(path); } //calculate probability //float couverage = Math.Min(uCount, kCount) / (float)Math.Max(uCount, kCount); float pUK = 0; float pKU = 0; float probUK = 0; float probKU = 0; //bool hasPolysemy = false; foreach (var item in paths) { //if (!item.LinkCU.Exists || !item.LinkCK.Exists) //containning non-existance link if (!item.LinkCU.Exists) { if (languageOption == 2) { completeGraph.AddEdge(new Edge <Word>(item.LinkCU.WordNonPivot, item.LinkCU.WordPivot)); } continue; } if (!item.LinkCK.Exists) { if (languageOption == 2) { completeGraph.AddEdge(new Edge <Word>(item.LinkCK.WordPivot, item.LinkCK.WordNonPivot)); } continue; } //if ((float)graph.InDegree(item.LinkCU.WordPivot) > 1 || (float)graph.OutDegree(item.LinkCK.WordPivot) > 1) // hasPolysemy = true; if (currentCycle == 1) { float PrCU = 1.0f / (float)semiCompleteGraph.OutDegree(item.LinkCU.WordNonPivot); //P(C|U) = P(C&U)/P(U) float PrKC = 1.0f / (float)semiCompleteGraph.OutDegree(item.LinkCK.WordPivot); //P(K|C) = P(K&C)/P(C) float PrCK = 1.0f / (float)semiCompleteGraph.InDegree(item.LinkCK.WordNonPivot); //P(C|K) = P(C&K)/P(K) float PrUC = 1.0f / (float)semiCompleteGraph.InDegree(item.LinkCU.WordPivot); //P(U|C) = P(U&C)/P(C) pKU += PrCU * PrKC; pUK += PrCK * PrUC; } else { float PrCU = 0.0f; float PrKC = 0.0f; float PrCK = 0.0f; float PrUC = 0.0f; foreach (var downEdgeCU in semiCompleteGraph.OutEdges(item.LinkCU.WordNonPivot)) //Loop through down-path from nonpivot1 to pivot { PrCU += 1.0f / LinkWeightCache[new SLink(downEdgeCU.Target, downEdgeCU.Source)]; //P(C|U) = P(C&U)/P(U) } foreach (var downEdgeCK in semiCompleteGraph.OutEdges(item.LinkCK.WordPivot)) //Loop through down-path from pivot to nonpivot2 { PrKC += 1.0f / LinkWeightCache[new SLink(downEdgeCK.Source, downEdgeCK.Target)]; //P(K|C) = P(K&C)/P(C) } foreach (var upEdgeCK in semiCompleteGraph.InEdges(item.LinkCK.WordNonPivot)) //Loop through up-path from nonpivot2 to pivot { PrCK += 1.0f / LinkWeightCache[new SLink(upEdgeCK.Target, upEdgeCK.Source)]; //P(C|K) = P(C&K)/P(K) } foreach (var upEdgeCU in semiCompleteGraph.InEdges(item.LinkCU.WordPivot)) //Loop through up-path from pivot to nonpivot1 { PrUC += 1.0f / LinkWeightCache[new SLink(upEdgeCU.Source, upEdgeCU.Target)]; //P(U|C) = P(U&C)/P(C) } PrCU = 1.0f / PrCU; PrKC = 1.0f / PrKC; PrCK = 1.0f / PrCK; PrUC = 1.0f / PrUC; pUK += PrUC * PrCK; pKU += PrKC * PrCU; } } probUK = pUK * pKU; //WordPair pair = new WordPair(uWord, kWord); //pair.HasMissingEdge = hasPolysemy; pair.Paths = paths; pair.Prob = (float)probUK; pair.Polysemy *= (1 - pair.Prob); //set link weights foreach (var item in pair.Paths) { //CU //float polysemyCost = 1 / ((float)graph.InDegree(item.LinkCU.WordPivot) * (float)graph.OutDegree(item.LinkCK.WordPivot)); if (item.LinkCU.Exists) { item.LinkCU.Pr = 1f; //polysemyCost; if (!LinkWeightCache.ContainsKey(item.LinkCU)) { LinkWeightCache.Add(item.LinkCU, item.LinkCU.Pr); } } else { //pair.HasMissingCUEdge = true; float value = 0; if (LinkWeightCache.TryGetValue(item.LinkCU, out value)) { if (pair.Prob > value) { item.LinkCU.Pr = LinkWeightCache[item.LinkCU] = pair.Prob; //polysemyCost * } else { item.LinkCU.Pr = value; } } else { item.LinkCU.Pr = pair.Prob; //polysemyCost * LinkWeightCache.Add(item.LinkCU, pair.Prob); } } //CK if (item.LinkCK.Exists) //false)// { item.LinkCK.Pr = 1f; //polysemyCost if (!LinkWeightCache.ContainsKey(item.LinkCK)) { LinkWeightCache.Add(item.LinkCK, item.LinkCK.Pr); } } else { float value = 0; if (LinkWeightCache.TryGetValue(item.LinkCK, out value)) { if (pair.Prob > value) { LinkWeightCache[item.LinkCK] = item.LinkCK.Pr = pair.Prob; //polysemyCost * } else { item.LinkCK.Pr = value; } } else { item.LinkCK.Pr = pair.Prob; //polysemyCost * LinkWeightCache.Add(item.LinkCK, pair.Prob); } } } return(pair); }
public static void ValidatePathsUsingDijkstra(Topology.IGP.Topology igp_topology, Topology.MPLS.HierarchicalLabelSwitchedPath.HierarchicalLabelSwitchedPath hlsp) { Console.WriteLine("\n====Validating Paths====\n"); List <yggdrasil2.Topology.Node.Node> nodes_copy = igp_topology.Nodes.DeepClone(); List <yggdrasil2.Topology.IGP.Link.Link> links_copy = igp_topology.Links.DeepClone(); BidirectionalGraph <string, TaggedEdge <string, yggdrasil2.Topology.IGP.Link.Link> > graph = new BidirectionalGraph <string, TaggedEdge <string, yggdrasil2.Topology.IGP.Link.Link> >(); Dictionary <TaggedEdge <string, yggdrasil2.Topology.IGP.Link.Link>, double> cost = new Dictionary <TaggedEdge <string, yggdrasil2.Topology.IGP.Link.Link>, double>(); var start = nodes_copy.Where(n => n.IPv4RouterIdentifier == hlsp.IPv4TunnelSenderAddress).SingleOrDefault(); var end = nodes_copy.Where(n => n.IPv4RouterIdentifier == hlsp.IPv4TunnelEndpointAddress).SingleOrDefault(); if (start != null && end != null) { foreach (var lsp in hlsp.Children) { graph.Clear(); foreach (var node in nodes_copy) { graph.AddVertex(node.Id); } if (!start.IsPseudonode) // it will never be a pseudonode, get rid of this { var nodeLinks = links_copy.Where(l => l.SourceNode == start.Id).ToList(); foreach (var l in nodeLinks) { if (!graph.ContainsEdge(l.SourceNode, l.TargetNode)) { if (l.OperationalStatus) { var forwardEdge = new TaggedEdge <string, yggdrasil2.Topology.IGP.Link.Link>(l.SourceNode, l.TargetNode, l); graph.AddEdge(forwardEdge); cost.Add(forwardEdge, 1); } } } } foreach (var hop in lsp.ComputedExplicitRouteObject) { var link = links_copy.Where(l => l.IPv4InterfaceAddress == hop).SingleOrDefault(); if (link != null) { if (!graph.ContainsEdge(link.SourceNode, link.TargetNode)) { if (link.OperationalStatus) { var backwardEdge = new TaggedEdge <string, yggdrasil2.Topology.IGP.Link.Link>(link.TargetNode, link.SourceNode, link); graph.AddEdge(backwardEdge); cost.Add(backwardEdge, 1); } //var srcNode = nodes_copy.Where(n => n.IgpRouterIdentifier == link.SourceNode).SingleOrDefault(); var dstNode = nodes_copy.Where(n => n.IgpRouterIdentifier == link.TargetNode).SingleOrDefault(); //if (srcNode != null) //{ // if (srcNode.IsPseudonode) // { // var nodeLinks = links_copy.Where(l => l.TargetNode == srcNode.Id).ToList(); // foreach (var l in nodeLinks) // { // if (!graph.ContainsEdge(l.SourceNode, l.TargetNode)) // { // if (l.OperationalStatus) // { // var forwardEdge = new TaggedEdge<string, yggdrasil2.Topology.IGP.Link.Link>(l.SourceNode, l.TargetNode, l); // graph.AddEdge(forwardEdge); // cost.Add(forwardEdge, 1); // } // } // } // } //} if (dstNode != null) { if (dstNode.IsPseudonode) { var nodeLinks = links_copy.Where(l => l.TargetNode == dstNode.Id).ToList(); foreach (var l in nodeLinks) { if (!graph.ContainsEdge(l.SourceNode, l.TargetNode)) { if (l.OperationalStatus) { var forwardEdge = new TaggedEdge <string, yggdrasil2.Topology.IGP.Link.Link>(l.SourceNode, l.TargetNode, l); graph.AddEdge(forwardEdge); cost.Add(forwardEdge, 1); } } } } } } } } DijkstraShortestPathAlgorithm <string, TaggedEdge <string, yggdrasil2.Topology.IGP.Link.Link> > dijkstra = new DijkstraShortestPathAlgorithm <string, TaggedEdge <string, yggdrasil2.Topology.IGP.Link.Link> >(graph, AlgorithmExtensions.GetIndexer <TaggedEdge <string, yggdrasil2.Topology.IGP.Link.Link>, double>(cost)); dijkstra.Compute(start.Id); if (dijkstra.Distances.ContainsKey(end.Id) && dijkstra.Distances[end.Id] != double.MaxValue) { lsp.Feasible = true; Console.WriteLine("Path {0} is \u001b[32mFEASIBLE\u001b[0m.\n\t{1} is REACHABLE from {2} in {3} hops (includes pseudonodes).", lsp.SymbolicPathName, lsp.IPv4TunnelEndpointAddress, lsp.IPv4TunnelSenderAddress, dijkstra.Distances[end.Id]); } else { lsp.Feasible = false; Console.WriteLine("Path {0} is \u001b[31mNOT FEASIBLE\u001b[0m.\n\t{1} is UREACHABLE from {2}.", lsp.SymbolicPathName, lsp.IPv4TunnelEndpointAddress, lsp.IPv4TunnelSenderAddress); } } } }
public bool ContainsEdge(TVertex source, TVertex target) => _graph.ContainsEdge(source, target);