Skip to content

Commit caefc2a

Browse files
Merge pull request #112 from RandomCyberCoder/config_fix
updated example file and code to line up
2 parents c26ff9e + 1bfbe2c commit caefc2a

3 files changed

Lines changed: 34 additions & 22 deletions

File tree

java/hello-world/src/main/java/org/acme/schooltimetabling/helperClasses/ScheduleConfig.java

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -72,34 +72,36 @@ public static void loadConfig(String yamlPath){
7272
Yaml yaml = new Yaml();
7373
HOLDER.scheduleConfig = yaml.loadAs(inputStream, ScheduleConfig.class);
7474

75-
//BitSet setup for times we want to compress into
76-
EnumSet<Days> MTWRF = EnumSet.allOf(Days.class);
77-
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("h:mma");
78-
LocalTime startTime = LocalTime.parse(HOLDER.scheduleConfig.compressStart, formatter);
79-
LocalTime endTime = LocalTime.parse(HOLDER.scheduleConfig.compressEnd, formatter);
80-
//normalize times
81-
startTime = roundToNearestHalfHour(startTime);
82-
endTime = roundToNearestHalfHour(endTime);
83-
if(startTime.isAfter(endTime)){
84-
LOGGER.error("The start time for the compressed start is after the end time; Exiting program");
85-
System.exit(1);
75+
if(HOLDER.scheduleConfig.compressStart != null && HOLDER.scheduleConfig.compressEnd != null) {//BitSet setup for times we want to compress into
76+
EnumSet<Days> MTWRF = EnumSet.allOf(Days.class);
77+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("h:mma");
78+
LocalTime startTime = LocalTime.parse(HOLDER.scheduleConfig.compressStart, formatter);
79+
LocalTime endTime = LocalTime.parse(HOLDER.scheduleConfig.compressEnd, formatter);
80+
//normalize times
81+
startTime = roundToNearestHalfHour(startTime);
82+
endTime = roundToNearestHalfHour(endTime);
83+
if (startTime.isAfter(endTime)) {
84+
LOGGER.error("The start time for the compressed start is after the end time; Exiting program");
85+
System.exit(1);
86+
}
87+
//get number of 30 minute blocks
88+
long numBlcks = Duration.between(startTime, endTime).toMinutes() / 30;
89+
final int bsSizeRep = 150;
90+
BitSet buildCmprsIn = new BitSet(bsSizeRep);
91+
buildCmprsIn.or(BitSetHelper.timeSlotBitSet(startTime, (int) numBlcks, MTWRF));
92+
BitSet buildCmprsOut = (BitSet) buildCmprsIn.clone();
93+
buildCmprsOut.flip(0, bsSizeRep);
94+
95+
HOLDER.scheduleConfig.cpmrsInBs = buildCmprsIn;
96+
HOLDER.scheduleConfig.cmprsOutBs = buildCmprsOut;
8697
}
87-
//get number of 30 minute blocks
88-
long numBlcks = Duration.between(startTime,endTime).toMinutes() / 30;
89-
final int bsSizeRep = 150;
90-
BitSet buildCmprsIn = new BitSet(bsSizeRep);
91-
buildCmprsIn.or(BitSetHelper.timeSlotBitSet(startTime, (int) numBlcks, MTWRF));
92-
BitSet buildCmprsOut = (BitSet) buildCmprsIn.clone();
93-
buildCmprsOut.flip(0, bsSizeRep);
94-
95-
HOLDER.scheduleConfig.cpmrsInBs = buildCmprsIn;
96-
HOLDER.scheduleConfig.cmprsOutBs = buildCmprsOut;
9798
} catch (Exception e){
9899
final int PROGRAM_FAILURE = 1;
99100
LOGGER.error("Program is terminating. Couldn't read the yaml file");
100101
LOGGER.error(String.format("Program assumes yaml file is located at '%s' int the resources directory",
101102
yamlPath));
102103
LOGGER.error(String.format("Related error: %s", e.getMessage()));
104+
e.printStackTrace();
103105
System.exit(PROGRAM_FAILURE);
104106
}
105107
}

java/hello-world/src/main/java/org/acme/schooltimetabling/solver/TimetableConstraintProvider.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,13 +575,23 @@ Constraint inPrimeTime(ConstraintFactory constraintFactory){
575575
.asConstraint("Penalizing for being in prime time");
576576
}
577577

578+
579+
/**
580+
* This constraint is used when we choose the "Aggressive" version of the solver that aims to compress and REWARD
581+
* time that is in the time interval specified in the configuration file
582+
*/
578583
Constraint inBestTime(ConstraintFactory constraintFactory){
579584
return constraintFactory.forEach(Lesson.class)
580585
.filter(lesson -> lesson.maskInCmprs().cardinality() > 0)
581586
.reward(HardMediumSoftScore.ONE_SOFT)
582587
.asConstraint("Reward time in preferred time interval");
583588
}
584589

590+
591+
/**
592+
* This constraint is used when we choose the "Aggressive" version of the solver that aims to compress and PENALIZE
593+
* time that is in the time interval specified in the configuration file
594+
*/
585595
Constraint outBestTime(ConstraintFactory constraintFactory){
586596
return constraintFactory.forEach(Lesson.class)
587597
.filter(lesson -> lesson.maskOutCmprs().cardinality() > 0)

java/hello-world/src/main/resources/constants/config.example.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ prevTerm: "2264"
44
seasonTerm: "fall"
55
testing: false
66
useApi: true
7+
aggressiveChoice: "AGGRESSIVE_PENALTY"
78
# ------- Optional -------
89
# this setting changes how we model the PrimeTime constraint
9-
aggressiveChoice: "AGGRESSIVE_PENALTY"
1010
compressStart: "7:00AM"
1111
compressEnd: "6:00PM"
1212
prescheduledFileName: "PrescheduledTimes_ExampleFile.example.json"

0 commit comments

Comments
 (0)