reformatted

master
Malar Kannan 2017-07-03 17:25:08 +05:30
parent b2ebfddd8b
commit b2cfa7297c
2 changed files with 43 additions and 32 deletions

View File

@ -1,7 +1,9 @@
from cyclic_utils import rem_routes
class Route(object):
"""docstring for Route."""
def __init__(self, route_id, contract_id, load, src, dst):
super(Route, self).__init__()
self.route_id = route_id
@ -20,6 +22,7 @@ class Route(object):
class Contract(object):
"""docstring for Contract."""
def __init__(self, contract_id, routes):
super(Contract, self).__init__()
self.contract_id = contract_id
@ -28,8 +31,10 @@ class Contract(object):
def __repr__(self):
return "\tContract : " + str(self.contract_id) + "\n\tRoutes\n\t\t" + "\n\t\t".join(map(repr, self.routes))
class Transporter(object):
"""docstring for Transporter."""
def __init__(self, contracts):
super(Transporter, self).__init__()
self.contracts = contracts
@ -49,7 +54,8 @@ class Transporter(object):
c_dict[c_id].append(Route(route_id, int(c_id), load, src, dst))
else:
c_dict[c_id] = [Route(0, int(c_id), load, src, dst)]
contracts = [Contract(int(i),c_dict[i]) for i in sorted(c_dict.keys())]
contracts = [Contract(int(i), c_dict[i])
for i in sorted(c_dict.keys())]
return contracts

View File

@ -1,6 +1,7 @@
CYCLE_LIMIT = 3
def rem_routes(routes):
loop_routes = routes
while len(loop_routes) > 0:
@ -15,6 +16,7 @@ def rem_routes(routes):
partial_routes = filter(lambda x: x not in lp, partial_routes)
return partial_paths
def route_deps(routes):
routes_map = {}
for r in routes:
@ -26,6 +28,7 @@ def route_deps(routes):
routes_map[r.dst] = []
return routes_map
def largest_loop(routes):
deps = route_deps(routes)
circ_paths = [find_loop(r.src, r.src, deps, set(), []) for r in routes]
@ -34,6 +37,7 @@ def largest_loop(routes):
rem_paths = filter(lambda x: x not in paths, routes)
return (circ, paths, rem_paths)
def longest_path(routes):
def route_path(r, deps):
if not deps.has_key(r.dst) or len(deps[r.dst]) == 0:
@ -46,6 +50,7 @@ def longest_path(routes):
longest = max(all_paths, key=len)
return longest
def find_loop(elem, dep_elem, deps, checked, path):
found_loop = False
if dep_elem not in checked and deps.has_key(dep_elem):