From f6159f3cbcbee45c214f1351296b268c5a052a1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Spada=20=E2=9A=94=EF=B8=8F?= <75368540+PierpaoloSpadafora@users.noreply.github.com> Date: Thu, 12 Dec 2024 01:05:15 +0100 Subject: [PATCH] fix --- .../rdm/utils/ScheduleConstraintConfiguration.java | 2 +- .../rdm/utils/ScheduleConstraintProvider.java | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Backend/src/main/java/unical/demacs/rdm/utils/ScheduleConstraintConfiguration.java b/Backend/src/main/java/unical/demacs/rdm/utils/ScheduleConstraintConfiguration.java index 50656cc..d351f4e 100644 --- a/Backend/src/main/java/unical/demacs/rdm/utils/ScheduleConstraintConfiguration.java +++ b/Backend/src/main/java/unical/demacs/rdm/utils/ScheduleConstraintConfiguration.java @@ -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); diff --git a/Backend/src/main/java/unical/demacs/rdm/utils/ScheduleConstraintProvider.java b/Backend/src/main/java/unical/demacs/rdm/utils/ScheduleConstraintProvider.java index f421a25..76f35f2 100644 --- a/Backend/src/main/java/unical/demacs/rdm/utils/ScheduleConstraintProvider.java +++ b/Backend/src/main/java/unical/demacs/rdm/utils/ScheduleConstraintProvider.java @@ -100,7 +100,7 @@ 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"); } @@ -108,8 +108,14 @@ private Constraint balanceMachineLoad(ConstraintFactory constraintFactory) { 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"); } @@ -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"); }