Skip to content

Commit 23ecc6f

Browse files
committed
Bug fix of printschedule and schedulecost.
1 parent e235c45 commit 23ecc6f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

chapter5/optimization.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ def printschedule(r):
2828
for d in range(len(r)/2):
2929
name=people[d][0]
3030
origin=people[d][1]
31-
out=flights[(origin,destination)][int(r[d])]
32-
ret=flights[(destination,origin)][int(r[d+1])]
31+
out=flights[(origin,destination)][int(r[d*2])]
32+
ret=flights[(destination,origin)][int(r[d*2+1])]
3333
print '%10s%10s %5s-%5s $%3s %5s-%5s $%3s' % (name,origin,
3434
out[0],out[1],out[2],
3535
ret[0],ret[1],ret[2])
@@ -42,8 +42,8 @@ def schedulecost(sol):
4242
for d in range(len(sol)/2):
4343
# Get the inbound and outbound flights
4444
origin=people[d][1]
45-
outbound=flights[(origin,destination)][int(sol[d])]
46-
returnf=flights[(destination,origin)][int(sol[d+1])]
45+
outbound=flights[(origin,destination)][int(sol[d*2])]
46+
returnf=flights[(destination,origin)][int(sol[d*2+1])]
4747

4848
# Total price is the price of all outbound and return flights
4949
totalprice+=outbound[2]
@@ -58,8 +58,8 @@ def schedulecost(sol):
5858
totalwait=0
5959
for d in range(len(sol)/2):
6060
origin=people[d][1]
61-
outbound=flights[(origin,destination)][int(sol[d])]
62-
returnf=flights[(destination,origin)][int(sol[d+1])]
61+
outbound=flights[(origin,destination)][int(sol[d*2])]
62+
returnf=flights[(destination,origin)][int(sol[d*2+1])]
6363
totalwait+=latestarrival-getminutes(outbound[1])
6464
totalwait+=getminutes(returnf[0])-earliestdep
6565

0 commit comments

Comments
 (0)