/******************************************************************************* * Copyright (C) 2013 Stefan Schroeder * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Contributors: * Stefan Schroeder - initial API and implementation ******************************************************************************/ package examples; import java.io.File; import java.util.Arrays; import java.util.Collection; import util.Coordinate; import util.Solutions; import algorithms.VehicleRoutingAlgorithms; import analysis.AlgorithmSearchProgressChartListener; import analysis.SolutionPlotter; import analysis.SolutionPrinter; import analysis.SolutionPrinter.Print; import analysis.StopWatch; import basics.VehicleRoutingAlgorithm; import basics.VehicleRoutingProblem; import basics.VehicleRoutingProblem.FleetSize; import basics.VehicleRoutingProblemSolution; import basics.algo.VehicleRoutingAlgorithmListeners.Priority; import basics.io.VrpXMLReader; import basics.route.PenaltyVehicleType; import basics.route.Vehicle; import basics.route.VehicleImpl; import basics.route.VehicleType; import basics.route.VehicleTypeImpl; public class MultipleDepotExampleWithPenaltyVehicles { /** * @param args */ public static void main(String[] args) { /* * some preparation - create output folder */ File dir = new File("output"); // if the directory does not exist, create it if (!dir.exists()){ System.out.println("creating directory ./output"); boolean result = dir.mkdir(); if(result) System.out.println("./output created"); } VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); /* * Read cordeau-instance p01, BUT only its services without any vehicles */ new VrpXMLReader(vrpBuilder).read("input/vrp_cordeau_08.xml"); /* * add vehicles with its depots * 2 depots: * (-33,33) * (33,-33) * * each with 14 vehicles each with a capacity of 500 and a maximum duration of 310 */ int nuOfVehicles = 14; int capacity = 500; double maxDuration = 310; Coordinate firstDepotCoord = Coordinate.newInstance(-33, 33); Coordinate second = Coordinate.newInstance(33, -33); int depotCounter = 1; for(Coordinate depotCoord : Arrays.asList(firstDepotCoord,second)){ for(int i=0;i solutions = vra.searchSolutions(); SolutionPrinter.print(Solutions.getBest(solutions),Print.VERBOSE); SolutionPlotter.plotSolutionAsPNG(vrp, Solutions.getBest(solutions), "output/p08_solution.png", "p08"); } }