Пример #1
0
        public decimal GetCost(InputOption inputOption, Edge cnn, Station station)
        {
            var commonStations = cnn.ConnectedStation.Lines.Intersect(station.Lines).ToList();
            var isInNeOrNs     = commonStations.Intersect(new List <string> {
                "NE", "NS"
            }).Any();
            var isPeakHour  = inputOption.JourneyTime.IsPeak();
            var interchange = !commonStations.Any();

            return((!isInNeOrNs && !interchange && isPeakHour ? 10 : 0) + _inner.GetCost(inputOption, cnn, station));
        }
        public IEnumerable <Node> AddNodeToRoute(Node node, IReadOnlyList <Node> stops, out double changeInCost)
        {
            int    numStops      = stops.Count;
            double bestCost      = int.MaxValue;
            int    bestInsertion = -1;

            for (int i = 0; i < numStops; i++)
            {
                double cost;
                if (i == 0 || i == numStops - 1)
                {
                    cost = _costCalculator.GetCost(stops[numStops - 1], node) +
                           _costCalculator.GetCost(node, stops[0]) -
                           _costCalculator.GetCost(stops[0], stops[numStops - 1]);
                }
                else
                {
                    cost = _costCalculator.GetCost(stops[i - 1], node) + _costCalculator.GetCost(node, stops[i]) -
                           _costCalculator.GetCost(stops[i - 1], stops[i]);
                }

                if (cost < bestCost)
                {
                    bestInsertion = i;
                    bestCost      = cost;
                }
            }

            changeInCost = bestCost;
            return(stops.Take(bestInsertion).Append(node).Union(stops.Skip(bestInsertion)));
        }
Пример #3
0
        private double CalculateSwapCost(Route route, int i, int j)
        {
            double cost = 0;

            if (j == route.Nodes.Count - 1)
            {
                cost += _costCalculator.GetCost(route.Nodes[i], route.Nodes[j])
                        + _costCalculator.GetCost(route.Nodes[i + 1], route.Nodes[0])
                        - _costCalculator.GetCost(route.Nodes[i], route.Nodes[i + 1])
                        - _costCalculator.GetCost(route.Nodes[j], route.Nodes[0]);
            }
            else
            {
                cost += _costCalculator.GetCost(route.Nodes[i], route.Nodes[j])
                        + _costCalculator.GetCost(route.Nodes[i + 1], route.Nodes[j + 1])
                        - _costCalculator.GetCost(route.Nodes[i], route.Nodes[i + 1])
                        - _costCalculator.GetCost(route.Nodes[j], route.Nodes[j + 1]);
            }

            return(cost);
        }
Пример #4
0
 public decimal GetCost(InputOption inputOption, Edge cnn, Station station)
 {
     return((cnn.IsInterchanged(station) && inputOption.JourneyTime.IsPeak() ? CostCalculationConfigs.InterchangingAtPeakHourCost : 0)
            + _inner.GetCost(inputOption, cnn, station));
 }
Пример #5
0
 public decimal GetCost(InputOption inputOption, Edge cnn, Station station)
 {
     return((inputOption.JourneyTime.IsNonPeakBeforeNight() && cnn.IsInterchanged(station) ? CostCalculationConfigs.InterchangingAtNonPeakCost : 0)
            + _inner.GetCost(inputOption, cnn, station));
 }
Пример #6
0
        private double CalculateCost(Route route, int i, int j)
        {
            double cost = 0;

            if (i == j + 1 || i == j)
            {
                return(cost);
            }

            if (i == 0 && j == route.Nodes.Count - 1)
            {
                cost = 0;
            }
            else if (i == 0)
            {
                cost += _costCalculator.GetCost(route.Nodes[route.Nodes.Count - 1], route.Nodes[i + 1])
                        + _costCalculator.GetCost(route.Nodes[j], route.Nodes[i])
                        + _costCalculator.GetCost(route.Nodes[i], route.Nodes[j + 1])
                        - _costCalculator.GetCost(route.Nodes[route.Nodes.Count - 1], route.Nodes[i])
                        - _costCalculator.GetCost(route.Nodes[i], route.Nodes[i + 1])
                        - _costCalculator.GetCost(route.Nodes[j], route.Nodes[j + 1]);
            }
            else if (j == route.Nodes.Count - 1)
            {
                cost += _costCalculator.GetCost(route.Nodes[i - 1], route.Nodes[i + 1])
                        + _costCalculator.GetCost(route.Nodes[j], route.Nodes[i])
                        + _costCalculator.GetCost(route.Nodes[i], route.Nodes[0])
                        - _costCalculator.GetCost(route.Nodes[i - 1], route.Nodes[i])
                        - _costCalculator.GetCost(route.Nodes[i], route.Nodes[i + 1])
                        - _costCalculator.GetCost(route.Nodes[j], route.Nodes[0]);
            }
            else
            {
                cost += _costCalculator.GetCost(route.Nodes[i - 1], route.Nodes[i + 1])
                        + _costCalculator.GetCost(route.Nodes[j], route.Nodes[i])
                        + _costCalculator.GetCost(route.Nodes[i], route.Nodes[j + 1])
                        - _costCalculator.GetCost(route.Nodes[i - 1], route.Nodes[i])
                        - _costCalculator.GetCost(route.Nodes[i], route.Nodes[i + 1])
                        - _costCalculator.GetCost(route.Nodes[j], route.Nodes[j + 1]);
            }

            return(cost);
        }
 public decimal GetCost(InputOption inputOption, Edge cnn, Station station)
 {
     return(inputOption.JourneyTime.IsDisabled() ? new BaseCostCalculator().GetCost(inputOption, cnn, station) : _inner.GetCost(inputOption, cnn, station));
 }
Пример #8
0
 public decimal GetCost(InputOption inputOption, Edge cnn, Station station)
 {
     return((inputOption.JourneyTime.IsNight() && !cnn.IsInTe(station) && !cnn.IsInterchanged(station) ? CostCalculationConfigs.NightInOtherLinesCost : 0)
            + _inner.GetCost(inputOption, cnn, station));
 }