-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItineraryReader.py
47 lines (41 loc) · 1.09 KB
/
ItineraryReader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from Itinerary import Itinerary
from Arcs import TripStartArc,NextDayArc
class ItineraryReader:
def __init__(self, file):
self.f = open(file)
def read(self, flights, deps, sinks):
itins = []
self.f.readline()
line = self.f.readline()
while line is not '':
args = line.split(',')
ff = flights.get(int(args[0]), None)
sf = flights.get(int(args[1]), None)
psgrs = int(args[2])
if sf is None:
sink = sinks[ff.j.j]
else:
sink = sinks[sf.j.j]
itin = Itinerary(ff, sf, psgrs, sink)
itins.append(itin)
line = self.f.readline()
self.f.close()
list = []
for itin in itins:
if itin.canceled():
#Next-day flight arcs
list.append(itin)
nd = NextDayArc(itin,sinks[itin.end().j])
itin.outgoing.append(nd)
itin.end().incoming.append(nd)
#Itinerary arrival arcs
for dep in deps.get(itin.j.j,[]):
if dep.t >= itin.t:
sa = TripStartArc(itin,dep)
itin.outgoing.append(sa)
dep.incoming.append(sa)
else:
itin.ff.reduce(itin.psgrs)
if itin.sf != None:
itin.sf.reduce(itin.psgrs)
return list