Skip to content

Commit

Permalink
refactor regret scoring
Browse files Browse the repository at this point in the history
  • Loading branch information
oblonski committed Nov 14, 2024
1 parent 0852cca commit 25507f8
Showing 1 changed file with 20 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ public static class Builder {

private ScoringFunction regretScorer = null;

private RegretScoringFunction regretScoringFunction = null;

private Map<SearchStrategy, Double> customStrategies = new HashMap<>();

private VehicleFleetManager fleetManager = null;
Expand Down Expand Up @@ -318,6 +320,11 @@ public Builder setRegretScorer(ScoringFunction scoringFunction) {
return this;
}

public Builder setRegretScoringFunction(RegretScoringFunction scoringFunction) {
this.regretScoringFunction = scoringFunction;
return this;
}

public VehicleRoutingAlgorithm buildAlgorithm() {
return new Jsprit(this).create(vrp);
}
Expand Down Expand Up @@ -382,6 +389,8 @@ public int createNumberToBeRemoved() {

private ScoringFunction regretScorer;

private RegretScoringFunction regretScoringFunction;

private final Map<SearchStrategy, Double> customStrategies = new HashMap<>();

private VehicleFleetManager vehicleFleetManager;
Expand All @@ -398,12 +407,18 @@ private Jsprit(Builder builder) {
this.activityInsertion = builder.activityInsertionCalculator;
this.acceptor = builder.solutionAcceptor;
regretScorer = builder.regretScorer;
regretScoringFunction = builder.regretScoringFunction;
customStrategies.putAll(builder.customStrategies);
vehicleFleetManager = builder.fleetManager;
}

private void ini(VehicleRoutingProblem vrp) {
if (regretScorer == null) regretScorer = getRegretScorer(vrp);
if (regretScorer == null) {
regretScorer = getRegretScorer(vrp);
}
if (regretScoringFunction == null) {
regretScoringFunction = new DefaultRegretScoringFunction(regretScorer);
}
}

private VehicleRoutingAlgorithm create(final VehicleRoutingProblem vrp) {
Expand Down Expand Up @@ -533,7 +548,6 @@ private VehicleRoutingAlgorithm create(final VehicleRoutingProblem vrp) {
ruinTimeRelated.setRandom(random);

AbstractInsertionStrategy regret;
final ScoringFunction scorer;

boolean fastRegret = Boolean.parseBoolean(getProperty(Parameter.FAST_REGRET.toString()));
if (es != null) {
Expand All @@ -546,8 +560,7 @@ private VehicleRoutingAlgorithm create(final VehicleRoutingProblem vrp) {
.setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString())))
.setActivityInsertionCostCalculator(activityInsertion)
.build();
scorer = regretScorer;
regretInsertion.setScoringFunction(scorer);
regretInsertion.setRegretScoringFunction(regretScoringFunction);
regretInsertion.setDependencyTypes(constraintManager.getDependencyTypes());
regret = regretInsertion;
}
Expand All @@ -559,8 +572,7 @@ private VehicleRoutingAlgorithm create(final VehicleRoutingProblem vrp) {
.setAllowVehicleSwitch(toBoolean(getProperty(Parameter.VEHICLE_SWITCH.toString())))
.setActivityInsertionCostCalculator(activityInsertion)
.build();
scorer = regretScorer;
regretInsertion.setScoringFunction(scorer);
regretInsertion.setRegretScoringFunction(regretScoringFunction);
regret = regretInsertion;
}
} else {
Expand All @@ -572,8 +584,7 @@ private VehicleRoutingAlgorithm create(final VehicleRoutingProblem vrp) {
.considerFixedCosts(toDouble(getProperty(Parameter.FIXED_COST_PARAM.toString())))
.setActivityInsertionCostCalculator(activityInsertion)
.build();
scorer = regretScorer;
regretInsertion.setScoringFunction(scorer);
regretInsertion.setRegretScoringFunction(regretScoringFunction);
regretInsertion.setDependencyTypes(constraintManager.getDependencyTypes());
regret = regretInsertion;
}
Expand All @@ -584,8 +595,7 @@ private VehicleRoutingAlgorithm create(final VehicleRoutingProblem vrp) {
.considerFixedCosts(toDouble(getProperty(Parameter.FIXED_COST_PARAM.toString())))
.setActivityInsertionCostCalculator(activityInsertion)
.build();
scorer = regretScorer;
regretInsertion.setScoringFunction(scorer);
regretInsertion.setRegretScoringFunction(regretScoringFunction);
regret = regretInsertion;
}
}
Expand Down

0 comments on commit 25507f8

Please sign in to comment.