Ejemplo n.º 1
0
        public void Remove(Vertex key)
        {
            PathRecord value = pathRecords[key];

            pathRecords.Remove(key);
            sortedValues.Remove(value);
        }
Ejemplo n.º 2
0
    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));
    }
Ejemplo n.º 3
0
    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);
    }
Ejemplo n.º 4
0
 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);
     }
 }
Ejemplo n.º 5
0
    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);
        }
        ;
    }
Ejemplo n.º 6
0
        public PathRecord PopMinValue()
        {
            PathRecord value = sortedValues.Dequeue();

            pathRecords.Remove(value.node);
            return(value);
        }
Ejemplo n.º 7
0
        public DiskTile(PathRecord pr) : this()
        {
            _recordReference = pr;
            _recordReference.DiskInfoUpdated += Pr_DiskInfoUpdated;

            UpdateUserInterface();
        }
Ejemplo n.º 8
0
        public void InvalidPathRecordPath()
        {
            var pr = new PathRecord {
                Path = "invalidpath"
            };

            pr.RequestDiskInfo();
            Assert.AreEqual(0, pr.Capacity.Bytes); //expect zero capacity
        }
Ejemplo n.º 9
0
        public void PathRecordShortcut1()
        {
            var pr = new PathRecord {
                Path = "C:\\"
            };
            var result = pr.ShortcutName;

            Assert.AreEqual("C", result);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
    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
            }
        }
    }
Ejemplo n.º 12
0
        public void ZeroCapacity()
        {
            Assert.IsFalse(TestPathRecord.HasZeroCapacity);

            var pr = new PathRecord {
                DiskAttributes = new DiskAttributes(0, 0, 0)
            };

            Assert.IsTrue(pr.HasZeroCapacity);
        }
Ejemplo n.º 13
0
        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);
        }
Ejemplo n.º 14
0
    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);
        }
    }
Ejemplo n.º 15
0
        public void DiskInfoAync()
        {
            var pr = new PathRecord {
                Path = Windows.InstallDirectory, FriendlyName = "Test"
            };

            Assert.IsTrue(pr.HasZeroCapacity);

            pr.RequestInfoTask.Wait();

            Assert.IsFalse(pr.HasZeroCapacity);
        }
Ejemplo n.º 16
0
    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);
    }
Ejemplo n.º 17
0
    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);
        });
    }
Ejemplo n.º 18
0
    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));
        }
    }
Ejemplo n.º 19
0
    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));
    }
Ejemplo n.º 20
0
    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);
    }
Ejemplo n.º 21
0
        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);
        }
Ejemplo n.º 22
0
        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());
        }
Ejemplo n.º 23
0
        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);
        }
Ejemplo n.º 24
0
 void UpdateNotificationPicture(PathRecord pathRecord)
 {
     notificationPicture.Image = pathRecord.Notifications
         ? Resources.ic_notifications_black_18dp
         : Resources.ic_notifications_off_black_18dp;
 }
Ejemplo n.º 25
0
 public PropertiesForm()
 {
     _record = new PathRecord();
     InitializeComponent();
 }
Ejemplo n.º 26
0
 private float GetCost(PathRecord from, PathRecord to)
 {
     return(GetCost(from.node, to.node));
 }
Ejemplo n.º 27
0
 public void UpdateUserInterface(PathRecord pathRecord)
 {
     _recordReference = pathRecord;
     UpdateUserInterface();
 }
Ejemplo n.º 28
0
    private List <PathRecord> GetSuccecessors(PathRecord pathRecord)
    {
        List <Vertex> succecessorsNodes = positionResolver.GetVertextSuccessors(pathRecord.node);

        return(succecessorsNodes.Select(n => GetOrCreateIfAbsent(n)).ToList());
    }
Ejemplo n.º 29
0
 public void ProvideData(PathRecord record)
 {
     _record = record;
     UpdateUi();
 }
Ejemplo n.º 30
0
 public void Add(Vertex key, PathRecord value)
 {
     pathRecords.Add(key, value);
     sortedValues.Enqueue(value, value.GetCostEstimation());
 }