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

Commit

Permalink
* Renamed "Trip.load_time" to "Trip.origin_duration". #49
Browse files Browse the repository at this point in the history
* Included "Trip.destination_duration". #49
  • Loading branch information
garciparedes committed Oct 19, 2019
1 parent f6fb178 commit 3c63981
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 25 deletions.
2 changes: 1 addition & 1 deletion jinete/algorithms/utils/models/three_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def load_time_by_position_idx(self, idx: int) -> float:
trip = self.trip_by_position_idx(idx)
if trip is None:
return 0
return trip.load_time
return trip.origin_duration

def _build_uniqueness_constraints(self) -> List[lp.LpConstraint]:
constraints = list()
Expand Down
22 changes: 12 additions & 10 deletions jinete/loaders/formatters/cordeau_laporte.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,32 @@ def job(self, surface: Surface, *args, **kwargs) -> Job:

def build_trip(self, surface: Surface, idx: int, n: int) -> Trip:
origin_idx = idx + 2
destination_idx = origin_idx + n

origin_row = self.data[origin_idx]
destination_row = self.data[destination_idx]

origin = surface.get_or_create_position(origin_row[1:3])
destination = surface.get_or_create_position(destination_row[1:3])
load_time = origin_row[3]
capacity = origin_row[4]

origin_earliest, origin_latest = origin_row[5:7]
origin_duration = origin_row[3]

destination_idx = origin_idx + n
destination_row = self.data[destination_idx]
destination = surface.get_or_create_position(destination_row[1:3])
destination_earliest, destination_latest = destination_row[5:7]
destination_duration = destination_row[3]

identifier = f'{origin_row[0]:.0f}'

assert origin_row[4] == -destination_row[4]
capacity = origin_row[4]

trip = Trip(
identifier=identifier,
origin=origin,
destination=destination,
origin_earliest=origin_earliest,
origin_latest=origin_latest,
origin_duration=origin_duration,
destination=destination,
destination_earliest=destination_earliest,
destination_latest=destination_latest,
load_time=load_time,
destination_duration=destination_duration,
capacity=capacity,
)
return trip
Expand Down
2 changes: 1 addition & 1 deletion jinete/models/stops.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def load_time(self) -> float:
if not any(self.pickups):
self._load_time = 0.0
else:
self._load_time = max((pt.trip.load_time for pt in self.planned_trips))
self._load_time = max((pt.trip.origin_duration for pt in self.planned_trips))
return self._load_time

@property
Expand Down
15 changes: 9 additions & 6 deletions jinete/models/trips.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ class Trip(object):
__slots__ = (
'identifier',
'origin',
'destination',
'origin_earliest',
'origin_latest',
'origin_duration',
'destination',
'destination_earliest',
'destination_latest',
'destination_duration',
'on_time_bonus',
'load_capacity',
'load_time',
'capacity',
)
identifier: str
Expand All @@ -41,23 +42,25 @@ class Trip(object):
origin_earliest: float
timeout: Optional[float]
on_time_bonus: float
load_time: float
origin_duration: float
capacity: float

def __init__(self, identifier: str, origin: Position, destination: Position, origin_earliest: float = 0.0,
origin_latest: float = MAX_FLOAT, on_time_bonus: float = 0.0, load_time: float = 0.0,
capacity: float = 1, destination_earliest: float = 0.0, destination_latest: float = MAX_FLOAT):
origin_latest: float = MAX_FLOAT, on_time_bonus: float = 0.0, origin_duration: float = 0.0,
capacity: float = 1, destination_earliest: float = 0.0, destination_latest: float = MAX_FLOAT,
destination_duration: float = 0.0):
self.identifier = identifier
self.origin = origin
self.origin_earliest = origin_earliest
self.origin_latest = origin_latest
self.origin_duration = origin_duration

self.destination = destination
self.destination_earliest = destination_earliest
self.destination_latest = destination_latest
self.destination_duration = destination_duration

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

@property
Expand Down
2 changes: 1 addition & 1 deletion jinete/storers/formatters/columnar.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def planned_trip_to_str(self, planned_trip: PlannedTrip) -> List[str]:
f'TW: {planned_trip.trip.origin_earliest:6.01f} to {planned_trip.trip.origin_latest:6.01f}',
f'WT: {planned_trip.pickup.waiting_time:5.01f}',
f'NT: {planned_trip.pickup.navigation_time:5.01f}',
f'LT: {planned_trip.trip.load_time:4.01f}',
f'LT: {planned_trip.trip.origin_duration:4.01f}',
f'TT: {planned_trip.duration:6.01f}',
f'T: {planned_trip.pickup_time:6.01f} to {planned_trip.delivery_time:6.01f}',
f'L: {planned_trip.capacity}',
Expand Down
2 changes: 1 addition & 1 deletion tests/test_loaders/test_formatters/test_cordeau_laporte.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TestCordeauLaporteLoaderFormatter(unittest.TestCase):
@classmethod
def setUpClass(cls) -> None:
cls.data = (
(1.0, 2.0, 480, 6.0, 90.0),
(1.0, 4.0, 480, 6.0, 90.0),
(0.0, -1.044, 2.000, 0.0, 0.0, 0.0, 1440.0),
(1.0, -2.973, 6.414, 10.0, 1.0, 0.0, 1440.0),
(2.0, -7.667, 9.934, 10.0, 1.0, 325.0, 358.0),
Expand Down
10 changes: 5 additions & 5 deletions tests/test_models/test_trips.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_trip(self):
self.assertEqual(destination, trip.destination)
self.assertEqual(earliest, trip.origin_earliest)
self.assertEqual(trip.origin_latest, jit.MAX_FLOAT)
self.assertEqual(0, trip.load_time)
self.assertEqual(0, trip.origin_duration)
self.assertEqual(1, trip.capacity)
self.assertEqual(distance, trip.distance)
self.assertEqual(duration, trip.duration(trip.origin_earliest))
Expand All @@ -44,7 +44,7 @@ def test_trip_with_capacity(self):
self.assertEqual(destination, trip.destination)
self.assertEqual(earliest, trip.origin_earliest)
self.assertEqual(trip.origin_latest, jit.MAX_FLOAT)
self.assertEqual(0, trip.load_time)
self.assertEqual(0, trip.origin_duration)
self.assertEqual(capacity, trip.capacity)
self.assertEqual(distance, trip.distance)
self.assertEqual(duration, trip.duration(trip.origin_earliest))
Expand All @@ -65,7 +65,7 @@ def test_trip_with_timeout(self):
self.assertEqual(destination, trip.destination)
self.assertEqual(earliest, trip.origin_earliest)
self.assertEqual(earliest + timeout, trip.origin_latest)
self.assertEqual(0, trip.load_time)
self.assertEqual(0, trip.origin_duration)
self.assertEqual(1, trip.capacity)
self.assertEqual(distance, trip.distance)
self.assertEqual(duration, trip.duration(trip.origin_earliest))
Expand All @@ -80,12 +80,12 @@ def test_trip_with_load_time(self):
duration = origin.time_to(destination, earliest)

trip = jit.Trip(identifier=identifier, origin=origin, destination=destination, origin_earliest=earliest,
load_time=load_time)
origin_duration=load_time)

self.assertEqual(origin, trip.origin)
self.assertEqual(destination, trip.destination)
self.assertEqual(trip.origin_latest, jit.MAX_FLOAT)
self.assertEqual(load_time, trip.load_time)
self.assertEqual(load_time, trip.origin_duration)
self.assertEqual(1, trip.capacity)
self.assertEqual(earliest, trip.origin_earliest)
self.assertEqual(distance, trip.distance)
Expand Down

0 comments on commit 3c63981

Please sign in to comment.