Package jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners

Examples of jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener


    //threading
    final ExecutorService executorService;
    if(nuOfThreads > 0){
      log.info("setup executor-service with " + nuOfThreads + " threads");
      executorService = Executors.newFixedThreadPool(nuOfThreads);
      algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, new AlgorithmEndsListener() {

        @Override
        public void informAlgorithmEnds(VehicleRoutingProblem problem,Collection<VehicleRoutingProblemSolution> solutions) {
          log.info("shutdown executor-service");
          executorService.shutdown();
        }
      }));
      Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {

        @Override
        public void uncaughtException(Thread arg0, Throwable arg1) {
          System.err.println(arg1.toString());
          System.exit(0);
        }
      });
      Runtime.getRuntime().addShutdownHook(new Thread(){
        public void run(){
          if(!executorService.isShutdown()){
            System.err.println("shutdowHook shuts down executorService");
            executorService.shutdown();
          }
        }
      });
    }
    else executorService = null;


    //create fleetmanager
    final VehicleFleetManager vehicleFleetManager = createFleetManager(vrp);

        String switchString = config.getString("construction.insertion.allowVehicleSwitch");
        final boolean switchAllowed;
        if(switchString != null){
            switchAllowed = Boolean.parseBoolean(switchString);
        }
        else switchAllowed = true;
        ActivityTimeTracker.ActivityPolicy activityPolicy;
        if(stateManager.timeWindowUpdateIsActivated()){
            UpdateVehicleDependentPracticalTimeWindows timeWindowUpdater = new UpdateVehicleDependentPracticalTimeWindows(stateManager,vrp.getTransportCosts());
            timeWindowUpdater.setVehiclesToUpdate(new UpdateVehicleDependentPracticalTimeWindows.VehiclesToUpdate() {

                @Override
                public Collection<Vehicle> get(VehicleRoute route) {
                    Collection<Vehicle> vehicles = new ArrayList<Vehicle>();
                    vehicles.add(route.getVehicle());
                    if(switchAllowed) {
                        vehicles.addAll(vehicleFleetManager.getAvailableVehicles(route.getVehicle()));
                    }
                    return vehicles;
                }

            });
            stateManager.addStateUpdater(timeWindowUpdater);
            activityPolicy = ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS;
        }
        else{
            activityPolicy = ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_ARRIVED;
        }
        stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts(),activityPolicy));
        stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager, activityPolicy));

    SolutionCostCalculator costCalculator;
    if(solutionCostCalculator==null) costCalculator = getDefaultCostCalculator(stateManager);
    else costCalculator = solutionCostCalculator;
   
    //construct initial solution creator
    AlgorithmStartsListener createInitialSolution = createInitialSolution(config,vrp,vehicleFleetManager,stateManager,algorithmListeners,definedClasses,executorService,nuOfThreads,costCalculator, constraintManager, addDefaultCostCalculators);
    if(createInitialSolution != null) algorithmListeners.add(new PrioritizedVRAListener(Priority.MEDIUM, createInitialSolution));

    //construct algorithm, i.e. search-strategies and its modules
    int solutionMemory = config.getInt("strategy.memory");
    SearchStrategyManager searchStratManager = new SearchStrategyManager();
    List<HierarchicalConfiguration> strategyConfigs = config.configurationsAt("strategy.searchStrategies.searchStrategy");
View Full Code Here


            log.info("set prematureBreak based on time");
            String timeString = config.getString("time");
            if(timeString == null) throw new IllegalStateException("time is missing");
            double time = Double.valueOf(timeString);
            TimeTermination timeBreaker = new TimeTermination(time);
            algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, timeBreaker));
            return timeBreaker;
        }
        if(basedOn.equals("variationCoefficient")){
            log.info("set prematureBreak based on variation coefficient");
            String thresholdString = config.getString("threshold");
            String iterationsString = config.getString("iterations");
            if(thresholdString == null) throw new IllegalStateException("threshold is missing");
            if(iterationsString == null) throw new IllegalStateException("iterations is missing");
            double threshold = Double.valueOf(thresholdString);
            int iterations = Integer.valueOf(iterationsString);
            VariationCoefficientTermination variationCoefficientBreaker = new VariationCoefficientTermination(iterations, threshold);
            algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, variationCoefficientBreaker));
            return variationCoefficientBreaker;
        }
        throw new IllegalStateException("prematureBreak basedOn " + basedOn + " is not defined");
    }
View Full Code Here

      log.info("set prematureBreak based on time");
      String timeString = config.getString("prematureBreak.time");
      if(timeString == null) throw new IllegalStateException("prematureBreak.time is missing");
      double time = Double.valueOf(timeString);
      TimeTermination timeBreaker = new TimeTermination(time);
      algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, timeBreaker));
      return timeBreaker;
    }
    if(basedOn.equals("variationCoefficient")){
      log.info("set prematureBreak based on variation coefficient");
      String thresholdString = config.getString("prematureBreak.threshold");
      String iterationsString = config.getString("prematureBreak.iterations");
      if(thresholdString == null) throw new IllegalStateException("prematureBreak.threshold is missing");
      if(iterationsString == null) throw new IllegalStateException("prematureBreak.iterations is missing");
      double threshold = Double.valueOf(thresholdString);
      int iterations = Integer.valueOf(iterationsString);
      VariationCoefficientTermination variationCoefficientBreaker = new VariationCoefficientTermination(iterations, threshold);
      algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, variationCoefficientBreaker));
      return variationCoefficientBreaker;
    }
    throw new IllegalStateException("prematureBreak basedOn " + basedOn + " is not defined");
  }
View Full Code Here

      String nuWarmupIterations = strategyConfig.getString("acceptor.warmup");
      double alpha = strategyConfig.getDouble("acceptor.alpha");
      SchrimpfAcceptance schrimpf = new SchrimpfAcceptance(solutionMemory, alpha);
      if(nuWarmupIterations!=null){
        SchrimpfInitialThresholdGenerator iniThresholdGenerator = new SchrimpfInitialThresholdGenerator(schrimpf, Integer.parseInt(nuWarmupIterations));
        algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, iniThresholdGenerator));
      }
      else{
        double threshold = strategyConfig.getDouble("acceptor.initialThreshold");
        schrimpf.setInitialThreshold(threshold);
      }
      algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, schrimpf));
      typedMap.put(acceptorKey, schrimpf);
      return schrimpf;
    }
    if(acceptorName.equals("experimentalSchrimpfAcceptance")){
      int iterOfSchrimpf = strategyConfig.getInt("acceptor.warmup");
      double alpha = strategyConfig.getDouble("acceptor.alpha");
      ExperimentalSchrimpfAcceptance schrimpf = new ExperimentalSchrimpfAcceptance(solutionMemory, alpha, iterOfSchrimpf);
      algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, schrimpf));
      typedMap.put(acceptorKey, schrimpf);
      return schrimpf;
    }
    else{
      throw new IllegalStateException("solution acceptor " + acceptorName + " is not known");
View Full Code Here

TOP

Related Classes of jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener

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.