I am having trouble setting the time limit value of the search parameters in Java. I would like to pass an int at "XXX" below but setTimeLimit expects a com.google.protobuf.Duration. A new instance of that Duration object can not be created with an integer either. It requires a "builder", something like com.google.protobuf.GeneratedMessageV3.Builder. Surely I am overcomplicating things here.
Can you please give a Java example of setting the time out?
RoutingSearchParameters searchParameters =
main.defaultRoutingSearchParameters()
.toBuilder()
.setFirstSolutionStrategy(FirstSolutionStrategy.Value.PATH_CHEAPEST_ARC)
.setTimeLimit(XXX)
.build();
First import Duration
import com.google.protobuf.Duration;
then you can use:
RoutingSearchParameters searchParameters =
main.defaultRoutingSearchParameters()
.toBuilder()
.setFirstSolutionStrategy(FirstSolutionStrategy.Value.PATH_CHEAPEST_ARC)
.setLogSearch(true)
.setTimeLimit(Duration.newBuilder().setSeconds(10).build())
.build();
Using builder:
src: https://developers.google.com/protocol-buffers/docs/javatutorial#builders
src: https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/Duration#newBuilder--
thank you!
For the record adding the sample: https://github.com/google/or-tools/blob/master/ortools/constraint_solver/samples/VrpWithTimeLimit.java