@Override
  public void informAlgorithmStarts(
      VehicleRoutingProblem problem,
      VehicleRoutingAlgorithm algorithm,
      Collection<VehicleRoutingProblemSolution> solutions) {
    logger.info("prepare schrimpfAcceptanceFunction, i.e. determine initial threshold");
    double now = System.currentTimeMillis();

    /*
     * randomWalk to determine standardDev
     */
    final double[] results = new double[nOfRandomWalks];

    URL resource = Resource.getAsURL("randomWalk.xml");
    AlgorithmConfig algorithmConfig = new AlgorithmConfig();
    new AlgorithmConfigXmlReader(algorithmConfig).read(resource);
    VehicleRoutingAlgorithm vra =
        VehicleRoutingAlgorithms.createAlgorithm(problem, algorithmConfig);
    vra.setMaxIterations(nOfRandomWalks);
    vra.getAlgorithmListeners()
        .addListener(
            new IterationEndsListener() {

              @Override
              public void informIterationEnds(
                  int iteration,
                  VehicleRoutingProblem problem,
                  Collection<VehicleRoutingProblemSolution> solutions) {
                double result = Solutions.bestOf(solutions).getCost();
                //				logger.info("result="+result);
                results[iteration - 1] = result;
              }
            });
    vra.searchSolutions();

    StandardDeviation dev = new StandardDeviation();
    double standardDeviation = dev.evaluate(results);
    double initialThreshold = standardDeviation / 2;

    schrimpfAcceptance.setInitialThreshold(initialThreshold);

    logger.info("took " + ((System.currentTimeMillis() - now) / 1000.0) + " seconds");
    logger.debug("initial threshold: " + initialThreshold);
    logger.info("---------------------------------------------------------------------");
  }
Пример #2
0
 double standardDeviation() {
   return deviation.getResult();
 }
Пример #3
0
 public void add(long duration) {
   count++;
   totalDuration += duration;
   deviation.increment(duration);
 }