Exemple #1
0
    def finalAnswers(self):
        # in accordance to the user reports we conclude if the node is "good" or "bad" during the round
        lista = []
        scores = self.scoring()
        for i in range(len(self.nodes)):
            sumYes, sumNo, noNo, noYes, yesScore, noScore = 0, 0, 0, 0, 0, 0
            usersOnNode = compFunctions.indices(self.assignement, i)
            for user in usersOnNode:
                if self.informationReports[user] == 0:
                    sumNo += scores[user]
                    noNo += 1
                elif self.informationReports[user] == 1:
                    sumYes += scores[user]
                    noYes += 1
                if noNo == 0:
                    noScore = 0
                else:
                    noScore = sumNo / noNo

                if noYes == 0:
                    yesScore = 0
                else:
                    yesScore = sumYes / noYes

            if yesScore > noScore:
                lista.append(1)
            else:
                lista.append(0)

        return lista, scores
Exemple #2
0
    def computeCongs(self, assignment):
        # computing the Conegstion (on each node) values, according to the formulas
        lista = []
        totalItus = compFunctions.addIUS(self.users)
        for i in range(self.k):
            nodeISum = 0
            usersOnNode = compFunctions.indices(assignment, i)
            for userIndex in usersOnNode:
                nodeISum += self.users[userIndex].ongoingTask[0]
            lista.append(nodeISum / totalItus)

        return np.array(lista)
Exemple #3
0
    def getPeersRefs(self):
        # calculating the peers and reference nodes for each node
        references = []
        peers = []
        for i in range(len(self.users)):
            nodeIndex = self.assignement[i]
            usersOnNode = compFunctions.indices(self.assignement, nodeIndex)
            onNode = len(usersOnNode)
            userIndex = usersOnNode.index(i)
            references.append(usersOnNode[(userIndex + 1) % onNode])
            peers.append(usersOnNode[(userIndex + 2) % onNode])

        return references, peers
Exemple #4
0
    def computeUGGP(self, assignment, tOver, eOver):
        # computing the UGGP values, according to the formulas
        lista = []
        for i in range(self.k):
            nodeSum = 0
            usersOnNode = compFunctions.indices(assignment, i)
            onNode = len(usersOnNode)
            for userIndex in usersOnNode:
                nodeSum += tOver[userIndex] / constants.TIMESLOTDURATION
                nodeSum += eOver[userIndex] / self.users[userIndex].eu
            if onNode == 0:
                lista.append(0)
            else:
                lista.append(nodeSum / onNode)

        return np.array(lista)
Exemple #5
0
    def computeRFKs(self, assignment, fuks):
        # computing the Reputation Factor (used in the reward calculation below)

        lista = []
        for i in range(self.k):
            perNode = 0
            usersOnNode = compFunctions.indices(assignment, i)
            onNode = len(usersOnNode)
            for userIndex in usersOnNode:
                perNode += fuks[userIndex]
            if onNode == 0:
                lista.append(0)
            else:
                lista.append(perNode / onNode)

        divisor = sum(lista)

        array = np.array(lista)
        array /= divisor

        return array