Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix round error #47

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pytest-cov = "^2.10.1"
black = {version = "^20.8b1", allow-prereleases = true}

[build-system]
requires = ["poetry-core>=1.0.0"]
requires = ["poetry-core==1.0.0"]
build-backend = "poetry.core.masonry.api"

[tool.semantic_release]
Expand Down
10 changes: 6 additions & 4 deletions pyraptor/model/raptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def is_dominating(self, other: Label):
return self.earliest_arrival_time <= other.earliest_arrival_time

def __repr__(self) -> str:
return f"Label(earliest_arrival_time={self.earliest_arrival_time}, trip={self.trip}, from_stop={self.from_stop})"
return f"Label(earliest_arrival_time={self.earliest_arrival_time}, trip={self.trip}, " \
f"from_stop={self.from_stop})"


class RaptorAlgorithm:
Expand All @@ -43,7 +44,7 @@ def __init__(self, timetable: Timetable):
self.timetable = timetable
self.bag_star = None

def run(self, from_stops, dep_secs, rounds) -> Dict[int, Dict[Stop, Label]]:
def run(self, from_stops, dep_secs, rounds) -> Dict[Stop, Label]:
"""Run Round-Based Algorithm"""

# Initialize empty bag of labels, i.e. B_k(p) = Label() for every k and p
Expand All @@ -67,6 +68,7 @@ def run(self, from_stops, dep_secs, rounds) -> Dict[int, Dict[Stop, Label]]:
marked_stops.append(from_stop)

# Run rounds
k = 0
for k in range(1, rounds + 1):
logger.info(f"Analyzing possibilities round {k}")
bag_round_stop[k] = deepcopy(bag_round_stop[k - 1])
Expand Down Expand Up @@ -95,9 +97,9 @@ def run(self, from_stops, dep_secs, rounds) -> Dict[int, Dict[Stop, Label]]:
else:
break

logger.info("Finish round-based algorithm to create bag with best labels")
logger.info("Finish round-based algorithm to create bag with best labels")

return bag_round_stop
return bag_round_stop[k]

def accumulate_routes(self, marked_stops: List[Stop]) -> List[Tuple[Route, Stop]]:
"""Accumulate routes serving marked stops from previous round, i.e. Q"""
Expand Down
3 changes: 1 addition & 2 deletions pyraptor/query_range_raptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ def run_range_raptor(

# Run Round-Based Algorithm
raptor = RaptorAlgorithm(timetable)
bag_round_stop = raptor.run(from_stops, dep_secs, rounds)
best_labels = bag_round_stop[rounds]
best_labels = raptor.run(from_stops, dep_secs, rounds)

# Determine the best destination ID, destination is a platform
for destination_station_name, to_stops in destination_stops.items():
Expand Down
3 changes: 1 addition & 2 deletions pyraptor/query_raptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ def run_raptor(

# Run Round-Based Algorithm
raptor = RaptorAlgorithm(timetable)
bag_round_stop = raptor.run(from_stops, dep_secs, rounds)
best_labels = bag_round_stop[rounds]
best_labels = raptor.run(from_stops, dep_secs, rounds)

# Determine the best journey to all possible destination stations
journey_to_destinations = dict()
Expand Down