Skip to content

Commit

Permalink
Documentation and aesthetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
azhow committed Mar 8, 2017
1 parent 97755fe commit 9195baf
Show file tree
Hide file tree
Showing 6 changed files with 253 additions and 167 deletions.
11 changes: 10 additions & 1 deletion modules/experiment/classes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
from ksp.KSP import Edge
"""
Changelog:
v1.0 - Created. <08/03/2017>
Author: Arthur Zachow Coelho ([email protected])
Created: 08/03/2017
This module has the classes used in the simulation.
"""
from py_expression_eval import Parser
from ksp.KSP import Edge


class EdgeRC(Edge):
Expand Down
39 changes: 16 additions & 23 deletions modules/experiment/experiment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#!/usr/bin/env python
"""
Use spaces instead of tabs, or configure your editor to transform tab to 4
spaces.
Changelog:
v1.0 - Changelog created. <08/03/2017>
Maintainer: Arthur Zachow Coelho ([email protected])
Created (changelog): 08/03/2017
This module contains the Experiment class, which is the experiment or simulation itself.
Warning: Use spaces instead of tabs, or configure your editor to transform tab to 4 spaces.
"""

#Standard modules
Expand All @@ -21,7 +28,6 @@ class Experiment(object):
'''
Sets up an experiment.
'''

def __init__(self, k, net_file, group_size, net_name, table_fill_file=None,
flow=0, p_travel_time=False, p_drivers_link=False, p_od_pair=False, p_interval=1,
epsilon=1.0, p_drivers_route=False, TABLE_INITIAL_STATE='fixed',
Expand All @@ -48,31 +54,13 @@ def __init__(self, k, net_file, group_size, net_name, table_fill_file=None,
self.mini = MINI
self.maxi = MAXI
self.fixed = fixed
#Init_network_data is to be erased
self.init_network_data(self.k, net_file, self.group_size, self.flow)

if TABLE_INITIAL_STATE == 'coupling':
self.TABLE_FILL = generate_table_fill(table_fill_file)

def init_network_data(self, k, network_file, group_size, flow):
'''
Initialize the network data.
Inputs:
k: integer = Number of KSP routes to generate
network_file: file = .net file
group_size: integer = Size of the grouping

This method set some of the attributes of the experiment but doesn't help much because
there are some attributes being set ''outside'' the class contructor method.
Needs to be changed in the future.
'''
self.ODlist = []
self.ODL = []
self.ODheader = ""

funtest = dec_test(generateGraph)
self.Vo, self.Eo, odInputo = funtest(network_file, flow=flow)
self.Vo, self.Eo, odInputo = read_infos(net_file, flow=flow)

for tup_od in odInputo:
if round(tup_od[2]) % self.group_size != 0:
print tup_od[2]
Expand Down Expand Up @@ -110,6 +98,9 @@ def init_network_data(self, k, network_file, group_size, flow):
for i in range(int(round(od_pair.numTravels))):
self.drivers.append(Driver(od_pair))

if TABLE_INITIAL_STATE == 'coupling':
self.TABLE_FILL = generate_table_fill(table_fill_file)

def __repr__(self):
"""
__repr__ method override.
Expand Down Expand Up @@ -347,6 +338,7 @@ def run_ql(self, num_episodes, alpha, decay):
self.outputFile.write(headerstr + '\n')

for episode in range(num_episodes):
print_progress(episode+1, num_episodes)
(instance, value) = self.ql.runEpisode()
self.__print_step(episode, instance, qlTT=value)

Expand Down Expand Up @@ -437,6 +429,7 @@ def travelTimeByOD(self, string_actions):
for edge in path:
traveltime += edgesTravelTimes[edge]
odTravelTimeDict[self.drivers[driverIdx].od_s()].append(traveltime)

return odTravelTimeDict

def calculateIndividualTravelTime(self, string_actions):
Expand Down
Loading

0 comments on commit 9195baf

Please sign in to comment.