Skip to content

Commit 2381c5a

Browse files
committed
Update OptimisationService.java
1 parent a3636eb commit 2381c5a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: src/main/java/org/ojalgo/optimisation/service/OptimisationService.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
/**
4747
* Basic usage:
4848
* <ol>
49-
* <li>Put optimisation problems on the solve queue bu calling {@link #putOnQueue(Sense, byte[], FileFormat)}
49+
* <li>Put optimisation problems on the solve queue by calling {@link #putOnQueue(Sense, byte[], FileFormat)}
5050
* <li>Check the status of the optimisation by calling {@link #getStatus(String)} – is it {@link Status#DONE}
5151
* or still {@link Status#PENDING}?
5252
* <li>Get the result of the optimisation by calling {@link #getResult(String)} – when {@link Status#DONE}
@@ -136,7 +136,6 @@ private static String generateKey() {
136136
private final ProcessingService myProcessingService = ProcessingService.newInstance("optimisation-worker");
137137
private final BlockingQueue<Problem> myQueue = new LinkedBlockingQueue<>(128);
138138
private final ForgetfulMap<String, Optimisation.Result> myResultCache = ForgetfulMap.newBuilder().expireAfterAccess(Duration.ofHours(1)).build();
139-
140139
private final ForgetfulMap<String, Status> myStatusCache = ForgetfulMap.newBuilder().expireAfterAccess(Duration.ofHours(1)).build();
141140

142141
public OptimisationService() {
@@ -146,9 +145,10 @@ public OptimisationService() {
146145
Parallelism baseParallelism = Parallelism.THREADS;
147146
int nbStrategies = IntegerStrategy.DEFAULT.countUniqueStrategies();
148147

149-
myNumberOfWorkers = baseParallelism.divideBy(2 * nbStrategies).getAsInt();
148+
int targetNbWorkers = baseParallelism.divideBy(2 * nbStrategies).getAsInt();
149+
myNumberOfWorkers = Math.max(2, targetNbWorkers);
150150

151-
IntegerStrategy integerStrategy = IntegerStrategy.DEFAULT.withParallelism(baseParallelism.divideBy(myNumberOfWorkers));
151+
IntegerStrategy integerStrategy = IntegerStrategy.DEFAULT.withParallelism(baseParallelism.divideBy(targetNbWorkers));
152152

153153
myOptimisationOptions = new Optimisation.Options();
154154
myOptimisationOptions.integer(integerStrategy);

0 commit comments

Comments
 (0)