コード例 #1
0
ファイル: system_test.py プロジェクト: subertd/CS325Group7
    def do_test_example_sets(self, algorithm):
        runner = Runner(algorithm)

        for i in self.TESTS_TO_RUN:
            input_file = self.EXAMPLE_FILES[i]
            output_file = "%s.tour" % input_file
            expected_total = self.EXPECTED_TOTALS[i]
            expected_time = self.EXPECTED_TIMES[i]

            # Run the algorithm and generate output file
            sys.argv[1] = '-f'
            sys.argv[2] = input_file
            runner.load()
            start_time = time.clock()
            runner.run()
            elapsed_time = time.clock() - start_time

            # verify that all cities are visited
            (all_match, problems) = visit.main(input_file, output_file)
            message = "For %s, possible problems include:\n" % output_file[3:]
            for each in problems:
                message = "%s%s\n" % (message, problems[each])
            self.assertTrue(all_match, message)

            # verify correct solution length
            cities = self.readinstance(input_file)
            solution = self.readsolution(output_file)
            self.checksolution(cities, solution[0][0], solution[1])

            # verify that the problem was solved within the allotted time frame
            message = "For %s, execution time of %f exceeded allotted time of %f" % (output_file[3:],
                                                                                     elapsed_time, expected_time)
            self.assertTrue(elapsed_time < expected_time, message)

            # verify that the solution is reasonably optimal if an optimal value is posted
            if expected_total >= 0:
                message = "For %s, the total distance %f exceeded the allowed %f" % (output_file[3:],
                                                                                     solution[0][0], expected_total)
                self.assertTrue(solution[0][0] <= expected_total, message)

            print "%s passed with distance %d/%d and time %d/%d" % (self.EXAMPLE_FILES[i][3:], solution[0][0],
                                                                expected_total, elapsed_time, expected_time)
コード例 #2
0
ファイル: app.py プロジェクト: subertd/CS325Group7
from runner.runner import Runner
from algorithm.collective_algorithm import RealTSPAlgorithm


runner = Runner(RealTSPAlgorithm())
runner.load()
runner.run()