Last active
November 27, 2024 14:54
-
-
Save TomCools/5986db42d25aa149217ee9144ac03f00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SantaConstraintProvider implements ConstraintProvider { | |
// NOTE: Normally you'd want to calculate a Distance Matrix before starting the solver. | |
DrivingTimeCalculator drivingTimeCalculator = DrivingTimeCalculator.getInstance(); | |
public static final String MINIMIZE_TRAVEL_TIME = "minimizeTravelTime"; | |
@Override | |
public Constraint[] defineConstraints(ConstraintFactory factory) { | |
return new Constraint[]{ | |
minimizeTravelTime(factory) | |
}; | |
} | |
/** | |
* Creates a constraint which will reduce the SOFT score by 1 for each second driven by a Santa. | |
*/ | |
Constraint minimizeTravelTime(ConstraintFactory factory) { | |
return factory.forEach(Santa.class) | |
.penalizeLong(HardSoftLongScore.ONE_SOFT, | |
santa -> drivingTimeCalculator.getTotalDrivingTimeSeconds(santa)) | |
.asConstraint(MINIMIZE_TRAVEL_TIME); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment