reformatted
parent
b2ebfddd8b
commit
b2cfa7297c
|
|
@ -1,7 +1,9 @@
|
||||||
from cyclic_utils import rem_routes
|
from cyclic_utils import rem_routes
|
||||||
|
|
||||||
|
|
||||||
class Route(object):
|
class Route(object):
|
||||||
"""docstring for Route."""
|
"""docstring for Route."""
|
||||||
|
|
||||||
def __init__(self, route_id, contract_id, load, src, dst):
|
def __init__(self, route_id, contract_id, load, src, dst):
|
||||||
super(Route, self).__init__()
|
super(Route, self).__init__()
|
||||||
self.route_id = route_id
|
self.route_id = route_id
|
||||||
|
|
@ -20,6 +22,7 @@ class Route(object):
|
||||||
|
|
||||||
class Contract(object):
|
class Contract(object):
|
||||||
"""docstring for Contract."""
|
"""docstring for Contract."""
|
||||||
|
|
||||||
def __init__(self, contract_id, routes):
|
def __init__(self, contract_id, routes):
|
||||||
super(Contract, self).__init__()
|
super(Contract, self).__init__()
|
||||||
self.contract_id = contract_id
|
self.contract_id = contract_id
|
||||||
|
|
@ -28,8 +31,10 @@ class Contract(object):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "\tContract : " + str(self.contract_id) + "\n\tRoutes\n\t\t" + "\n\t\t".join(map(repr, self.routes))
|
return "\tContract : " + str(self.contract_id) + "\n\tRoutes\n\t\t" + "\n\t\t".join(map(repr, self.routes))
|
||||||
|
|
||||||
|
|
||||||
class Transporter(object):
|
class Transporter(object):
|
||||||
"""docstring for Transporter."""
|
"""docstring for Transporter."""
|
||||||
|
|
||||||
def __init__(self, contracts):
|
def __init__(self, contracts):
|
||||||
super(Transporter, self).__init__()
|
super(Transporter, self).__init__()
|
||||||
self.contracts = contracts
|
self.contracts = contracts
|
||||||
|
|
@ -49,7 +54,8 @@ class Transporter(object):
|
||||||
c_dict[c_id].append(Route(route_id, int(c_id), load, src, dst))
|
c_dict[c_id].append(Route(route_id, int(c_id), load, src, dst))
|
||||||
else:
|
else:
|
||||||
c_dict[c_id] = [Route(0, int(c_id), load, src, dst)]
|
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
|
return contracts
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
CYCLE_LIMIT = 3
|
CYCLE_LIMIT = 3
|
||||||
|
|
||||||
|
|
||||||
def rem_routes(routes):
|
def rem_routes(routes):
|
||||||
loop_routes = routes
|
loop_routes = routes
|
||||||
while len(loop_routes) > 0:
|
while len(loop_routes) > 0:
|
||||||
|
|
@ -15,6 +16,7 @@ def rem_routes(routes):
|
||||||
partial_routes = filter(lambda x: x not in lp, partial_routes)
|
partial_routes = filter(lambda x: x not in lp, partial_routes)
|
||||||
return partial_paths
|
return partial_paths
|
||||||
|
|
||||||
|
|
||||||
def route_deps(routes):
|
def route_deps(routes):
|
||||||
routes_map = {}
|
routes_map = {}
|
||||||
for r in routes:
|
for r in routes:
|
||||||
|
|
@ -26,6 +28,7 @@ def route_deps(routes):
|
||||||
routes_map[r.dst] = []
|
routes_map[r.dst] = []
|
||||||
return routes_map
|
return routes_map
|
||||||
|
|
||||||
|
|
||||||
def largest_loop(routes):
|
def largest_loop(routes):
|
||||||
deps = route_deps(routes)
|
deps = route_deps(routes)
|
||||||
circ_paths = [find_loop(r.src, r.src, deps, set(), []) for r in 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)
|
rem_paths = filter(lambda x: x not in paths, routes)
|
||||||
return (circ, paths, rem_paths)
|
return (circ, paths, rem_paths)
|
||||||
|
|
||||||
|
|
||||||
def longest_path(routes):
|
def longest_path(routes):
|
||||||
def route_path(r, deps):
|
def route_path(r, deps):
|
||||||
if not deps.has_key(r.dst) or len(deps[r.dst]) == 0:
|
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)
|
longest = max(all_paths, key=len)
|
||||||
return longest
|
return longest
|
||||||
|
|
||||||
|
|
||||||
def find_loop(elem, dep_elem, deps, checked, path):
|
def find_loop(elem, dep_elem, deps, checked, path):
|
||||||
found_loop = False
|
found_loop = False
|
||||||
if dep_elem not in checked and deps.has_key(dep_elem):
|
if dep_elem not in checked and deps.has_key(dep_elem):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue