public static bool SetActiveEdge(FlowEdge edge) { bool ret = !ActiveEdge?.Equals(edge) ?? edge != null; ActiveEdge = edge; return(ret); }
protected override void OnBeforePathStepExtended(FlowEdge edge) { this.smtSolver.Push(); this.Heap.PushState(); if (edge is OuterFlowEdge outerEdge) { if (outerEdge.Kind == OuterFlowEdgeKind.MethodCall && outerEdge.To is EnterFlowNode enterNode) { var callNode = (CallFlowNode)outerEdge.From; if (callNode.IsObjectCreation) { // This is needed in the case when the exploration itself started from a constructor (or from a // method called by it). We need to let the heap know that this object is not a part of the input // heap. var newVar = enterNode.Parameters[0]; var versionedVar = new VersionedVariable(newVar, this.GetVariableVersion(newVar)); this.Heap.AllocateNew(versionedVar); } else if (callNode.IsInstanceCall) { var thisVar = enterNode.Parameters[0]; var versionedThisVar = new VersionedVariable(thisVar, this.GetVariableVersion(thisVar)); this.Heap.AssertEquality(false, versionedThisVar, VersionedVariable.Null); } } } }
private void Push(FlowEdge edge, int v, int other) { double flow = Math.Min(edge.ResidualCapacityTo(other), excess[v]); excess[v] -= flow; excess[other] += flow; edge.AddFlow(flow, other); }
public void addEdge(FlowEdge e) { int from = e.from(); int to = e.to(); flowGraph[from].Add(new FlowEdge(e)); flowGraph[to].Add(new FlowEdge(e)); edgeCount++; }
private void AddFlowEdge(int from, int to, double cap) { FlowEdge e1 = new FlowEdge(from, to, cap, 0); FlowEdge e2 = new FlowEdge(to, from, 0, 0); nodes[from].Add(fEdges.Count); fEdges.Add(e1); nodes[to].Add(fEdges.Count); fEdges.Add(e2); }
private bool IsSpecialEdge(FlowEdge e) { if (2 * delta <= e.ResidualCapacityTo(e.To) && e.ResidualCapacityTo(e.To) < 3 * delta && dist[e.To] == dist[e.From] && e.ResidualCapacityTo(e.From) >= 3 * delta) { return(true); } else { return(false); } }
private int BinaryLength(FlowEdge e) { if (IsSpecialEdge(e) || e.ResidualCapacityTo(e.To) >= (3 * delta)) { return(0); } else { return(1); } }
public void AddEdge(FlowEdge e) { int v = e.From; int w = e.To; ValidateVertex(v); ValidateVertex(w); _adj[v].Add(e); _adj[w].Add(e); E++; }
public void AddEdge(GUIVertex start, GUIVertex end, FlowEdge fe) { GUIFlowEdge edge = new GUIFlowEdge(start, end, fe); edge.Brush = GUIEdge.DefaultBrush; edge.LineWidth = GUIEdge.DefaultLineWidth; edges.Add(edge); selectables.Add(edge); Refresh(); }
private bool IsEdgeAllowed(FlowEdge edge) { var ignoredMethods = this.context.Options.IgnoredMethods; if (ignoredMethods.Length > 0 && edge is OuterFlowEdge) { var extensionGraphId = edge.From.Graph.Id; var extensionGraphLocation = this.context.FlowGraphProvider.GetLocation(extensionGraphId); return(!ignoredMethods.Any(m => extensionGraphLocation.ToString().EndsWith(m))); } return(true); }
public AnimationType Type; //Тип анимации //Тип object используется для возможности анимации не только рёбер, но и вершин public Animation(object obj, AnimationType type) { Type = type; if (Type == AnimationType.EdgeFlowChanged || Type == AnimationType.EdgeMarked || Type == AnimationType.EdgeUnmarked) { //Проверка соответствия типа анимации классу переданого объекта if (!(obj is FlowEdge)) { throw new InvalidConfigurationException("This types requires FLowEdge object"); } //Edge = new FlowEdge((FlowEdge) obj); Edge = (FlowEdge)obj; } }
private DependencyFlowEdge ToDependencyFlowEdge( FlowEdge flowEdge, IReadOnlyDictionary <string, DependencyFlowNode> nodesById, IReadOnlyDictionary <Guid, Subscription> subscriptionsById) { var fromNode = nodesById[flowEdge.FromId]; var toNode = nodesById[flowEdge.ToId]; var subscription = subscriptionsById[flowEdge.SubscriptionId]; return(new DependencyFlowEdge(fromNode, toNode, subscription) { BackEdge = flowEdge.BackEdge, IsToolingOnly = flowEdge.IsToolingOnly, OnLongestBuildPath = flowEdge.OnLongestBuildPath, PartOfCycle = flowEdge.PartOfCycle }); }
protected override void OnBeforePathStepRetracted(FlowEdge edge) { this.Nodes.Add(edge.From); this.areAssignmentsPostponedToNextNode = edge is OuterFlowEdge; // Swap the next node interpretations with the emptied stack of the current one making it ready for the // current node var hlpInt = this.currentNodeInterpretations; this.currentNodeInterpretations = this.nextNodeInterpretations; this.nextNodeInterpretations = hlpInt; // Do the same in the case of reference models var hlpRef = this.currentNodeHeapLocations; this.currentNodeHeapLocations = this.nextNodeHeapLocations; this.nextNodeHeapLocations = hlpRef; }
public void End(GraphApp app, GraphAppGUI appGUI, Point p) { if (!HasBegun) { return; } GraphPanel gp = appGUI.CurrentGraphPanel; List <GUIVertex> verts = gp.Vertices; bool foundVert = false; foreach (GUIVertex v in verts) { if (GeometryHelper.Intersects(p, new Circle(v.Pos, v.Radius))) { endVert = v; Console.WriteLine("Edge tool ended on vertex " + v.Vertex.Label); foundVert = true; //Add vertex if (isFlowNetwork) { FlowEdge fe = app.AddFlowEdge(startVert.Vertex, endVert.Vertex); gp.AddEdge(startVert, endVert, fe); } else { //Change to add two edges, for both directions Edge e = app.AddEdge(startVert.Vertex, endVert.Vertex); gp.AddEdge(startVert, endVert, e); } break; } } HasBegun = false; if (!foundVert) { startVert = null; endVert = null; return; } }
protected override void OnAfterPathStepRetracted(FlowEdge edge) { // Identify the creation of new objects on the heap if (edge is OuterFlowEdge outerEdge && outerEdge.Kind == OuterFlowEdgeKind.MethodCall && outerEdge.From is CallFlowNode callNode && callNode.IsObjectCreation) { // "this" must be the first variable in the constructor by convention var thisVar = edge.To.Graph.LocalVariables[0]; Contract.Assert(thisVar.IsReference); var versionedVar = new VersionedVariable(thisVar, this.GetVariableVersion(thisVar)); this.heapModelRecorder.AllocateNew(versionedVar); } this.AddNodeValues(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); //string str = @"tiny.txt"; //List<int>[] G = IOOperations.ReadGraph(str); ///* reverse Graph */ //List<int>[] GT = GraphHelper.ReverseGraph(G); //Kosaraju ks = new Kosaraju(); ////ks.Run(G, GT, G.Length); //ks.Kosaraju_BFSRun(G, GT, G.Length); //ks.PrintComponents(); //int[] VertexKey = {5, 4, 3, 2, 1}; //int[] VertexElements = {0, 1, 2, 3, 4}; //IndexedPriorityQueue<int, int> pQ = new IndexedPriorityQueue<int, int>(VertexElements, VertexKey); //pQ.Decrease_Key(0, -1); //while (pQ.Count > 0) //{ // Console.WriteLine(pQ.Minimum()); // pQ.Extract_Minimum(); //} /* * string str = @"spath.txt"; * AdjacencyList adjList = IOOperations.ReadAdjacencyGraph(str); * Dijkstra ds = new Dijkstra(adjList, 0); * ds.Run(); * for (int i = 1; i < 8; ++i) * Console.WriteLine(ds.DistanceTo(i)); */ List <FlowEdge> fdgList = new List <FlowEdge>(); FlowEdge a = new FlowEdge(0, 1, 10); fdgList.Add(a); FlowEdge[] fdgarr = new FlowEdge[10]; fdgarr[5] = fdgList[0]; fdgarr[5].a = 5; fdgarr[5].addResidualFlowTo(5, 4); Console.WriteLine(fdgList[0].ToString()); }
private void Push(FlowEdge e, int from) { //вычислляем максимальный объем потока, который можно протолкнуть через ребро var f = Math.Min(excess[from], e.ResidualCapacityTo(e.Other(from))); //если ребро допустимо if (height[from] == height[e.Other(from)] + 1 && f > 0) { //проталкиваем поток в ребро e.AddFlow(f, e.Other(from)); //обновляем избыток в узлах ребра excess[e.Other(from)] += f; excess[from] -= f; //добавляем в Bucket узел, в сторону которого протолкнули поток if (e.Other(from) != graph.Source) { Enq(e.Other(from)); } } }
static void CopyFlowEdges(Data copyData, IEnumerable <VFXFlowEdgeController> flowEdges, ScriptableObject[] allSerializedObjects) { copyData.flowEdges = new FlowEdge[flowEdges.Count()]; int cpt = 0; foreach (var edge in flowEdges) { FlowEdge copyPasteEdge = new FlowEdge(); var inputController = edge.input as VFXFlowAnchorController; var outputController = edge.output as VFXFlowAnchorController; copyPasteEdge.input.contextIndex = System.Array.IndexOf(allSerializedObjects, inputController.owner); copyPasteEdge.input.flowIndex = inputController.slotIndex; copyPasteEdge.output.contextIndex = System.Array.IndexOf(allSerializedObjects, outputController.owner); copyPasteEdge.output.flowIndex = outputController.slotIndex; copyData.flowEdges[cpt++] = copyPasteEdge; } }
void CopyFlowEdges(ref SerializableGraph serializableGraph, IEnumerable <VFXFlowEdgeController> flowEdges) { serializableGraph.flowEdges = new FlowEdge[flowEdges.Count()]; int cpt = 0; foreach (var edge in flowEdges) { FlowEdge copyPasteEdge = new FlowEdge(); var inputController = edge.input as VFXFlowAnchorController; var outputController = edge.output as VFXFlowAnchorController; copyPasteEdge.input.contextIndex = modelIndices[inputController.context]; copyPasteEdge.input.flowIndex = inputController.slotIndex; copyPasteEdge.output.contextIndex = modelIndices[outputController.context]; copyPasteEdge.output.flowIndex = outputController.slotIndex; serializableGraph.flowEdges[cpt++] = copyPasteEdge; } }
private double DFS(ref FlowNetwork graph, ref List <FlowEdge> path, int[] ptr, int dest, int u, double f) { if (u == dest) { return(f); } for (; ptr[u] < graph.Nodes[u].OutcomingEdges.Count(); ++ptr[u]) { FlowEdge e = graph.Nodes[u].OutcomingEdges[ptr[u]]; if (e.Flow < e.Capacity) { double df = DFS(ref graph, ref path, ptr, dest, e.To, Math.Min(f, e.Capacity - e.Flow)); if (df > 0) { path.Add(e); return(df); } } } return(0); }
/**//**/ public static void main(string[] strarr) { int num = Integer.parseInt(strarr[0]); int num2 = Integer.parseInt(strarr[1]); int i = 2 * num; int i2 = 2 * num + 1; FlowNetwork flowNetwork = new FlowNetwork(2 * num + 2); for (int j = 0; j < num2; j++) { int k = StdRandom.uniform(num); int num3 = StdRandom.uniform(num) + num; flowNetwork.addEdge(new FlowEdge(k, num3, double.PositiveInfinity)); StdOut.println(new StringBuilder().append(k).append("-").append(num3).toString()); } for (int j = 0; j < num; j++) { flowNetwork.addEdge(new FlowEdge(i, j, (double)1f)); flowNetwork.addEdge(new FlowEdge(j + num, i2, (double)1f)); } FordFulkerson fordFulkerson = new FordFulkerson(flowNetwork, i, i2); StdOut.println(); StdOut.println(new StringBuilder().append("Size of maximum matching = ").append(ByteCodeHelper.d2i(fordFulkerson.value())).toString()); for (int k = 0; k < num; k++) { Iterator iterator = flowNetwork.adj(k).iterator(); while (iterator.hasNext()) { FlowEdge flowEdge = (FlowEdge)iterator.next(); if (flowEdge.from() == k && flowEdge.flow() > (double)0f) { StdOut.println(new StringBuilder().append(flowEdge.from()).append("-").append(flowEdge.to()).toString()); } } } }
private void pbDraw_MouseMove(object sender, MouseEventArgs e) { bool needInvalidate = false; if (RuntimeManipulations.CreatingEdgeFromNode != -1) { needInvalidate = true; } RuntimeManipulations.CanvasCursorPosition = e.Location; #region Pan if (e.Button == MouseButtons.Middle) { changeCanvasOffset(e); return; } RuntimeManipulations.LastPanPosition = new Point(); #endregion #region Hover if (Runtime.EditionEnabled) { FlowNode hoverNode = null; FlowEdge hoverEdge = null; if (e.Button == MouseButtons.Left && RuntimeManipulations.ActiveNode != null) { RuntimeManipulations.ActiveNode.Position = Visualizer.TranslateScreenToAbsolutePoint(e.X, e.Y); needInvalidate = true; } else { hoverNode = RuntimeManipulations.GetHoverNode(e); if (hoverNode != null) { Cursor = Cursors.Hand; } else { hoverEdge = RuntimeManipulations.GetHoverEdge(e); if (hoverEdge != null) { Cursor = Cursors.Hand; } else { Cursor = Cursors.Default; } } if (RuntimeManipulations.SetActiveNode(hoverNode)) { needInvalidate = true; } if (RuntimeManipulations.SetActiveEdge(hoverEdge)) { needInvalidate = true; } } } #endregion if (needInvalidate) { pbDraw.Invalidate(); } }
public FlowEdge(FlowEdge e) : this(e.From, e.To, e.Capacity, e.Flow) { }
public GUIFlowEdge(GUIVertex start, GUIVertex end, FlowEdge fe) : base(start, end, fe) { this.fe = fe; }
private static CallSiteStack GetNewCallSiteStack(ExplorationState currentState, FlowEdge edge) { CallSiteStack callSiteStack; if (edge.From is ReturnFlowNode) { Contract.Assert(edge is OuterFlowEdge); Contract.Assert(((OuterFlowEdge)edge).Kind == OuterFlowEdgeKind.Return); callSiteStack = currentState.CallSiteStack.Push((CallFlowNode)edge.To); } else if (edge.To is EnterFlowNode) { Contract.Assert(edge is OuterFlowEdge); Contract.Assert(((OuterFlowEdge)edge).Kind == OuterFlowEdgeKind.MethodCall); callSiteStack = currentState.CallSiteStack.IsEmpty ? currentState.CallSiteStack : currentState.CallSiteStack.Pop(); } else { callSiteStack = currentState.CallSiteStack; } return(callSiteStack); }
private FlowNetwork ContractZeroLengthSCC(out List <List <int> > scc) { int[] ids = new int[graph.NodeCount]; int[] lowLinks = new int[graph.NodeCount]; var admissible_edges = new List <FlowEdge>(); foreach (var edge in graph.Edges) { if (dist[edge.From] == dist[edge.To] + BinaryLength(edge))//length[edge]) //admissible edge { admissible_edges.Add(edge); } } scc = new List <List <int> >(); var stack = new Stack <int>(); var sorted_nodes = TopologicalSort(admissible_edges); // поиск сильно связанных компонентов int id = 0; foreach (var node in sorted_nodes) { if (ids[node] == 0) { SCC(node, id, ref stack, ref scc, ref ids, ref lowLinks); } } // устанавливаем пропускные способности ребер связанных компонентов var contracted_admissible_edges = new List <FlowEdge>(); foreach (var edge in admissible_edges) { string res = "00"; foreach (var contracted in scc.Where((list) => list.Count() > 1)) { res = $"{(contracted.Contains(edge.From) ? 1 : 0)}{(contracted.Contains(edge.To) ? 1 : 0)}"; switch (res) { //case "00": contracted_admissible_edges.Add(edge); break; case "01": var e = new FlowEdge(edge.From, contracted.First(), edge.ResidualCapacityTo(edge.To)); var idx = contracted_admissible_edges.IndexOf(e); if (idx == -1) { contracted_admissible_edges.Add(e); } else { contracted_admissible_edges[idx].Capacity += edge.ResidualCapacityTo(edge.To); } break; case "10": e = new FlowEdge(contracted.First(), edge.To, edge.ResidualCapacityTo(edge.To)); idx = contracted_admissible_edges.IndexOf(e); if (idx == -1) { contracted_admissible_edges.Add(e); } else { contracted_admissible_edges[idx].Capacity += edge.ResidualCapacityTo(edge.To); } break; } } if (String.Equals(res, "00")) { contracted_admissible_edges.Add(new FlowEdge(edge)); } } // создаем граф var contracted_graph = new FlowNetwork(contracted_admissible_edges); contracted_graph.Source = graph.Source; contracted_graph.Target = graph.Target; return(contracted_graph); }
public void EdgeFlowChanged(BaseMaxFlowAlgorithm algorithm, FlowNetwork network, FlowEdge edge) { AddAnimation(new Animation(edge, AnimationType.EdgeFlowChanged)); }