def test_format_job(self): n = int(self.data[0][1] // 2) timeout = self.data[0][-1] formatter = jit.CordeauLaporteLoaderFormatter(self.data) surface = formatter.surface() job = formatter.job(surface) self.assertIsInstance(job, jit.Job) self.assertEqual(n, len(job.trips)) for idx, trip in enumerate( sorted(job.trips, key=attrgetter('identifier'))): origin_row = self.data[2 + idx] destination_row = self.data[2 + idx + n] origin_earliest, origin_latest = origin_row[-2:] origin_duration = origin_row[3] origin_position = surface.get_or_create_position(origin_row[1:3]) destination_earliest, destination_latest = destination_row[-2:] destination_duration = destination_row[3] destination_position = surface.get_or_create_position( destination_row[1:3]) self.assertEqual(str(idx + 1), trip.identifier) self.assertEqual(self.data[0][4], trip.timeout) self.assertIsInstance(trip, jit.Trip) self.assertEqual(1.0, trip.capacity) self.assertEqual(0.0, trip.on_time_bonus) self.assertEqual( max(destination_earliest - destination_duration - timeout, origin_earliest), trip.origin_earliest, ) self.assertEqual( min( destination_latest - destination_duration - origin_position.time_to(destination_position), origin_latest), trip.origin_latest, ) self.assertEqual( max( origin_earliest + origin_duration + origin_position.time_to(destination_position), destination_earliest), trip.destination_earliest, ) self.assertEqual( min(origin_latest + origin_duration + timeout, destination_latest), trip.destination_latest, ) self.assertIsInstance(trip.origin_position, jit.GeometricPosition) self.assertEqual(origin_position, trip.origin_position) self.assertIsInstance(trip.destination_position, jit.GeometricPosition) self.assertEqual(destination_position, trip.destination_position)
def test_format_fleet(self): formatter = jit.CordeauLaporteLoaderFormatter(self.data) surface = formatter.surface() fleet = formatter.fleet(surface) self.assertIsInstance(fleet, jit.Fleet) self.assertEqual(int(self.data[0][0]), len(fleet.vehicles)) for idx, vehicle in enumerate(fleet.vehicles): self.assertEqual(str(idx), vehicle.identifier) self.assertIsInstance(vehicle, jit.Vehicle) self.assertEqual(self.data[0][2], vehicle.timeout) self.assertEqual(self.data[0][3], vehicle.capacity) position = vehicle.origin_position self.assertEqual(vehicle.origin_position, vehicle.destination_position) self.assertIsInstance(position, jit.GeometricPosition) self.assertEqual(self.data[1][1:3], position.coordinates)
def test_format_surface(self): formatter = jit.CordeauLaporteLoaderFormatter(self.data) surface = formatter.surface() self.assertIsInstance(surface, jit.GeometricSurface) self.assertEqual(0, len(surface.positions))
def test_creation(self): formatter = jit.CordeauLaporteLoaderFormatter(self.data) self.assertEqual(formatter.data, self.data)