コード例 #1
0
def testIsEdgeJammedByJammer():
    global interfModelType, g_ConflictGraph, commodities
    interfModelType = '802.11-MAC-protocol'
    gridSize = 5
    commodities[0] = (0, gridSize * gridSize - 1)
    commodities[1] = ((gridSize - 1) * gridSize, gridSize - 1)
    commodities[2] = (gridSize, 3*gridSize - 1)
    print commodities
    #source = 0
    #dest = gridSize * gridSize - 1
    G = wnj_interference.createConnectivityGraph(gridSize, interfModelType, 'grid')
    print G.edges(data=True)
    wiredNetworkFlow = wnj_interference.getNetworkMaxTotalThroughput(G, commodities, 'none')
    print "wiredNetworkFlow:", wiredNetworkFlow
    
    g_ConflictGraph = wnj_interference.createConflictGraph(G, interfModelType)
    print "CG edges", g_ConflictGraph.edges(data=True)
    
    JammingGraph = wnj_interference.createPotentialJammingLocations(gridSize)
    jammingSolution = [0] * (gridSize*2)**2
    print "jammingSolution", jammingSolution
    
    counter = 0
    for node in JammingGraph.nodes():
        JammingGraph.node[node]['selected'] = jammingSolution[counter]
        counter += 1
    print "jammed", [node for node in JammingGraph.nodes() if JammingGraph.node[node]['selected'] > 0.0]
    
    for e in G.edges():
        for loc in JammingGraph.nodes():
            print e, loc, wnj_interference.isEdgeJammedByJammer_Protocol(G, e, loc, interfModelType)
コード例 #2
0
def runPhysicalTest():
    interfModelType = 'simple-physical'
    gridSize = 3
    source = 0
    dest = gridSize * gridSize - 1
    G = wnj_interference.createConnectivityGraph(gridSize, interfModelType)
    wiredNetworkFlow = nx.max_flow(G, source, dest)
    print "wiredNetworkFlow:", wiredNetworkFlow
    
    ConflictGraph = wnj_interference.createConflictGraph(G, interfModelType)
    #print ConflictGraph.edges(data=True)
    
    ISets = []
    capacityDuals = dict([(edge, 1.0) for edge in G.edges()])
    count = 0
    maxWeight, selected = wnj_interference.maxWtIndepSet(ConflictGraph, capacityDuals, interfModelType)
    ISets.append(selected)
    #print "selected ", selected
    interdictionFeasibleRegion = [(i+0.5, j+0.5) for i in range(gridSize - 1) for j in range(gridSize - 1)]
    interdictionVars = dict([(tuple, 1.0) for tuple in interdictionFeasibleRegion])
    wnj_interference.createThroughputModel(G, source, dest, [selected], interdictionVars)
    while True:
        print "ITERATION", count
        maxWeight, selected = wnj_interference.maxWtIndepSet(ConflictGraph, capacityDuals, interfModelType)
        ISets.append(selected)
        print "selected ", selected
        throughput, capacityDuals, jammingDuals, usageDual = wnj_interference.addISetAsCol_AndSolveTHProb(G, interdictionVars, ISets, selected, count)
        if((maxWeight - (usageDual + sum([jammingDuals[key] for key in jammingDuals.keys()]))) <= 0.0001):
            break
        count += 1
コード例 #3
0
def test_showGraph(interference, gridSize):
    global interfModelType, g_ConflictGraph, commodities, Paths, ISets, maxNumHops
    interfModelType = 'none'
    bottomLeft = 0
    topLeft = gridSize - 1
    topRight = gridSize * gridSize - 1
    bottomRight = gridSize * (gridSize - 1)
    print "corners", bottomLeft, topLeft, topRight, bottomRight
    commodities[0] = (bottomLeft, topRight)
    #commodities[1] = (bottomLeft, topLeft)
    #commodities[2] = (bottomLeft, bottomRight)
    #commodities[3] = (topLeft, topRight)
    #commodities[4] = (topLeft, bottomRight)
    #commodities[5] = (topRight, bottomRight)
    G = wnj_interference.createConnectivityGraph(gridSize, interfModelType, 'grid', False, 
                                                 wnj_interference.numRadiosPerNode, wnj_interference.numChannels)
    if(interference):
        nx.draw(G, wnj_interference.pos, edgelist = [])
    else:
        nx.draw(G, wnj_interference.pos)
    #print G.nodes()
    nx.draw(G, wnj_interference.pos, edgelist = [], nodelist = [0, 15], node_color = '0.9')
    if(interference):
        nx.draw_networkx_nodes(G, wnj_interference.pos, alpha = 0.1, node_size = 50000, node_color='purple', node_shape='o', nodelist = G.nodes(), with_labels=False)
    plt.savefig("/home/hmedal/Dropbox/2_msu/PROJECT_ncitec_safe_multimodal/figures/wiredSoln.jpg") # save as jpg
    plt.show() # display
コード例 #4
0
def test_showWiredSolution_withJamming():
    print "runProtocolWithJamming_FullMIP_RowGenCallback_PathBased_Test"
    global interfModelType, g_ConflictGraph, commodities
    interfModelType = '802.11-MAC-protocol'
    gridSize = 5
    bottomLeft = 0
    topLeft = gridSize - 1
    topRight = gridSize * gridSize - 1
    bottomRight = gridSize * (gridSize - 1)
    print "corners", bottomLeft, topLeft, topRight, bottomRight
    commodities[0] = (bottomLeft, topRight)
    #commodities[1] = (bottomLeft, topLeft)
    #commodities[2] = (bottomLeft, bottomRight)
    #commodities[3] = (topLeft, topRight)
    #commodities[4] = (topLeft, bottomRight)
    #commodities[5] = (topRight, bottomRight)
    G = wnj_interference.createConnectivityGraph(gridSize, interfModelType, 'grid', False)
    print G.edges(data=True)
    
    
    g_ConflictGraph = wnj_interference.createConflictGraph(G, interfModelType)
    print "CG edges", g_ConflictGraph.edges(data=True)
    
    JammingGraph = wnj_interference.createPotentialJammingLocations(gridSize)
    jammingSolution = [0] * (gridSize*2)**2
    jammingSolution[39] = 1
    print "jammingSolution", jammingSolution
    jammedNodes = []
    jammedPos = {}
    counter = 0
    for node in JammingGraph.nodes():
        print node, counter
        JammingGraph.node[node]['selected'] = jammingSolution[counter]
        if(jammingSolution[counter] == 1.0):
            jammedNodes.append(node)
            jammedPos[node] = node
        counter += 1
    print "jammedNodes", jammedNodes
    print "jammed", [node for node in JammingGraph.nodes() if JammingGraph.node[node]['selected'] > 0.0]
    g_JamGraph = JammingGraph
    
    throughput, flowSoln = wnj_interference.getNetworkMaxTotalThroughput(G, commodities, 'none')
    print "wiredNetworkFlow:", throughput
    print "wiredFlows", flowSoln
    flowLinks = []
    for key in flowSoln.keys():
        for edge in flowSoln[key].keys():
            flowLinks.append(edge)
    print "flowLinks", flowLinks
    nx.draw(G, wnj_interference.pos)
    nx.draw_networkx_nodes(G, jammedPos, alpha = 0.1, node_size = 25000, node_color='blue', node_shape='o', nodelist = jammedNodes, with_labels=False)
    nx.draw_networkx_edges(G, wnj_interference.pos, edge_color='red', width=3.0, edgelist = flowLinks)
    nx.draw_networkx_nodes(G, jammedPos, node_size = 100, node_color='green', node_shape='s', nodelist = jammedNodes, with_labels=False)
    plt.savefig("/home/hmedal/Dropbox/2_msu/PROJECT_ncitec_safe_multimodal/figures/wiredSoln_withJamming.jpg") # save as jpg
    plt.show() # display
コード例 #5
0
def runPhysicalWithJamming_Test():
    global interfModelType, g_ConflictGraph
    interfModelType = 'simple-physical'
    gridSize = 3
    source = 0
    dest = gridSize * gridSize - 1
    G = wnj_interference.createConnectivityGraph(gridSize, interfModelType, 'grid')
    print G.edges(data=True)
    wiredNetworkFlow = nx.max_flow(G, source, dest)
    print "wiredNetworkFlow:", wiredNetworkFlow
    
    g_ConflictGraph = wnj_interference.createConflictGraph(G, interfModelType)
    
    JammingGraph = wnj_interference.createPotentialJammingLocations(gridSize)
    jammingSolution = [0] * (gridSize*2)**2
    #jammingSolution[18] = 1
    print "jammingSolution", jammingSolution
    
    counter = 0
    for node in JammingGraph.nodes():
        JammingGraph.node[node]['selected'] = jammingSolution[counter]
        counter += 1
    print "jammed", [node for node in JammingGraph.nodes() if JammingGraph.node[node]['selected'] > 0.0]
    ISets = []
    capacityDuals = dict([(edge, 1.0) for edge in G.edges()])
    jammingDuals = dict([(node, 1.0) for node in JammingGraph.nodes()])
    count = 0
    maxWeight, selected = wnj_interference.maxWtIndepSet(g_ConflictGraph, capacityDuals, interfModelType)
    ISets.append(selected)
    wnj_interference.createThroughputModel(G, source, dest, [selected], JammingGraph, interfModelType)
    while True:
        print "ITERATION", count
        nodeWeights = wnj_interference.getWeightsForMaxIndSet(G, JammingGraph, capacityDuals, jammingDuals, interfModelType)
        print "node weights", nodeWeights
        maxWeight, selected = wnj_interference.maxWtIndepSet(g_ConflictGraph, nodeWeights, interfModelType)
        ISets.append(selected)
        throughput, capacityDuals, jammingDuals, usageDual = wnj_interference.addISetAsCol_AndSolveTHProb(G, JammingGraph, ISets, selected, count, interfModelType)
        print "selected ", selected
        if((maxWeight - usageDual) <= 0.0001):
            break
        count += 1
コード例 #6
0
def test_showWiredSolution():
    print "runProtocolWithJamming_FullMIP_RowGenCallback_PathBased_Test"
    global interfModelType, g_ConflictGraph, commodities
    interfModelType = '802.11-MAC-protocol'
    gridSize = 5
    bottomLeft = 0
    topLeft = gridSize - 1
    topRight = gridSize * gridSize - 1
    bottomRight = gridSize * (gridSize - 1)
    print "corners", bottomLeft, topLeft, topRight, bottomRight
    commodities[0] = (bottomLeft, topRight)
    #commodities[1] = (bottomLeft, topLeft)
    #commodities[2] = (bottomLeft, bottomRight)
    #commodities[3] = (topLeft, topRight)
    #commodities[4] = (topLeft, bottomRight)
    #commodities[5] = (topRight, bottomRight)
    G = wnj_interference.createConnectivityGraph(gridSize, interfModelType, 'grid', False)
    print G.edges(data=True)
    
    
    g_ConflictGraph = wnj_interference.createConflictGraph(G, interfModelType)
    print "CG edges", g_ConflictGraph.edges(data=True)
    
    JammingGraph = wnj_interference.createPotentialJammingLocations(gridSize)
    jammingSolution = [0] * (gridSize*2)**2
    jammingSolution[15] = 1
    print "jammingSolution", jammingSolution
    
    throughput, flowSoln = wnj_interference.getNetworkMaxTotalThroughput(G, commodities, 'none')
    print "wiredNetworkFlow:", throughput
    print "wiredFlows", flowSoln
    flowLinks = []
    for key in flowSoln.keys():
        for edge in flowSoln[key].keys():
            flowLinks.append(edge)
    nx.draw(G, wnj_interference.pos)
    nx.draw_networkx_edges(G, wnj_interference.pos,edge_color='red', width=3.0, edgelist=flowLinks)
    plt.savefig("/home/hmedal/Dropbox/2_msu/PROJECT_ncitec_safe_multimodal/figures/wiredSoln.jpg") # save as jpg
    plt.show() # display
コード例 #7
0
def test_showInterferenceSolution(interdictedNodes):
    global interfModelType, g_ConflictGraph, commodities, Paths, ISets, maxNumHops
    interfModelType = '802.11-MAC-protocol'
    gridSize = 4
    bottomLeft = 0
    topLeft = gridSize - 1
    topRight = gridSize * gridSize - 1
    bottomRight = gridSize * (gridSize - 1)
    print "corners", bottomLeft, topLeft, topRight, bottomRight
    commodities[0] = (bottomLeft, topRight)
    #commodities[1] = (bottomLeft, topLeft)
    #commodities[2] = (bottomLeft, bottomRight)
    #commodities[3] = (topLeft, topRight)
    #commodities[4] = (topLeft, bottomRight)
    #commodities[5] = (topRight, bottomRight)
    G = wnj_interference.createConnectivityGraph(gridSize, interfModelType, 'grid', False)
    print G.edges(data=True)
    
    
    g_ConflictGraph = wnj_interference.createConflictGraph(G, interfModelType)
    print "CG edges", g_ConflictGraph.edges(data=True)
    
    JammingGraph = wnj_interference.createPotentialJammingLocations(gridSize)
    jammingSolution = [0] * (gridSize*2)**2
    for node in interdictedNodes:
        jammingSolution[node] = 1
    print "jammingSolution", jammingSolution
    
    jammedNodes = []
    jammedPos = {}
    counter = 0
    for node in JammingGraph.nodes():
        print node, counter
        JammingGraph.node[node]['selected'] = jammingSolution[counter]
        if(jammingSolution[counter] == 1.0):
            jammedNodes.append(node)
            jammedPos[node] = node
        counter += 1
    print "jammedNodes", jammedNodes
    
    ISets = []
    maxNumHops = gridSize * 2
    
    PathsList = nx.all_simple_paths(G, 0, gridSize * gridSize - 1)
    Paths = {}
    for commod in commodities.keys():
        Paths[commod] = []
    edgesJammed = wnj_interference.getEdgesJammedByJammers(G, jammedNodes, interfModelType)
    print "edgesJammed", edgesJammed
    
    flowVarSoln, isetUsageSoln = wnj_interference.solveThroughputProblem_Pricing_CormicanPathBased(G, edgesJammed, maxNumHops, interfModelType, JammingGraph)
    print "flowVarSoln", flowVarSoln
    print "isetUsageSoln", isetUsageSoln
    ISetsUsed = [ISets[k] for k in range(len(ISets)) if isetUsageSoln[k] > wnj_interference.FUZZ]
    
    #throughput, flowSoln = getNetworkMaxTotalThroughput(G, commodities, interfModelType)
    #print "wiredNetworkFlow:", throughput
    print "ISetsUsed", ISetsUsed
    pathCtr = 0
    pathColors = ['red', 'green', 'blue', 'orange', 'yellow', 'purple']
    pathStyle = ['solid', 'dotted', 'dashdot', 'dashed']
    #nx.draw_networkx(G, pos, style = 'dashed')
    nx.draw(G, wnj_interference.pos, edgelist = [])
    nx.draw(G, wnj_interference.pos, edgelist = [], nodelist = [0, 15], node_color = '0.9')
    for commod in flowVarSoln.keys():
        print "numPaths", len(Paths[commod])
        for path in flowVarSoln[commod].keys():
            flowAmt = flowVarSoln[commod][path]
            if(flowVarSoln[commod][path] > wnj_interference.FUZZ):
                print "flowAmt", flowAmt
                for edge in Paths[commod][path][1]:
                    flowLinks = []
                    flowLinks.append(edge)
                    isetIndex = wnj_interference.getISetIndexForEdge(edge, ISetsUsed)
                    print edge, "isetIndex", isetIndex
                    nx.draw_networkx_edges(G, wnj_interference.pos,edge_color = pathColors[isetIndex], width= flowAmt * 25.0, style = pathStyle[pathCtr], edgelist=flowLinks)
                #print "pathCtr", pathCtr
                pathCtr += 1
    #print "flowLinks", flowLinks
    nx.draw_networkx_nodes(G, jammedPos, alpha = 0.1, node_size = 90000, node_color='blue', node_shape='o', nodelist = jammedNodes, with_labels=False)
    nx.draw_networkx_nodes(G, jammedPos, node_size = 100, node_color='black', node_shape='s', nodelist = jammedNodes, with_labels=False)
    plt.savefig("/home/hmedal/Dropbox/2_msu/PROJECT_ncitec_safe_multimodal/figures/wiredSoln.jpg") # save as jpg
    plt.show() # display