public void Remove(Vertex key) { PathRecord value = pathRecords[key]; pathRecords.Remove(key); sortedValues.Remove(value); }
private Key CalculateKey(PathRecord pathRecord) { float minPath = Mathf.Min(pathRecord.costSoFar, pathRecord.rightHandSide); float heuristic = heuristicEstimate.Estimate(pathRecord.node.pos, startNode.node.pos); return(new Key(minPath + heuristic + k, minPath)); }
List <int> FindPathBetweenIntersectionIndices(int i0, int i1) { int ITERCOUNT = 30; List <PathRecord> openPaths = new List <PathRecord>(); List <int> startPath = new List <int>(); startPath.Add(i0); PathRecord start = new PathRecord(myCity, i1, startPath); openPaths.Add(start); int iterationsSoFar = 0; while (openPaths.Count > 0) { if (iterationsSoFar > ITERCOUNT) { //Debug.Log("ITER MAX"); return(openPaths[0].pathSoFar); } iterationsSoFar++; PathRecord test = openPaths[0]; openPaths.RemoveAt(0); //Debug.Log("have a candidate path " + test); int pathLen = test.pathSoFar.Count; int lastIndex = test.pathSoFar[pathLen - 1]; //Debug.Log("path steps : " + pathLen); //Debug.Log("last step : " + lastIndex); List <int> neighbors = myCity.GetIntersectionNeighbors(lastIndex); //Debug.Log(string.Format("found {0} neighbors", neighbors.Count)); foreach (int n in neighbors) { if (!test.pathSoFar.Contains(n)) { PathRecord next = new PathRecord(myCity, i1, test.pathSoFar); next.pathSoFar.Add(n); if (n == i1) { return(next.pathSoFar); } //Debug.Log("Adding new path with step " + n); openPaths.Add(next); } } openPaths.Sort(); //Debug.LogFormat("have {0} paths", openPaths.Count); //Debug.Log("breaking out for testing"); //break; } //Debug.Log("returning null because ran out of paths"); return(null); }
private void UpdatePathRecordState(PathRecord pathRecord) { if (openList.Contains(pathRecord)) { if (Mathf.Abs(pathRecord.costSoFar - pathRecord.rightHandSide) > Mathf.Epsilon) { pathRecord.key = CalculateKey(pathRecord); openList.UpdatePriority(pathRecord, pathRecord.key); #region Not a part of algorithm, visualization purposes only gridMarkerController.PutOpenNodeMarker(pathRecord.node); #endregion } else { openList.Remove(pathRecord); #region Not a part of algorithm, visualization purposes only gridMarkerController.RemoveNonPathMarker(pathRecord.node); #endregion } } else if (Mathf.Abs(pathRecord.costSoFar - pathRecord.rightHandSide) > Mathf.Epsilon) { #region Not a part of algorithm, visualization purposes only gridMarkerController.PutOpenNodeMarker(pathRecord.node); #endregion pathRecord.key = CalculateKey(pathRecord); openList.Enqueue(pathRecord, pathRecord.key); } }
public void UpdatePath(Vertex updatedVertex) { PathRecord changedPathRecord = null; if (pathRecords.TryGetValue(updatedVertex, out changedPathRecord)) { if (changedPathRecord != goalNode) { List <PathRecord> successors = GetSuccecessors(changedPathRecord); if (successors.Count == 0) { #region Not a part of algorithm, visualization purposes only gridMarkerController.RemoveMarker(updatedVertex); #endregion changedPathRecord.costSoFar = changedPathRecord.rightHandSide = float.PositiveInfinity; } else { changedPathRecord.rightHandSide = successors.Min(s => s.costSoFar + GetCost(changedPathRecord, s)); } } UpdatePathRecordState(changedPathRecord); } ; }
public PathRecord PopMinValue() { PathRecord value = sortedValues.Dequeue(); pathRecords.Remove(value.node); return(value); }
public DiskTile(PathRecord pr) : this() { _recordReference = pr; _recordReference.DiskInfoUpdated += Pr_DiskInfoUpdated; UpdateUserInterface(); }
public void InvalidPathRecordPath() { var pr = new PathRecord { Path = "invalidpath" }; pr.RequestDiskInfo(); Assert.AreEqual(0, pr.Capacity.Bytes); //expect zero capacity }
public void PathRecordShortcut1() { var pr = new PathRecord { Path = "C:\\" }; var result = pr.ShortcutName; Assert.AreEqual("C", result); }
public void PathRecordShortcut3() { var pr = new PathRecord { Path = "\\\\192.169.10.1\\Share\\Share 2\\" }; var result = pr.ShortcutName; Assert.AreEqual("192_169_10_1 Share Share 2", result); }
public IEnumerator MoveByPath(Vertex starVertex, Vertex goalVertex, System.Action startPathSearch = null, System.Action startMove = null) { startNode = new PathRecord(starVertex); startNode.costSoFar = startNode.rightHandSide = float.PositiveInfinity; pathRecords.Add(startNode.node, startNode); goalNode = new PathRecord(goalVertex); pathRecords.Add(goalNode.node, goalNode); goalNode.key = CalculateKey(goalNode); openList.Enqueue(goalNode, goalNode.key); yield return(ComputeShortestPath()); #region Not a part of algorithm, visualization purposes only yield return(DrawFoundPath()); #endregion if (pathFound) { PathRecord nextNode = startNode; startMove?.Invoke(); while (nextNode != goalNode && pathFound) { List <PathRecord> succecessors = GetSuccecessors(nextNode); nextNode = succecessors.Aggregate((s1, s2) => s1.costSoFar + GetCost(nextNode, s1) < s2.costSoFar + GetCost(nextNode, s2) ? s1 : s2); #region Not a part of algorithm, visualization purposes only gridMarkerController.PutCurrentMoveNode(nextNode.node); yield return(new WaitForSeconds(moveTimeDelay)); #endregion if (float.IsPositiveInfinity(nextNode.costSoFar) || Mathf.Abs(nextNode.rightHandSide - nextNode.costSoFar) > Mathf.Epsilon) { #region Not a part of algorithm, visualization purposes only gridMarkerController.RemoveAllPathMarkers(); #endregion k += heuristicEstimate.Estimate(startNode.node.pos, nextNode.node.pos); startNode = nextNode; yield return(ComputeShortestPath()); if (pathFound) { #region Not a part of algorithm, visualization purposes only yield return(DrawFoundPath()); #endregion startMove?.Invoke(); } } #region Not a part of algorithm, visualization purposes only gridMarkerController.PutMovedPathNodeMarker(nextNode.node); yield return(new WaitForSeconds(moveTimeDelay)); #endregion } } }
public void ZeroCapacity() { Assert.IsFalse(TestPathRecord.HasZeroCapacity); var pr = new PathRecord { DiskAttributes = new DiskAttributes(0, 0, 0) }; Assert.IsTrue(pr.HasZeroCapacity); }
public void PathRecordShortcut4() { var pr = new PathRecord { Path = "\\\\192.169.10.1\\Share\\Share 2\\", FriendlyName = "Te*stin|g:Inv?alid\\Chars.<Text>" }; var result = pr.ShortcutName; Assert.AreEqual("TestingInvalid Chars_Text", result); }
public System.Collections.IEnumerator FindPath(Vertex startVertex, Vertex goalVertex, System.Action <List <Edge> > callback = null) { openList.Add(startVertex, new PathRecord(startVertex)); PathRecord current = null; #region Not a part of algorithm, visualization purposes only gridMarkerController.PutOpenNodeMarker(startVertex); #endregion while (openList.Count > 0) { current = openList.PopMinValue(); #region Not a part of algorithm, visualization purposes only gridMarkerController.PutCurrentNodeMarker(current.node); #endregion if (current.node == goalVertex) { //WOW! we found goal! break; } yield return(ProcessAllEdgesFromCurrent(current, goalVertex)); closeList.Add(current.node, current); #region Not a part of algorithm, visualization purposes only gridMarkerController.RemoveMarker(current.node); gridMarkerController.PutClosedNodeMarker(current.node); #endregion yield return(new WaitForSecondsRealtime(sleepTime)); } List <Edge> path = new List <Edge>(); if (current.node == goalVertex) { while (current.node != startVertex) { #region Not a part of algorithm, visualization purposes only if (goalVertex != current.node) { gridMarkerController.PutPathNodeMarker(current.node); yield return(new WaitForSecondsRealtime(sleepTime)); } #endregion path.Add(current.connection.edge); current = current.connection.fromRecord; } path.Reverse(); } if (callback != null) { callback.Invoke(path); } }
public void DiskInfoAync() { var pr = new PathRecord { Path = Windows.InstallDirectory, FriendlyName = "Test" }; Assert.IsTrue(pr.HasZeroCapacity); pr.RequestInfoTask.Wait(); Assert.IsFalse(pr.HasZeroCapacity); }
private PathRecord GetOrCreateIfAbsent(Vertex node) { PathRecord predecessor; if (!pathRecords.TryGetValue(node, out predecessor)) { predecessor = new PathRecord(node); predecessor.costSoFar = float.PositiveInfinity; predecessor.rightHandSide = float.PositiveInfinity; pathRecords.Add(node, predecessor); } return(predecessor); }
private void ProcessOverconsistentNode(PathRecord currentNode) { currentNode.costSoFar = currentNode.rightHandSide; List <PathRecord> predecessorPathRecords = GetPredecessors(currentNode); predecessorPathRecords.ForEach(p => { if (p != goalNode) { p.rightHandSide = Mathf.Min(p.rightHandSide, currentNode.costSoFar + GetCost(p, currentNode)); } UpdatePathRecordState(p); }); }
private System.Collections.IEnumerator ProcessAllEdgesFromCurrent(PathRecord current, Vertex goalVertex) { foreach (Edge edge in current.node.edges) { PathRecord nextNode; float nextNodeCostSoFar = current.costSoFar + edge.cost; float nextNodeHeuristic; if (closeList.ContainsKey(edge.to)) { nextNode = closeList[edge.to]; if (nextNode.costSoFar <= nextNodeCostSoFar) { continue; } nextNodeHeuristic = nextNode.heuristicValue; closeList.Remove(nextNode.node); #region Not a part of algorithm, visualization purposes only gridMarkerController.RemoveMarker(nextNode.node); #endregion } else if (openList.ContainsKey(edge.to)) { nextNode = openList[edge.to]; if (nextNode.costSoFar <= nextNodeCostSoFar) { continue; } nextNodeHeuristic = nextNode.heuristicValue; } else { nextNode = new PathRecord(edge.to); nextNodeHeuristic = heuristic.Estimate(nextNode.node.pos, goalVertex.pos); } nextNode.costSoFar = nextNodeCostSoFar; nextNode.heuristicValue = nextNodeHeuristic; nextNode.connection = new PathConnection(edge, current); if (!openList.ContainsKey(nextNode.node)) { openList.Add(nextNode.node, nextNode); #region Not a part of algorithm, visualization purposes only gridMarkerController.PutOpenNodeMarker(nextNode.node); #endregion } yield return(new WaitForSecondsRealtime(sleepTime)); } }
private IEnumerator DrawFoundPath() { PathRecord pathNodeForMarker = startNode; int maxSteps = 40; while (pathNodeForMarker != goalNode && pathFound) { if (maxSteps-- == 0) { yield break; } pathNodeForMarker = GetSuccecessors(pathNodeForMarker).Aggregate((s1, s2) => s1.costSoFar + GetCost(pathNodeForMarker, s1) < s2.costSoFar + GetCost(pathNodeForMarker, s2) ? s1 : s2); gridMarkerController.PutPathNodeMarker(pathNodeForMarker.node); } yield return(new WaitForSeconds(moveTimeDelay)); }
private void ProcessUnderconsistentNode(PathRecord currentNode) { float costSoFarCurrent = currentNode.costSoFar; currentNode.costSoFar = float.PositiveInfinity; List <PathRecord> predecessorPathRecords = GetPredecessors(currentNode); predecessorPathRecords.ForEach(p => { if (p != goalNode && p.rightHandSide == costSoFarCurrent + GetCost(p, currentNode)) { List <PathRecord> succecessors = GetSuccecessors(p); p.rightHandSide = succecessors.Min(s => s.costSoFar + GetCost(p, s)); } UpdatePathRecordState(p); }); UpdatePathRecordState(currentNode); }
public void LowDiskSpace() { Assert.IsFalse(TestPathRecord.HasLowDiskSpace); var pr = new PathRecord { DiskAttributes = new DiskAttributes(20, 512, 32) }; //94% Console.WriteLine(pr.FillLevel); Assert.IsTrue(pr.HasLowDiskSpace); var pr2 = new PathRecord { DiskAttributes = new DiskAttributes(20, 512, 52) }; //90% Console.WriteLine(pr2.FillLevel); Assert.IsFalse(pr2.HasLowDiskSpace); }
public void CheckLocation() { var list = new DiskUsage(saveToDisk: false); var local = new PathRecord { FriendlyName = "F", Path = "F:\\" }; Assert.AreEqual(PathLocation.Local, local.Location()); var remote = new PathRecord { FriendlyName = "Share", Path = "\\\\Server\\Share" }; Assert.AreEqual(PathLocation.Remote, remote.Location()); var os = new PathRecord { FriendlyName = "OS Disk", Path = $"{Windows.InstallDirectory}" }; Assert.AreEqual(PathLocation.Os, os.Location()); }
public static bool TryCreate(PathRecord record, bool notify = true) { try { //create shortcut string shortcutLocation = $"{Windows.Desktop}\\{record.ShortcutName} - Shortcut.lnk"; Windows.CreateShortcut(record.Path, shortcutLocation); if (notify) { MessageBox.Show($@"A shortcut to ""{record.Path}"" was placed on your Desktop."); } return(true); } catch (Exception ex) when(ex is System.IO.FileNotFoundException || ex is ArgumentException) { MessageBox.Show(@"The directory could not be found, a shortcut cannot be created.", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(false); }
void UpdateNotificationPicture(PathRecord pathRecord) { notificationPicture.Image = pathRecord.Notifications ? Resources.ic_notifications_black_18dp : Resources.ic_notifications_off_black_18dp; }
public PropertiesForm() { _record = new PathRecord(); InitializeComponent(); }
private float GetCost(PathRecord from, PathRecord to) { return(GetCost(from.node, to.node)); }
public void UpdateUserInterface(PathRecord pathRecord) { _recordReference = pathRecord; UpdateUserInterface(); }
private List <PathRecord> GetSuccecessors(PathRecord pathRecord) { List <Vertex> succecessorsNodes = positionResolver.GetVertextSuccessors(pathRecord.node); return(succecessorsNodes.Select(n => GetOrCreateIfAbsent(n)).ToList()); }
public void ProvideData(PathRecord record) { _record = record; UpdateUi(); }
public void Add(Vertex key, PathRecord value) { pathRecords.Add(key, value); sortedValues.Enqueue(value, value.GetCostEstimation()); }