private void ConfigureGraph(RetiredColonyData.RetiredColonyStatistic statistic, GameObject layoutBlockGameObject) { GameObject gameObject = Util.KInstantiateUI(lineGraphPrefab, layoutBlockGameObject, true); activeColonyWidgets.Add(statistic.name, gameObject); GraphBase componentInChildren = gameObject.GetComponentInChildren <GraphBase>(); componentInChildren.graphName = statistic.name; componentInChildren.label_title.SetText(componentInChildren.graphName); componentInChildren.axis_x.name = statistic.nameX; componentInChildren.axis_y.name = statistic.nameY; componentInChildren.label_x.SetText(componentInChildren.axis_x.name); componentInChildren.label_y.SetText(componentInChildren.axis_y.name); LineLayer componentInChildren2 = gameObject.GetComponentInChildren <LineLayer>(); componentInChildren.axis_y.min_value = 0f; componentInChildren.axis_y.max_value = statistic.GetByMaxValue().second * 1.2f; componentInChildren.axis_x.min_value = 0f; componentInChildren.axis_x.max_value = statistic.GetByMaxKey().first; componentInChildren.axis_x.guide_frequency = (componentInChildren.axis_x.max_value - componentInChildren.axis_x.min_value) / 10f; componentInChildren.axis_y.guide_frequency = (componentInChildren.axis_y.max_value - componentInChildren.axis_y.min_value) / 10f; componentInChildren.RefreshGuides(); Tuple <float, float>[] value = statistic.value; GraphedLine graphedLine = componentInChildren2.NewLine(value, statistic.id); if (statColors.ContainsKey(statistic.id)) { componentInChildren2.line_formatting[componentInChildren2.line_formatting.Length - 1].color = statColors[statistic.id]; } graphedLine.line_renderer.color = componentInChildren2.line_formatting[componentInChildren2.line_formatting.Length - 1].color; }
public void RemoveVertex_ShouldThrowKeyNotFoundException_WhenKeyDoesNotExist(GraphBase <int> graph) { Assert.Throws <KeyNotFoundException>(() => { graph.RemoveVertex(1); }); }
/// <summary> /// Creates a new edge difference calculator. /// </summary> /// <param name="data"></param> /// <param name="witnessCalculator"></param> public EdgeDifferenceContractedSearchSpace(GraphBase <CHEdgeData> data, INodeWitnessCalculator witnessCalculator) { _data = data; _witnessCalculator = witnessCalculator; _contractionCount = new Dictionary <uint, int>(); _depth = new Dictionary <long, int>(); }
public void AddVertex_ShouldAddVertex_WhenUniqueKeySpecified(GraphBase <int> graph) { graph.AddVertex(0); Assert.Contains(0, graph.AdjacencyLists); Assert.Empty(graph.AdjacencyLists[0]); }
private void btnOpenData_Click(object sender, RoutedEventArgs e) { try { drawingPad.Children.Clear(); lstPoint.Clear(); dataset = null; OpenFileDialog openDlg = new OpenFileDialog(); openDlg.ShowDialog(); dataset = Dataset.Read(openDlg.FileName); datasetName = openDlg.FileName; switch (cbFunction.SelectedItem.ToString()) { case "Spectral Graph for GB-S3VDD": case "Spectral Graph": case "Clustering": lstPoint = dataset.Data.ToList(); graph = new GraphBase(dataset, double.Parse(txtXichma.Text), int.Parse(txtK.Text)); graph.myCanvas = drawingPad; graph.DrawDataset(); break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public static PathStats ShortestPath(GraphBase g, int s) { #region Initialization var ps = new PathStats(g.V); for (int i = 0; i < ps.Dist.Length; i++) { ps.Dist[i] = int.MaxValue; ps.Prev[i] = -1; } ps.Dist[s] = 0; #endregion for (int i = 0; i < g.V - 1; i++)//run |V|-1 times { for (var u = g.V - 1; u >= 0; u--)//'S' starts first, earlier to get finall status { foreach (var e in g.Adjacent(u)) { if (ps.Dist[u] == int.MaxValue)//if distance of u hasn't ever be udpated, skip break; if (ps.Dist[e.V2] > ps.Dist[e.V1] + e.Weight) { ps.Dist[e.V2] = ps.Dist[e.V1] + e.Weight; ps.Prev[e.V2] = u; } } } } return ps; }
/// <summary> /// Creates a new edge difference calculator. /// </summary> /// <param name="data"></param> /// <param name="witnessCalculator"></param> public EdgeDifferenceContractedSearchSpace(GraphBase<CHEdgeData> data, INodeWitnessCalculator witnessCalculator) { _data = data; _witnessCalculator = witnessCalculator; _contractionCount = new Dictionary<uint, int>(); _depth = new Dictionary<long, int>(); }
public NodeParseResult(GraphBase element, List <GraphObject> objects, List <GraphRelation> relations, List <GraphCluster> clusters) { Element = element; Objects = objects; Relations = relations; Clusters = clusters; }
/// <summary> /// Creates a new preprocessor. /// </summary> public DefaultPreprocessor(GraphBase <CHEdgeData> graph) { var witnessCalculator = new DykstraWitnessCalculator(); var edgeDifference = new EdgeDifferenceContractedSearchSpace(graph, witnessCalculator); _preprocessor = new CHPreprocessor(graph, edgeDifference, witnessCalculator); }
/// <summary> /// Initializes a new instance of the <see cref="TopologicalSorter<TVertex, TEdge>"/> class. /// </summary> /// <param name="graphToCrawl">The directed graph to crawl.</param> /// <param name="directionMeansOrder">If set to true, a directed edge from A to B is interpreted as the order in which A and B should be done, i.e. first A /// then B. When false is passed (default) the edge from A to B is interpreted as A is depending on B and therefore B should be done before A.</param> public TopologicalSorter(GraphBase <TVertex, TEdge> graphToCrawl, bool directionMeansOrder) : base(graphToCrawl, true) { ArgumentVerifier.CantBeNull(graphToCrawl, "graphToCrawl"); ArgumentVerifier.ShouldBeTrue(g => g.IsDirected, graphToCrawl, "graphToCrawl has to be a directed graph"); this.SortResults = new List <TVertex>(); this.SeeCycleCreatingEdgesAsNonExistend = false; _directionMeansOrder = directionMeansOrder; }
public void CyclesDetector_ShouldDetermineWhetherGraphContainsAnyCycle(GraphBase <int> graph, int initialVertex, bool expectedResult) { var cyclesDetector = new CyclesDetector <GraphBase <int>, int>(); var result = cyclesDetector.Execute(graph, initialVertex); Assert.Equal(expectedResult, result); }
public override void OnValidate(GraphBase flowGraph) { base.OnValidate(flowGraph); if (!string.IsNullOrEmpty(_luaFileRelaPath)) { _luaFileName = System.IO.Path.GetFileNameWithoutExtension(_luaFileRelaPath); } }
/// <summary> /// Initializes a new instance of the <see cref="SubGraphView<TVertex, TEdge>"/> class. /// </summary> /// <param name="mainGraph">The main graph this SubGraphView is a view on.</param> /// <param name="isCommandified">If set to true, the SubGraphView is a commandified SubGraphView, which means all actions taken on this SubGraphView /// which mutate its state are undoable.</param> public SubGraphView(GraphBase <TVertex, TEdge> mainGraph, bool isCommandified) { ArgumentVerifier.CantBeNull(mainGraph, "mainGraph"); _isCommandified = isCommandified; _vertices = new HashSet <TVertex>(); _edges = new HashSet <TEdge>(); this.MainGraph = mainGraph; BindEvents(); }
/// <summary> /// CTor /// </summary> /// <param name="toCrawl"></param> public RootDetector(GraphBase <TVertex, TEdge> toCrawl) : base(toCrawl, false) { if (toCrawl.IsDirected) { throw new InvalidOperationException("This algorithm can't be used on a directed graph"); } _rootsFound = new HashSet <TVertex>(); }
public void AddVertex_ShouldThrowArgumentException_WhenDuplicateKeySpecified(GraphBase <int> graph) { graph.AddVertex(0); graph.AddVertex(1); Assert.Throws <ArgumentException>(() => { graph.AddVertex(1); }); }
/// <summary> /// Returns true if the given vertex has a witness calculator. /// </summary> /// <param name="graph"></param> /// <param name="from"></param> /// <param name="to"></param> /// <param name="maxWeight"></param> /// <param name="maxSettles"></param> /// <param name="toSkip"></param> /// <returns></returns> public bool Exists(GraphBase<CHEdgeData> graph, uint from, uint to, float maxWeight, int maxSettles, uint toSkip) { var tos = new List<uint>(1); tos.Add(to); var tosWeights = new List<float>(1); tosWeights.Add(maxWeight); var forwardExists = new bool[1]; var backwardExists = new bool[1]; this.Exists(graph, from, tos, tosWeights, maxSettles, ref forwardExists, ref backwardExists, toSkip); return forwardExists[0]; }
private void graph_UserChangedViewport(GraphBase graph, bool xChanged, bool yChanged) { if (yChanged == true) { SetVerticalAutoscaleIndex(-1, true); } if (xChanged == true) { SetHorizontalAutoscaleIndex(-1, true); } }
private void DrawGraphLine(IGUIContext ctx, GraphBase graph, RectangleF bounds) { PointF PPaint; PointF PPaintLast = new PointF(); Pen pen = null; bool PlotFlag = true; float offsetX = bounds.X; float offsetY = bounds.Y; try { //pen = new Pen(graph.GraphColor); pen = new Pen(Color.FromArgb(200, Theme.Colors.Blue)); pen.Width = DefaultCurveWidth; bool bFirstPoint = true; foreach (GraphPoint gp in Graph.Points) { if (bFirstPoint) { bFirstPoint = false; PPaintLast = Point2Client((double)gp.X, (double)gp.Y, bounds); continue; } //double x = Client2PointX(i, Bounds); //double y = (double)graph.FX(x); //double y = Client2PointY(i, Bounds); PPaint = Point2Client((double)gp.X, (double)gp.Y, bounds); if (PlotFlag && (PPaint.Y >= 0 || PPaintLast.Y >= 0) && (PPaint.Y <= Bounds.Height || PPaintLast.Y <= bounds.Height)) { try { ctx.DrawLine(pen, PPaintLast.X + offsetX, PPaintLast.Y + offsetY, PPaint.X + offsetX, PPaint.Y + offsetY); } catch { } } PPaintLast = PPaint; PlotFlag = true; } } catch (Exception ex) { ex.LogError(); } finally { pen.Dispose(); } }
private void btnDraw_Click(object sender, RoutedEventArgs e) { switch (cbFunction.SelectedItem.ToString()) { case "Spectral Graph for GB-S3VDD": //Draw Visual Spectral Graph for GB-S3VDD //Clear old Edge for (int i = 0; i < drawingPad.Children.Count; ++i) { string obj = drawingPad.Children[i].ToString(); if (obj.IndexOf("Line") != -1) { drawingPad.Children.RemoveAt(i); i--; } } dataset = new Dataset(lstPoint.ToArray()); graph = new GraphBase(dataset, double.Parse(txtXichma.Text), int.Parse(txtK.Text)); graph.myCanvas = drawingPad; graph.DrawSG_for_GBS3VDD(); tbStatus.Text = "Visual Spectral Graph for GB-S3VDD (with k = " + txtK.Text + " & σ = " + txtXichma.Text + ") completed !"; break; case "Spectral Graph": //Draw Visual spectral graph //Clear old Edge for (int i = 0; i < drawingPad.Children.Count; ++i) { string obj = drawingPad.Children[i].ToString(); if (obj.IndexOf("Line") != -1) { drawingPad.Children.RemoveAt(i); i--; } } dataset = new Dataset(lstPoint.ToArray()); graph = new GraphBase(dataset, double.Parse(txtXichma.Text), int.Parse(txtK.Text)); graph.myCanvas = drawingPad; graph.DrawVSG(); tbStatus.Text = "Visual Spectral Graph (with k = " + txtK.Text + " & σ = " + txtXichma.Text + ") completed !"; break; } }
/// <summary> /// Returns true if the given vertex has a witness calculator. /// </summary> /// <param name="graph"></param> /// <param name="from"></param> /// <param name="to"></param> /// <param name="maxWeight"></param> /// <param name="maxSettles"></param> /// <param name="toSkip"></param> /// <returns></returns> public bool Exists(GraphBase <CHEdgeData> graph, uint from, uint to, float maxWeight, int maxSettles, uint toSkip) { var tos = new List <uint>(1); tos.Add(to); var tosWeights = new List <float>(1); tosWeights.Add(maxWeight); var forwardExists = new bool[1]; var backwardExists = new bool[1]; this.Exists(graph, from, tos, tosWeights, maxSettles, ref forwardExists, ref backwardExists, toSkip); return(forwardExists[0]); }
/// <summary> /// Calculates witnesses from one source to multiple targets at once but using only one hop. /// </summary> /// <param name="graph"></param> /// <param name="from"></param> /// <param name="tos"></param> /// <param name="tosWeights"></param> /// <param name="maxSettles"></param> /// <param name="forwardExists"></param> /// <param name="backwardExists"></param> private void ExistsOneHop(GraphBase <CHEdgeData> graph, uint from, List <uint> tos, List <float> tosWeights, int maxSettles, ref bool[] forwardExists, ref bool[] backwardExists) { var toSet = new HashSet <uint>(); float maxWeight = 0; for (int idx = 0; idx < tosWeights.Count; idx++) { if (!forwardExists[idx] || !backwardExists[idx]) { toSet.Add(tos[idx]); if (maxWeight < tosWeights[idx]) { maxWeight = tosWeights[idx]; } } } if (toSet.Count > 0) { var neighbours = graph.GetEdges(from); while (neighbours.MoveNext()) { if (toSet.Contains(neighbours.Neighbour)) { // ok, this is a to-edge. int index = tos.IndexOf(neighbours.Neighbour); toSet.Remove(neighbours.Neighbour); var edgeData = neighbours.EdgeData; if (edgeData.CanMoveForward && edgeData.Weight < tosWeights[index]) { forwardExists[index] = true; } if (edgeData.CanMoveBackward && edgeData.Weight < tosWeights[index]) { backwardExists[index] = true; } if (toSet.Count == 0) { break; } } } } }
private void CreateGraphEditor(AStarData.GraphType type, GraphBase graphObj) { switch (type) { case AStarData.GraphType.GridGraph: { GridGraphEditor gridGraph = new GridGraphEditor(); gridGraph.targetGraph = graphObj; graphEditors.Add(graphObj.graphIndex, gridGraph); } break; default: break; } }
/// <summary> /// Creates a new pre-processor. /// </summary> /// <param name="target"></param> /// <param name="calculator"></param> /// <param name="witnessCalculator"></param> public CHPreprocessor(GraphBase<CHEdgeData> target, INodeWeightCalculator calculator, INodeWitnessCalculator witnessCalculator) { _target = target; _calculator = calculator; _witnessCalculator = witnessCalculator; _queue = new BinaryHeap<uint>(target.VertexCount + (uint)System.Math.Max(target.VertexCount * 0.1, 5)); _lowestPriorities = new float[target.VertexCount + (uint)System.Math.Max(target.VertexCount * 0.1, 5)]; for (int idx = 0; idx < _lowestPriorities.Length; idx++) { // uncontracted = priority != float.MinValue. _lowestPriorities[idx] = float.MaxValue; } }
/// <summary> /// Creates a new pre-processor. /// </summary> /// <param name="target"></param> /// <param name="calculator"></param> /// <param name="witnessCalculator"></param> public CHPreprocessor(GraphBase <CHEdgeData> target, INodeWeightCalculator calculator, INodeWitnessCalculator witnessCalculator) { _target = target; _calculator = calculator; _witnessCalculator = witnessCalculator; _queue = new BinaryHeap <uint>(target.VertexCount + (uint)System.Math.Max(target.VertexCount * 0.1, 5)); _lowestPriorities = new float[target.VertexCount + (uint)System.Math.Max(target.VertexCount * 0.1, 5)]; for (int idx = 0; idx < _lowestPriorities.Length; idx++) { // uncontracted = priority != float.MinValue. _lowestPriorities[idx] = float.MaxValue; } }
public static GraphBase TrianglesToGraph(IEnumerable <Triangle> triangles, RandomFunc rndFunc) { Dictionary <int, GraphNode> nodeMap = new Dictionary <int, GraphNode>(); List <GraphEdge> openEdges = new List <GraphEdge>(); int[] indices0 = new int[3]; int[] indices1 = new int[3]; foreach (Triangle triangle in triangles) { indices0[0] = triangle.v0; indices0[1] = triangle.v1; indices0[2] = triangle.v2; indices1[0] = triangle.v1; indices1[1] = triangle.v2; indices1[2] = triangle.v0; for (int i = 0; i < 3; i++) { int index0 = indices0[i]; int index1 = indices1[i]; nodeMap.TryGetValue(index0, out GraphNode node); if (node == null) { node = new GraphNode(index0); nodeMap[node.index] = node; } bool found = false; foreach (GraphEdge edge in openEdges) { if ((edge.from == index0 && edge.to == index1) || (edge.from == index1 && edge.to == index0)) { found = true; break; } } if (!found) { openEdges.Add(node.AddEdge(index0, index1, rndFunc())); } } } GraphBase graph = new GraphBase(); graph.nodes = nodeMap.Values.ToArray(); return(graph); }
public GraphMonitorPanelCompact(GraphBase graph, DataCollectorAdapter dataCollectorAdapter, HealthLevel healthLevel, PipPanel pipPanel, PipPanel pipPanelRight) { graph.PipPanel = pipPanel; graph.PipPanelRight = pipPanelRight; this.dataCollectorAdapter = dataCollectorAdapter; this.healthLevel = healthLevel; InitializeComponent(); var mainLayoutTable = new TableLayoutPanel(); mainLayoutTable.ColumnCount = 1; mainLayoutTable.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F)); mainLayoutTable.Dock = DockStyle.Fill; textPanel = new TextPanel(StringAlignment.Center); if (String.IsNullOrEmpty(dataCollectorAdapter.Name)) { mainLayoutTable.RowCount = 1; mainLayoutTable.RowStyles.Add(new RowStyle(SizeType.Percent, 100F)); } else { mainLayoutTable.RowCount = 2; mainLayoutTable.RowStyles.Add(new RowStyle(SizeType.Percent, 80F)); mainLayoutTable.RowStyles.Add(new RowStyle(SizeType.Percent, 20F)); textPanel.BackColor = ColorCoderUnknown.Instance.BackColor; textPanel.Dock = DockStyle.Fill; textPanel.ForeColor = Color.White; textPanel.Margin = new Padding(0, 2, 0, 0); textPanel.Text = dataCollectorAdapter.Name; mainLayoutTable.Controls.Add(textPanel, 0, 1); } this.graph = graph; this.graph.Dock = DockStyle.Fill; this.graph.BackColor = ColorCoderUnknown.Instance.BackColor; this.graph.ForeColor = ColorCoderUnknown.Instance.ForeColor1; this.graph.ForeColor2 = ColorCoderUnknown.Instance.ForeColor2; mainLayoutTable.Controls.Add(graph, 0, 0); Controls.Add(mainLayoutTable); worker = new Thread(RunWorker); }
public GraphMonitorPanel(GraphBase graph, DataCollectorAdapter dataCollectorAdapter, HealthLevel healthLevel) { this.dataCollectorAdapter = dataCollectorAdapter; this.healthLevel = healthLevel; InitializeComponent(); this.graph = graph; this.graph.Dock = DockStyle.Fill; this.graph.BackColor = ColorCoderUnknown.Instance.BackColor; this.graph.ForeColor = ColorCoderUnknown.Instance.ForeColor1; this.graph.ForeColor2 = ColorCoderUnknown.Instance.ForeColor2; mainLayoutTable.Controls.Add(this.graph, 0, 0); CounterName = dataCollectorAdapter.Name; Description = dataCollectorAdapter.Description; worker = new Thread(RunWorker); }
/// <summary> /// Breadth-first search on g with start vertice: s /// </summary> /// <param name="g">Graph for search</param> /// <param name="s">Start vertice</param> /// <returns>Breadth-first search results</returns> public static BfsStats BreadthFirstSearch(GraphBase g, int s) { var stats = new BfsStats(g.V); stats.Dist[s] = 0; var q = new Ds.Queue.Queue<int>(); q.Enqueue(s); while (!q.IsEmpty()) { var u = q.Dequeue(); foreach (var e in g.Adjacent(u)) { if (stats.Dist[e.V2] == int.MaxValue) { q.Enqueue(e.V2); stats.Dist[e.V2] = stats.Dist[u] + 1; } } } return stats; }
public void AddGraph(GraphBase graph, bool UseSameName) { GraphBase g = null; if (UseSameName) { foreach (string s in Graphs.Keys) { g = Graphs[s]; if (g.GraphDescription.ToUpper() == graph.GraphDescription.ToUpper()) { Graphs.Remove(s); break; } } } this.Graphs.Add(graph.Key, graph); Invalidate(); OnItemChanged(); }
public PlotterContainer(string name) : base(name, SplitOrientation.Vertical, -240f) { Plotter = new Graph2DPlotter("plotter"); Panel1.AddChild(Plotter); GRD = new DataGridView("dgv"); GRD.RowHeaderWidth = 0; GRD.AlternatingRowColor = Color.FromArgb(50, Theme.Colors.Cyan); Panel2.AddChild(GRD); Graphs = new GraphList(); GraphBase GB = new GraphBase(null, GRD); Graphs.Add(GB); GRD.SetDataProvider(GB); GB.OnDataLoaded(); Plotter.Graphs = Graphs; Plotter.Graph = GB; GB.GraphColor = Theme.Colors.Orange; }
/// <summary> /// Gets an edge from the given graph taking into account 'can have duplicates'. /// </summary> /// <param name="graph"></param> /// <param name="from"></param> /// <param name="to"></param> /// <param name="existingData"></param> /// <param name="shape"></param> /// <returns></returns> private bool GetEdge(GraphBase <TEdgeData> graph, uint from, uint to, out TEdgeData existingData, out ICoordinateCollection shape) { if (!graph.CanHaveDuplicates) { graph.GetEdgeShape(from, to, out shape); return(graph.GetEdge(from, to, out existingData)); } else { var edges = graph.GetEdges(from, to); while (edges.MoveNext()) { if (edges.Neighbour == to) { existingData = edges.EdgeData; shape = edges.Intermediates; return(true); } } existingData = default(TEdgeData); shape = null; return(false); } }
/// <summary> /// Calculates witnesses from on source to multiple targets at once. /// </summary> /// <param name="graph"></param> /// <param name="from"></param> /// <param name="tos"></param> /// <param name="tosWeights"></param> /// <param name="maxSettles"></param> /// <param name="forwardExists"></param> /// <param name="backwardExists"></param> /// <param name="toSkip"></param> public void Exists(GraphBase<CHEdgeData> graph, uint from, List<uint> tos, List<float> tosWeights, int maxSettles, ref bool[] forwardExists, ref bool[] backwardExists, uint toSkip) { int maxHops = _hopLimit; if (maxHops == 1) { this.ExistsOneHop(graph, from, tos, tosWeights, maxSettles, ref forwardExists, ref backwardExists); return; } // creates the settled list. var backwardSettled = new HashSet<uint>(); var forwardSettled = new HashSet<uint>(); var backwardToSet = new HashSet<uint>(); var forwardToSet = new HashSet<uint>(); float forwardMaxWeight = 0, backwardMaxWeight = 0; for (int idx = 0; idx < tosWeights.Count; idx++) { if (!forwardExists[idx]) { forwardToSet.Add(tos[idx]); if (forwardMaxWeight < tosWeights[idx]) { forwardMaxWeight = tosWeights[idx]; } } if (!backwardExists[idx]) { backwardToSet.Add(tos[idx]); if (backwardMaxWeight < tosWeights[idx]) { backwardMaxWeight = tosWeights[idx]; } } } if (forwardMaxWeight == 0 && backwardMaxWeight == 0) { // no need to search! return; } // creates the priorty queue. var forwardMinWeight = new Dictionary<uint, float>(); var backwardMinWeight = new Dictionary<uint, float>(); var heap = _reusableHeap; heap.Clear(); heap.Push(new SettledVertex(from, 0, 0, forwardMaxWeight > 0, backwardMaxWeight > 0), 0); // keep looping until the queue is empty or the target is found! while (heap.Count > 0) { // pop the first customer. var current = heap.Pop(); if (current.Hops + 1 < maxHops) { // the current vertex has net been settled. if(current.VertexId == toSkip) { continue; } bool forwardWasSettled = forwardSettled.Contains(current.VertexId); bool backwardWasSettled = backwardSettled.Contains(current.VertexId); if (forwardWasSettled && backwardWasSettled) { continue; } if (current.Forward) { // this is a forward settle. forwardSettled.Add(current.VertexId); forwardMinWeight.Remove(current.VertexId); if (forwardToSet.Contains(current.VertexId)) { int index = tos.IndexOf(current.VertexId); forwardExists[index] = current.Weight <= tosWeights[index]; //if (forwardExists[index]) //{ forwardToSet.Remove(current.VertexId); //} } } if (current.Backward) { // this is a backward settle. backwardSettled.Add(current.VertexId); backwardMinWeight.Remove(current.VertexId); if (backwardToSet.Contains(current.VertexId)) { int index = tos.IndexOf(current.VertexId); backwardExists[index] = current.Weight <= tosWeights[index]; //if (backwardExists[index]) //{ backwardToSet.Remove(current.VertexId); //} } } if (forwardToSet.Count == 0 && backwardToSet.Count == 0) { // there is nothing left to check. break; } if (forwardSettled.Count >= maxSettles && backwardSettled.Count >= maxSettles) { // do not continue searching. break; } bool doForward = current.Forward && forwardToSet.Count > 0 && !forwardWasSettled; bool doBackward = current.Backward && backwardToSet.Count > 0 && !backwardWasSettled; if (doForward || doBackward) { // get the neighbours. var neighbours = graph.GetEdges(current.VertexId); while (neighbours.MoveNext()) { // move next. var edgeData = neighbours.EdgeData; var neighbourWeight = current.Weight + edgeData.Weight; var doNeighbourForward = doForward && edgeData.CanMoveForward && neighbourWeight <= forwardMaxWeight && !forwardSettled.Contains(neighbours.Neighbour); var doNeighbourBackward = doBackward && edgeData.CanMoveBackward && neighbourWeight <= backwardMaxWeight && !backwardSettled.Contains(neighbours.Neighbour); if (doNeighbourBackward || doNeighbourForward) { float existingWeight; if (doNeighbourForward) { if (forwardMinWeight.TryGetValue(neighbours.Neighbour, out existingWeight)) { if(existingWeight <= neighbourWeight) { doNeighbourForward = false; } else { forwardMinWeight[neighbours.Neighbour] = neighbourWeight; } } else { forwardMinWeight[neighbours.Neighbour] = neighbourWeight; } } if (doNeighbourBackward) { if (backwardMinWeight.TryGetValue(neighbours.Neighbour, out existingWeight)) { if (existingWeight <= neighbourWeight) { doNeighbourBackward = false; } else { backwardMinWeight[neighbours.Neighbour] = neighbourWeight; } } else { backwardMinWeight[neighbours.Neighbour] = neighbourWeight; } } if (doNeighbourBackward || doNeighbourForward) { var neighbour = new SettledVertex(neighbours.Neighbour, neighbourWeight, current.Hops + 1, doNeighbourForward, doNeighbourBackward); heap.Push(neighbour, neighbour.Weight); } } } } } } }
/// <summary> /// Creates a new preprocessor. /// </summary> public DefaultPreprocessor(GraphBase<CHEdgeData> graph) { var witnessCalculator = new DykstraWitnessCalculator(); var edgeDifference = new EdgeDifferenceContractedSearchSpace(graph, witnessCalculator); _preprocessor = new CHPreprocessor(graph, edgeDifference, witnessCalculator); }
public void CyclesDetector_ShouldThrowArgumentException_WhenNotExistingInitialVertexSpecified(GraphBase <int> graph, int initialVertex) { var cyclesDetector = new CyclesDetector <GraphBase <int>, int>(); Assert.Throws <ArgumentException>(() => { cyclesDetector.Execute(graph, initialVertex); }); }
/// <summary> /// Returns true if the given vertex has a witness calculator. /// </summary> /// <param name="graph"></param> /// <param name="from"></param> /// <param name="to"></param> /// <param name="maxWeight"></param> /// <param name="maxSettles"></param> public bool Exists(GraphBase<CHEdgeData> graph, uint from, uint to, float maxWeight, int maxSettles) { return this.Exists(graph, from, to, maxWeight, maxSettles, uint.MaxValue); }
public override void OnValidate(GraphBase flowGraph) { base.OnValidate(flowGraph); //_actionKey = GenerateLuaKey(_luaFileName); _actionKey = ID.ToString(); }
/// <summary> /// Initializes a new instance of the <see cref="DepthFirstSearchCrawler<TVertex, TEdge>"/> class. /// </summary> /// <param name="graphToCrawl">The graph to crawl.</param> /// <param name="detectCycles">if set to true, the crawler will notify derived classes that a cycle has been detected if the graph to crawl is a /// directed graph, as cycles in directed graphs influence algorithms which work with directed graphs.</param> protected DepthFirstSearchCrawler(GraphBase <TVertex, TEdge> graphToCrawl, bool detectCycles) { ArgumentVerifier.CantBeNull(graphToCrawl, "graphToCrawl"); _graphToCrawl = graphToCrawl; _detectCycles = detectCycles; }
public void Load(GraphBase newGraph = null) { graph = newGraph != null ? newGraph : graph; StartCoroutine(IE_Load()); }
/// <summary> /// Calculates witnesses from on source to multiple targets at once. /// </summary> /// <param name="graph"></param> /// <param name="from"></param> /// <param name="tos"></param> /// <param name="tosWeights"></param> /// <param name="maxSettles"></param> /// <param name="forwardExists"></param> /// <param name="backwardExists"></param> public void Exists(GraphBase<CHEdgeData> graph, uint from, List<uint> tos, List<float> tosWeights, int maxSettles, ref bool[] forwardExists, ref bool[] backwardExists) { this.Exists(graph, from, tos, tosWeights, maxSettles, ref forwardExists, ref backwardExists, uint.MaxValue); }
/// <summary> /// Calculates witnesses from one source to multiple targets at once but using only one hop. /// </summary> /// <param name="graph"></param> /// <param name="from"></param> /// <param name="tos"></param> /// <param name="tosWeights"></param> /// <param name="maxSettles"></param> /// <param name="forwardExists"></param> /// <param name="backwardExists"></param> private void ExistsOneHop(GraphBase<CHEdgeData> graph, uint from, List<uint> tos, List<float> tosWeights, int maxSettles, ref bool[] forwardExists, ref bool[] backwardExists) { var toSet = new HashSet<uint>(); float maxWeight = 0; for (int idx = 0; idx < tosWeights.Count; idx++) { if (!forwardExists[idx] || !backwardExists[idx]) { toSet.Add(tos[idx]); if (maxWeight < tosWeights[idx]) { maxWeight = tosWeights[idx]; } } } if (toSet.Count > 0) { var neighbours = graph.GetEdges(from); while (neighbours.MoveNext()) { if (toSet.Contains(neighbours.Neighbour)) { // ok, this is a to-edge. int index = tos.IndexOf(neighbours.Neighbour); toSet.Remove(neighbours.Neighbour); var edgeData = neighbours.EdgeData; if (edgeData.CanMoveForward && edgeData.Weight < tosWeights[index]) { forwardExists[index] = true; } if (edgeData.CanMoveBackward && edgeData.Weight < tosWeights[index]) { backwardExists[index] = true; } if (toSet.Count == 0) { break; } } } } }
/// <summary> /// Creates a new pre-processor. /// </summary> /// <param name="graph"></param> public GraphSimplificationPreprocessor(GraphBase<Edge> graph) { _graph = graph; }