/*******************************************************************************
 * Copyright (C) 2013  Stefan Schroeder
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either 
 * version 3.0 of the License, or (at your option) any later version.
 * 
 * This library 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
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public 
 * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
 ******************************************************************************/
package jsprit.examples;

import java.util.Collection;

import jsprit.analysis.toolbox.Plotter;
import jsprit.analysis.toolbox.Plotter.Label;
import jsprit.analysis.toolbox.SolutionPrinter;
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.VehicleRoutingProblem.Builder;
import jsprit.core.problem.io.VrpXMLReader;
import jsprit.core.problem.job.Job;
import jsprit.core.problem.job.Service;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.util.Solutions;
import jsprit.util.Examples;


public class MultipleDepotWithInitialRoutesExample {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		/*
		 * some preparation - create output folder
		 */
		Examples.createOutputFolder();
		
		VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
		/*
		 * Read cordeau-instance p01, BUT only its services without any vehicles 
		 */
		new VrpXMLReader(vrpBuilder).read("input/cordeau01.xml");
		VehicleRoute initialRoute = VehicleRoute.Builder.newInstance(getVehicle("1_4_vehicle",vrpBuilder)).addService(getService("44",vrpBuilder))
				.addService(getService("26",vrpBuilder)).build();
		vrpBuilder.addInitialVehicleRoute(initialRoute);
		
		/*
		 * build the problem
		 */
		VehicleRoutingProblem vrp = vrpBuilder.build();
		assert !vrp.getJobs().containsKey("26") : "strange. service 26 should not be part of the problem";
		assert !vrp.getJobs().containsKey("44") : "strange. service 26 should not be part of the problem";
		
		/*
		 * plot to see how the problem looks like
		 */
		new Plotter(vrp).setLabel(Label.ID).plot("output/cordeau01_problem_withInitialRoute.png", "c");

		/*
		 * solve the problem
		 */
		VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_noVehicleSwitch.xml");
		Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
		
		SolutionPrinter.print(Solutions.bestOf(solutions));
		
		new Plotter(vrp, Solutions.bestOf(solutions)).setLabel(Label.ID).plot("output/cordeau01_solution_withInitialRoute.png", "p01");
		
		
	}

	private static Service getService(String serviceId, Builder vrpBuilder) {
		for(Job j : vrpBuilder.getAddedJobs()){
			if(j.getId().equals(serviceId)){
				return (Service)j;
			}
		}
		return null;
	}

	private static Vehicle getVehicle(String vehicleId, Builder vrpBuilder) {
		for(Vehicle v : vrpBuilder.getAddedVehicles()){
			if(v.getId().equals(vehicleId)) return v;
		}
		return null;
	}

}

@@ -1978,54 +1978,9 @@
  p01
-, BUT only its services without any vehicles 
 %0A
+
 %09%09 *
@@ -2041,16 +2041,90 @@
 .xml%22);%0A
+%09%09%0A%09%09/*%0A%09%09 * Add initial route with 1_4_vehicle and services 44, 26%0A%09%09 */%0A
 %09%09Vehicl
@@ -2448,16 +2448,214 @@
 uild();%0A
+%09%09/*%0A%09%09 * since job (service) 26 and 44 are already planned in initial route and thus static AND sequence is fixed they%0A%09%09 * should not be in jobMap anymore (only variable jobs are in jobMap)%0A%09%09 */%0A
 %09%09assert
@@ -2801,34 +2801,34 @@
 trange. service 
-26
+44
  should not be p

Update MultipleDepotWithInitialRoutesExample.java