Skip to content

Commit

Permalink
autopep formatting #22
Browse files Browse the repository at this point in the history
  • Loading branch information
behrisch committed Jan 20, 2024
1 parent f7b8fdb commit c6b7b48
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 28 deletions.
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ repos:
- id: astyle_py
args: [--style=java --unpad-paren --pad-header --pad-oper --add-brackets --indent-switches --align-pointer=type]
exclude: 'src/foreign/.*'
- repo: https://github.com/hhatto/autopep8
rev: v2.0.4
hooks:
- id: autopep8
args: ['--max-line-length', '120', '--in-place']
4 changes: 2 additions & 2 deletions tools/assign/duaIterate_reroutingAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
def parse_args(args=None):
USAGE = "Usage: " + sys.argv[0] + " [options]"
parser = sumolib.options.ArgumentParser(
usage=USAGE,
description="Extract fraction of vehicles that changed their route per iteration")
usage=USAGE,
description="Extract fraction of vehicles that changed their route per iteration")
parser.add_argument("-d", "--base-directory", dest="baseDir", category="input", default=".", type=str,
help="Base directory of duaIterate run")
parser.add_argument("-v", "--verbose", action="store_true", default=False,
Expand Down
3 changes: 2 additions & 1 deletion tools/build_config/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ def generateTemplate(app, appBin):
print("Obtaining " + app + " template")
# obtain template piping stdout using check_output
try:
template = formatBinTemplate(subprocess.check_output([appBin, "--save-template", "stdout"], universal_newlines=True))
template = formatBinTemplate(subprocess.check_output(
[appBin, "--save-template", "stdout"], universal_newlines=True))
except subprocess.CalledProcessError as e:
sys.stderr.write("Error when generating template for " + app + ": '%s'" % e)
template = ""
Expand Down
13 changes: 5 additions & 8 deletions tools/drt/drtOnline.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ def find_dua_times(options):
with open("temp_dua/dua_file.xml", "w+") as dua_file:
dua_file.write("<routes>\n")
for comb_edges in list(combination_edges):
dua_file.write('\t<trip id="%s_%s" depart="0" from="%s" to="%s"/>\n'
dua_file.write(' <trip id="%s_%s" depart="0" from="%s" to="%s"/>\n'
% (comb_edges[0], comb_edges[1], comb_edges[0], comb_edges[1]))
dua_file.write('\t<trip id="%s_%s" depart="0" from="%s" to="%s"/>\n'
dua_file.write(' <trip id="%s_%s" depart="0" from="%s" to="%s"/>\n'
% (comb_edges[1], comb_edges[0], comb_edges[1], comb_edges[0]))
dua_file.write("</routes>\n")

Expand Down Expand Up @@ -176,13 +176,11 @@ def ilp_solve(options, veh_num, res_num, costs, veh_constraints,
# add constraints
for index in range(veh_num):
prob += pl.lpSum([veh_constraints[i][index] * Trips_vars[i]
for i in order_trips]) <= 1, \
"Max_1_trip_per_vehicle_%s" % index
for i in order_trips]) <= 1, "Max_1_trip_per_vehicle_%s" % index

for index in range(res_num):
prob += pl.lpSum([res_constraints[i][index] * Trips_vars[i]
for i in order_trips]) <= 1, \
"Max_1_trip_per_reservation_%s" % index
for i in order_trips]) <= 1, "Max_1_trip_per_reservation_%s" % index

prob += pl.lpSum([sum(veh_constraints[i]) * Trips_vars[i]
for i in order_trips]) >= 1, "Assing_at_least_one_vehicle"
Expand Down Expand Up @@ -440,8 +438,7 @@ def main():
for idx, trip_id in enumerate(trips):
# routes[route] = [travel_time, veh_bin, res_bin, value]
# TODO specific cost for vehicle can be consider here
bonus_cost = (sum(routes[trip_id][2]) + 1) * \
options.cost_per_trip
bonus_cost = (sum(routes[trip_id][2]) + 1) * options.cost_per_trip
# generate dict with costs
costs.update({idx: routes[trip_id][0] + bonus_cost})
# generate dict with vehicle used in the trip
Expand Down
2 changes: 1 addition & 1 deletion tools/game/racing.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

# Check for playsound import
try:
import playsound # noqa
import playsound # noqa
except ImportError:
sys.stderr.write("playsound not installed. Sounds will not be played on collisions.\n")
playsound = None
Expand Down
2 changes: 1 addition & 1 deletion tools/import/vissim/convert_vissimXML_flows_statRoutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def validate_rel_flow(routes_by_start_d, flow_d):
continue
else:
# check if the time frame starts are the same
assert np.array_equal(ref_time_shape[:, 0], route["rel_flow"][:, 0]),\
assert np.array_equal(ref_time_shape[:, 0], route["rel_flow"][:, 0]), \
"\nPROBLEM: flow count and relative flow time frames are not aligned\n\t"\
"for VISSIM start link id: " + start_link
# copy back modifications
Expand Down
1 change: 1 addition & 0 deletions tools/output/vehrouteCountValidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def get_options(args=None):

class Routes:
"""dummy class to allow using the same methods as routeSampler.py"""

def __init__(self):
self.unique = []

Expand Down
2 changes: 1 addition & 1 deletion tools/purgatory/dijkstra.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,4 @@ def least_cost(self, start, dest, costFactors=defaultdict(lambda: 1.0)):
return D[dest]
else:
raise ("No path between %s and %s found" %
(start.getID(), dest.getID()))
(start.getID(), dest.getID()))
2 changes: 1 addition & 1 deletion tools/runSeeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_options(args=None):
ap.add_option("-k", "--configuration", category="input", metavar="FILE", required=True,
type=ap.sumoconfig_file_list,
help="configuration to run or comma-separated list of configurations")
ap.add_option("-a", "--application", category="processing", default="sumo", metavar="FILE",
ap.add_option("-a", "--application", category="processing", default=sumolib.checkBinary("sumo"), metavar="FILE",
help="application to run or comma-separated list of applications")
ap.add_option("-p", "--output-prefix", category="processing", default="SEED.", dest="prefix",
help="output prefix",)
Expand Down
26 changes: 13 additions & 13 deletions tools/sumolib/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ def toXML(self):

def decodeXML(c):
colorSwitch = {
"red": RGBAColor(255, 0, 0, 255),
"green": RGBAColor(0, 255, 0, 255),
"blue": RGBAColor(0, 0, 255, 255),
"yellow": RGBAColor(255, 255, 0, 255),
"cyan": RGBAColor(0, 255, 255, 255),
"magenta": RGBAColor(255, 0, 255, 255),
"orange": RGBAColor(255, 128, 0, 255),
"white": RGBAColor(255, 255, 255, 255),
"black": RGBAColor(0, 0, 0, 255),
"grey": RGBAColor(128, 128, 128, 255),
"gray": RGBAColor(128, 128, 128, 255),
"invisible": RGBAColor(0, 0, 0, 0)
}
"red": RGBAColor(255, 0, 0, 255),
"green": RGBAColor(0, 255, 0, 255),
"blue": RGBAColor(0, 0, 255, 255),
"yellow": RGBAColor(255, 255, 0, 255),
"cyan": RGBAColor(0, 255, 255, 255),
"magenta": RGBAColor(255, 0, 255, 255),
"orange": RGBAColor(255, 128, 0, 255),
"white": RGBAColor(255, 255, 255, 255),
"black": RGBAColor(0, 0, 0, 255),
"grey": RGBAColor(128, 128, 128, 255),
"gray": RGBAColor(128, 128, 128, 255),
"invisible": RGBAColor(0, 0, 0, 0)
}
knownColor = colorSwitch.get(c)
if knownColor is None:
return RGBAColor(*[float(x) for x in c.split(",")])
Expand Down

0 comments on commit c6b7b48

Please sign in to comment.