@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("---------------------------------------------------------------------"); }
public static void main(String[] args) throws IOException { Config config = new Config(); config.addCoreModules(); Scenario scenario = ScenarioUtils.createScenario(config); new MatsimNetworkReader(scenario).readFile("sensitivity/network.xml"); BufferedWriter writer = new BufferedWriter( new FileWriter(new File("sensitivity/output/lcpas-with-two-types-and-two-tolls.txt"))); writer.write("lcpa\trun\tcomptime\trelations\n"); List<LCPAFactory> factories = new ArrayList<LCPAFactory>(); factories.add(new LCPAFactory("dijstra", LCPAFactories.getFastDijkstraFactory())); factories.add(new LCPAFactory("astar-eucl", LCPAFactories.getFastAStarEuclideanFactory())); factories.add(new LCPAFactory("astar-landm", LCPAFactories.getFastAStarLandmarksFactory())); for (LCPAFactory f : factories) { for (int run = 0; run < 10; run++) { StopRouting stopRouting = new StopRouting(); VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); new VrpXMLReader(builder).read("sensitivity/vrp_tight_tw_with_two_types.xml"); NetworkBasedTransportCosts.Builder costBuilder = NetworkBasedTransportCosts.Builder.newInstance(scenario.getNetwork()); addVehicleTypeSpecificCosts(costBuilder, builder.getAddedVehicles()); costBuilder.setThreadSafeLeastCostPathCalculatorFactory(f.factory); // create roadPricing Calc VehicleTypeDependentRoadPricingCalculator roadPricing = new VehicleTypeDependentRoadPricingCalculator(); // define and add a roadPricingSchema RoadPricingSchemeImpl cordonToll = new RoadPricingSchemeImpl(); new RoadPricingReaderXMLv1(cordonToll).parse("sensitivity/cordonToll20.xml"); roadPricing.addPricingScheme("type1", cordonToll); RoadPricingSchemeImpl distanceToll = new RoadPricingSchemeImpl(); new RoadPricingReaderXMLv1(distanceToll).parse("sensitivity/distanceToll1.xml"); roadPricing.addPricingScheme("type2", distanceToll); // finally add roadpricingcalc to netBasedTransportCosts costBuilder.setRoadPricingCalculator(roadPricing); NetworkBasedTransportCosts routingCosts = costBuilder.build(); routingCosts.getInternalListeners().add(stopRouting); builder.setRoutingCost(routingCosts); VehicleRoutingProblem vrp = builder.build(); VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "sensitivity/algorithm.xml"); StopAlgoCompTime compTimeStopper = new StopAlgoCompTime(); vra.getAlgorithmListeners().addListener(compTimeStopper, Priority.HIGH); Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions(); SolutionPrinter.print(Solutions.bestOf(solutions)); printLowerBoundOfNuVehicles(vrp, 40); long time = 0; for (StopWatch w : stopRouting.getRouterStopWatches().values()) { time += w.getTime(); } writer.write( f.name + "\t" + run + "\t" + time + "\t" + routingCosts.ttMemorizedCounter.getCounter() + "\n"); System.out.println("routingTime: " + time); System.out.println("compTime: " + compTimeStopper.stopWatch.toString()); } } writer.close(); }