Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
PierpaoloSpadafora committed Dec 12, 2024
1 parent 651ae95 commit f6159f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class ScheduleConstraintConfiguration {
private HardSoftScore jobDueDate = HardSoftScore.ofHard(1);

@ConstraintWeight("High priority jobs first")
private HardSoftScore highPriorityJobsFirst = HardSoftScore.ofSoft(1);
private HardSoftScore highPriorityJobsFirst = HardSoftScore.ofSoft(2500);

@ConstraintWeight("Short duration jobs first")
private HardSoftScore shortDurationJobsFirst = HardSoftScore.ofSoft(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,22 @@ private Constraint balanceMachineLoad(ConstraintFactory constraintFactory) {
.forEach(JobAssignment.class)
.groupBy(JobAssignment::getAssignedMachine,
sum(ja -> Math.toIntExact(ja.getSchedule().getDuration())))
.penalize(HardSoftScore.ONE_SOFT.multiply(100),
.penalize(HardSoftScore.ONE_SOFT.multiply(50), // Reduced weight
(machine, totalDuration) -> totalDuration / 3600)
.asConstraint("Balance machine load");
}

private Constraint prioritizeHighPriorityJobs(ConstraintFactory constraintFactory) {
return constraintFactory
.forEach(JobAssignment.class)
.reward(HardSoftScore.ONE_SOFT.multiply(3),
ja -> ja.getSchedule().getJob().getPriority().ordinal() * 100)
.filter(ja -> ja.getStartTimeGrain() != null)
.penalize(HardSoftScore.ONE_SOFT.multiply(2000),
ja -> {
int priorityFactor = (3 - ja.getSchedule().getJob().getPriority().ordinal());
long timeDelay = (ja.getStartTimeInSeconds() -
ja.getSchedule().getStartTime().toEpochSecond(ZoneOffset.UTC)) / 3600;
return (int)(priorityFactor * timeDelay * timeDelay);
})
.asConstraint("High priority jobs first");
}

Expand All @@ -127,7 +133,7 @@ private Constraint distributeJobsAcrossMachines(ConstraintFactory constraintFact
.groupBy(
ja -> ja.getSchedule().getMachineType().getId()
)
.reward(HardSoftScore.ONE_SOFT.multiply(1000))
.reward(HardSoftScore.ONE_SOFT.multiply(500))
.asConstraint("Distribute jobs across machines");
}

Expand Down

0 comments on commit f6159f3

Please sign in to comment.