Exemplo n.º 1
0
        public void BuildLRxTest()
        {
            DPNProblemContext   ctx     = GenerateProblemContext();
            DiscreteTimeAdapter adapter = new DiscreteTimeAdapter(ctx.StartTime, ctx.EndTime, 1);
            var graph = new LRxTravelHyperNetwork(ctx, adapter,
                                                  ObjectNetworkFactory.Create("", ctx, adapter),
                                                  new CustomerArrival(),
                                                  new Dictionary <CustomerArrival, List <TravelPath> >(),
                                                  new Dictionary <IServiceSegment, decimal>()
            {
                { ctx.Wor.RailwayTimeTable.Trains.First().ServiceSegments.First(), 0 },
                { ctx.Wor.RailwayTimeTable.Trains.First().ServiceSegments.Last(), 0 },
                { ctx.Wor.RailwayTimeTable.Trains.Last().ServiceSegments.First(), 0 }
            },
                                                  new Dictionary <CustomerArrival, Dictionary <TravelPath, decimal> >(),
                                                  new Dictionary <IEdge <TravelHyperNode>, decimal>());

            graph.Build();

            /*
             * In-train:4*3
             * Finish:3*3
             * Reservation:11*3*(2+1)
             * Waiting:10*3
             * Total:137
             */

            Assert.AreEqual(138, graph.EdgesCount);
        }
Exemplo n.º 2
0
        public void LRxPathSearchTest()
        {
            DPNProblemContext   ctx      = GenerateProblemContext();
            CustomerArrival     customer = new CustomerArrival();
            DiscreteTimeAdapter adapter  = new DiscreteTimeAdapter(ctx.StartTime, ctx.EndTime, 1);

            TravelPath p     = new TravelPath();
            var        graph = new LRxTravelHyperNetwork(ctx, adapter,
                                                         ObjectNetworkFactory.Create("", ctx, adapter),
                                                         customer,
                                                         new Dictionary <CustomerArrival, List <TravelPath> >()//path dict
            {
                { customer, new List <TravelPath>()
                  {
                      p
                  } }
            },
                                                         new Dictionary <IServiceSegment, decimal>()//rho
            {
                { ctx.Wor.RailwayTimeTable.Trains.First().ServiceSegments.First(), 0 },
                { ctx.Wor.RailwayTimeTable.Trains.First().ServiceSegments.Last(), 0 },
                { ctx.Wor.RailwayTimeTable.Trains.Last().ServiceSegments.First(), 0 }
            },
                                                         new Dictionary <CustomerArrival, Dictionary <TravelPath, decimal> >()
            {
                { customer, new Dictionary <TravelPath, decimal>()
                  {
                      { p, 1 }
                  } }
            },//mu
                                                         new Dictionary <IEdge <TravelHyperNode>, decimal>());

            graph.Build();

            DijkstraShortestPaths <DirectedWeightedSparseGraph <TravelHyperNode>, TravelHyperNode> dijkstra
                = new DijkstraShortestPaths <DirectedWeightedSparseGraph <TravelHyperNode>, TravelHyperNode>(graph,
                                                                                                             new TravelHyperNode()
            {
                Time = 0, Station = ctx.Wor.Net.StationCollection.First(), Price = 0
            });

            Assert.IsTrue(dijkstra.HasPathTo(new TravelHyperNode()
            {
                Time = adapter.Horizon + 1440, Station = ctx.Wor.Net.StationCollection.Last(), Price = 0
            }) == true);

            var desNode = new TravelHyperNode()
            {
                Time = adapter.Horizon + 1440, Station = ctx.Wor.Net.StationCollection.Last(), Price = 0
            };
            var pathToC      = string.Empty;
            var shortestPath = dijkstra.ShortestPathTo(desNode);

            foreach (var node in shortestPath)
            {
                pathToC = String.Format("{0}({1}) -> ", pathToC, node);
            }

            pathToC = pathToC.TrimEnd(new char[] { ' ', '-', '>' });
            Console.WriteLine("Shortest path to Station 'C': " + pathToC + "\r\n");
            Assert.AreEqual(202m, Math.Round(dijkstra.DistanceTo(desNode)));
        }