Commit c9f00073 authored by Jonathan Shahen's avatar Jonathan Shahen

Done adding the roleSchedule to the Uzun straight conversion - still requires...

Done adding the roleSchedule to the Uzun straight conversion - still requires testing (add test to the RegressionTests), but that will be done in the morning
parent 4b05d804
...@@ -7,12 +7,14 @@ import mohawk.converter.pieces.TimeInterval; ...@@ -7,12 +7,14 @@ import mohawk.converter.pieces.TimeInterval;
public class TimeIntervalHelper { public class TimeIntervalHelper {
public SortedSet<TimeInterval> _timeslots = new TreeSet<TimeInterval>(); public SortedSet<TimeInterval> _timeslots = new TreeSet<TimeInterval>();
public Integer maxTimeSlot = 0; public Integer maxTimeSlot = -1;
public Integer minTimeSlot = -1;
public void add(TimeInterval ti) { public void add(TimeInterval ti) {
_timeslots.add(ti); _timeslots.add(ti);
maxTimeSlot = Math.max(maxTimeSlot, ti._finish + 1); maxTimeSlot = Math.max(maxTimeSlot, ti._finish);
minTimeSlot = Math.min(minTimeSlot, ti._start);
} }
/** /**
...@@ -20,8 +22,9 @@ public class TimeIntervalHelper { ...@@ -20,8 +22,9 @@ public class TimeIntervalHelper {
* *
* @return the greatest timeslot that is valid * @return the greatest timeslot that is valid
*/ */
public Integer getMaxTimeSlotSeen() { public Integer getNumberOfTimeSlots() {
return maxTimeSlot - 1; if (maxTimeSlot == -1) { return -1; }
return maxTimeSlot - minTimeSlot + 1; // if maxTimeSlot == minTimeSlot => returns 1
} }
/** /**
...@@ -29,8 +32,8 @@ public class TimeIntervalHelper { ...@@ -29,8 +32,8 @@ public class TimeIntervalHelper {
* *
* @return the greatest timeslot that is valid and hasn't been used * @return the greatest timeslot that is valid and hasn't been used
*/ */
public Integer getNextTimeslot() { public Integer getNextTimeSlot() {
return maxTimeSlot; return maxTimeSlot + 1;
} }
public Integer size() { public Integer size() {
......
...@@ -9,6 +9,7 @@ public class UzunRule { ...@@ -9,6 +9,7 @@ public class UzunRule {
public Integer finishTime; public Integer finishTime;
public Integer role; public Integer role;
public Integer[] precondition; public Integer[] precondition;
public Integer[] roleSchedule;
public UzunRule(Rule r, RoleHelper rh, TimeIntervalHelper tih) { public UzunRule(Rule r, RoleHelper rh, TimeIntervalHelper tih) {
ruleType = r._type.toUzun(); ruleType = r._type.toUzun();
...@@ -34,5 +35,14 @@ public class UzunRule { ...@@ -34,5 +35,14 @@ public class UzunRule {
precondition[i] = 0; precondition[i] = 0;
} }
} }
roleSchedule = new Integer[tih.getNextTimeSlot()];
for (Integer i = 0; i < roleSchedule.length; i++) {
if (r._roleSchedule.contains(i)) {
roleSchedule[i] = 1;
} else {
roleSchedule[i] = 0;
}
}
} }
} }
...@@ -64,7 +64,7 @@ public class RegressionTests { ...@@ -64,7 +64,7 @@ public class RegressionTests {
// t0, t1, t2, t5 // t0, t1, t2, t5
assertEquals("Incorrect number of Timeslots", new Integer(4), parser.timeIntervalHelper.size()); assertEquals("Incorrect number of Timeslots", new Integer(4), parser.timeIntervalHelper.size());
// t0, t1, t2, t5 // t0, t1, t2, t5
assertEquals("Incorrect max Timeslot", new Integer(5), parser.timeIntervalHelper.getMaxTimeSlotSeen()); assertEquals("Incorrect max Timeslot", new Integer(5), parser.timeIntervalHelper.getNumberOfTimeSlots());
} }
@Test @Test
...@@ -89,7 +89,7 @@ public class RegressionTests { ...@@ -89,7 +89,7 @@ public class RegressionTests {
// t0, t1, t2, t5 // t0, t1, t2, t5
assertEquals("Incorrect number of Timeslots", new Integer(4), parser.timeIntervalHelper.size()); assertEquals("Incorrect number of Timeslots", new Integer(4), parser.timeIntervalHelper.size());
// t0, t1, t2, t5 // t0, t1, t2, t5
assertEquals("Incorrect max Timeslot", new Integer(5), parser.timeIntervalHelper.getMaxTimeSlotSeen()); assertEquals("Incorrect max Timeslot", new Integer(5), parser.timeIntervalHelper.getNumberOfTimeSlots());
} }
@Test @Test
...@@ -114,7 +114,7 @@ public class RegressionTests { ...@@ -114,7 +114,7 @@ public class RegressionTests {
// t0, t1, t2, t5 // t0, t1, t2, t5
assertEquals("Incorrect number of Timeslots", new Integer(4), parser.timeIntervalHelper.size()); assertEquals("Incorrect number of Timeslots", new Integer(4), parser.timeIntervalHelper.size());
// t0, t1, t2, t5 // t0, t1, t2, t5
assertEquals("Incorrect max Timeslot", new Integer(5), parser.timeIntervalHelper.getMaxTimeSlotSeen()); assertEquals("Incorrect max Timeslot", new Integer(5), parser.timeIntervalHelper.getNumberOfTimeSlots());
} }
@Test @Test
......
...@@ -24,7 +24,7 @@ public class ConvertToUzun implements ConvertTo { ...@@ -24,7 +24,7 @@ public class ConvertToUzun implements ConvertTo {
Charset.defaultCharset()); Charset.defaultCharset());
ST st = new ST(template); ST st = new ST(template);
st.add("numRoles", p.roleHelper.size()); st.add("numRoles", p.roleHelper.size());
st.add("numTimeSlots", p.timeIntervalHelper.getNextTimeslot()); st.add("numTimeSlots", p.timeIntervalHelper.getNextTimeSlot());
st.add("goalStates", p.query.toUzun(p.roleHelper)); st.add("goalStates", p.query.toUzun(p.roleHelper));
for (Rule r : p.canAssign.getRules()) { for (Rule r : p.canAssign.getRules()) {
......
<numRoles> <numTimeSlots><! Conversion to Uzun's Input Format !> <numRoles> <numTimeSlots><! Conversion to Uzun's Input Format !>
<goalStates; separator=" "><! Goal States {0,1} * numRoles !> <goalStates; separator=" "><! Goal States {0,1} * numRoles !>
<rules:{r|<r.ruleType> <r.startTime> <r.finishTime> <r.role><\n><\t><r.precondition; separator=" "><\n>}><! RuleType StartTime FinsihTime RoleToGive !> <rules:{r|<r.ruleType> <r.startTime> <r.finishTime> <r.role><\n><\t><r.precondition; separator=" "><\n><\t><r.roleSchedule; separator=" "><\n>}><! RuleType StartTime FinsihTime RoleToGive !>
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment