def test_nonEmptySet(self):
        Cu_mock = [[13], [14], [15], [16, 17], [18, 19], [20, 21, 22],
                   [23, 24, 25], [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12],
                   [26, 27, 28, 29, 30]]

        G = graphFromList(Cu_mock).to_undirected()
        G2, I, C_D = collapse_graph(G)
        G2, R_D = renameGraph(G2)
        drawNetwork(G2, [], 'test images/abcd.png')

        max_T = 5

        T_size = 5
        # greedyselect 1
        response1 = greedySelect(Cu_mock, max_T, T_size, rd.uniform(0, 0.99))
        bought = translate(response1, C_D, R_D)
        drawNetwork(G2, bought, 'test images/abcd2.png')

        Cu_mock += [[31, 32, 33, 34, 35], [36, 37, 38, 39, 40]]

        T_size = 15

        G = graphFromList(Cu_mock).to_undirected()
        G2, I, C_D = collapse_graph(G)
        G2, R_D = renameGraph(G2)
        drawNetwork(G2, [], 'test images/test2.png')

        # greedyselect 2
        response2 = greedySelect(Cu_mock, max_T, T_size, 1)
        bought2 = translate(response2, C_D, R_D)
        drawNetwork(G2, bought2, 'test images/test2.1.png')
    def test_custom(self):
        max_T, T_size, Cu = constructCu()

        G = graphFromList(Cu).to_undirected()
        G2, I, C_D = collapse_graph(G)
        G2, R_D = renameGraph(G2)
        drawNetwork(G2, [], 'test images/test1.0.png')

        print(max_T)

        Loop = True
        index = 1

        while Loop:
            alpha = float(input('Introduce an alpha to test: '))
            response1 = greedySelect(Cu, max_T, T_size, alpha)
            bought = translate(response1, C_D, R_D)
            drawNetwork(G2, bought, 'test images/test1.' + str(index) + '.png')
            index += 1
            Loop = int(
                input(
                    'Introduce 1 if you want to try again, otherwise introduce 0: '
                ))
Beispiel #3
0
 def test_MetaTreeConstruct(self):
     G, t_max = randomGraph(200)
     G2, I, C_D = collapse_graph(G, t_max)
     G2, R_D = renameGraph(G2)
     inverse_R_D = {value: key for key, value in R_D.items()}
     drawNetwork(G, [], 'test2.png')
     drawNetwork(G2, [], 'test_collapse2.png')
     l_I = [inverse_R_D[item] for item in I]
     M, M_D = constructMetaTree(G2, l_I)
     drawNetwork(M, [], 'test_metaTree.png')
Beispiel #4
0
    def test_custom(self):
        max_T, T_size, Cu = constructCu()
        At, Av = subSetSelect(len(Cu), T_size - 1, Cu, 5)

        print('T_size', T_size)
        print('Av total size: ', 1 + sum(list(map(lambda x: len(x), Av))))
        print('At total size: ', 1 + sum(list(map(lambda x: len(x), At))))

        G = graphFromList(Cu).to_undirected()
        G2, I, C_D = collapse_graph(G)
        G2, R_D = renameGraph(G2)
        drawNetwork(G2, [], 'test1.1.png')

        bought1 = translate(At, C_D, R_D)
        bought2 = translate(Av, C_D, R_D)
        drawNetwork(G2, bought1, 'test1.2.png')
        drawNetwork(G2, bought2, 'test1.3.png')
from maximum_carnage.src.utils.graph_utils import initial_utility
from maximum_carnage.test.utils.utils import drawNetwork, randomGraph3
import networkx as nx
import itertools
import random as rd
import os

if __name__ == '__main__':
    test = True
    iteration = 0
    while test:
        print('##########iteration ' + str(iteration) + '#############')
        iteration += 1
        n = 10
        G = randomGraph3(n, 1/n)
        drawNetwork(G, [], 'graphs/images/graph_' + str(n) + '_' + str(iteration) + '.png')
        nx.write_gpickle(G, os.path.dirname(os.path.abspath(__file__)) + './graphs/pickle/graph_' + str(n) + '_' +
                         str(iteration) + '.pickle')
        alpha = rd.uniform(1/2, 3)
        beta = rd.uniform(1/2, 5)
        print('alpha: ', alpha, '/ beta: ', beta)

        for i in range(0, G.number_of_nodes()):
            G2 = G.copy()
            print('------------ node' + str(i) + ' -------------')
            strategies = []
            utilities = []
            utilities2 = []
            aux = list(range(0, G.number_of_nodes()))
            aux.remove(i)
            for L in range(0, int(G.number_of_nodes()/alpha)):
Beispiel #6
0
 def test_MetaTreeConstruct2(self):
     target_size = 10
     G, Imm = randomGraph2(500, target_size)
     drawNetwork(G, [], 'test1.png')
     M, M_D = constructMetaTree(G, list(Imm))
     drawNetwork(M, [], 'test1_metaTree.png')
Beispiel #7
0
 def test_collapse(self):
     G, t_max = randomGraph(50)
     G2, I, C_D = collapse_graph(G, t_max)
     G2, R_D = renameGraph(G2)
     drawNetwork(G, [], 'test.png')
     drawNetwork(G2, [], 'test_collapse.png')