How to use multiple threads

Hi

Now, I’m trying to run JSprit API on multiple threads, and defined vehicle route algorithm like below.

    // Build VRA
    VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp, "resources/extSearch.xml");
    vraBuilder.setStateAndConstraintManager(stateManager,constraintManager);
    //Required Steps ------
    vraBuilder.addCoreConstraints();
    vraBuilder.addDefaultCostCalculators();
    //---------------------
    // Set concurrency
    int count = Thread.activeCount();
    vraBuilder.setNuOfThreads(count);
    System.out.println("currently active threads = " + count);
    VehicleRoutingAlgorithm vra = vraBuilder.build();	

I thought it would run on multiple threads, but once I ran it, a console appeared like below, and it looked like not running on multiple threads.

>java -jar sample.jar
2016-05-12 21:21:15,000 [main] INFO jsprit.core.problem.VehicleRoutingProblem - setup problem: [fleetSize=FINITE][#jobs=100][#vehicles=100][#vehicleTypes=10][transportCost=jsprit.core.util.FastVehicleRoutingTransportCostsMatrix@6690267f][activityCosts=jsprit.core.problem.cost.WaitingTimeCosts@9f19c5cb]
currently active threads = 4
2016-05-12 21:21:15,287 [main] INFO jsprit.core.algorithm.VehicleRoutingAlgorithm - algorithm starts: [maxIterations=1000]
2016-05-12 21:21:15,289 [main] INFO jsprit.core.algorithm.InsertionInitialSolutionFactory - create initial solution
2016-05-12 21:21:17,158 [main] INFO jsprit.core.algorithm.VehicleRoutingAlgorithm - iterations start
2016-05-12 21:21:17,827 [main] INFO jsprit.core.algorithm.VehicleRoutingAlgorithm$Counter - iterations 1
2016-05-12 21:21:18,366 [main] INFO jsprit.core.algorithm.VehicleRoutingAlgorithm$Counter - iterations 2
2016-05-12 21:21:19,862 [main] INFO jsprit.core.algorithm.VehicleRoutingAlgorithm$Counter - iterations 4
2016-05-12 21:21:23,299 [main] INFO jsprit.core.algorithm.VehicleRoutingAlgorithm$Counter - iterations 8

Result contained 4 routes.
I commanded “top” while calculating, but there was only one thread running this java application.

Could you help to solve this?

try to substitute
VehicleRoutingAlgorithm vra = vraBuilder.build();
with
VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.THREADS,“5”).buildAlgorithm();

1 Like

Thank you for replying.

In that case, how can I set “resources/extSearch.xml” and add “CoreConstraints”, “DefaultCostCalculators” ?