示例#1
0
def drawEvenGraph(nodes, tasks):
    xs = []
    ys = []
    fx = []
    fy = []
    i = 0
    for _ in range(nodes):
        n = next(generateFileIDs())
        n = i / nodes * MAX
        x = math.sin(2 * math.pi * n / MAX)
        y = math.cos(2 * math.pi * n / MAX)
        xs.append(x)
        ys.append(y)
        i += 1

    for _ in range(tasks):
        n = next(generateFileIDs())
        x = math.sin(2 * math.pi * n / MAX)
        y = math.cos(2 * math.pi * n / MAX)
        fx.append(x)
        fy.append(y)
    #plt.axes([-1.0,1.0,-1.0,1.0] )
    plt.plot(xs, ys, 'ro')
    plt.plot(fx, fy, 'b+')
    plt.show()
示例#2
0
文件: plotter.py 项目: abrosen/thesis
def drawEvenGraph(nodes, tasks):
    xs = []
    ys = [] 
    fx = []
    fy = []
    i = 0
    for _ in range(nodes):
        n = next(generateFileIDs())
        n = i/nodes * MAX
        x = math.sin(2*math.pi*n/ MAX)
        y = math.cos(2*math.pi*n/ MAX)
        xs.append(x)
        ys.append(y)
        i += 1
    
    for _ in range(tasks):
        n = next(generateFileIDs())
        x = math.sin(2*math.pi*n/ MAX)
        y = math.cos(2*math.pi*n/ MAX)
        fx.append(x)
        fy.append(y)
    #plt.axes([-1.0,1.0,-1.0,1.0] )
    plt.plot(xs,ys, 'ro')
    plt.plot(fx,fy, 'b+')
    plt.show()
示例#3
0
 def setupSimulation(self, strategy= None, homogeneity= None, workMeasurement=None ,  numNodes = 100, numTasks = 10000, churnRate = 0.01, adaptationRate = 5, maxSybil = 10, sybilThreshold = 0.1, numSuccessors=5):
     self.strategy = strategy
     
     self.nodeIDs = []   # the network topology
     self.superNodes = [] # the nodes that will do the sybilling  
     self.sybils = {} # (node, [] of sybils)
     self.pool = []
     self.nodes = {}  # (id: int, Node: object)
     
     
     self.numNodes = numNodes
     self.numTasks = numTasks
     self.churnRate = churnRate # chance of join/leave per tick per node
     self.adaptationRate = adaptationRate # number of ticks  
     self.maxSybil = maxSybil
     self.sybilThreshold = int((self.numTasks/self.numNodes) * sybilThreshold)
     self.numSuccessors = numSuccessors
     self.homogeneity = homogeneity
     self.workMeasurement = workMeasurement
     
     self.perfectTime = self.numTasks/self.numNodes
     
         
     
     self.numDone = 0
     self.time = 0
     self.numSybils = 0
     
     #self.nodeIDs = builder.createStaticIDs(self.numNodes)
     for _ in range(self.numNodes):
         id = next(builder.generateFileIDs())
         self.nodeIDs.append(id)
         self.superNodes.append(id)
     self.addToPool(self.numNodes)
     
     self.nodeIDs = sorted(self.nodeIDs)
     self.superNodes = sorted(self.superNodes)
     
     #print("Creating Nodes")
     
     expectedWorkPerTick = 0
     for id in self.superNodes:
         n = SimpleNode(id, self.maxSybil, self.homogeneity)
         self.nodes[id] = n
         if workMeasurement == "perStrength":
             expectedWorkPerTick += n.strength
     
     if workMeasurement == "perStrength":
         self.perfectTime = self.numTasks/expectedWorkPerTick
         
     #print("Creating Tasks")
     for key in [next(builder.generateFileIDs()) for _ in range(self.numTasks)]:
         id, _ = self.whoGetsFile(key)
         #print(id % 10000)
         self.nodes[id].addTask(key)
示例#4
0
 def addSybil(self, superNode, sybilID = None):
     if sybilID is None:
         sybilID =  next(builder.generateFileIDs())
     if superNode not in self.sybils:
         self.sybils[superNode] = [sybilID]
     else:
         self.sybils[superNode].append(sybilID)
     
     self.nodes[sybilID] = self.nodes[superNode]
     self.numSybils += 1
     self.insertWorker(sybilID, self.nodes[sybilID])
示例#5
0
    def addSybil(self, superNode, sybilID=None):
        if sybilID is None:
            sybilID = next(builder.generateFileIDs())
        if superNode not in self.sybils:
            self.sybils[superNode] = [sybilID]
        else:
            self.sybils[superNode].append(sybilID)

        self.nodes[sybilID] = self.nodes[superNode]
        self.numSybils += 1
        self.insertWorker(sybilID, self.nodes[sybilID])
示例#6
0
 def addToPool(self, num):
     # Adds num nodes to the pool of possible joining nodes
     for _ in range(num):
         x = next(builder.generateFileIDs())
         assert(x not in self.nodeIDs)
         self.pool.append(x)
示例#7
0
 def addToPool(self, num):
     # Adds num nodes to the pool of possible joining nodes
     for _ in range(num):
         x = next(builder.generateFileIDs())
         assert (x not in self.nodeIDs)
         self.pool.append(x)
示例#8
0
    def setupSimulation(self,
                        strategy=None,
                        homogeneity=None,
                        workMeasurement=None,
                        numNodes=100,
                        numTasks=10000,
                        churnRate=0.01,
                        adaptationRate=5,
                        maxSybil=10,
                        sybilThreshold=0.1,
                        numSuccessors=5):
        self.strategy = strategy

        self.nodeIDs = []  # the network topology
        self.superNodes = []  # the nodes that will do the sybilling
        self.sybils = {}  # (node, [] of sybils)
        self.pool = []
        self.nodes = {}  # (id: int, Node: object)

        self.numNodes = numNodes
        self.numTasks = numTasks
        self.churnRate = churnRate  # chance of join/leave per tick per node
        self.adaptationRate = adaptationRate  # number of ticks
        self.maxSybil = maxSybil
        self.sybilThreshold = int(
            (self.numTasks / self.numNodes) * sybilThreshold)
        self.numSuccessors = numSuccessors
        self.homogeneity = homogeneity
        self.workMeasurement = workMeasurement

        self.perfectTime = self.numTasks / self.numNodes

        self.numDone = 0
        self.time = 0
        self.numSybils = 0

        #self.nodeIDs = builder.createStaticIDs(self.numNodes)
        for _ in range(self.numNodes):
            id = next(builder.generateFileIDs())
            self.nodeIDs.append(id)
            self.superNodes.append(id)
        self.addToPool(self.numNodes)

        self.nodeIDs = sorted(self.nodeIDs)
        self.superNodes = sorted(self.superNodes)

        #print("Creating Nodes")

        expectedWorkPerTick = 0
        for id in self.superNodes:
            n = SimpleNode(id, self.maxSybil, self.homogeneity)
            self.nodes[id] = n
            if workMeasurement == "perStrength":
                expectedWorkPerTick += n.strength

        if workMeasurement == "perStrength":
            self.perfectTime = self.numTasks / expectedWorkPerTick

        #print("Creating Tasks")
        for key in [
                next(builder.generateFileIDs()) for _ in range(self.numTasks)
        ]:
            id, _ = self.whoGetsFile(key)
            #print(id % 10000)
            self.nodes[id].addTask(key)