예제 #1
0
def run_test(algorithm, dataset):
    if algorithm == "BruteForce":
        result = BruteForce.BruteForce(dataset[1])
        test_result = TestResult(result[0], dataset[0][0], dataset[0][1], 
                                 dataset[0][2], dataset[0][3], dataset[0][4], 
                                 result[3], result[1], 1).get_result()
    elif algorithm == "BranchNBound":
        result = BranchNBound.BranchNBound(dataset[1])
        test_result = TestResult(result[0], dataset[0][0], dataset[0][1], 
                                 dataset[0][2], dataset[0][3], dataset[0][4], 
                                 result[3], result[1], 1).get_result()
    elif algorithm == "Greedy":
        #bb_result = BranchNBound.BranchNBound(dataset[1])
        result = Greedy.better_greedy(dataset[1])
        test_result = TestResult(result[0], dataset[0][0], dataset[0][1], 
                                 dataset[0][2], dataset[0][3], dataset[0][4], 
                                 result[3], 
                                 result[1], result[1]).get_result()
    elif algorithm == "Randomized":
        #bb_result = BranchNBound.BranchNBound(dataset[1])
        result = Randomized.better_result_of_randomized(dataset[1])
        test_result = TestResult(result[0], dataset[0][0], dataset[0][1], 
                                 dataset[0][2], dataset[0][3], dataset[0][4], 
                                 result[3], 
                                 result[1], result[1]).get_result()
    elif algorithm == "MinSpanTree":
        #bb_result = BranchNBound.BranchNBound(dataset[1])
        result = MinSpanTree.MinSpanTree(dataset[1])
        test_result = TestResult(result[0], dataset[0][0], dataset[0][1], 
                                 dataset[0][2], dataset[0][3], dataset[0][4], 
                                 result[3], 
                                 result[1], result[1]).get_result()
    elif algorithm == "EA_hillclimbing":
        #bb_result = BranchNBound.BranchNBound(dataset[1])
        result = EA_hillclimbing.hillclimbing_algorithm(dataset[1], dataset[0][0])
        test_result = TestResult(result[0], dataset[0][0], dataset[0][1], 
                                 dataset[0][2], dataset[0][3], dataset[0][4], 
                                 result[3], 
                                 result[1], result[1]).get_result()
    elif algorithm == "Genetic":
        #bb_result = BranchNBound.BranchNBound(dataset[1])
        result = GA.genetic_algorithm(dataset[1], dataset[0][0])
        test_result = TestResult(result[0], dataset[0][0], dataset[0][1],
                                 dataset[0][2], dataset[0][3], dataset[0][4],
                                 result[3],
                                 result[1], result[1]).get_result()
            
    elif algorithm == "TwoOpt":
        #bb_result = BranchNBound.BranchNBound(dataset[1])
        result = TwoOpt.two_opt(dataset[1])
        test_result = TestResult(result[0], dataset[0][0], dataset[0][1], 
                                 dataset[0][2], dataset[0][3], dataset[0][4], 
                                 result[3], 
                                 result[1], result[1]).get_result()    
    else:
        raise Exception("Wrong algorithm chosen!")
    
    return test_result