Disjunction feature step 2

- selection of disjoint path set for each synchronization vector

Signed-off-by: EstherLerouzic <esther.lerouzic@orange.com>
This commit is contained in:
EstherLerouzic
2018-09-18 18:03:35 +01:00
parent fb49f7fb5d
commit 7558721642
2 changed files with 84 additions and 55 deletions

View File

@@ -75,6 +75,7 @@ def disjunctions_from_json(json_data):
for snc in json_data['synchronization']: for snc in json_data['synchronization']:
params = {} params = {}
params['disjunction_id'] = snc['synchronization-id']
params['relaxable'] = snc['svec']['relaxable'] params['relaxable'] = snc['svec']['relaxable']
params['link_diverse'] = snc['svec']['link-diverse'] params['link_diverse'] = snc['svec']['link-diverse']
params['node_diverse'] = snc['svec']['node-diverse'] params['node_diverse'] = snc['svec']['node-diverse']
@@ -171,12 +172,17 @@ def compute_path_dsjctn(network, equipment, pathreqlist, disjunctions_list):
# for each remaining request compute a set of simple path # for each remaining request compute a set of simple path
rqs = {} rqs = {}
simple_rqs = {} simple_rqs = {}
simple_rqs_reversed = {}
for pathreq in pathreqlist_disjt : for pathreq in pathreqlist_disjt :
print(pathreq.request_id) print(pathreq.request_id)
all_simp_pths = list(all_simple_paths(network,\ all_simp_pths = list(all_simple_paths(network,\
source=next(el for el in network.nodes() if el.uid == pathreq.source),\ source=next(el for el in network.nodes() if el.uid == pathreq.source),\
target=next(el for el in network.nodes() if el.uid == pathreq.destination))) target=next(el for el in network.nodes() if el.uid == pathreq.destination)))
rqs[pathreq.request_id] = all_simp_pths # reversed direction paths required to check disjunction on both direction
all_simp_pths_reversed = []
for pth in all_simp_pths:
all_simp_pths_reversed.append(find_reversed_path(pth,network))
# rqs[pathreq.request_id] = all_simp_pths
temp =[] temp =[]
for p in all_simp_pths : for p in all_simp_pths :
# build a short list representing each roadm+direction with the first item # build a short list representing each roadm+direction with the first item
@@ -184,74 +190,96 @@ def compute_path_dsjctn(network, equipment, pathreqlist, disjunctions_list):
temp.append([e.uid for i,e in enumerate(p[1:-1]) \ temp.append([e.uid for i,e in enumerate(p[1:-1]) \
if (isinstance(e,Roadm) | (isinstance(p[i],Roadm) ))] ) if (isinstance(e,Roadm) | (isinstance(p[i],Roadm) ))] )
simple_rqs[pathreq.request_id] = temp simple_rqs[pathreq.request_id] = temp
for p in all_simp_pths : temp =[]
print ([e.uid for e in p if isinstance (e,Roadm)]) for p in all_simp_pths_reversed :
tab = {} # build a short list representing each roadm+direction with the first item
tab2 = {} # start enumeration at 1 to avoid Trx in the list
temp.append([e.uid for i,e in enumerate(p[1:-1]) \
if (isinstance(e,Roadm) | (isinstance(p[i],Roadm) ))] )
simple_rqs_reversed[pathreq.request_id] = temp
# step 2 # step 2
# for each pair in the set of requests that need to be disjoint # for each set of requests that need to be disjoint
# count the non disjoint cases tab[path] = list of disjoint path # select the disjoint path combination
candidates = {}
for d in disjunctions_list : for d in disjunctions_list :
print(d) print(d)
temp = d.disjunctions_req.copy() dlist = d.disjunctions_req.copy()
for e1 in temp : # each line of dpath is one combination of path that satisfies disjunction
for i,p1 in enumerate(simple_rqs[e1]): dpath = []
if temp: for p in simple_rqs[dlist[0]]:
for e2 in temp : dpath.append([p])
if e1 != e2 : # in each loop, dpath is updated with a path for rq that satisfies
for j,p2 in enumerate(simple_rqs[e2]): # disjunction with each path in dpath
# print(f'{id(p1)} {id(p2)}') # for example, assume set of disjunction_list is {rq1,rq2, rq3}
try : # rq1 p1: abcg
tab[id(p1)] += isdisjoint(p1,p2) # p2: aefhg
if isdisjoint(p1,p2)==0: # p3: abfhg
tab2[id(p1)] = tab2[id(p1)].append(p2) # rq2 p8: bf
print(f'{e1} is {isdisjoint(p1,p2)} {e2} tab : {tab2[id(p1),e2]}') # rq2 p4: abcgh
except KeyError: # p6: aefh
tab[id(p1)] = isdisjoint(p1,p2) # p7: abfh
if isdisjoint(p1,p2)==0: # initiate with rq1
tab2[id(p1)] = [p2] # dpath = [p1
try : # p2
tab[id(p2)] += isdisjoint(p1,p2) # p3]
if isdisjoint(p1,p2)==0: # after first loop:
tab2[id(p2)] = tab2[id(p2)].append(p1) # dpath = [p1 p8
except KeyError: # p3 p8]
tab[id(p2)] = isdisjoint(p1,p2) # since p2 and p8 are not disjoint
if isdisjoint(p1,p2)==0: # after second loop:
tab2[id(p2)] = [p1] # dpath = [ p1 P8 p6 ]
# remove the request from the list to avoid computind ij and ji cases # since p1 and p4 are not disjoint
temp = temp.remove(e1) # p1 and p7 are not disjoint
# p3 and p4 are not disjoint
# p3 and p7 are not disjoint
for e1 in dlist[1:] :
temp = []
for j,p1 in enumerate(simple_rqs[e1]):
# can use index j in simple_rqs_reversed because index
# of direct and reversed paths have been kept identical
p1_reversed = simple_rqs_reversed[e1][j]
# print(p1_reversed)
# print('\n\n')
for c in dpath :
# print(f' c: \t{c}')
temp2 = c.copy()
for p in c :
if isdisjoint(p1,p)+ isdisjoint(p1_reversed,p)==0 :
temp2.append(p1)
temp.append(temp2)
# print(f' coucou {e1}: \t{temp}')
dpath = temp
# print(f' coucou : \t{temp}')
# print(dpath)
candidates[d.disjunction_id] = dpath
print( candidates)
# print(tab) # now for each request, select the path that satisfies all disjunctions
# print(len(tab)) # path must be in candidates[id] for all concerned ids
el = disjunctions_list[0].disjunctions_req[0]
# print(tab[id(simple_rqs[el][0])])
# now for each request, select the path that has the least nb of disjunction
# and completely disjoined from the already selected paths in the constraint
for pathreq in pathreqlist_disjt :
pths = [ tab[id(e)] for e in simple_rqs[pathreq.request_id]]
pths2 = []
for p in simple_rqs[pathreq.request_id] :
print(f'{p} disjoint de {tab2[id(p)]}')
i = pths.index(min(pths))
print(simple_rqs[pathreq.request_id][i])
print(pths)
print(pths2)
def isdisjoint(p1,p2) : def isdisjoint(p1,p2) :
# returns 0 if disjoint # returns 0 if disjoint
# TODO add reverse direction in the test
edge1 = list(pairwise(p1)) edge1 = list(pairwise(p1))
edge2 = list(pairwise(p2)) edge2 = list(pairwise(p2))
edge3 = list(pairwise(reversed(p2)))
for e in edge1 : for e in edge1 :
if (e in edge2) | (e in edge3) : if e in edge2 :
return 1 return 1
return 0 return 0
def find_reversed_path(p,network) :
# select of intermediate roadms and find the path between them
reversed_roadm_path = list(reversed([e for e in p if isinstance (e,Roadm)]))
source = p[-1]
destination = p[0]
total_path = [source]
for node in reversed_roadm_path :
total_path.extend(dijkstra_path(network, source, node)[1:])
source = node
total_path.append(destination)
return total_path
def path_result_json(pathresult): def path_result_json(pathresult):
data = { data = {

View File

@@ -32,7 +32,7 @@ logger = getLogger(__name__)
RequestParams = namedtuple('RequestParams','request_id source destination trx_type'+ RequestParams = namedtuple('RequestParams','request_id source destination trx_type'+
' trx_mode nodes_list loose_list spacing power nb_channel frequency format baud_rate OSNR bit_rate roll_off') ' trx_mode nodes_list loose_list spacing power nb_channel frequency format baud_rate OSNR bit_rate roll_off')
DisjunctionParams = namedtuple('DisjunctionParams','relaxable link_diverse node_diverse disjunctions_req') DisjunctionParams = namedtuple('DisjunctionParams','disjunction_id relaxable link_diverse node_diverse disjunctions_req')
class Path_request: class Path_request:
def __init__(self, *args, **params): def __init__(self, *args, **params):
@@ -72,6 +72,7 @@ class Path_request:
class Disjunction: class Disjunction:
def __init__(self, *args, **params): def __init__(self, *args, **params):
params = DisjunctionParams(**params) params = DisjunctionParams(**params)
self.disjunction_id = params.disjunction_id
self.relaxable = params.relaxable self.relaxable = params.relaxable
self.link_diverse = params.link_diverse self.link_diverse = params.link_diverse
self.node_diverse = params.node_diverse self.node_diverse = params.node_diverse