Skip to content

Commit dbcf6b2

Browse files
committed
Fixed missing check for unassigned stops
1 parent 06cdf8a commit dbcf6b2

File tree

1 file changed

+21
-10
lines changed
  • jsprit-integration/src/main/java/com/opendoorlogistics/components/jsprit

1 file changed

+21
-10
lines changed

jsprit-integration/src/main/java/com/opendoorlogistics/components/jsprit/VRPComponent.java

+21-10
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ private void runOptimiser(final ComponentExecutionApi api, ODLDatastore<? extend
392392
// store the best every solution found and it isn't always the one returned...
393393
class BestEver {
394394
VehicleRoutingProblemSolution solution;
395-
double cost = Double.POSITIVE_INFINITY;
395+
//double cost = Double.POSITIVE_INFINITY;
396396
}
397397
final BestEver bestEver = new BestEver();
398398

@@ -410,11 +410,24 @@ class LastUpdate {
410410

411411
@Override
412412
public void informIterationEnds(int i, VehicleRoutingProblem problem, Collection<VehicleRoutingProblemSolution> solutions) {
413-
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);
414-
if (bestSolution != null) {
415-
if (bestSolution.getCost() < bestEver.cost) {
416-
bestEver.solution = VehicleRoutingProblemSolution.copyOf(bestSolution);
417-
bestEver.cost = bestSolution.getCost();
413+
VehicleRoutingProblemSolution newSln = Solutions.bestOf(solutions);
414+
if (newSln != null) {
415+
// accept if we don't have a solution
416+
boolean accept = bestEver.solution==null;
417+
418+
// accept if the new solution has less unassigned jobs
419+
if(!accept && (newSln.getUnassignedJobs().size() < bestEver.solution.getUnassignedJobs().size())){
420+
accept = true;
421+
}
422+
423+
// accept if we have the same number of unassigned jobs but the cost is less
424+
if(!accept && (newSln.getUnassignedJobs().size() == bestEver.solution.getUnassignedJobs().size())
425+
&& (newSln.getCost() < bestEver.solution.getCost())){
426+
accept = true;
427+
}
428+
429+
if (accept) {
430+
bestEver.solution = VehicleRoutingProblemSolution.copyOf(newSln);
418431
}
419432
}
420433

@@ -426,11 +439,9 @@ public void informIterationEnds(int i, VehicleRoutingProblem problem, Collection
426439

427440
builder.append("Runtime " + ((time - startTime) / 1000) + "s");
428441
builder.append(", Step " + i);
429-
if (bestEver.cost != Double.POSITIVE_INFINITY) {
430-
builder.append(", " + DecimalFormat.getInstance().format(bestEver.cost) + " cost");
431-
}
432-
442+
433443
if (bestEver.solution != null) {
444+
builder.append(", " + DecimalFormat.getInstance().format(bestEver.solution.getCost()) + " cost");
434445
builder.append(", " + bestEver.solution.getRoutes().size() + " routes");
435446
builder.append(", " + bestEver.solution.getUnassignedJobs().size() + " unassigned jobs");
436447
}

0 commit comments

Comments
 (0)