def PrimaryPath(src,tgt,primary_path,request): #for i in range(len(primary_path)-1): #g.ep.weight_temp[primary_path[i],primary_path[i+1]] = 9999 graph_weight2 = g.new_edge_property("float") #graph tool property for edges g.ep.weight_temp = graph_weight2 #adding a temporary weight for e in g.edges(): g.ep.weight_temp[e] = 1 for i in range(len(primary_path)-1): g.ep.weight_temp[primary_path[i],primary_path[i+1]] = 9999 #print("pred"+str(i)) while True: rev_path = [] destination_node = request[1] dist, pred = gt.dijkstra_search(g, src, g.ep.weight_temp) g.vp.pred_tree = pred while g.vertex(destination_node) != src: #print(destination_node) rev_path.append(destination_node) temp = destination_node destination_node = g.vp.pred_tree[g.vertex(destination_node)] #print("dest:"+str(destination_node)) #print("temp:"+str(temp)) if temp == destination_node: rev_path = [] #break tmp=1 temp_value=1 if len(rev_path) == 0: backup_paths_all[request_key] = "Blocked" else: path = [] path.append(request[0]) for i in range(len(rev_path) - 1, -1, -1): path.append(rev_path[i]) print("new primary path searched: "+str(path)) channel_available = [] for i in range (int(number_wavelengths)): channel_available.append(1) if dist[tgt] < 9999: for i in range(len(path) - 1): #print("counter alt: "+str(g.ep.counter_alt[path[i],path[i+1]])) if g.ep.counter_high[path[i],path[i+1]] > 0: print("traversing edge: " + str(path[i]) + " --> " + str(path[i + 1])) for j in range(int(channels_high)): print("Channel " + str(j) + "\t" + str(edge_flags[str(path[i]) + " --> " + str(path[i + 1])][j])) available_wavelengths[str(path[i]) + " --> " + str(path[i + 1])][j] = available_wavelengths[str(path[i]) + " --> " + str(path[i + 1])][j] & edge_flags[str(path[i]) + " --> " + str(path[i + 1])][j] channel_available[j] = channel_available[j] & available_wavelengths[str(path[i]) + " --> " + str(path[i + 1])][j] else: temp_value = 0 g.ep.weight_temp[path[i],path[i+1]] = 9999 #print "weight alt " +str(g.ep.weight_alt[path[i],path[i+1]]) break #find another backup path if temp_value == 1: for j in range (int(channels_high)): if channel_available[j] == 1: temp_value=1 if temp_value == 1: return (path,channel_available) ''' print("primary path allocated : "+str(path)) for i in range(len(path)-1): for j in range (int(channels_high)): if available_wavelengths[str(path[i]) + " --> " + str(path[i + 1])][j] == 1: edge_flags[str(path[i]) + " --> " + str(path[i + 1])][j] = 0 g.ep.counter_high[path[i],path[i+1]] -= 1 available_wavelengths_alt[str(path[i]) + " --> " + str(path[i + 1])][j] = 0 print("Channel "+str(j)+" allocated for backup; " + " for edge: " + str(path[i]) + " --> " + str(path[i+1])) op.write(str(j) + " is the backup channel allocated\n") break #all_requests_with_primary[request_key] = path ''' #return path else: path = [] print("no primary path found; request blocked") primary_paths_all[request_key] = "Blocked" return (path,channel_available)
def BackupPath(src,tgt,primary_path,request): #print("source"+ str(src) + "dest "+str(tgt)+" path: "+str(primary_path)+ " request"+str(request) ) graph_weight = g.new_edge_property("float") #graph tool property for edges g.ep.weight_alt = graph_weight #adding a temporary weight for e in g.edges(): g.ep.weight_alt[e] = 1 for i in range(len(primary_path)-1): g.ep.weight_alt[primary_path[i],primary_path[i+1]] = 9999 #tmp=1 #print("pred"+str(i)) path_count=0 while True: path_count += 1 rev_path = [] destination_node = request[1] dist, pred = gt.dijkstra_search(g, src, g.ep.weight_alt) g.vp.pred_tree = pred while g.vertex(destination_node) != src: #print(destination_node) rev_path.append(destination_node) temp = destination_node destination_node = g.vp.pred_tree[g.vertex(destination_node)] #print("dest:"+str(destination_node)) #print("temp:"+str(temp)) if temp == destination_node: rev_path = [] #break tmp=1 temp_value=1 if len(rev_path) == 0: backup_paths_all[request_key] = "Blocked" else: path = [] path.append(request[0]) for i in range(len(rev_path) - 1, -1, -1): path.append(rev_path[i]) print("backup path searched: " +str(path) +"cost of path found is : " +str(dist[tgt]) ) #temp_value = 0 channel_available = [] for i in range (int(number_wavelengths)): channel_available.append(1) if dist[tgt] < 9999: for i in range(len(path) - 1): #print("counter alt: "+str(g.ep.counter_alt[path[i],path[i+1]])) if g.ep.counter_alt[path[i],path[i+1]] > 0: print("traversing edge: " + str(path[i]) + " --> " + str(path[i + 1])) for j in range(int(channels_high),number_wavelengths): print("Channel " + str(j) + "\t" + str(edge_flags[str(path[i]) + " --> " + str(path[i + 1])][j + number_wavelengths])) available_wavelengths_alt[str(path[i]) + " --> " + str(path[i + 1])][j] = available_wavelengths_alt[str(path[i]) + " --> " + str(path[i + 1])][j] & edge_flags[str(path[i]) + " --> " + str(path[i + 1])][j + number_wavelengths] channel_available[j] = channel_available[j] & available_wavelengths_alt[str(path[i]) + " --> " + str(path[i + 1])][j] else: print("traversing edge: " + str(path[i]) + " --> " + str(path[i + 1])) print("no channel available ") temp_value = 0 g.ep.weight_alt[path[i],path[i+1]] = 9999 #print "weight alt " +str(g.ep.weight_alt[path[i],path[i+1]]) break #find another backup path if temp_value == 1: for j in range (int(channels_high),number_wavelengths): if channel_available[j] == 1: print("backup path allocated : "+str(path)) tmp = 0 for i in range(len(path)-1): edge_flags[str(path[i]) + " --> " + str(path[i + 1])][j + number_wavelengths] = 0 g.ep.counter_alt[path[i],path[i+1]] -= 1 available_wavelengths_alt[str(path[i]) + " --> " + str(path[i + 1])][j] = 0 print("Channel "+str(j)+" allocated for backup; " + " for edge: " + str(path[i]) + " --> " + str(path[i+1])) #op.write(str(j) + " is the backup channel allocated\n") break if tmp == 0: backup_paths_all[request_key] = path return 1 else: print("no backup path found cost of path found is : " +str(dist[tgt])) return 0 else: if dist[tgt] < 9999 and path_count <= 30: continue else: print("no backup path found cost of path found is : " +str(dist[tgt])) #backup_paths_all[request_key] = "Blocked" return 0
established_high = 0 established_low = 0 for request in all_requests: if request[2] > 0.5*number_wavelengths: request_key = str(request[0]) + " --> " + str(request[1]) + " " +str(randint(0,10000)) print("\nRequest is " + request_key) print("Request is high priority") number_high += 1 while True: rev_path = [] src = g.vertex(request[0]) tgt = g.vertex(request[1]) destination_node = request[1] dist, pred = gt.dijkstra_search(g, src, g.ep.weight_high) g.vp.pred_tree = pred #previous vertex of graph taken #print pred.a #print g.vp.pred_tree.a while g.vertex(destination_node) != src: #backtracing till destination is equal to source (reverse path used) rev_path.append(destination_node) #destination node added to reverse path array temp = destination_node #temp: nodes from destination to source destination_node = g.vp.pred_tree[g.vertex(destination_node)] #destination_node gives parent nodes from destination to source if temp == destination_node: #check for same source and destination since temp =last to source-1 and destination=dest-1 to source are going to be different rev_path = [] break #rev_path.append(request[0]) temp = 0 tmp = 1 if len(rev_path) == 0: primary_paths_all[request_key] = "Blocked"
def BackupPath(src, tgt, primary_path, request, request_key): #print("source"+ str(src) + "dest "+str(tgt)+" path: "+str(primary_path)+ " request"+str(request) ) graph_weight = g.new_edge_property("float") #graph tool property for edges g.ep.weight_alt = graph_weight #adding a temporary weight for e in g.edges(): g.ep.weight_alt[e] = 1 for i in range(len(primary_path) - 1): g.ep.weight_alt[primary_path[i], primary_path[i + 1]] = 9999 #print("pred"+str(i)) while True: for e in g.edges(): for j in range(number_wavelengths): edge_flags[str(e.source()) + " --> " + str(e.target())][j + (2 * number_wavelengths)] = 1 edge_flags[str(e.target()) + " --> " + str(e.source())][j + (2 * number_wavelengths)] = 1 non_disjointlist = [] rev_path = [] destination_node = request[1] dist, pred = gt.dijkstra_search(g, src, g.ep.weight_alt) g.vp.pred_tree = pred while g.vertex(destination_node) != src: #print(destination_node) rev_path.append(destination_node) temp = destination_node destination_node = g.vp.pred_tree[g.vertex(destination_node)] #print("dest:"+str(destination_node)) #print("temp:"+str(temp)) if temp == destination_node: rev_path = [] tmp = 1 temp_value = 1 if len(rev_path) == 0: backup_paths_all[request_key] = "Blocked" else: path = [] path.append(request[0]) for i in range(len(rev_path) - 1, -1, -1): path.append(rev_path[i]) for key in primary_paths_high_all_temp.keys(): flag = 0 temp_path = primary_paths_high_all_temp[key] # print("temp path cal is : " +str(temp_path)) # print("primary path cal is : " + str(primary_path)) for i in range(len(primary_path) - 1): for j in range(len(temp_path) - 2): if primary_path[i] == temp_path[j] and primary_path[ i + 1] == temp_path[j + 1]: non_disjointlist.append(key) # print("non list : " +str(non_disjointlist)) flag = 1 break if flag == 1: break print("backup path searched: " + str(path) + "cost of path found is : " + str(dist[tgt])) print("non-disjoint list : " + str(non_disjointlist)) for i in range(len(non_disjointlist)): temp_path = backup_paths_all[non_disjointlist[i]] print("temp path : " + str(temp_path)) temp_channel = backup_paths_all[non_disjointlist[i]][-1] print("temp channel : " + str(temp_channel)) for j in range(len(temp_path) - 2): edge_flags[str(temp_path[j]) + " --> " + str( temp_path[j + 1])][temp_channel + (2 * number_wavelengths)] = 0 channel_available = [] for i in range(int(number_wavelengths)): channel_available.append(1) if dist[tgt] < 9999: for i in range(len(path) - 1): #print("counter alt: "+str(g.ep.counter_alt[path[i],path[i+1]])) if g.ep.counter_channels[path[i], path[i + 1]] > 0: print("traversing edge: " + str(path[i]) + " --> " + str(path[i + 1])) for j in range(int(number_wavelengths)): print( "Channel " + str(j) + "\t" + str(edge_flags[str(path[i]) + " --> " + str(path[i + 1])][j]) + "\t" + str(edge_flags[str(path[i]) + " --> " + str( path[i + 1])][j + 2 * number_wavelengths])) #available_wavelengths_alt[str(path[i]) + " --> " + str(path[i + 1])][j] = available_wavelengths_alt[str(path[i]) + " --> " + str(path[i + 1])][j] & edge_flags[str(path[i]) + " --> " + str(path[i + 1])][j + int(number_wavelengths)] & edge_flags[str(path[i]) + " --> " + str(path[i + 1])][j] #print("Channel " + str(j) + "\t" + str(available_wavelengths_alt[str(path[i]) + " --> " + str(path[i + 1])][j])) channel_available[j] = channel_available[ j] & edge_flags[str(path[i]) + " --> " + str( path[i + 1])][j] & edge_flags[ str(path[i]) + " --> " + str(path[i + 1])][j + 2 * number_wavelengths] else: temp_value = 0 g.ep.weight_alt[path[i], path[i + 1]] = 9999 #print "weight alt " +str(g.ep.weight_alt[path[i],path[i+1]]) break #find another backup path if temp_value == 1: for j in range(int(number_wavelengths)): if channel_available[j] == 1: print("backup path allocated : " + str(path)) tmp = 0 for i in range(len(path) - 1): edge_flags[str(path[i]) + " --> " + str( path[i + 1])][j + int(number_wavelengths)] = 0 #g.ep.counter_channels[path[i],path[i+1]] -= 1 #available_wavelengths_alt[str(path[i]) + " --> " + str(path[i + 1])][j] = 0 print("Channel " + str(j) + " allocated for backup; " + " for edge: " + str(path[i]) + " --> " + str(path[i + 1])) channel_key = str(path[i]) + " --> " + str( path[i + 1]) + " " + str(j) channels_all[channel_key] = request_key backup_paths_all[request_key] = path backup_paths_all[request_key].append(j) break if tmp == 0: return 1 else: print("no backup path found cost of path found is : " + str(dist[tgt])) return 0 else: #return 0 if dist[tgt] < 9999: continue else: print("no backup path found; request blocked") #backup_paths_all[request_key] = "Blocked" return 0
print "debugg1" print total_request simulate(50) request_served = 0 if request[2] > 0.5 * number_wavelengths: request_key = str(request[0]) + " --> " + str(request[1]) + " " + str( randint(0, 10000)) print("\nRequest is " + request_key) print("Request is high priority") number_high += 1 while True: rev_path = [] src = g.vertex(request[0]) tgt = g.vertex(request[1]) destination_node = request[1] dist, pred = gt.dijkstra_search(g, src, g.ep.weight_primary) g.vp.pred_tree = pred #previous vertex of graph taken #print pred.a #print g.vp.pred_tree.a while g.vertex( destination_node ) != src: #backtracing till destination is equal to source (reverse path used) rev_path.append( destination_node ) #destination node added to reverse path array temp = destination_node #temp: nodes from destination to source destination_node = g.vp.pred_tree[g.vertex( destination_node )] #destination_node gives parent nodes from destination to source if temp == destination_node: #check for same source and destination since temp =last to source-1 and destination=dest-1 to source are going to be different rev_path = []
def PrimaryPath(src, tgt, primary_path, request): graph_weight2 = g.new_edge_property("float") g.ep.weight_temp = graph_weight2 for e in g.edges(): g.ep.weight_temp[e] = 1 for i in range(len(primary_path) - 1): g.ep.weight_temp[primary_path[i], primary_path[i + 1]] = 9999 while True: rev_path = [] destination_node = request[1] dist, pred = gt.dijkstra_search(g, src, g.ep.weight_temp) g.vp.pred_tree = pred while g.vertex(destination_node) != src: rev_path.append(destination_node) temp = destination_node destination_node = g.vp.pred_tree[g.vertex(destination_node)] if temp == destination_node: rev_path = [] tmp = 1 temp_value = 0 if len(rev_path) == 0: backup_paths_all[request_key] = "Blocked" else: path = [] path.append(request[0]) for i in range(len(rev_path) - 1, -1, -1): path.append(rev_path[i]) print("new primary path searched: " + str(path)) channel_available = [] for i in range(int(number_wavelengths)): channel_available.append(1) if dist[tgt] < 9999: for i in range(len(path) - 1): if g.ep.counter_high[path[i], path[i + 1]] > 0: print("traversing edge: " + str(path[i]) + " --> " + str(path[i + 1])) for j in range(int(channels_high)): print( "Channel " + str(j) + "\t" + str(edge_flags[str(path[i]) + " --> " + str(path[i + 1])][j])) available_wavelengths[str(path[i]) + " --> " + str( path[i + 1])][j] = available_wavelengths[ str(path[i]) + " --> " + str(path[i + 1])][j] & edge_flags[ str(path[i]) + " --> " + str(path[i + 1])][j] channel_available[j] = channel_available[ j] & available_wavelengths[str(path[i]) + " --> " + str(path[i + 1])][j] else: tmp = 0 g.ep.weight_temp[path[i], path[i + 1]] = 9999 break if tmp == 1: for j in range(int(channels_high)): if channel_available[j] == 1: temp_value = 1 if temp_value == 1: return (path, channel_available) else: if dist[tgt] < 9999: continue else: path = [] #print("no primary path found; request blocked") #primary_paths_all[request_key] = "Blocked" return (path, channel_available)
for e in g.edges(): edges_logger[str(e.source()) + " --> " + str(e.target())][0] = 1 edges_logger[str(e.target()) + " --> " + str(e.source())][0] = 1 request_key = str(request[0]) + " --> " + str(request[1]) print("Request is " + request_key) #file.write("Requested source and destination" + str(request_key)+ "\n") rev_path = [] src = g.vertex(request[0]) tgt = g.vertex(request[1]) tracer = request[1] dist, pred = gt.dijkstra_search(g, src, g.ep.weight) g.vp.pred_tree = pred ##print pred.a ##print g.vp.pred_tree.a while g.vertex(tracer) != src: rev_path.append(tracer) ##print(tracer) temp = tracer tracer = g.vp.pred_tree[g.vertex(tracer)] if temp == tracer: rev_path = [] break if len(rev_path) == 0: