def create_with_shortest_path(self, topo, flow, from_srcs, to_dsts, link_caps):
for src_key in from_srcs:
path_from_src = from_srcs[src_key]
if not self.check_capacity(topo, path_from_src, link_caps, flow.vol, flow.reversed_vol):
continue
for dst_key in to_dsts:
path_to_dst = to_dsts[dst_key]
if self.checking_joint(path_from_src, path_to_dst):
continue
else:
if not self.check_capacity(topo, path_to_dst, link_caps, flow.vol, flow.reversed_vol):
continue
try:
in_path = path_from_src + path_to_dst
mid_paths = [p for p in topo.get_shortest_paths(src_key, dst_key, False)]
for mid_path in mid_paths:
if mid_path != [] and not self.checking_joint(mid_path, in_path):
path = path_from_src + mid_path + path_to_dst
if not self.check_capacity(topo, path, link_caps, flow.vol, flow.reversed_vol):
continue
flow.path = path
flow.skip_mdbxes = [src_key, dst_key]
self.log.info(flow.path)
self.allocate_link_cap(flow.path, link_caps, flow.vol, flow.reversed_vol)
return True
except nx.exception.NetworkXNoPath:
continue
return False
评论列表
文章目录