示例#1
0
def runSimulation(theNetwork, startingPoint, virus):
    """
    Description:
        This function calls runSimulation passing in the network, starting point for the virus
        to start, the virus, and a True/False value. The infected percentage is then calcualted
        by getting the infectedCount array and counting the number of infected and dividing by
        network size.
    Pre:
        theNetwork is a Network object predefined. startingPoint is an integer value
        specifying the starting point. virus is the type of virus and is either a Trojan
        or a Worm object.
    Post:
        returns the infectedPercent
    """
    if virus == "W":
        virus = viruses.Worm()
    else:
        virus = viruses.Trojan()

    sim.runOnce(theNetwork, startingPoint, virus, False)

    infectedCount = 0
    for node in theNetwork.infectedList[1:]:
        if node == n.State.infected:
            infectedCount += 1

    infectedPercent = (infectedCount / networkSize) * 100

    return infectedPercent
示例#2
0
def runTrojan(theNetwork):
    startingPoint = N.random.randint(1, networkSize + 1)

    virus = viruses.Trojan()
    sim.runOnce(theNetwork, startingPoint, virus, False)

    infectedCount = 0
    for node in theNetwork.infectedList[1:]:
        if node == n.State.infected:
            infectedCount += 1

    infectedPercent = (infectedCount / networkSize) * 100

    return infectedPercent
示例#3
0
def runSimulation(theNetwork, startingPoint, virus):

    if virus == "LB":
        virus = viruses.LogicBomb()
    if virus == "W":
        virus = viruses.Worm((0, .1))
    else:
        virus = viruses.Trojan()

    sim.runOnce(theNetwork, startingPoint, virus, False)

    infectedCount = 0
    for node in theNetwork.infectedList[1:]:
        if node == n.State.infected:
            infectedCount += 1

    infectedPercent = (infectedCount / networkSize) * 100

    return infectedPercent
示例#4
0
    0: viruses.Worm,
    1: viruses.Trojan,
    2: viruses.LogicBomb,
    3: viruses.SuperVirus
}

#Modify the varibles below to Change Simulation Types. IT is not recommend to do
# make the NETWORK_SIZE greater than 15
#=============================================================================
# 0 = WORM
# 1 = TROJAN
# 2 = LOGIC BOMB
# 3 = SUPER VIRUS
RUN_VIRUS = 0
# 0 = STAR
# 1 = TREE
# 2 = RING
# 3 = LINE
# 4 = FULLY CONNECTED
# 5 = MESH
NETWORK_SHAPE = 4
NETWORK_SIZE = 15
#=============================================================================

#Running the Simulation
shapeMaker[NETWORK_SHAPE](NETWORK_SIZE)
virus = virusDispatch[RUN_VIRUS]()
theNetwork = n.Network(shapeOfNetwork[NETWORK_SHAPE])
theNetwork.createnetwork(shapeFileName[NETWORK_SHAPE])
sim.runOnce(theNetwork, 1, virus)
time.sleep(1)  #allow the graph to stay on screen for 1 second
示例#5
0
    plt.xlabel("Network Cycles")
    plt.title(title)
    plt.plot(range(time_turns), rates)
    plt.savefig(fileName)


#fileMaker.main(50)

Types = ["Worm", "Trojan", "Logic Bomb"]
virus = [viruses.Worm(), viruses.Trojan(), viruses.LogicBomb()]

#create 6 line graphs of the rate of infection over time.
for x in range(3):
    theNetwork = n.Network(disp.graphType.LINE)
    theNetwork.createnetwork("line.txt")
    numberOfSteps, infectionRates, percentatages = sim.runOnce(
        theNetwork, 1, virus[x], False)
    drawGraph(numberOfSteps, infectionRates, Types[x], "Line")

    theNetwork = n.Network(disp.graphType.RING)
    theNetwork.createnetwork("ring.txt")
    numberOfSteps, infectionRates, percentatages = sim.runOnce(
        theNetwork, 1, virus[x], False)
    drawGraph(numberOfSteps, infectionRates, Types[x], "Ring")

    theNetwork = n.Network(disp.graphType.MESH)
    theNetwork.createnetwork("mesh.txt")
    numberOfSteps, infectionRates, percentatages = sim.runOnce(
        theNetwork, 1, virus[x], False)
    drawGraph(numberOfSteps, infectionRates, Types[x], "Mesh")

    theNetwork = n.Network(disp.graphType.ALL_CONNECTED)
示例#6
0
averageInfectionRatesAllConnected = [[], [], []]
averagePercentagesAllConnected = [[], [], []]
averageInfectionRatesStar = [[], [], []]
averagePercentagesStar = [[], [], []]
averageInfectionRatesTree = [[], [], []]
averagePercentagesTree = [[], [], []]

#fileMaker.main(50)

#Run 100 simulations for each virus. Does not display the graphs for any
#simulation.
for current in range(100):
    for x in range(3):
        theNetwork = n.Network(disp.graphType.LINE)
        theNetwork.createnetwork("line.txt")
        numberOfSteps, infectionRates, percentatages = sim.runOnce(
            theNetwork, 1, dispatcher[x](), False)
        averageInfectionRate = sum(infectionRates) / len(infectionRates)
        averagePercentage = sum(percentatages) / len(percentatages)

        averageInfectionRatesLine[x].append(averageInfectionRate)
        averagePercentagesLine[x].append(getPercentage(theNetwork))

        theNetwork = n.Network(disp.graphType.RING)
        theNetwork.createnetwork("ring.txt")
        numberOfSteps, infectionRates, percentatages = sim.runOnce(
            theNetwork, 1, dispatcher[x](), False)
        averageInfectionRatesRing[x].append(averageInfectionRate)
        averagePercentagesRing[x].append(getPercentage(theNetwork))

        theNetwork = n.Network(disp.graphType.MESH)
        theNetwork.createnetwork("mesh.txt")
示例#7
0
for i in range(10):    
    fm.main(nod_strengths[i])
    line_Network = n.Network(disp.graphType.LINE)
    line_Network.createnetwork("line.txt")
    ring_Network = n.Network(disp.graphType.RING)
    ring_Network.createnetwork("ring.txt")
    star_Network = n.Network(disp.graphType.STAR)
    star_Network.createnetwork("star.txt")
    tree_Network = n.Network(disp.graphType.TREE)
    tree_Network.createnetwork("tree.txt")
    all_connected_Network = n.Network(disp.graphType.ALL_CONNECTED)
    all_connected_Network.createnetwork("fullconnect.txt")
    mesh_Network = n.Network(disp.graphType.MESH)
    mesh_Network.createnetwork("mesh.txt")

    time_turns1,infectionRates, percent_infected = sim.runOnce(line_Network, 1, virus, False)
    time_turns2,infectionRates, percent_infected = sim.runOnce(ring_Network, 1, virus, False)
    time_turns3,infectionRates, percent_infected = sim.runOnce(star_Network, 1, virus, False)
    time_turns4,infectionRates, percent_infected = sim.runOnce(tree_Network, 1, virus, False)
    time_turns5,infectionRates, percent_infected = sim.runOnce(all_connected_Network, 1, virus, False)
    time_turns6,infectionRates, percent_infected = sim.runOnce(mesh_Network, 1, virus, False)

    time_taken.append(time_turns1)
    time_taken.append(time_turns2)
    time_taken.append(time_turns3)
    time_taken.append(time_turns4)
    time_taken.append(time_turns5)
    time_taken.append(time_turns6)

# rows = size of network
# columns = shape of network