public CVRPData(TSPLIBParser myParser) { this.myParser = myParser; BestKnownQuality = myParser.BestKnown; Capacity = myParser.Capacity; MaxLength = myParser.MaxLength; // Add by Will&Ying 10252012 Coordinates = myParser.Vertices; Demands = myParser.Demands; Dimension = myParser.Dimension; Name = myParser.Name; CalculateDistanceMatrix(); Validate(); }
/// <summary> /// Entry point of the program /// </summary> /// <param name="args">The first argument can be the name of the input file</param> static void Main(string[] args) { // Start the timer Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); Console.WriteLine("Welcome to our Savings Method implementation"); // The name of the input file String inputFileName; // If there are command line arguments, the first one is the file name if (args.Length != 0) { inputFileName = args[0]; } else { inputFileName = "D022-04g.dat"; } // Create the parser object, and read in all the data from file. This object can read ANY TSPLIB file. Code borrowed from HeuristicLab. TSPLIBParser myParser = new TSPLIBParser(inputFileName); myParser.Parse(); // Create the vrp data object, using the parsed data CVRPData vrpData = new CVRPData(myParser); // Run the heuristic CVRPSolution mySolution = SavingsMethodHeuristic(vrpData); // Check if solution makes sense int solutionCheck = IsFeasible(mySolution.Solution, vrpData); switch (IsFeasible(mySolution.Solution, vrpData)) { case 0: Console.WriteLine("Solution verified"); break; case 1: Console.WriteLine("Not allocating nodes correctly"); break; case 2: Console.WriteLine("Using node many times"); break; case 3: Console.WriteLine("Not using node"); break; ////////////////////////////////////////////////////////////////////////////// //Add by Zihan&Ying case 4: Console.WriteLine("Exceeding max distance"); break; ////////////////////////////////////////////////////////////////////////////// } // Calculate the total time stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; // Output the solution mySolution.WriteToFile(inputFileName + ".opt", ts); Console.WriteLine("Press any key to exit."); Console.ReadKey(); }