示例#1
0
        public override void Compute(MSInput input, out MSOutput output)
        {
            output = new MSOutput();
            var trajectory = input.Trajectory;

            ShortcutProvider.Init(input, output, false);

            LinkedList <TPoint2D> prevShortestPath = null;

            for (var level = input.NumLevels; level >= 1; level--)
            {
                var epsilon        = input.GetEpsilon(level);
                var levelShortcuts = ShortcutProvider.GetShortcuts(level, epsilon);

                LinkedList <TPoint2D> shortestPath;

                if (prevShortestPath == null)
                {
                    var pointPath = ShortestPathProvider.FindShortestPath(levelShortcuts, trajectory.First(), trajectory.Last());
                    shortestPath = pointPath.Points;
                }
                else
                {
                    shortestPath = new LinkedList <TPoint2D>();
                    var prevPoint = trajectory.First();

                    foreach (var point in prevShortestPath)
                    {
                        if (point == trajectory.First())
                        {
                            continue;
                        }

                        var pointPath = ShortestPathProvider.FindShortestPath(levelShortcuts, prevPoint, point);

                        foreach (var p in pointPath.Points)
                        {
                            shortestPath.AddLast(p);
                        }

                        prevPoint = point;
                    }
                }

                shortestPath.AddFirst(trajectory.First());

                var newTrajectory = new Trajectory2D(shortestPath);

                //report shortest path
                //output.LogObject("Level Shortest Path", levelTrajectory);
                output.LogLine("Level " + level + " trajectory found. Length: " + newTrajectory.Count);
                output.SetTrajectoryAtLevel(level, newTrajectory);

                prevShortestPath = shortestPath;

                ShortcutProvider.SetSearchIntervals(shortestPath);
            }
        }
示例#2
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);
        }
        public override void Compute(MSInput input, out MSOutput output)
        {
            output = new MSOutput();
            var trajectory = input.Trajectory;

            ShortcutProvider.Init(input, output, false);

            ICollection <TPoint2D> prevShortestPath = trajectory;

            for (var level = 1; level <= input.NumLevels; level++)
            {
                var epsilon = input.GetEpsilon(level);

                var levelShortcuts = ShortcutProvider.GetShortcuts(level, epsilon);

                var levelShortestPath = ShortestPathProvider.FindShortestPath(levelShortcuts, trajectory.First(), trajectory.Last()).Points;
                levelShortestPath.AddFirst(trajectory.First());

                //O(n)
                var levelTrajectory = new Trajectory2D(levelShortestPath);

                //O(n)
                var levelShortestPathSet = new HashSet <TPoint2D>(levelShortestPath);

                //report level trajectory
                output.SetTrajectoryAtLevel(level, levelTrajectory);

                //prune shortcutgraph and shortcuts
                //only consider points that are not the first/last
                foreach (var point in prevShortestPath)
                {
                    //O(1)
                    if (!levelShortestPathSet.Contains(point))
                    {
                        //remove shortcuts from shortcut set
                        ShortcutProvider.RemovePoint(point);
                    }
                }

                prevShortestPath = levelShortestPath;
            }
        }
示例#4
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);
        }
示例#5
0
        public override void Compute(MSInput input, out MSOutput output)
        {
            output = new MSOutput();
            var trajectory = input.Trajectory;

            ShortcutProvider.Init(input, output, false);

            for (var level = 1; level <= input.NumLevels; level++)
            {
                var epsilon = input.GetEpsilon(level);

                var levelShortcuts = ShortcutProvider.GetShortcuts(level, epsilon);

                var shortestPath = ShortestPathProvider.FindShortestPath(levelShortcuts, trajectory.First(), trajectory.Last()).Points;

                shortestPath.AddFirst(trajectory.First());

                //O(n)
                var levelTrajectory = new Trajectory2D(shortestPath);

                output.SetTrajectoryAtLevel(level, levelTrajectory);
            }
        }
        public override void Compute(MSInput input, out MSOutput output)
        {
            output = new MSOutput();
            var trajectory = input.Trajectory;

            ShortcutProvider.Init(input, output, false);

            var onDemandShortcutProvider = (ShortcutsOnDemand)ShortcutProvider;
            var prevTrajectory           = trajectory;

            for (var level = 1; level <= input.NumLevels; level++)
            {
                var epsilon = input.GetEpsilon(level);

                var shortcutAlgo  = onDemandShortcutProvider.Algorithm;
                var shortcutInput = new MSSInput(prevTrajectory, new List <double> {
                    epsilon
                });
                MSSOutput shortcutOutput;

                shortcutAlgo.Compute(shortcutInput, out shortcutOutput);
                var levelShortcuts = shortcutOutput.GetShortcuts(1);

                output.LogObject("Number of shortcuts found on level " + level, levelShortcuts.Count);

                var levelShortestPath = ShortestPathProvider.FindShortestPath(levelShortcuts, prevTrajectory.First(), prevTrajectory.Last()).Points;
                levelShortestPath.AddFirst(prevTrajectory.First());

                //O(n)
                var levelTrajectory = new Trajectory2D(levelShortestPath);

                //report level trajectory
                output.SetTrajectoryAtLevel(level, levelTrajectory);

                prevTrajectory = levelTrajectory;
            }
        }
        public override void Compute(MSInput input, out MSOutput output)
        {
            //output = new MSOutput();
            output = new Output();

            var trajectory = input.Trajectory;

            ShortcutProvider.Init(input, output, true);

            var shortcutGraphs = ((Output)output).Graphs;
            //var shortcutGraphs = new Dictionary<int, ShortcutGraph>();

            ShortcutGraph prevShortcutGraph = null;

            for (var level = 1; level <= input.NumLevels; level++)
            {
                var epsilon = input.GetEpsilon(level);

                ShortcutGraph shortcutGraph;
                if (prevShortcutGraph != null)
                {
                    //clone graph from previous level
                    shortcutGraph = (ShortcutGraph)prevShortcutGraph.Clone();
                }
                else
                {
                    //build initial graph (just a simple sequence of nodes like in the trajectory)
                    shortcutGraph = new ShortcutGraph(trajectory);
                }

                //select correct shortcuts
                var shortcutsLevel = ShortcutProvider.GetShortcuts(level, epsilon);
                //output.LogObject("Number of shortcuts found for level " + level, () => shortcutsLevel.Count);

                if (level == 1)
                {
                    foreach (var shortcut in shortcutsLevel)
                    {
                        shortcutGraph.AddShortcut(shortcut);
                    }
                }
                else
                {
                    var weights         = new Dictionary <Shortcut, int>();
                    var shortcutWeights = GetShortcutWeights(shortcutGraph, shortcutsLevel);

                    foreach (var pair in shortcutWeights)
                    {
                        var shortcut = pair.Key;
                        var weight   = pair.Value;
                        weights[shortcut] = weight;
                    }

                    foreach (var shortcut in shortcutsLevel)
                    {
                        shortcutGraph.AddShortcut(shortcut, weights[shortcut]);
                    }

                    //increment weights of all edges by 1
                    shortcutGraph.IncrementAllWeights();
                }

                //output.LogObject("Shortcut Graph", shortcutGraph);

                shortcutGraphs[level] = shortcutGraph;
                prevShortcutGraph     = shortcutGraph;
            }

            output.LogLine("Shortcut graph size at scale m: " + shortcutGraphs[input.NumLevels].Count);
            output.LogLine("Average amount of shortcuts handled per scale: " + shortcutGraphs[input.NumLevels].Count / input.NumLevels);

            output.LogLine("");
            output.LogLine("Starting calculations of level trajectories bottom-up");
            output.LogLine("");

            //bottom up calculation of level trajectories
            LinkedList <TPoint2D> prevShortestPath = null;

            for (var level = input.NumLevels; level >= 1; level--)
            {
                var shortcutGraph = shortcutGraphs[level];
                LinkedList <TPoint2D> shortestPath;

                if (prevShortestPath == null)
                {
                    var pointPath = ShortestPathProvider.FindShortestPath(shortcutGraph, trajectory.First(), trajectory.Last());
                    shortestPath = pointPath.Points;
                }
                else
                {
                    shortestPath = new LinkedList <TPoint2D>();
                    var prevPoint = trajectory.First();

                    foreach (var point in prevShortestPath)
                    {
                        var pointPath = ShortestPathProvider.FindShortestPath(shortcutGraph, prevPoint, point);

                        foreach (var p in pointPath.Points)
                        {
                            shortestPath.AddLast(p);
                        }

                        prevPoint = point;
                    }
                }

                var newTrajectory = new Trajectory2D();
                newTrajectory.AppendPoint(trajectory.First().X, trajectory.First().Y);
                foreach (var point in shortestPath)
                {
                    newTrajectory.AppendPoint(point.X, point.Y);
                }

                //report shortest path
                //output.LogObject("Level Shortest Path", levelTrajectory);
                output.LogLine("Level " + level + " trajectory found. Length: " + newTrajectory.Count);
                output.SetTrajectoryAtLevel(level, newTrajectory);

                prevShortestPath = shortestPath;
            }
        }
        private void shortestPathProviderComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            ChosenShortestPathProvider = (ShortestPathProvider)shortestPathProviderComboBox.SelectedItem;

            shortestPathProviderOptions.Fill(ChosenShortestPathProvider.OptionsControl);
        }
        public ShortcutOptions(BindingList <ShortcutProvider> shortcutProviders, ShortcutProvider ChosenShortcutProvider,
                               BindingList <ShortestPathProvider> shortestPathroviders, ShortestPathProvider ChosenShortestPathProvider)
        {
            InitializeComponent();

            this.shortcutProviders    = shortcutProviders;
            this.shortestPathroviders = shortestPathroviders;

            PopulateControls();

            shortestPathProviderComboBox.SelectedItem = ChosenShortestPathProvider;
            shortcutProviderComboBox.SelectedItem     = ChosenShortcutProvider;
        }