예제 #1
0
파일: Functions.cs 프로젝트: yawenLUO/VRP
        // only called when route contain >=3 customers
        // called in final step to reset routes
        public static void write_linkernInputFile_2(Route route, Customer depot)
        {
            StreamWriter writer;
            try
            {
                writer = new StreamWriter("linkern_input");
                writer.WriteLine("NAME : 2L-HFVRP");
                writer.WriteLine("COMMENT : 2L-HFVRP");
                writer.WriteLine("COMMENT : 2L-HFVRP");
                writer.WriteLine("TYPE : TSP");
                // existing customers+depot+new customer
                int numNodes = route.get_customerSequence().Count + 1;
                writer.WriteLine("DIMENSION : " + numNodes);
                writer.WriteLine("EDGE_WEIGHT_TYPE : EUC_2D");
                writer.WriteLine("NODE_COORD_SECTION");

                writer.WriteLine("1 " + depot.get_x() + " " + depot.get_y());

                for (int i = 2; i <= numNodes; i++)
                {
                    Customer currentCus = route.get_customerSequence()[i - 2];
                    writer.WriteLine(i + " " + currentCus.get_x() + " " + currentCus.get_y());
                }

                writer.Close();
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
        }
예제 #2
0
파일: Functions.cs 프로젝트: yawenLUO/VRP
        public static void printRoutes(List<Route> routes, Customer depot)
        {
            double totalCost = 0;
            for (int i = 0; i < routes.Count; i++)
            {
                Console.WriteLine();
                Console.WriteLine("Route " + i + ":");
                Console.Write("vehicleType is: ");
                routes[i].get_VehicleType().print();
                Console.WriteLine("Total Weight: " + routes[i].get_totalWeight() + " Total Distance: " + routes[i].get_totalDistance() + " Total Cost: " + routes[i].get_totalCost());
                totalCost += routes[i].get_totalCost();
                Console.WriteLine();
                // print the customer sequence of this route
                Console.WriteLine("depot " + "(" + depot.get_x() + "," + depot.get_y() + ")  ");
                Console.WriteLine();
                Console.WriteLine("-->");
                List<Customer> sequence = routes[i].get_customerSequence();
                for (int j = 0; j < sequence.Count; j++)
                {
                    Customer currentCus = sequence[j];
                    currentCus.print();
                    Console.WriteLine("-->");
                    // System.out.print("Cus"+currentCus.get_index()+" Weight:"+currentCus.get_totalWeight()+" ("+currentCus.get_x()+","+currentCus.get_y()+") -> ");
                }
                Console.WriteLine("  depot " + "(" + depot.get_x() + "," + depot.get_y() + ")");
                Console.WriteLine();

                // print all items and the coordinates
                Console.WriteLine("Items and coordinates:");
                for (int j = 0; j < sequence.Count; j++)
                {
                    Customer currentCus = sequence[j];
                    List<Item> items = currentCus.get_items();
                    for (IEnumerator iterator = items.GetEnumerator(); ;)
                    {
                        if (!iterator.MoveNext())
                            break;
                        Item item = (Item)iterator.Current;
                        Console.WriteLine(item.ToString());
                    }
                }
                Console.WriteLine();
            }
            Console.WriteLine("------------------------------------------------");
            Console.WriteLine("totalCost: " + totalCost);
        }