Skip to content
Snippets Groups Projects
Verified Commit dff78c05 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Implement method to get possible nodes from ticket list

parent 2f9a989a
Branches
No related tags found
No related merge requests found
......@@ -38,14 +38,26 @@ class Board:
return graph
def __init__(self):
self.ticket_graphs = {}
def add_connection(self, ticket: str, departure: str, destination: str, oneway: bool = False) -> None:
self.ticket_graphs.setdefault(ticket, {}).setdefault(departure, set()).add(destination)
if not oneway:
self.ticket_graphs.setdefault(ticket, {}).setdefault(destination, set()).add(departure)
def get_possible_nodes(self, last: str, tickets: list[str]) -> list[str]:
possible = set((last,))
for ticket in tickets:
graph = self.full_graph if ticket == "*" else self.ticket_graphs[ticket]
new_possible = set()
for node in possible:
new_possible.update(graph[node])
possible = new_possible
return possible
def __init__(self):
self.ticket_graphs = {}
@classmethod
def from_dot(cls, filename: str) -> "Board":
board = cls()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment