Using multiple threads to run algorithm

Hello,

I am trying to run the algorithm with multiple threads but i am unable to do so. I tried using below methods-

Jsprit.Builder jspritAlgoBuilder = Jsprit.Builder.newInstance(problem); jspritAlgoBuilder.setExecutorService(Executors.newFixedThreadPool(4), 4);

And

VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(problem, algoConfig); vraBuilder.setNuOfThreads(4);

However, both of them are not working here, algorithm is using only one thread to execute.
I am not sure what i am doing wrong here, please suggest.

– Thanks

If you use the first, the builder should select RegretInsertionConcurrent or RegretInsertionConcurrentFast. Would you mind to debug this again?

Thank you for the quick reply @stefan, let me debug this.

Is there a difference using:

Jsprit.Builder algorithmBuilder = Jsprit.Builder.newInstance(problem);
VehicleRoutingAlgorithm algorithm = algorithmBuilder.
setProperty(Jsprit.Parameter.THREADS, “2”)
.buildAlgorithm();

and that what you use above? Or is the setProperty(Jsprit.Parameter.THREADS … outdated?

The only difference is YOU just determine the number of threads. This way the creation of the executor managing the threads is hidden to you. The other option is to create this executor explicitly and to give it to the algorithm.

Hi @stefan,

I debugged this and i could see that builder has selected > RegretInsertionConcurrent but i was not able to see algorithm creating multiple threads for its run, please find the log below -

> 2016-10-11 21:47:38 - [INFO] [http-nio-8080-exec-6] [com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm.searchSolutions:194]
> 				: algorithm starts: [maxIterations=2000]
> 2016-10-11 21:47:38 - [INFO] [http-nio-8080-exec-6] [com.graphhopper.jsprit.core.algorithm.InsertionInitialSolutionFactory.createSolution:52]
> 				: create initial solution
> 2016-10-11 21:47:43 - [INFO] [http-nio-8080-exec-6] [com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm.searchSolutions:202]
> 				: iterations start
> 2016-10-11 21:47:43 - [INFO] [http-nio-8080-exec-6] [com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm$Counter.incCounter:79]
> 				: iterations 1
> 2016-10-11 21:47:43 - [INFO] [http-nio-8080-exec-6] [com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm$Counter.incCounter:79]
> 				: iterations 2
> 2016-10-11 21:47:43 - [INFO] [http-nio-8080-exec-6] [com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm$Counter.incCounter:79]
> 				: iterations 4
> 2016-10-11 21:47:43 - [INFO] [http-nio-8080-exec-6] [com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm$Counter.incCounter:79]
> 				: iterations 8
> 2016-10-11 21:47:43 - [INFO] [http-nio-8080-exec-6] [com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm$Counter.incCounter:79]
> 				: iterations 16
> 2016-10-11 21:47:43 - [INFO] [http-nio-8080-exec-6] [com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm$Counter.incCounter:79]
> 				: iterations 32
> 2016-10-11 21:47:43 - [INFO] [http-nio-8080-exec-6] [com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm$Counter.incCounter:79]
> 				: iterations 64
> 2016-10-11 21:47:43 - [INFO] [http-nio-8080-exec-6] [com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm$Counter.incCounter:79]
> 				: iterations 128
> 2016-10-11 21:47:43 - [INFO] [http-nio-8080-exec-6] [com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm$Counter.incCounter:79]
> 				: iterations 256
> 2016-10-11 21:47:43 - [INFO] [http-nio-8080-exec-6] [com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm$Counter.incCounter:79]
> 				: iterations 512
> 2016-10-11 21:47:43 - [INFO] [http-nio-8080-exec-6] [com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm$Counter.incCounter:79]
> 				: iterations 1024
> 2016-10-11 21:47:43 - [INFO] [http-nio-8080-exec-6] [com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm.searchSolutions:219]
> 				: iterations end at 2000 iterations

Please let me know if i am doing something wrong here.

P.S. - I am using 1.6.3-SNAPSHOT

Hi @stefan @patrick_wisniewski19 @koradeprashant : I am also facing similar issue as @koradeprashant . I am not able to run algorithm on multiple threads using suggested approach. Execution time remains almost same when I use multiple threads compared to the instance of running on single thread.
This issue is very critical for performance improvement because we will be able to save huge amount of time. Please let me know incase anyone finds some solution.

Hello All,

Did we manage to find a solution for using JSPRIT on multiple threads ?


Karim