コード例 #1
0
 def test_differentGraphs(self):
     n = 100
     density = 0.8
     k = 5
     g = genGraph(n, density, k)
     f = genGraph(n, density, k)
     self.assertFalse(g == f)
コード例 #2
0
 def test_seedTwoGens(self):
     n = 100
     density = 0.8
     seed = time()
     g = genGraph(n, density, seed=seed)
     f = genGraph(n, density, seed=seed)
     self.assertTrue(g == f)
コード例 #3
0
def testit(f, arguments):
    """
    Collect execution times of function f with different parameters, process it
    and pass it to function outputBenchmarkResults() to print it
    :param f: Function to test
    :param arguments: Values defining function f's arguments in each run

    """

    vertexNumber, density, divisibility, problemCount, step, instanceCount, useTmpfile = arguments

    infoToOutput = (f.__name__, vertexNumber, density, divisibility,
                    problemCount, step, instanceCount)

    if useTmpfile:
        removeTmpFile()
        dumpTmpData((f.__name__, vertexNumber, density, divisibility,
                     problemCount, step, instanceCount))

    data = []
    # data = [[vertexNumber, measuredTime, q(n), colorsUsed], ...]

    # warming up
    WelshPowell(genGraph(1000, 0.75, 5))

    for i in range(problemCount):
        data.append([])
        timeSum = 0.0
        edgeCount = 0
        colorsUsedSum = 0.0

        for _ in range(instanceCount):
            g = genGraph(vertexNumber + step * i, density, divisibility)
            edgeCount = g.getEdgeCount()
            colorsUsed, timeSpent = timing(f, g)
            colorsUsedSum += colorsUsed
            timeSum += timeSpent

        colorsUsedAvg = colorsUsedSum / instanceCount
        timeAvg = timeSum / instanceCount

        data[i].append(vertexNumber + step * i)
        data[i].append(timeAvg)
        data[i].append(edgeCount)
        data[i].append(colorsUsedAvg)

        if useTmpfile:
            dumpTmpData(data[i])

    tmedian, Tmedian = calcMedian(f.__name__, data)

    calcQ(f.__name__, data, tmedian, Tmedian)

    outputBenchmarkResults(infoToOutput, data)
コード例 #4
0
 def test_seed(self):
     n = 5
     d = 0.4
     seed = 3
     g = genGraph(n, d, seed=seed)
     self.assertDictEqual({'0': ['4', '3'], '1': [], '2': ['4', '3'], '3': ['0', '2'], '4': ['0', '2']},
                          g.getAdjDict())
コード例 #5
0
 def test_genGraph(self):
     n = 100
     density = 0.8
     edgesCount = int(n * (n - 1) / 2 * density)
     g = genGraph(n, density)
     self.assertEqual(n, g.getVertexCount())
     self.assertEqual(edgesCount, g.getEdgeCount())
コード例 #6
0
 def test_genGraphWithGroups(self):
     n = 100
     density = 1.0
     i = 20
     for groupsCount in range(1, i+1):
         g = genGraph(n, density, groupsCount)
         chromatic = WelshPowell(g)[1]
         # print(groupsCount, chromatic)
         self.assertTrue(groupsCount == chromatic)
コード例 #7
0
            drawUnit.drawGraph(graph)
        solution = None
        solution = bruteForceWithHeuristics(graph) if args['b'] else WelshPowell(graph)
        print(solution)
        if args['g']:
            drawUnit.drawGraph(graph, solution)

    # Handle m2 scenario
    elif args['scenario'] == 'm2':
        if args['n'] is None:
            parser_m2.print_help()
            exit()
        vertexNumber = args['n']
        density = args['d']
        divisibility = args['k']
        graph = genGraph(vertexNumber, density, divisibility)
        if args['g']:
            drawUnit.drawGraph(graph)
        solution = None
        solution = bruteForceWithHeuristics(graph) if args['b'] else WelshPowell(graph)
        print(solution)
        if args['g']:
            drawUnit.drawGraph(graph, solution)

    # Handle m3 scenario
    elif args['scenario'] == 'm3':
        fun = None
        if args['w']:
            fun = WelshPowell
        elif args['b']:
            fun = bruteForceWithHeuristics