Commit f1b8b2bd authored by Georgios Dagkakis's avatar Georgios Dagkakis

changes in frozen simulation

parent 6227d142
......@@ -18,6 +18,6 @@ class PostProcessingOfferPhase(plugin.OutputPreparationPlugin):
data['result']['result_list'][-1][self.configuration_dict['output_id']] = {
'name': 'Result.xlsx',
'mime_type': 'application/vnd.ms-excel',
'data': G.tabSchedule.xlsx.encode('base64')
'data': G.reportResults.xlsx.encode('base64')
}
return data
\ No newline at end of file
......@@ -10,10 +10,10 @@ class projTabular(plugin.OutputPreparationPlugin):
"""
def postprocess(self, data):
data['result']['result_list'][0]['exit_output'] = [['Project', 'Earliest Completion Date']]
data['result']['result_list'][0]['exit_output'] = [['Project', 'Earliest Completion Date', 'Conservative estimate Completion Date']]
from dream.simulation.applications.FrozenSimulation.Globals import G
for proj in G.completionDate.keys():
data['result']['result_list'][0]['exit_output'].append([proj, G.completionDate[proj]])
for proj in G.completionDate['Earliest'].keys():
data['result']['result_list'][0]['exit_output'].append([proj, G.completionDate['Earliest'][proj], G.completionDate['Latest'][proj]])
return data
......
......@@ -2,7 +2,7 @@
from dream.plugins import plugin
from operator import itemgetter
class schedTabular(plugin.OutputPreparationPlugin):
class schedTabularEarliest(plugin.OutputPreparationPlugin):
""" Output the schedule in a tab
"""
......@@ -11,11 +11,29 @@ class schedTabular(plugin.OutputPreparationPlugin):
from dream.simulation.applications.FrozenSimulation.Globals import G
# sort schedule items in start time ascending order
sList = []
for entry in G.tabSchedule:
for entry in G.tabSchedule['Earliest']:
if 'End Time' not in entry:
sList.append([x for x in entry])
sList = sorted(sList, key=itemgetter(5))
for item in sList:
data['result']['result_list'][0]['schedule_output'].append(item)
return data
class schedTabularLatest(plugin.OutputPreparationPlugin):
""" Output the schedule in a tab
"""
def postprocess(self, data):
data['result']['result_list'][0]['schedule_output_latest'] = [['Project', 'Part', 'Task ID', 'Station', 'Operator', 'Start Time', 'End Time']]
from dream.simulation.applications.FrozenSimulation.Globals import G
# sort schedule items in start time ascending order
sList = []
for entry in G.tabSchedule['Latest']:
if 'End Time' not in entry:
sList.append([x for x in entry])
sList = sorted(sList, key=itemgetter(5))
for item in sList:
data['result']['result_list'][0]['schedule_output_latest'].append(item)
return data
\ No newline at end of file
......@@ -9,14 +9,25 @@ import tablib
class G:
Schedule={}
seqPrjDone = None
resAvailability = None
MachPool = None
PMPool = None
Projects = None
xlreftime = None
reportResults = tablib.Databook()
tabSchedule = tablib.Dataset(title='Schedule')
tabSchedule.headers = (['Project', 'Part', 'Task ID', 'Station', 'Operator', 'Start Time', 'End Time'])
OrderDates = None
completionDate = None
jsonInput = None
excelInput = None
simMode = None
# reporting tabs
reportResults = tablib.Databook()
tabSchedule = {}
pmSchedule = {}
tabScheduleOrig = []
pmScheduleOrig = []
# re-initialised variables
completionDate = {}
seqPrjDone = None
resAvailability = None
seqPrjDoneOrig = None
resAvailabilityOrig = None
......@@ -4,7 +4,7 @@ Created on 20 Aug 2015
@author: Anna
'''
from jsonReader import importInput
from jsonReader import importInput, initGlobals
from findSequence import findSequence
from timeCalculations import availableTimeInterval_MA, updateAvailTime, availableTimeInterval_MM, availableTimeInterval_Manual
from operator import itemgetter
......@@ -18,8 +18,6 @@ def manual_allocation(currentOp):
tStart = currentOp['minStartTime'] # earliest start date for current operation
remPT = dt.timedelta(hours=currentOp['manualTime'])
print 'in manual allocation', currentOp['id']
print 'tStart manual', tStart, remPT
while remPT > dt.timedelta(seconds=0):
startTimeMach = [] # collects earliest keyDate for machines
......@@ -42,30 +40,25 @@ def manual_allocation(currentOp):
# sort available time
sorted_startTimeOp = sorted(startTimeOp, key=itemgetter('start', 'avPT'))
print tStart
print 'sort mach', sorted_startTimeMach
print 'sort pm', sorted_startTimeOp
# calculate available PT
if sorted_startTimeOp[0]['start'] <= tStart:
print 'first op'
# print 'first op'
availablePT = min(sorted_startTimeMach[0]['avPT']*(-1), sorted_startTimeOp[0]['avPT']*(-1), remPT)
elif sorted_startTimeOp[0]['start'] < tStart + sorted_startTimeMach[0]['avPT']:
print 'sec op'
# print 'sec op'
tEnd = min(tStart+sorted_startTimeMach[0]['avPT'], sorted_startTimeOp[0]['start']+sorted_startTimeOp[0]['avPT'])
tStart = sorted_startTimeOp[0]['start']
availablePT = min(tEnd - tStart, remPT)
else:
print '3 op'
# print '3 op'
availablePT = dt.timedelta(seconds=0)
tStart = sorted_startTimeOp[0]['start']
# update remaining PT
remPT -= availablePT
print 'fine all', tStart, availablePT, remPT
if availablePT > dt.timedelta(seconds=0):
# update machine and operator availability
......@@ -74,28 +67,28 @@ def manual_allocation(currentOp):
G.resAvailability[sorted_startTimeOp[0]['pm']] = updateAvailTime(sorted_startTimeOp[0]['start'], availablePT, tStart,
G.resAvailability[sorted_startTimeOp[0]['pm']])
# aggiorna schedule
if currentOp['id'] not in G.Schedule.keys():
G.Schedule[currentOp['id']]={}
G.Schedule[currentOp['id']]['startDate'] = tStart
# update schedule
if currentOp['id'] not in G.Schedule[G.simMode].keys():
G.Schedule[G.simMode][currentOp['id']]={}
G.Schedule[G.simMode][currentOp['id']]['startDate'] = tStart
tEnd = tStart + availablePT
G.Schedule[currentOp['id']]['endDate'] = tEnd
G.Schedule[currentOp['id']].setdefault('rList',{})[(tStart,tEnd)] = {'mach':sorted_startTimeMach[0]['mach'],'operator':sorted_startTimeOp[0]['pm']}
G.tabSchedule.append([currentOp['project'], currentOp['part'], currentOp['id'],sorted_startTimeMach[0]['mach'],sorted_startTimeOp[0]['pm'],tStart,tEnd])
G.Schedule[G.simMode][currentOp['id']]['endDate'] = tEnd
G.Schedule[G.simMode][currentOp['id']].setdefault('rList',{})[(tStart,tEnd)] = {'mach':sorted_startTimeMach[0]['mach'],'operator':sorted_startTimeOp[0]['pm']}
G.tabSchedule[G.simMode].append([currentOp['project'], currentOp['part'], currentOp['id'],sorted_startTimeMach[0]['mach'],sorted_startTimeOp[0]['pm'],tStart,tEnd])
G.pmSchedule[G.simMode].append([sorted_startTimeOp[0]['pm'],tStart,tEnd,currentOp['id']])
if currentOp['preID'] != None:
G.Schedule[currentOp['preID']] = G.Schedule[currentOp['id']]
if G.completionDate[currentOp['project']] < tEnd:
G.completionDate[currentOp['project']] = tEnd
G.Schedule[G.simMode][currentOp['preID']] = G.Schedule[G.simMode][currentOp['id']]
if G.completionDate[G.simMode][currentOp['project']] < tEnd:
G.completionDate[G.simMode][currentOp['project']] = tEnd
tStart = tEnd
print currentOp['id'], G.Schedule[currentOp['id']]
def MAM_allocation(currentOp):
# set earliest start date for current operation
tStart = currentOp['minStartTime'] # earliest start date for current operation
print 'tStart', tStart
# set processing time
remPT = currentOp['manualTime'] + currentOp['autoTime']
while remPT:
......@@ -107,38 +100,31 @@ def MAM_allocation(currentOp):
for mach in G.MachPool[currentOp['operation']]:
# find available time (availableTimeInterval_MA)
print 'man', currentOp['manualTime']
mTime = dt.timedelta(hours=currentOp['manualTime'])
aTime = dt.timedelta(hours=currentOp['autoTime'])
print 'mach av', mach, G.resAvailability[mach]
if currentOp['mode'] == 'MM':
if currentOp['mode'] == 'MM' or currentOp['mode'] == 'M':
res = availableTimeInterval_MM(mTime, aTime, tStart, G.resAvailability[mach])
startTimeMach.append({'mach':mach, 'start':res[0], 'eqPT':res[1]})
else:
res = availableTimeInterval_MA(mTime, aTime, tStart, G.resAvailability[mach])
#startTimeMach.append({'mach':mach, 'start':res, 'eqPT':mTime+aTime})
startTimeMach.append({'mach':mach, 'start':res[0], 'eqPT':res[1]+aTime})
print 'start time mach', startTimeMach
# sort available time
sorted_startTimeMach = sorted(startTimeMach, key=itemgetter('start', 'eqPT'))
tStart = max(sorted_startTimeMach[0]['start'],tStart)
print 'mach tent', sorted_startTimeMach[0]['mach'], tStart
# verify whether PM are available in the same time
# verify whether PM are available during the same time interval
for pm in G.PMPool[currentOp['operation']]:
print 'operator', pm
#find available time
if currentOp['mode'] == 'MM':
if currentOp['mode'] == 'MM' or currentOp['mode'] == 'M':
res = availableTimeInterval_MM(mTime, aTime, tStart, G.resAvailability[pm])
startTimeOp.append({'pm':pm, 'start':res[0], 'eqPT':res[1]})
else:
res = availableTimeInterval_MA(mTime, dt.timedelta(hours=0), tStart, G.resAvailability[pm])
# startTimeOp.append({'pm':pm, 'start':res[0], 'eqPT':mTime})
startTimeOp.append({'pm':pm, 'start':res[0], 'eqPT':res[1]})
startTimeOp.append({'pm':pm, 'start':res[0], 'eqPT':res[1]})
# sort available time
sorted_startTimeOp = sorted(startTimeOp, key=itemgetter('start', 'eqPT'))
......@@ -148,11 +134,6 @@ def MAM_allocation(currentOp):
tStart = sorted_startTimeOp[0]['start']
print 'machine chosen', sorted_startTimeMach[0]['mach']
print 'operator chosen', sorted_startTimeOp[0]['pm'], sorted_startTimeOp
print G.resAvailability[sorted_startTimeMach[0]['mach']]
print G.resAvailability[sorted_startTimeOp[0]['pm']]
# update machine availability
G.resAvailability[sorted_startTimeMach[0]['mach']] = updateAvailTime(sorted_startTimeMach[0]['start'], sorted_startTimeMach[0]['eqPT'], tStart,
G.resAvailability[sorted_startTimeMach[0]['mach']])
......@@ -161,22 +142,23 @@ def MAM_allocation(currentOp):
G.resAvailability[sorted_startTimeOp[0]['pm']] = updateAvailTime(sorted_startTimeOp[0]['start'], sorted_startTimeOp[0]['eqPT'], tStart,
G.resAvailability[sorted_startTimeOp[0]['pm']])
# aggiorna schedule
G.Schedule.setdefault(currentOp['id'],{})
G.Schedule[currentOp['id']]['startDate'] = tStart
# update schedule
G.Schedule[G.simMode].setdefault(currentOp['id'],{})
G.Schedule[G.simMode][currentOp['id']]['startDate'] = tStart
tEnd = tStart + sorted_startTimeMach[0]['eqPT']
G.Schedule[currentOp['id']]['endDate'] = tEnd
G.Schedule[currentOp['id']].setdefault('rList',{})[(tStart,tEnd)] = {'mach':sorted_startTimeMach[0]['mach'],'operator':sorted_startTimeOp[0]['pm']}
G.Schedule[G.simMode][currentOp['id']]['endDate'] = tEnd
G.Schedule[G.simMode][currentOp['id']].setdefault('rList',{})[(tStart,tEnd)] = {'mach':sorted_startTimeMach[0]['mach'],'operator':sorted_startTimeOp[0]['pm']}
if currentOp['preID'] != None:
G.Schedule[currentOp['preID']] = G.Schedule[currentOp['id']]
if G.completionDate[currentOp['project']] < tEnd:
G.completionDate[currentOp['project']] = tEnd
G.tabSchedule.append([currentOp['project'], currentOp['part'], currentOp['preID'],sorted_startTimeMach[0]['mach'],sorted_startTimeOp[0]['pm'],tStart,tEnd-aTime])
G.tabSchedule.append([currentOp['project'], currentOp['part'], currentOp['id'],sorted_startTimeMach[0]['mach'],'automatic',tEnd-aTime,tEnd])
print 'schedule', G.Schedule
print G.resAvailability[sorted_startTimeOp[0]['pm']]
G.Schedule[G.simMode][currentOp['preID']] = G.Schedule[G.simMode][currentOp['id']]
if G.completionDate[G.simMode][currentOp['project']] < tEnd:
G.completionDate[G.simMode][currentOp['project']] = tEnd
if currentOp['mode'] == 'MM' or currentOp['mode'] == 'MA':
G.tabSchedule[G.simMode].append([currentOp['project'], currentOp['part'], currentOp['preID'],sorted_startTimeMach[0]['mach'],sorted_startTimeOp[0]['pm'],tStart,tEnd-aTime])
G.tabSchedule[G.simMode].append([currentOp['project'], currentOp['part'], currentOp['id'],sorted_startTimeMach[0]['mach'],'automatic',tEnd-aTime,tEnd])
G.pmSchedule[G.simMode].append([sorted_startTimeOp[0]['pm'],tStart,tEnd-aTime,currentOp['id']])
else:
G.tabSchedule[G.simMode].append([currentOp['project'], currentOp['part'], currentOp['id'],sorted_startTimeMach[0]['mach'],sorted_startTimeOp[0]['pm'],tStart,tEnd])
G.pmSchedule[G.simMode].append([sorted_startTimeOp[0]['pm'],tStart,tEnd,currentOp['id']])
def exeSim(jsonInput, workplanInput, algorithmAttributes):
......@@ -190,53 +172,88 @@ def exeSim(jsonInput, workplanInput, algorithmAttributes):
excelInput = attachement_data
# read input data
G.simMode = 'Earliest'
importInput(jInput, excelInput, algorithmAttributes)
#==========================
# Earliest Completion Date
#==========================
initGlobals()
# find initial operation
opDone = []
seq = deepcopy(G.seqPrjDone)
proj = deepcopy(G.Projects)
opReady = findSequence(proj, seq, opDone)
print 'opready', opReady, G.seqPrjDone
while len(opReady):
# set current operation
currentOp = opReady[0]
print 'chosen operation', currentOp['id']
# check op mode
# check op mode and allocate operation
if currentOp['mode'] == 'MA' or currentOp['mode'] == 'MM':
MAM_allocation(currentOp)
else:
manual_allocation(currentOp)
# elif currentOp['mode'] == 'MM':
# print 'MM'
# MM_allocation(currentOp)
# save results
# save results and update sequence number
opDone.append(currentOp['id'])
G.seqPrjDone[currentOp['project']][currentOp['part']] += 1
print 'op', currentOp
if currentOp['preID'] != None:
opDone.append(currentOp['preID'])
G.seqPrjDone[currentOp['project']][currentOp['part']] += 1
# aggiorna seqPrjDone
# find next operation
seq = deepcopy(G.seqPrjDone)
proj = deepcopy(G.Projects)
opReady = findSequence(proj, seq, opDone)
# add result sheets
G.reportResults.add_sheet(G.tabSchedule[G.simMode])
G.reportResults.add_sheet(G.pmSchedule[G.simMode])
#==========================
# Latest Completion Date
#==========================
G.simMode = 'Latest'
initGlobals()
# find initial operation
opDone = []
seq = deepcopy(G.seqPrjDone)
proj = deepcopy(G.Projects)
opReady = findSequence(proj, seq, opDone)
while len(opReady):
# set current operation
currentOp = opReady[0]
# allocate operation
MAM_allocation(currentOp)
# save results
opDone.append(currentOp['id'])
G.seqPrjDone[currentOp['project']][currentOp['part']] += 1
if currentOp['preID'] != None:
opDone.append(currentOp['preID'])
G.seqPrjDone[currentOp['project']][currentOp['part']] += 1
# find following operation
seq = deepcopy(G.seqPrjDone)
proj = deepcopy(G.Projects)
opReady = findSequence(proj, seq, opDone)
print opDone
print 'completion date', G.completionDate
# report results
G.reportResults.add_sheet(G.tabSchedule[G.simMode])
G.reportResults.add_sheet(G.pmSchedule[G.simMode])
G.reportResults.add_sheet(G.tabSchedule)
with open('schedule.xlsx', 'wb') as f: #time level schedule info
f.write(G.reportResults.xlsx)
# with open('schedule.xlsx', 'wb') as f: #time level schedule info
# f.write(G.reportResults.xlsx)
if __name__ == '__main__':
......
......@@ -11,9 +11,6 @@ def findSequence(Projects, seqPrjDone, idDone):
opReady = []
print 'find sequence', Projects
print 'find sequence', seqPrjDone
for proj in seqPrjDone.keys():
for part in seqPrjDone[proj].keys():
......@@ -22,12 +19,11 @@ def findSequence(Projects, seqPrjDone, idDone):
possibleOp = True
print 'part', part, Projects[proj][part][seqPrjDone[proj][part]]['id']
if seqPrjDone[proj][part]==0 or Projects[proj][part][seqPrjDone[proj][part]-1]['id'] not in G.Schedule.keys():
# set minimum start time for operation
if seqPrjDone[proj][part]==0 or Projects[proj][part][seqPrjDone[proj][part]-1]['id'] not in G.Schedule[G.simMode].keys():
minStartTime = max(G.xlreftime, G.OrderDates[proj])
else:
minStartTime = G.Schedule[Projects[proj][part][seqPrjDone[proj][part]-1]['id']]['endDate']
minStartTime = G.Schedule[G.simMode][Projects[proj][part][seqPrjDone[proj][part]-1]['id']]['endDate']
# verify whether the operation can be performed in terms of prerequisite operations
for preReq in Projects[proj][part][seqPrjDone[proj][part]]['preReq']:
......@@ -37,12 +33,11 @@ def findSequence(Projects, seqPrjDone, idDone):
break
else:
if minStartTime < G.Schedule[preReq]['endDate']:
minStartTime = G.Schedule[preReq]['endDate']
if minStartTime < G.Schedule[G.simMode][preReq]['endDate']:
minStartTime = G.Schedule[G.simMode][preReq]['endDate']
if possibleOp:
newOp = Projects[proj][part][seqPrjDone[proj][part]]
print newOp['id'], 'possible'
newOp['minStartTime'] = minStartTime
newOp['project'] = proj
newOp['part'] = part
......@@ -59,7 +54,6 @@ def findSequence(Projects, seqPrjDone, idDone):
seqPrjDone[proj][part] += 1
# verify that the operation is the same
print followOp['operation'], newOp['operation']
assert (followOp['operation'].split('-')[0] in newOp['operation'])
# update operation (erase set)
......@@ -91,10 +85,8 @@ def findSequence(Projects, seqPrjDone, idDone):
opReady.append(newOp)
print 'pre', opReady
opReady = sorted(opReady, key=itemgetter('sequence', 'manualTime', 'autoTime'))
print 'seq', seqPrjDone, G.seqPrjDone
return opReady
......@@ -114,22 +114,18 @@ def importInput(jInput, excelInput, algorithmAttributes):
part = item[0].encode('ascii', 'ignore')
#print 'startDate', startDate.date()
if pt.seconds > 0 or pt.days>0:
forzenOpsData.append([startDate.date(), part, order, item[3], item[7], station, startDate.time(), dateOut.time(), ordinalOutDate, 'X'])
frozen[item[3]] = 'X'
G.tabSchedule.append([order,part, item[3],station,item[7],startDate,dateOut])
G.tabScheduleOrig.append([order,part, item[3],station,item[7],startDate,dateOut])
if station not in takenPeriods:
takenPeriods[station] = {}
takenPeriods[station][startDate] = {'endDate': dateOut, 'taskID':item[3]}
PMschedule = dataJSON['result']['result_list'][selSol]['operator_gantt']['task_list']
takenPeriods.setdefault(station,{})[startDate] = {'endDate': dateOut, 'taskID':item[3]}
# import PM schedule
PMschedule = dataJSON['result']['result_list'][selSol]['operator_gantt']['task_list']
# extract resource availability
for item in PMschedule:
if 'parent' in item.keys():
pm = item['parent']
......@@ -143,22 +139,17 @@ def importInput(jInput, excelInput, algorithmAttributes):
continue
if pt:
print pm, taskID
if pm not in takenPeriods:
takenPeriods[pm] = {}
takenPeriods[pm][startDate] = {'endDate': stopDate, 'taskID': taskID}
G.pmScheduleOrig.append([pm,startDate,stopDate,taskID])
print 'frozen operations', forzenOpsData
print 'taken periods', takenPeriods
#=================================
# Import Workplan from Excel file
#=================================
global numParts
WorkPlan = wb.sheet_by_index(0)
Projects = {}
......@@ -304,6 +295,15 @@ def importInput(jInput, excelInput, algorithmAttributes):
if 'INJM-MAN' in skills:
skills.remove('INJM-MAN')
skills.append('INJM')
if 'INJM-SET' in skills:
skills.remove('INJM-SET')
skills.append('INJM')
if 'EDM-SET' in skills:
skills.remove('EDM-SET')
skills.append('EDM')
if 'MILL-SET' in skills:
skills.remove('MILL-SET')
skills.append('MILL')
PMInfo.append({'name':PMskills[item][0], 'skills': skills, 'sched':'FIFO', 'status':''})
for sk in skills:
......@@ -348,11 +348,25 @@ def importInput(jInput, excelInput, algorithmAttributes):
resAvailability[mach] = availableTime_Shift(unavailDate,takenPeriods[mach][unavailDate]['endDate'],resAvailability[mach])
# set global variables
G.resAvailability = deepcopy(resAvailability)
G.seqPrjDone = deepcopy(seqPrjDone)
G.resAvailability = deepcopy(resAvailability)
G.seqPrjDoneOrig = deepcopy(seqPrjDone)
G.resAvailabilityOrig = deepcopy(resAvailability)
G.MachPool = deepcopy(MachPool)
print 'mach pool',G.MachPool
G.PMPool = deepcopy(PMPool)
G.Projects = deepcopy(Projects)
G.OrderDates = deepcopy(OrderDates)
G.completionDate = deepcopy(OrderDates)
def initGlobals():
G.resAvailability = deepcopy(G.resAvailabilityOrig)
G.seqPrjDone = deepcopy(G.seqPrjDoneOrig)
G.Schedule[G.simMode] = {}
G.completionDate[G.simMode] = deepcopy(G.OrderDates)
G.tabSchedule[G.simMode] = tablib.Dataset(title='Schedule'+str(G.simMode))
G.tabSchedule[G.simMode].headers = (['Project', 'Part', 'Task ID', 'Station', 'Operator', 'Start Time', 'End Time'])
for item in G.tabScheduleOrig:
G.tabSchedule[G.simMode].append(item)
G.pmSchedule[G.simMode] = tablib.Dataset(title='PMschedule'+str(G.simMode))
for item in G.pmScheduleOrig:
G.pmSchedule[G.simMode].append(item)
......@@ -12,8 +12,10 @@ def availableTimeInterval_Manual(manualTime, tStart, availTime):
# suitable for manual operations...returns available time until the end
# sort time intervals according to ascending start date
sortedTime = sorted(availTime.keys())
# find the interval for which the start date is just above tStart
i = 0
while i<len(sortedTime) and sortedTime[i] <= tStart:
i += 1
......@@ -25,6 +27,7 @@ def availableTimeInterval_Manual(manualTime, tStart, availTime):
# if i == 0 and tStart + manualTime < sortedTime[i]:
# return None
# go to next interval if available time is null
if availTime[sortedTime[i]]['end'] - max(tStart,sortedTime[i]) <= dt.timedelta(seconds=0):
i += 1
......@@ -59,6 +62,10 @@ def availableTimeInterval_MM(manualTime, autoTime, tStart, availTime):
if availTime[sortedTime[i]]['endMode'] == 'EOS':
if i+1 < len(sortedTime) and availTime[sortedTime[i+1]]['preDay'] == sortedTime[i].date() and availTime[sortedTime[i+1]]['startMode'] == 'SOS':
tCumulative += availTime[sortedTime[i]]['end'] - max(tStart,sortedTime[i])
else:
tCumulative = dt.timedelta(seconds=0)
if i+1 < len(sortedTime):
startSorted = sortedTime[i+1]
else:
tCumulative = dt.timedelta(seconds=0)
......@@ -79,8 +86,6 @@ def availableTimeInterval_MA(manualTime, autoTime, tStart, availTime):
sortedTime = sorted(availTime.keys())
print sortedTime
i = 0
while i<len(sortedTime) and sortedTime[i] <= tStart:
i += 1
......@@ -92,8 +97,6 @@ def availableTimeInterval_MA(manualTime, autoTime, tStart, availTime):
# if i == 0 and tStart + autoTime + manualTime < sortedTime[i]:
# return None
print 'start', sortedTime[i]
while True:
tCumulative = dt.timedelta(seconds=0)
......@@ -104,6 +107,10 @@ def availableTimeInterval_MA(manualTime, autoTime, tStart, availTime):
if availTime[sortedTime[i]]['endMode'] == 'EOS':
if i+1 < len(sortedTime) and availTime[sortedTime[i+1]]['preDay'] == sortedTime[i].date() and availTime[sortedTime[i+1]]['startMode'] == 'SOS':
tCumulative += availTime[sortedTime[i]]['end'] - max(tStart,sortedTime[i])
else:
tCumulative = dt.timedelta(seconds=0)
if i+1 < len(sortedTime):
startSorted = sortedTime[i+1]
else:
tCumulative = dt.timedelta(seconds=0)
......@@ -124,8 +131,6 @@ def availableTimeInterval_MA(manualTime, autoTime, tStart, availTime):
if i>=len(sortedTime):
return None
# print 'end manual', sortedTime[i]
if autoTime:
if availTime[sortedTime[i]]['end']- max(tManualEnd,sortedTime[i]) <= autoTime:
if availTime[sortedTime[i]]['endMode'] == 'EOS':
......@@ -181,7 +186,6 @@ def updateAvailTime(keyStart, reqTime, tStart, availTime):
print 'WARNING: beyond planning horizon'
return availTime
# print 'find next time', sortedTime[i], i
if tStart+reqTime > sortedTime[i]:
# repeat procedure
availTime = updateAvailTime(sortedTime[i], reqTime - (sortedTime[i]-tStart), sortedTime[i], availTime)
......@@ -198,8 +202,6 @@ def availableTime_Shift(tStart, tEnd, availTime):
i += 1
# print i, sortedTime[i], availTime[sortedTime[i]]['end'], tStart, tEnd
if i>=len(sortedTime):
print 'WARNING: time interval not found'
return availTime
......@@ -219,7 +221,6 @@ def availableTime_Shift(tStart, tEnd, availTime):
availTime = updateAvailTime(sortedTime[i], tEnd - max(tStart,sortedTime[i]), max(tStart,sortedTime[i]), availTime)
elif availTime[sortedTime[i+1]]['startMode']=='SOS' and availTime[sortedTime[i+1]]['preDay'] == sortedTime[i].date() and availTime[sortedTime[i+1]]['end'] >= tEnd:
print 'beyond eos', max(tStart,sortedTime[i]), tEnd - max(tStart,sortedTime[i])
availTime = updateAvailTime(sortedTime[i], tEnd - max(tStart,sortedTime[i]), max(tStart,sortedTime[i]), availTime)
else:
return availTime
......
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