added more and better constraints, 2slot workgroups do not support constraints
This commit is contained in:
parent
ad97a5a376
commit
c646051058
|
@ -9,7 +9,7 @@ SLOT_LEN = 120
|
||||||
|
|
||||||
DAYS = 1
|
DAYS = 1
|
||||||
START = 480
|
START = 480
|
||||||
END = 1080
|
END = 1200
|
||||||
|
|
||||||
|
|
||||||
class WorkGroup:
|
class WorkGroup:
|
||||||
|
@ -21,20 +21,24 @@ class WorkGroup:
|
||||||
self.reso = 'true' if reso else 'false'
|
self.reso = 'true' if reso else 'false'
|
||||||
self.length = floor(length/SLOT_LEN) + 1
|
self.length = floor(length/SLOT_LEN) + 1
|
||||||
self.leaders = leaders
|
self.leaders = leaders
|
||||||
self.after_time = []
|
self.constrainted_time = []
|
||||||
self.before_time = []
|
self.not_on_day = []
|
||||||
|
self.only_on_day = []
|
||||||
|
|
||||||
for constraint in constraints:
|
for constraint in constraints:
|
||||||
if constraint["type"] == 'OnlyAfterTime':
|
if constraint["type"] == 'OnlyAfterTime':
|
||||||
if constraint['workGroup'] is None:
|
if constraint['workGroup'] is None:
|
||||||
self.after_time.append({'day': constraint['day'], 'time': constraint['time']})
|
self.constrainted_time.append({'day': constraint['day'], 'time': constraint['time'], 'type':'after'})
|
||||||
elif constraint["type"] == 'OnlyBeforeTime':
|
elif constraint["type"] == 'OnlyBeforeTime':
|
||||||
self.before_time.append({'day': constraint['day'], 'time': constraint['time']})
|
self.constrainted_time.append({'day': constraint['day'], 'time': constraint['time'], 'type':'before'})
|
||||||
|
|
||||||
|
print(self.constrainted_time)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
leader_rules = ''
|
leader_rules = ''
|
||||||
for leader in self.leaders:
|
for leader in self.leaders:
|
||||||
leader_rules += f'leader({self.id}, "{leader}").\n'
|
leader_rules += f'leader({self.id}, "{leader}").\n'
|
||||||
return f'ak({self.id}, {self.interest}, "{self.track}", {self.projector}, {self.reso}, {self.length}).' + leader_rules
|
return f'ak({self.id}, {self.interest}, "{self.track}", {self.projector}, {self.reso}, {self.length}).\n' + leader_rules
|
||||||
|
|
||||||
|
|
||||||
class Room:
|
class Room:
|
||||||
|
@ -140,19 +144,45 @@ for room in rooms:
|
||||||
|
|
||||||
timeslots = [(start, start+SLOT_LEN, day) for day in range(DAYS) for start in range(START, END, SLOT_LEN)]
|
timeslots = [(start, start+SLOT_LEN, day) for day in range(DAYS) for start in range(START, END, SLOT_LEN)]
|
||||||
|
|
||||||
|
del timeslots[0] # remove slot thursday morning
|
||||||
|
if DAYS >= 3: del timeslots[-1] #remove last slot for Abschlussplenum
|
||||||
|
print(len(timeslots))
|
||||||
for order, timeslot in enumerate(timeslots):
|
for order, timeslot in enumerate(timeslots):
|
||||||
|
if order == 8:
|
||||||
|
continue # remove slot for Resovorstellung, keep order to avoid two-slot-workgroups to be scheduled before and after reso.
|
||||||
rules += str(Timeslot(order, timeslot)) + '\n'
|
rules += str(Timeslot(order, timeslot)) + '\n'
|
||||||
|
|
||||||
|
############################
|
||||||
|
# ADD MORE CONSTRAINTS #
|
||||||
|
############################
|
||||||
|
|
||||||
def time_to_id(timeslots, day, time):
|
def time_to_id(timeslots, day, time):
|
||||||
timeslots = list(filter(lambda ts: time>= ts[1][0] and time <= ts[1][1] and day == ts[1][2], enumerate(timeslots)))
|
timeslots = list(filter(lambda ts: time>= ts[1][0] and time < ts[1][1] and day == ts[1][2], enumerate(timeslots)))
|
||||||
return timeslots[0][0]
|
return timeslots[0][0]
|
||||||
|
|
||||||
for workgroup in filter(lambda wg: wg.after_time, workgroups):
|
def get_last_on_day(day):
|
||||||
for after_time in workgroup.after_time:
|
if day == 0:
|
||||||
timeslot_id = time_to_id(timeslots, after_time['day'], after_time['time'])
|
return 4
|
||||||
|
else:
|
||||||
|
return (day+1)*5
|
||||||
|
|
||||||
|
def get_first_on_day(day):
|
||||||
|
if day == 3:
|
||||||
|
return 15
|
||||||
|
else:
|
||||||
|
return (day)*5
|
||||||
|
|
||||||
|
for workgroup in filter(lambda wg: wg.constrainted_time, workgroups):
|
||||||
|
for constrainted_time in workgroup.constrainted_time:
|
||||||
|
# TODO constraint for 2 slot workgroups missing!
|
||||||
|
timeslot_id = time_to_id(timeslots, constrainted_time['day'], constrainted_time['time'])
|
||||||
timeslot = timeslots[timeslot_id] # after this slot: ok
|
timeslot = timeslots[timeslot_id] # after this slot: ok
|
||||||
print(f':- schedule({workgroup.id}, TIMESLOT, _), ak({workgroup.id},_,_,_,_,_), timeslot(TIMESLOT, ORDER, _, _, _), ORDER < {timeslot_id + 1}.')
|
operator1 = '<' if constrainted_time['type'] == 'after' else '>'
|
||||||
rules += f':- schedule({workgroup.id}, TIMESLOT, _), ak({workgroup.id},_,_,_,_,_), timeslot(TIMESLOT, ORDER, _, _, _), ORDER < {timeslot_id + 1}.\n'
|
operator2 = '>' if constrainted_time['type'] == 'after' else '<'
|
||||||
|
day_restriction = get_last_on_day(constrainted_time['day']) + 1 if constrainted_time['type'] == 'before' else get_first_on_day(constrainted_time['day']) -1 #first or last slot on this day
|
||||||
|
timeslot2 = timeslot_id if constrainted_time['type'] == 'before' else timeslot_id
|
||||||
|
print(f':- schedule({workgroup.id}, TIMESLOT, _), timeslot(TIMESLOT, ORDER, _, _, _), ORDER {operator1} {timeslot2}, ORDER {operator2} {day_restriction}.')
|
||||||
|
rules += f':- schedule({workgroup.id}, TIMESLOT, _), timeslot(TIMESLOT, ORDER, _, _, _), ORDER {operator1} {timeslot2}, ORDER {operator2} {day_restriction}.\n'
|
||||||
|
|
||||||
rules += "#show schedule/3."
|
rules += "#show schedule/3."
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue