Example #1
0
        public IEnumerable <Shortcut> Shortcuts(AdjacencyMatrix matrix, int start)
        {
            var iterations = CreateIterations(matrix, start).ToList();
            var shortcuts  = new List <Shortcut>();

            for (var node = 1; node <= matrix.Width; node++)
            {
                var shortcut = IterationDescent(iterations.ToImmutableList(), node, new List <int>());
                shortcut.Reverse();
                shortcuts.Add(new Shortcut(shortcut, iterations.Last()[node - 1]));
            }

            return(shortcuts);
        }
Example #2
0
        private List <Iteration> CreateIterations(AdjacencyMatrix matrix, int start)
        {
            var firstIterationState = new List <int>(matrix.Width);

            for (var index = 0; index < matrix.Width; index++)
            {
                firstIterationState.Add(index != start - 1 ? int.MaxValue : 0);
            }

            var result = new List <Iteration>
            {
                new Iteration(firstIterationState, 1)
            };

            for (var iteration = 1; iteration < matrix.Height; iteration++)
            {
                var currentMinIndex       = result.Last().IndexOfMinElement(iteration);
                var currentMinElement     = result.Last()[currentMinIndex];
                var currentIterationState = result.Last().Relaxation(matrix[currentMinIndex], currentMinElement);
                result.Add(new Iteration(currentIterationState, iteration + 1));
            }

            return(result);
        }