Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Commit

Permalink
* Removed "Trip.timeout" and added "Trip.latest". #49
Browse files Browse the repository at this point in the history
  • Loading branch information
garciparedes committed Oct 19, 2019
1 parent eaa60c6 commit 5ec0cc7
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 25 deletions.
3 changes: 1 addition & 2 deletions jinete/loaders/formatters/cordeau_laporte.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,14 @@ def build_trip(self, surface: Surface, idx: int, n: int) -> Trip:
raise LoaderFormatterException('It is not possible to distinguish between inbound and outbound task.')

identifier = f'{origin_row[0]:.0f}'
timeout = latest - earliest

trip = Trip(
identifier=identifier,
origin=origin,
destination=destination,
inbound=inbound,
earliest=earliest,
timeout=timeout,
latest=latest,
load_time=load_time,
capacity=capacity,
)
Expand Down
3 changes: 1 addition & 2 deletions jinete/loaders/formatters/hashcode.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ def _build_trip(self, surface: Surface, identifier: str, bonus: float, x1: float
earliest: float, latest: float) -> Trip:
origin = surface.get_or_create_position([x1, y1])
destination = surface.get_or_create_position([x2, y2])
timeout = latest - earliest
trip = Trip(identifier, origin, destination, earliest, timeout, bonus)
trip = Trip(identifier, origin, destination, earliest, latest, bonus)
logger.debug(f'Created trip!')
return trip

Expand Down
13 changes: 4 additions & 9 deletions jinete/models/trips.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Trip(object):
'origin',
'destination',
'earliest',
'timeout',
'latest',
'on_time_bonus',
'load_capacity',
'load_time',
Expand All @@ -44,24 +44,19 @@ class Trip(object):
capacity: float

def __init__(self, identifier: str, origin: Position, destination: Position, earliest: float = 0.0,
timeout: Optional[float] = None, on_time_bonus: float = 0.0, load_time: float = 0.0,
latest: float = MAX_FLOAT, on_time_bonus: float = 0.0, load_time: float = 0.0,
inbound: bool = True, capacity: float = 1):
self.identifier = identifier
self.origin = origin
self.destination = destination
self.earliest = earliest
self.timeout = timeout
self.latest = latest

self.on_time_bonus = on_time_bonus
self.load_time = load_time
self.inbound = inbound
self.capacity = capacity

@property
def latest(self) -> float:
if self.timeout is None:
return MAX_FLOAT
return self.earliest + self.timeout

@property
def empty(self) -> bool:
return self.capacity == 0
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models/test_criterions/test_longest_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def setUpClass(cls) -> None:
origin=surface.get_or_create_position([0, 0]),
destination=surface.get_or_create_position([1, 1]),
earliest=0.0,
timeout=10.0,
latest=10.0,
),
pickup=pickup_stop_1,
delivery=delivery_stop_1,
Expand All @@ -47,7 +47,7 @@ def setUpClass(cls) -> None:
origin=surface.get_or_create_position([0, 0]),
destination=surface.get_or_create_position([10, 10]),
earliest=0.0,
timeout=20.0,
latest=20.0,
),
pickup=pickup_stop_2,
delivery=delivery_stop_2,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models/test_criterions/test_shortest_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def setUpClass(cls) -> None:
origin=surface.get_or_create_position([0, 0]),
destination=surface.get_or_create_position([1, 1]),
earliest=0.0,
timeout=10.0,
latest=10.0,
),
pickup=pickup_stop_1,
delivery=delivery_stop_1,
Expand All @@ -49,7 +49,7 @@ def setUpClass(cls) -> None:
origin=surface.get_or_create_position([0, 0]),
destination=surface.get_or_create_position([10, 10]),
earliest=0.0,
timeout=20.0,
latest=20.0,
),
pickup=pickup_stop_2,
delivery=delivery_stop_2,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models/test_objectives/test_dial_a_ride.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ def setUpClass(cls) -> None:
origin=surface.get_or_create_position([0, 0]),
destination=surface.get_or_create_position([1, 1]),
earliest=0.0,
timeout=10.0,
latest=10.0,
), jit.Trip(
identifier='TEST_1',
origin=surface.get_or_create_position([1, 1]),
destination=surface.get_or_create_position([10, 10]),
earliest=0.0,
timeout=20.0,
latest=20.0,
),
]
job = jit.Job(set(trips), jit.DialARideObjective)
Expand Down
6 changes: 1 addition & 5 deletions tests/test_models/test_trips.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def test_trip(self):
self.assertEqual(origin, trip.origin)
self.assertEqual(destination, trip.destination)
self.assertEqual(earliest, trip.earliest)
self.assertIsNone(trip.timeout)
self.assertEqual(trip.latest, jit.MAX_FLOAT)
self.assertEqual(0, trip.load_time)
self.assertEqual(1, trip.capacity)
Expand All @@ -44,7 +43,6 @@ def test_trip_with_capacity(self):
self.assertEqual(origin, trip.origin)
self.assertEqual(destination, trip.destination)
self.assertEqual(earliest, trip.earliest)
self.assertIsNone(trip.timeout)
self.assertEqual(trip.latest, jit.MAX_FLOAT)
self.assertEqual(0, trip.load_time)
self.assertEqual(capacity, trip.capacity)
Expand All @@ -61,12 +59,11 @@ def test_trip_with_timeout(self):
duration = origin.time_to(destination, earliest)

trip = jit.Trip(identifier=identifier, origin=origin, destination=destination, earliest=earliest,
timeout=timeout)
latest=earliest + timeout)

self.assertEqual(origin, trip.origin)
self.assertEqual(destination, trip.destination)
self.assertEqual(earliest, trip.earliest)
self.assertEqual(timeout, trip.timeout)
self.assertEqual(earliest + timeout, trip.latest)
self.assertEqual(0, trip.load_time)
self.assertEqual(1, trip.capacity)
Expand All @@ -87,7 +84,6 @@ def test_trip_with_load_time(self):

self.assertEqual(origin, trip.origin)
self.assertEqual(destination, trip.destination)
self.assertIsNone(trip.timeout)
self.assertEqual(trip.latest, jit.MAX_FLOAT)
self.assertEqual(load_time, trip.load_time)
self.assertEqual(1, trip.capacity)
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def generate_one_trip(identifier: str = None,
capacity = randint(capacity_min, capacity_max)
if load_time is None:
load_time = uniform(load_time_min, load_time_max)
return jit.Trip(identifier, origin, destination, earliest, timeout, load_time, capacity)
return jit.Trip(identifier, origin, destination, earliest, earliest + timeout, load_time, capacity)


def generate_trips(n: int, *args, **kwargs) -> Set[jit.Trip]:
Expand Down

0 comments on commit 5ec0cc7

Please sign in to comment.