Package jsprit.core.algorithm.recreate

Examples of jsprit.core.algorithm.recreate.InsertionStrategy


    if(config.containsKey("[@name]")){
      String insertionName = config.getString("[@name]");
      if(!insertionName.equals("bestInsertion") && !insertionName.equals("regretInsertion")){
        new IllegalStateException(insertionName + " is not supported. use either \"bestInsertion\" or \"regretInsertion\"");
      }
      InsertionStrategy insertionStrategy = null;
      List<InsertionListener> insertionListeners = new ArrayList<InsertionListener>();
      List<PrioritizedVRAListener> algoListeners = new ArrayList<PrioritizedVRAListener>();
 
      BestInsertionBuilder iBuilder = new BestInsertionBuilder(vrp, vehicleFleetManager, routeStates, constraintManager);
     
      if(executorService != null){
        iBuilder.setConcurrentMode(executorService, nuOfThreads);
      }
     
      if(config.containsKey("level")){
        String level = config.getString("level");
        if(level.equals("local")){
          iBuilder.setLocalLevel(addDefaultCostCalculators);
        }
        else if(level.equals("route")){
          int forwardLooking = 0;
          int memory = 1;
          String forward = config.getString("level[@forwardLooking]");
          String mem = config.getString("level[@memory]");
          if(forward != null) forwardLooking = Integer.parseInt(forward);
          else log.warn("parameter route[@forwardLooking] is missing. by default it is 0 which equals to local level");
          if(mem != null) memory = Integer.parseInt(mem);
          else log.warn("parameter route[@memory] is missing. by default it is 1");
          iBuilder.setRouteLevel(forwardLooking, memory, addDefaultCostCalculators);
        }
        else throw new IllegalStateException("level " + level + " is not known. currently it only knows \"local\" or \"route\"");
      }
      else iBuilder.setLocalLevel(addDefaultCostCalculators);
     
      if(config.containsKey("considerFixedCosts") || config.containsKey("considerFixedCost")){
        if(addDefaultCostCalculators){
          String val = config.getString("considerFixedCosts");
          if(val == null) val = config.getString("considerFixedCost");
          if(val.equals("true")){
            double fixedCostWeight = 0.5;
            String weight = config.getString("considerFixedCosts[@weight]");
            if(weight == null) weight = config.getString("considerFixedCost[@weight]");
            if(weight != null) fixedCostWeight = Double.parseDouble(weight);
            else throw new IllegalStateException("fixedCostsParameter 'weight' must be set, e.g. <considerFixedCosts weight=1.0>true</considerFixedCosts>.\n" +
                "this has to be changed in algorithm-config-xml-file.");
            iBuilder.considerFixedCosts(fixedCostWeight);
          }
          else if(val.equals("false")){

          }
          else throw new IllegalStateException("considerFixedCosts must either be true or false, i.e. <considerFixedCosts weight=1.0>true</considerFixedCosts> or \n<considerFixedCosts weight=1.0>false</considerFixedCosts>. " +
              "if latter, you can also omit the tag. this has to be changed in algorithm-config-xml-file");
        }
      }
      String timeSliceString = config.getString("experimental[@timeSlice]");
      String neighbors = config.getString("experimental[@neighboringSlices]");
      if(timeSliceString != null && neighbors != null){
        iBuilder.experimentalTimeScheduler(Double.parseDouble(timeSliceString),Integer.parseInt(neighbors));
      }
      String allowVehicleSwitch = config.getString("allowVehicleSwitch");
      if(allowVehicleSwitch != null){
        iBuilder.setAllowVehicleSwitch(Boolean.parseBoolean(allowVehicleSwitch));
      }
      if(insertionName.equals("bestInsertion")){   
        insertionStrategy = iBuilder.build();
      }
      else throw new IllegalStateException("currently only 'bestInsertion' is supported");
     
      for(InsertionListener l : insertionListeners) insertionStrategy.addListener(l);

      algorithmListeners.addAll(algoListeners);
     
      return insertionStrategy;
    }
View Full Code Here


  private static void registerInsertionListeners(TypedMap definedClasses, List<InsertionListener> insertionListeners) {
    for(AbstractKey<?> key : definedClasses.keySet()){
      if(key instanceof InsertionStrategyKey){
        InsertionStrategyKey insertionKey = (InsertionStrategyKey) key;
        InsertionStrategy insertionStrategy = definedClasses.get(insertionKey);
        for(InsertionListener l : insertionListeners){
          insertionStrategy.addListener(l);
        }
      }
    }
  }
View Full Code Here

    if(insertionName == null) throw new IllegalStateException("insertion[@name] is missing.");
    String insertionId = modConfig.getString("[@id]");
    if(insertionId == null) insertionId = "noId";
    ModKey modKey = makeKey(insertionName,insertionId);
    InsertionStrategyKey insertionStrategyKey = new InsertionStrategyKey(modKey);
    InsertionStrategy insertionStrategy = definedClasses.get(insertionStrategyKey);
    if(insertionStrategy == null){
      List<PrioritizedVRAListener> prioListeners = new ArrayList<PrioritizedVRAListener>();
      insertionStrategy = createInsertionStrategy(modConfig, vrp, vehicleFleetManager, routeStates, prioListeners, executorService, nuOfThreads, constraintManager, addDefaultCostCalculators);
      algorithmListeners.addAll(prioListeners);
      definedClasses.put(insertionStrategyKey,insertionStrategy);
    }
    final InsertionStrategy finalInsertionStrategy = insertionStrategy;

    return new AlgorithmStartsListener() {

      @Override
      public void informAlgorithmStarts(VehicleRoutingProblem problem, VehicleRoutingAlgorithm algorithm, Collection<VehicleRoutingProblemSolution> solutions) {
View Full Code Here

      if(insertionName == null) throw new IllegalStateException("module.insertion[@name] is missing. set it to \"regretInsertion\" or \"bestInsertion\"");
      String insertionId = moduleConfig.getString("insertion[@id]");
      if(insertionId == null) insertionId = "noId";
      ModKey insertionKey = makeKey(insertionName,insertionId);
      InsertionStrategyKey insertionStrategyKey = new InsertionStrategyKey(insertionKey);
      InsertionStrategy insertion = definedClasses.get(insertionStrategyKey);
      if(insertion == null){
        List<HierarchicalConfiguration> insertionConfigs = moduleConfig.configurationsAt("insertion");
        if(insertionConfigs.size() != 1) throw new IllegalStateException("this should be 1");
        List<PrioritizedVRAListener> prioListeners = new ArrayList<PrioritizedVRAListener>();
        insertion = createInsertionStrategy(insertionConfigs.get(0), vrp, vehicleFleetManager, routeStates, prioListeners, executorService, nuOfThreads, constraintManager, addDefaultCostCalculators);
        algorithmListeners.addAll(prioListeners);
      }
      final InsertionStrategy final_insertion = insertion;
   
      RuinAndRecreateModule rrModule =  new RuinAndRecreateModule("ruin_and_recreate", final_insertion, ruin);
      return rrModule;
    }
    throw new NullPointerException("no module found with moduleName=" + moduleName +
View Full Code Here

     */
    BestInsertionBuilder iBuilder = new BestInsertionBuilder(vrp, fleetManager, stateManager, constraintManager);
    /*
     * no need to set further options
     */
    InsertionStrategy iStrategy = iBuilder.build();
   
    /*
     * second, define random-ruin that ruins 50-percent of the selected solution
     */
    RuinStrategy randomRuin = new RandomRuinStrategyFactory(0.5).createStrategy(vrp);
View Full Code Here

        constraintManager.addLoadConstraint();

        VehicleFleetManager fleetManager = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager();

        BestInsertionBuilder bestIBuilder = new BestInsertionBuilder(vrp, fleetManager, stateManager,constraintManager);
        InsertionStrategy bestInsertion = bestIBuilder.build();


        RuinStrategy radial = new RadialRuinStrategyFactory( 0.3, new AvgServiceAndShipmentDistance(vrp.getTransportCosts())).createStrategy(vrp);
        RuinStrategy random = new RandomRuinStrategyFactory(0.5).createStrategy(vrp);
View Full Code Here

    cManager.addTimeWindowConstraint();
   
       
    VehicleFleetManager fleetManager = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager();
   
    InsertionStrategy bestInsertion = new BestInsertionBuilder(vrp, fleetManager, stateManager, cManager).build();
   
    RuinStrategy radial = new RadialRuinStrategyFactory(0.15, new AvgServiceDistance(vrp.getTransportCosts())).createStrategy(vrp);
    RuinStrategy random = new RandomRuinStrategyFactory(0.25).createStrategy(vrp);
   
    SolutionCostCalculator solutionCostCalculator = new SolutionCostCalculator() {
View Full Code Here

     
      VehicleFleetManager fleetManager = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager();
     
      BestInsertionBuilder iBuilder = new BestInsertionBuilder(vrp, fleetManager, stateManager, constraintManager);
//      iBuilder.setConstraintManager(constraintManger);
      InsertionStrategy bestInsertion = iBuilder.build();
       
      RuinStrategy radial = new RadialRuinStrategyFactory( 0.15, new AvgServiceDistance(vrp.getTransportCosts())).createStrategy(vrp);
      RuinStrategy random = new RandomRuinStrategyFactory(0.25).createStrategy(vrp);
     
      SolutionCostCalculator solutionCostCalculator = new SolutionCostCalculator() {
View Full Code Here

     */
    BestInsertionBuilder iBuilder = new BestInsertionBuilder(vrp, fleetManager, stateManager, constraintManager);
    /*
     * no need to set further options
     */
    InsertionStrategy iStrategy = iBuilder.build();
   
    /*
     * second, define random-ruin that ruins 50-percent of the selected solution
     */
    RuinStrategy randomRuin = new RandomRuinStrategyFactory(0.5).createStrategy(vrp);
View Full Code Here

TOP

Related Classes of jsprit.core.algorithm.recreate.InsertionStrategy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.