Example #1
0
 def from_tspfile(cls, fname):
     ncount, data = _CCutil_gettsplib(fname)
     if data is None:
         raise RuntimeError("Error in loading {}".format(fname))
     self = cls()
     self._ncount = ncount
     self._data = data
     return self
Example #2
0
    def test_get_file_does_not_exist(self):
        # Given
        fname = "no_such.tsp"

        # When
        ncount, datagroup = _CCutil_gettsplib(fname)

        # Then
        self.assertEqual(ncount, -1)
        self.assertIsNone(datagroup)
Example #3
0
    def test_get_file_exists(self):
        # Given
        fname = get_dataset_path('berlin52')

        # When
        ncount, datagroup = _CCutil_gettsplib(fname)

        # Then
        self.assertEqual(ncount, 52)
        self.assertIsNotNone(datagroup)
Example #4
0
 def from_tspfile(cls, fname):
     print(fname)
     with open(fname) as f:
         data = f.readlines()
         print(data)
     ncount, data = _CCutil_gettsplib(fname)
     if data is None:
         raise RuntimeError("Error in loading {}".format(fname))
     self = cls()
     self._ncount = ncount
     self._data = data
     return self
Example #5
0
    def test_solve_berlin_normal(self):
        # Given
        fname = get_dataset_path('berlin52')
        expected_tour, expected_opt_value = get_solution_data('berlin52')
        ncount, datagroup = _CCutil_gettsplib(fname)

        # When
        tour, val, success, foundtour, timebound = \
            _CCtsp_solve_dat(ncount, datagroup, "berlin", 0, 0)

        # Then
        nptest.assert_array_equal(tour, expected_tour)
        self.assertAlmostEqual(val, expected_opt_value)
        self.assertTrue(success)
        self.assertTrue(foundtour)