public void AddVertex(Vertex <TData, TMetric> vertex, Edge <TData, TMetric> edge) { Vertices.Add(vertex, edge); Edges.AddRange(vertex.Edges); Edges.RemoveAll(e => Vertices.ContainsKey(e.Ending)); }
/// <summary> /// Add a new edge to this graph. /// Time complexity: O(1). /// </summary> public void AddOrUpdateEdge(T source, T dest, TW weight, IFlowOperators <TW> flow) { if (source == null || dest == null) { throw new ArgumentException(); } if (!Vertices.ContainsKey(source) || !Vertices.ContainsKey(dest)) { throw new Exception("Source or Destination Vertex is not in this graph."); } if (Vertices[source].OutEdges.TryGetValue(Vertices[dest], out var wOut)) { Vertices[source].OutEdges[Vertices[dest]] = flow.AddWeights(wOut, weight); } else { Vertices[source].OutEdges.Add(Vertices[dest], weight); } if (Vertices[dest].InEdges.TryGetValue(Vertices[source], out var wIn)) { Vertices[dest].InEdges[Vertices[source]] = flow.AddWeights(wIn, weight); } else { Vertices[dest].InEdges.Add(Vertices[source], weight); } }
public void AddVertex(Vertex <T> vertex) { if (!Vertices.ContainsKey(vertex.ID)) { Vertices.Add(vertex.ID, vertex); Edges.Add(vertex.ID, new HashSet <int>()); } }
public WeightedGraphVertex <T, TW> FindVertex(T value) { if (Vertices.ContainsKey(value)) { return(Vertices[value]); } return(null); }
public List <Tuple <T, TW> > GetAllEdges(T vertex) { if (!Vertices.ContainsKey(vertex)) { throw new ArgumentException("Vertex is not in this graph."); } return(Vertices[vertex].Edges.Select(x => new Tuple <T, TW>(x.Key.Value, x.Value)).ToList()); // ToList(); }
public void AddVertex(string vertexName) { if (!Vertices.ContainsKey(vertexName)) { Vertices[vertexName] = new Vertex(vertexName); Struct[Vertices[vertexName]] = new Dictionary <Vertex, int>(); } }
public void SetDataForVertex(long id, T data) { if (Vertices.ContainsKey(id)) { Vertex <T> vertex = Vertices[id]; vertex.Data = data; } }
public IEnumerable <Tuple <T, TW> > OutEdges(T vertex) { if (!Vertices.ContainsKey(vertex)) { throw new ArgumentException("vertex is not in this graph."); } return(Vertices[vertex].OutEdges.Select(x => new Tuple <T, TW>(x.Key.Key, x.Value))); }
public IEnumerable <T> InEdges(T vertex) { if (!Vertices.ContainsKey(vertex)) { throw new ArgumentException("vertex is not in this graph."); } return(Vertices[vertex].InEdges.Select(x => x.Value)); }
public List <T> GetAllInEdges(T vertex) { if (!Vertices.ContainsKey(vertex)) { throw new ArgumentException("vertex is not in this graph."); } return(Vertices[vertex].InEdges.Select(x => x.Value).ToList()); }
public DiGraphVertex <T> FindVertex(T value) { if (Vertices.ContainsKey(value)) { return(Vertices[value]); } return(null); }
/// <summary> /// Do we have an edge between given source and destination? /// Time complexity: O(1). /// </summary> public bool HasEdge(T source, T dest) { if (!Vertices.ContainsKey(source) || !Vertices.ContainsKey(dest)) { throw new ArgumentException("source or destination is not in this graph."); } return(Vertices[source].Edges.ContainsKey(Vertices[dest]) && Vertices[dest].Edges.ContainsKey(Vertices[source])); }
public void AddVertex(IVertex vertex) { if (Vertices.ContainsKey(vertex.Id)) { throw new ArgumentOutOfRangeException("vertex", string.Format("Vertex with Id {0} already exists", vertex.Id)); } Vertices.Add(vertex); }
public void AddVertex(T @object) { if (Vertices.ContainsKey(@object)) { throw new InvalidOperationException("Can't add the same vertex twice to the graph."); } var newVertex = new Vertex <T>(@object); Vertices.Add(@object, newVertex); AdjancecyList.Add(@object, new List <Vertex <T> >()); }
public Vertex <T> GetOrCreateVertex(Vertex <T> v) { if (Vertices.ContainsKey(v.Key)) { return(Vertices[v.Key]); } var v1 = new Vertex <T>(this, v.Key); Vertices[v1.Key] = v1; return(v1); }
//This works only for directed graph because for undirected graph we can end up //adding edges two times to allEdges public void AddVertex(Vertex <T> vertex) { if (Vertices.ContainsKey(vertex.Id)) { return; } Vertices.Add(vertex.Id, vertex); foreach (Edge <T> edge in vertex.Edges) { Edges.Add(edge); } }
public Vertex <T> AddSingleVertex(long id) { if (Vertices.ContainsKey(id)) { return(Vertices[id]); } Vertex <T> v = new Vertex <T>(id); Vertices.Add(id, v); return(v); }
public Vertex Add(Vertex vertex) { if (Vertices.ContainsKey(vertex.point)) { Vertex existingVertex; Vertices.TryGetValue(vertex.point, out existingVertex); return(existingVertex); } else { Vertices.Add(vertex.point, vertex); return(vertex); } }
/// <summary> /// Add a new edge to this graph with given weight /// and between given source and destination vertex. /// Time complexity: O(1). /// </summary> /// <param name="source"></param> /// <param name="destination"></param> /// <param name="weight"></param> public void AddEdge(T source, T destination, TW weight) { if (source == null || destination == null) { throw new ArgumentException(); } if (!Vertices.ContainsKey(source) || !Vertices.ContainsKey(destination)) { throw new Exception("Source or Destination is not in this graph."); } Vertices[source].Edges.Add(Vertices[destination], weight); Vertices[destination].Edges.Add(Vertices[source], weight); }
private void AddOrUpdateVertex(EdgeDescriptor <V, E> edgeDescriptor, V v) { VertexDescriptor <V, E> vertexDescriptor; if (!Vertices.ContainsKey(v)) { vertexDescriptor = new VertexDescriptor <V, E>(v); vertexDescriptor.AddEdge(edgeDescriptor); Vertices.Add(v, vertexDescriptor); } else { Vertices[v].AddEdge(edgeDescriptor); } }
public void RemoveVertex(T value) { if (value == null) { throw new ArgumentNullException(); } if (!Vertices.ContainsKey(value)) { throw new Exception("Vertex is not in this graph."); } foreach (var vertex in Vertices[value].Edges) { vertex.Key.Edges.Remove(Vertices[value]); } Vertices.Remove(value); }
/// <summary> /// remove an existing vertex from this graph /// O(V) complexity /// </summary> /// <param name="vertex"></param> public void RemoveVertex(T vertex) { if (vertex == null) { throw new ArgumentNullException(); } if (!Vertices.ContainsKey(vertex)) { throw new Exception("Vertex not in this graph."); } foreach (var v in Vertices[vertex].Edges) { v.Edges.Remove(Vertices[vertex]); } Vertices.Remove(vertex); }
public void AddEdge(T source, T dest) { if (source == null || dest == null) { throw new ArgumentException(); } if (!Vertices.ContainsKey(source) || !Vertices.ContainsKey(dest)) { throw new Exception("Source or Destination Vertex is not in this graph."); } if (Vertices[source].OutEdges.Contains(Vertices[dest]) || Vertices[dest].InEdges.Contains(Vertices[source])) { throw new Exception("Edge already exists."); } Vertices[source].OutEdges.Add(Vertices[dest]); Vertices[dest].InEdges.Add(Vertices[source]); }
/// <summary> /// Remove given edge. /// Time complexity: O(1). /// </summary> /// <param name="source"></param> /// <param name="destination"></param> public void RemoveEdges(T source, T destination) { if (source == null || destination == null) { throw new ArgumentException(); } if (!Vertices.ContainsKey(source) || !Vertices.ContainsKey(destination)) { throw new Exception("Source or destination is not in this graph."); } if (!Vertices[source].Edges.ContainsKey(Vertices[destination]) || !Vertices[destination].Edges.ContainsKey(Vertices[source])) { throw new Exception("Edge does not exist."); } Vertices[source].Edges.Remove(Vertices[destination]); Vertices[destination].Edges.Remove(Vertices[source]); }
/// <summary> /// remove the given edge from this graph /// O(1) complexity /// </summary> /// <param name="source"></param> /// <param name="dest"></param> public void RemoveEdge(T source, T dest) { if (source == null || dest == null) { throw new ArgumentException(); } if (!Vertices.ContainsKey(source) || !Vertices.ContainsKey(dest)) { throw new Exception("Source or Destination Vertex is not in this graph."); } if (!Vertices[source].OutEdges.ContainsKey(Vertices[dest]) || !Vertices[dest].InEdges.ContainsKey(Vertices[source])) { throw new Exception("Edge do not exist."); } Vertices[source].OutEdges.Remove(Vertices[dest]); Vertices[dest].InEdges.Remove(Vertices[source]); }
public void AddEdge(long id1, long id2, int weight) { Vertex <T> vertex1; if (Vertices.ContainsKey(id1)) { vertex1 = Vertices[id1]; } else { vertex1 = new Vertex <T>(id1); Vertices.Add(id1, vertex1); } Vertex <T> vertex2; if (Vertices.ContainsKey(id2)) { vertex2 = Vertices[id2]; } else { vertex2 = new Vertex <T>(id2); Vertices.Add(id2, vertex2); } Edge <T> edge = new Edge <T>(vertex1, vertex2, IsDirected, weight); Edges.Add(edge); vertex1.AddAdjacentVertex(edge, vertex2); if (!IsDirected) { vertex2.AddAdjacentVertex(edge, vertex1); } }
public bool Contains(Vertex <TData, TMetric> vertex) { return(Vertices.ContainsKey(vertex)); }
public bool HasVertex(V vertex) { return(Vertices.ContainsKey(vertex)); }
public void AfterRun(IPexPathComponent host, object data) { MessageBox.Show("AfterRun"); // Getting the executions nodes in the current path var nodesInPath = host.PathServices.CurrentExecutionNodeProvider.ReversedNodes.Reverse().ToArray(); // Getting the sequence id of the current run var runId = host.ExplorationServices.Driver.Runs; // Iterating over the nodes in the path foreach (var node in nodesInPath) { var vertex = new CFGNode(node.UniqueIndex, false); // Adding the method name this early in order to color edges string methodName = null; int offset = 0; if (node.CodeLocation.Method == null) { if (node.InCodeBranch.Method != null) { methodName = node.InCodeBranch.Method.FullName; } } else { methodName = node.CodeLocation.Method.FullName; offset = node.CodeLocation.Offset; } // Setting the method name vertex.MethodName = methodName; // Setting the offset vertex.ILOffset = (uint)offset; var nodeIndex = nodesInPath.ToList().IndexOf(node); if (nodeIndex > 0) { var prevNode = nodesInPath [nodeIndex - 1]; // If there is no edge between the previous and the current node if (!(Edges.ContainsKey(prevNode.UniqueIndex) && Edges [prevNode.UniqueIndex].ContainsKey(node.UniqueIndex))) { var prevVertex = Vertices [prevNode.UniqueIndex]; var edge = new CFGEdge(new Random().Next(), prevVertex, vertex); Dictionary <int, CFGEdge> outEdges = null; if (Edges.TryGetValue(prevNode.UniqueIndex, out outEdges)) { outEdges.Add(node.UniqueIndex, edge); } else { Edges.Add(prevNode.UniqueIndex, new Dictionary <int, CFGEdge>()); Edges [prevNode.UniqueIndex].Add(node.UniqueIndex, edge); } // Edge coloring based on unit border detection if (UnitNamespace != null) { // Checking if pointing into the unit from outside if (!(prevVertex.MethodName.StartsWith(UnitNamespace + ".") || prevVertex.MethodName.Equals(UnitNamespace)) && (vertex.MethodName.StartsWith(UnitNamespace + ".") || vertex.MethodName.Equals(UnitNamespace))) { edge.Color = CFGEdge.EdgeColor.Green; } // Checking if pointing outside the unit from inside if ((prevVertex.MethodName.StartsWith(UnitNamespace + ".") || prevVertex.MethodName.Equals(UnitNamespace)) && !(vertex.MethodName.StartsWith(UnitNamespace + ".") || vertex.MethodName.Equals(UnitNamespace))) { edge.Color = CFGEdge.EdgeColor.Red; } } } } // If the node is new then it is added to the list and the metadata is filled if (!Vertices.ContainsKey(node.UniqueIndex)) { Vertices.Add(node.UniqueIndex, vertex); // Adding source code mapping vertex.SourceCodeMappingString = MapToSourceCodeLocationString(host, node); // Setting the border based on mapping existence vertex.Border = vertex.SourceCodeMappingString == null ? CFGNode.NodeBorder.Single : CFGNode.NodeBorder.Double; // Setting the color if (nodesInPath.LastOrDefault() == node) { if (!EmittedTestResult.ContainsKey(runId)) { vertex.Color = CFGNode.NodeColor.Orange; } else { if (EmittedTestResult [runId].Item1) { vertex.Color = CFGNode.NodeColor.Red; } else { vertex.Color = CFGNode.NodeColor.Green; } vertex.GenerateTestCode = EmittedTestResult [runId].Item2; } } else { vertex.Color = CFGNode.NodeColor.White; } // Setting the default shape vertex.Shape = CFGNode.NodeShape.Rectangle; // Adding path condition tasks and getting the required services TermEmitter termEmitter = new TermEmitter(host.GetService <TermManager>()); SafeStringWriter safeStringWriter = new SafeStringWriter(); IMethodBodyWriter methodBodyWriter = host.GetService <IPexTestManager>().Language.CreateBodyWriter(safeStringWriter, VisibilityContext.Private, 2000); PrettyPathConditionTasks.Add(vertex.Id, PrettyPrintPathCondition(termEmitter, methodBodyWriter, safeStringWriter, node)); // Setting the status vertex.Status = node.ExhaustedReason.ToString(); // Collecting the parent nodes for the later incremental path condition calculation if (nodeIndex > 0) { ParentNodes.Add(vertex.Id, nodesInPath [nodeIndex - 1].UniqueIndex); } } // Adding the Id of the run Vertices [node.UniqueIndex].Runs += (runId + ";"); } }
public bool ContainsVertex(T value) { return(Vertices.ContainsKey(value)); }