コード例 #1
0
 public override void Clear()
 {
     ShortcutSet = null;
     Source      = null;
     Targets     = new JHashSet <TPoint2D>();
     ShortcutSet = null;
 }
コード例 #2
0
        public override IShortcutSet GetShortcuts(int level, double epsilon)
        {
            var input = new MSSInput(Input.Trajectory, new List <double> {
                epsilon
            })
            {
                PrunedPoints    = prunedPoints,
                SearchIntervals = searchIntervals
            };

            MSSOutput output;

            Algorithm.Compute(input, out output);

            var shortcuts = output.GetShortcuts(1);

            if (Cumulative)
            {
                if (prunedShortcuts != null)
                {
                    shortcuts.Except(prunedShortcuts);
                    prunedShortcuts.Union(shortcuts);
                }
                else
                {
                    prunedShortcuts = shortcuts;
                }
            }

            //Output.LogLine(output.LogString);
            Output.LogObject("Number of shortcuts found on level " + level, shortcuts.Count);

            return(shortcuts);
        }
コード例 #3
0
 public override void Init(MSInput input, MSOutput output, bool cumulative)
 {
     base.Init(input, output, cumulative);
     prunedShortcuts = null;
     searchIntervals = null;
     prunedPoints    = new HashSet <TPoint2D>();
 }
コード例 #4
0
 public SPFInput(Trajectory2D Trajectory, IShortcutSet ShortcutSet, TPoint2D Source, JHashSet <TPoint2D> Targets, bool CreatePath = true)
 {
     this.Trajectory  = Trajectory;
     this.ShortcutSet = ShortcutSet;
     this.Source      = Source;
     this.Targets     = Targets;
     this.CreatePath  = CreatePath;
 }
コード例 #5
0
        public void Except(IShortcutSet set)
        {
            var graph = (ShortcutGraph)set;

            foreach (var shortcut in graph.Shortcuts.Keys)
            {
                RemoveShortcut(shortcut);
            }
        }
コード例 #6
0
        public void Union(IShortcutSet set)
        {
            var graph = (ShortcutGraph)set;

            foreach (var pair in graph.Shortcuts)
            {
                var weightedEdge = (WeightedEdge)pair.Value;
                AddShortcut(pair.Key, weightedEdge.Data);
            }
        }
コード例 #7
0
        public override Dictionary <TPoint2D, ShortcutPath> FindShortestPaths(IShortcutSet set, TPoint2D source, JHashSet <TPoint2D> targets, bool createPaths = true)
        {
            var input = new SPFInput
            {
                Trajectory  = set.Trajectory,
                ShortcutSet = set,
                Source      = source,
                Targets     = targets,
                CreatePath  = createPaths
            };

            SPFOutput output;

            algorithm.Compute(input, out output);

            return(output.ShortcutPaths);
        }
コード例 #8
0
        public override ShortcutPath FindShortestPath(IShortcutSet set, TPoint2D source, TPoint2D target, bool createPath = true)
        {
            var input = new SPFInput
            {
                Trajectory  = set.Trajectory,
                ShortcutSet = set,
                Source      = source,
                Targets     = new JHashSet <TPoint2D> {
                    target
                },
                CreatePath = createPath
            };

            SPFOutput output;

            algorithm.Compute(input, out output);

            return(output.GetPath(target));
        }
コード例 #9
0
        public void Intersect(IShortcutSet set)
        {
            var graph = (ShortcutGraph)set;

            var shortcutsToRemove = new HashSet <Shortcut>();

            foreach (var shortcut in Shortcuts.Keys)
            {
                if (!graph.Shortcuts.ContainsKey(shortcut))
                {
                    shortcutsToRemove.Add(shortcut);
                }
            }

            foreach (var shortcut in shortcutsToRemove)
            {
                RemoveShortcut(shortcut, false);
            }
        }
コード例 #10
0
 public abstract Dictionary <TPoint2D, ShortcutPath> FindShortestPaths(IShortcutSet set, TPoint2D source, JHashSet <TPoint2D> targets, bool createPaths = true);
コード例 #11
0
 public abstract ShortcutPath FindShortestPath(IShortcutSet set, TPoint2D source, TPoint2D target, bool createPath = true);
コード例 #12
0
        //worst case O(n^2), expected O(n)
        public void Except(IShortcutSet set)
        {
            var otherIntervalMap = ((ShortcutIntervalSet)set).IntervalMap;

            foreach (var start in otherIntervalMap.Keys)
            {
                if (!IntervalMap.ContainsKey(start))
                {
                    continue;
                }

                var intervals      = IntervalMap[start];
                var otherIntervals = otherIntervalMap[start];
                var intervalsNode  = intervals.First;
                var otherNode      = otherIntervals.First;

                //worst case O(n), expected O(1)
                while (intervalsNode != null)
                {
                    var interval = intervalsNode.Value;

                    if (otherNode == null)
                    {
                        break;
                    }

                    var otherInterval = otherNode.Value;

                    //other interval too far back, consider next one for overlap
                    if (otherInterval.End.Index < interval.Start.Index)
                    {
                        otherNode = otherNode.Next;
                        continue;
                    }

                    //interval too far back, consider next one for overlap
                    if (otherInterval.Start.Index > interval.End.Index)
                    {
                        intervalsNode = intervalsNode.Next;
                        continue;
                    }

                    //it overlaps at the start: prune interval start
                    if (otherInterval.End.Index < interval.End.Index && otherInterval.Start.Index <= interval.Start.Index)
                    {
                        interval.Start = Trajectory[otherInterval.End.Index + 1];
                        otherNode      = otherNode.Next;
                        continue;
                    }

                    //it overlaps at the end: prune interval end
                    if (otherInterval.Start.Index > interval.Start.Index && otherInterval.End.Index >= interval.End.Index)
                    {
                        interval.End  = Trajectory[otherInterval.Start.Index - 1];
                        intervalsNode = intervalsNode.Next;
                        continue;
                    }

                    //spanning other interval
                    if (otherInterval.Start.Index > interval.Start.Index && otherInterval.End.Index < interval.End.Index)
                    {
                        //second part
                        intervalsNode = intervals.AddAfter(intervalsNode, new Interval(Trajectory[otherInterval.End.Index + 1], interval.End));

                        //first part
                        interval.End = Trajectory[otherInterval.Start.Index - 1];

                        otherNode = otherNode.Next;
                        continue;
                    }

                    //full overlap
                    var nextNode = intervalsNode.Next;
                    intervals.Remove(intervalsNode);
                    intervalsNode = nextNode;
                }
            }
        }
コード例 #13
0
        //worst case O(n^2), expected O(n)
        public void Union(IShortcutSet set)
        {
            var otherIntervalMap = ((ShortcutIntervalSet)set).IntervalMap;

            foreach (var start in otherIntervalMap.Keys)
            {
                if (!IntervalMap.ContainsKey(start))
                {
                    continue;
                }

                var intervals      = IntervalMap[start];
                var otherIntervals = otherIntervalMap[start];

                var intervalsNode = intervals.First;
                var otherNode     = otherIntervals.First;

                while (otherNode != null)
                {
                    if (intervalsNode == null)
                    {
                        intervals.AddLast(otherNode.Value.Clone());
                        otherNode = otherNode.Next;
                        continue;
                    }

                    var interval      = intervalsNode.Value;
                    var otherInterval = otherNode.Value;

                    //not yet reached
                    if (otherInterval.Start.Index > interval.End.Index + 1)
                    {
                        intervalsNode = intervalsNode.Next;
                        continue;
                    }

                    //we passed it: simply add the interval
                    if (otherInterval.End.Index < interval.Start.Index - 1)
                    {
                        intervals.AddBefore(intervalsNode, new Interval(otherInterval.Start, otherInterval.End));
                        otherNode = otherNode.Next;
                        continue;
                    }

                    //it connects at the start: extend interval backwards
                    if (otherInterval.End.Index >= interval.Start.Index - 1)
                    {
                        interval.Start = otherInterval.Start;
                    }

                    //it connects at the end: extend interval forward
                    if (otherInterval.Start.Index <= interval.End.Index + 1)
                    {
                        interval.End = otherInterval.End;

                        var tempNode = intervalsNode.Next;
                        while (tempNode != null)
                        {
                            var nextNode        = tempNode.Next;
                            var furtherInterval = tempNode.Value;

                            //remove any fully overlapped intervals
                            if (furtherInterval.End.Index <= interval.End.Index)
                            {
                                intervals.Remove(tempNode);
                                tempNode = nextNode;
                                continue;
                            }

                            //merge any interval that may connect at the end
                            if (furtherInterval.Start.Index <= interval.End.Index + 1)
                            {
                                intervals.Remove(tempNode);
                                interval.End = furtherInterval.End;
                            }

                            break;
                        }
                    }

                    otherNode = otherNode.Next;
                }
            }
        }
コード例 #14
0
        //worst case O(n^2), expected O(n)
        public void Intersect(IShortcutSet set)
        {
            var otherIntervalMap = ((ShortcutIntervalSet)set).IntervalMap;

            foreach (var start in otherIntervalMap.Keys)
            {
                if (!IntervalMap.ContainsKey(start))
                {
                    continue;
                }

                var intervals      = IntervalMap[start];
                var otherIntervals = otherIntervalMap[start];
                var intervalsNode  = intervals.First;
                var otherNode      = otherIntervals.First;

                //worst case O(n), expected O(1)
                while (intervalsNode != null)
                {
                    var nextNode = intervalsNode.Next;
                    var interval = intervalsNode.Value;

                    if (otherNode == null)
                    {
                        intervals.Remove(intervalsNode);
                    }
                    else
                    {
                        var otherInterval = otherNode.Value;

                        //other interval too far back, consider next one for overlap
                        if (otherInterval.End.Index < interval.Start.Index)
                        {
                            otherNode = otherNode.Next;
                            continue;
                        }

                        //other interval too far ahead
                        if (otherInterval.Start.Index > interval.End.Index)
                        {
                            intervals.Remove(intervalsNode);
                        }
                        else //some overlap
                        {
                            var nextOtherInterval = otherNode.Next?.Value;
                            var nextOverlaps      = false;

                            if (nextOtherInterval != null)
                            {
                                nextOverlaps = nextOtherInterval.Start.Index <= interval.End.Index;
                            }

                            if (nextOverlaps) //split interval
                            {
                                var newInterval = new Interval(interval.Start, interval.End);

                                //it connects at the start: prune interval end
                                if (otherInterval.End.Index < interval.End.Index)
                                {
                                    newInterval.End = otherInterval.End;
                                }

                                //it connects at the end: prune interval start
                                if (otherInterval.Start.Index > interval.Start.Index)
                                {
                                    newInterval.Start = otherInterval.Start;
                                }

                                intervals.AddBefore(intervalsNode, newInterval);

                                otherNode = otherNode.Next;
                                continue;
                            }

                            //it connects at the start: prune interval end
                            if (otherInterval.End.Index < interval.End.Index)
                            {
                                interval.End = otherInterval.End;
                            }

                            //it connects at the end: prune interval start
                            if (otherInterval.Start.Index > interval.Start.Index)
                            {
                                interval.Start = otherInterval.Start;
                            }
                        }
                    }

                    intervalsNode = nextNode;
                }
            }
        }
コード例 #15
0
        protected override Dictionary <Shortcut, int> GetShortcutWeights(ShortcutGraph graph, IShortcutSet levelShortcuts)
        {
            var weights = new Dictionary <Shortcut, int>();

            foreach (var shortcut in levelShortcuts)
            {
                var path = ShortestPathProvider.FindShortestPath(graph, shortcut.Start, shortcut.End);
                weights[shortcut] = path.Weight;
            }

            return(weights);
        }
コード例 #16
0
        protected override Dictionary <Shortcut, int> GetShortcutWeights(ShortcutGraph graph, IShortcutSet levelShortcuts)
        {
            var levelMap = levelShortcuts.AsMap();

            var weights = new Dictionary <Shortcut, int>();

            foreach (var pair in levelMap)
            {
                var start = pair.Key;
                var ends  = pair.Value;

                var paths = ShortestPathProvider.FindShortestPaths(graph, start, ends, false);

                foreach (var end in ends)
                {
                    weights[new Shortcut(start, end)] = paths[end].Weight;
                }
            }

            return(weights);
        }
コード例 #17
0
 protected abstract Dictionary <Shortcut, int> GetShortcutWeights(ShortcutGraph graph, IShortcutSet levelShortcuts);