Skip to content

Commit

Permalink
going back
Browse files Browse the repository at this point in the history
  • Loading branch information
azhow committed Mar 17, 2018
1 parent a4d15e1 commit 1c52cf3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 29 deletions.
2 changes: 0 additions & 2 deletions modules/experiment/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,6 @@ def __init__(self, origin, destiny, num_paths, num_travels):
self.o = origin
self.d = destiny
self.numPaths = num_paths
if self.o == "s2" and self.d == "t2":
self.numPaths = 3
self.numTravels = num_travels
self.paths = None

Expand Down
18 changes: 5 additions & 13 deletions modules/experiment/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,11 +743,7 @@ def driversPerLink(self, driverString):
if(type(dr) != int):
print('problema!', driverString, '\n')
print type(dr)
#chinelagem
if dr <= self.drivers[inx].od.numPaths - 1:
path = self.drivers[inx].od.paths[dr]
else:
continue
path = self.drivers[inx].od.paths[dr]
for edge in path[0]:
if edge in dicti.keys():
dicti[edge] += self.group_size
Expand All @@ -761,14 +757,10 @@ def driversPerLink(self, driverString):
def evaluateActionTravelTime(self, driverIndex, action, edgesTravelTimes):
#calculates travel times for a driver
traveltime = 0.0
#chinelagem
if action <= self.drivers[driverIndex].od.numPaths - 1:
path = self.drivers[driverIndex].od.paths[action][0] # list of nodes of path
for edge in path:
traveltime += edgesTravelTimes[edge]
return traveltime
else:
return float("inf")
path = self.drivers[driverIndex].od.paths[action][0] # list of nodes of path
for edge in path:
traveltime += edgesTravelTimes[edge]
return traveltime

def initTravelTimeByODDict(self):
d = {}
Expand Down
15 changes: 2 additions & 13 deletions modules/q_learning/q_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ def runEpisode(self):
randomnb = random.uniform(0, 1)
if randomnb < self.epsilon:
# action is selected randomly
if float('-inf') in a:
curaction = random.randint(0, self.k-2)
else:
curaction = random.randint(0, self.k-1)
curaction = random.randint(0, self.k-1)
else:
# action is selected greedly
max_in_array = max(a)
Expand Down Expand Up @@ -116,15 +113,7 @@ def runEpisode(self):
if self.action_selection == "boltzmann":
self.temperature = self.temperature * self.decay

#chinelagem
def c_sum(l):
r = 0
for i in l:
if i != float('inf'):
r += i
return r

average_tt_time = c_sum(traveltimes)/self.numdrivers
average_tt_time = sum(traveltimes)/self.numdrivers
return (actions, average_tt_time)

def runEpisodeWithAction(self, actions):
Expand Down
2 changes: 1 addition & 1 deletion route_choice.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python2
#!/usr/bin/env python
"""
Changelog:
v1.0 - Changelog created. <08/03/2017>
Expand Down

0 comments on commit 1c52cf3

Please sign in to comment.