public void InitializeFlexibleSimulation(bool allowDropNodes) { var dataModel = DataModelFactory.Instance().CreateInitialSimulationDataModel(allowDropNodes, this); if (dataModel != null) { RoutingSolver routingSolver = new RoutingSolver(dataModel, false); var printableList = dataModel.GetSettingsPrintableList(); foreach (var tobePrinted in printableList) { Console.WriteLine(tobePrinted); } //dataModel.PrintDataStructures(); Assignment timeWindowSolution = null; RoutingSearchParameters searchParameters = operations_research_constraint_solver.DefaultRoutingSearchParameters(); searchParameters.FirstSolutionStrategy = FirstSolutionStrategy.Types.Value.ParallelCheapestInsertion; searchParameters.LocalSearchMetaheuristic = LocalSearchMetaheuristic.Types.Value.TabuSearch; searchParameters.TimeLimit = new Duration { Seconds = 20 }; timeWindowSolution = routingSolver.TryGetSolution(searchParameters); RoutingSolutionObject routingSolutionObject = null; if (timeWindowSolution != null) { routingSolver.PrintSolution(timeWindowSolution); routingSolutionObject = routingSolver.GetSolutionObject(timeWindowSolution); for (int j = 0; j < routingSolutionObject.VehicleNumber; j++) //Initializes the flexible trips { var solutionVehicle = routingSolutionObject.IndexToVehicle(j); var solutionVehicleStops = routingSolutionObject.GetVehicleStops(solutionVehicle); var solutionTimeWindows = routingSolutionObject.GetVehicleTimeWindows(solutionVehicle); var solutionVehicleCustomers = routingSolutionObject.GetVehicleCustomers(solutionVehicle); InitializeVehicleFlexibleRoute(solutionVehicle, solutionVehicleStops, solutionVehicleCustomers, solutionTimeWindows); } } } Simulate(); }
public void Test(RoutingDataModel dataModel, bool dropNodes) //tests the algorithm using different maxUpperBound values until it finds the earliest feasible maxupperbound value, then saves its metrics { Console.WriteLine(this.ToString() + " testing algorithm: " + Name + " (Search time: " + SearchTimeLimitInSeconds + " seconds)"); DataModel = dataModel; Solver = new RoutingSolver(dataModel, dropNodes); var watch = Stopwatch.StartNew(); var solution = GetSolution(); _hasBeenTested = true; watch.Stop(); var elapsedSeconds = watch.ElapsedMilliseconds * 0.001; SolutionIsFeasible = solution != null; if (SolutionIsFeasible) //solution != null (means earliest feasible solution was found) { //Saves the important metrics for the earliest feasible solution MaxUpperBoundInMinutes = (int)TimeSpan.FromSeconds(Solver.MaximumDeliveryDelayTime).TotalMinutes; ComputationTimeInSeconds = elapsedSeconds; Solution = solution; Solver.PrintSolution(solution); } }