I’m stuck on Exercise 2 (optimize_world_tour) because I’m seeing conflicting validator expectations.
In unittests.py, the validator is:
def is_valid_tour(graph_json, tour, start_node):
if tour[0] != start_node: ...
tour_nodes = set(tour)
if tour_nodes != set(graph_json['nodes']): ...
if len(tour) != len(tour_nodes):
return False, "Tour has duplicate nodes"
return True, ""
So this implies the tour must:
-
start with
start_node -
include all nodes exactly once
-
no duplicates → meaning it should be an open tour of length N (NOT
[... , start])
Also, calculate_tour_distance already closes the loop using modulo:
to_node = tour[(i + 1) % len(tour)]
My function returns for 8 nodes:
[0, 1, 7, 6, 5, 4, 3, 2]
-
starts ok

-
length ok

-
duplicates? False

But when I run the assignment test/grade cell I get:
“Invalid tour (5/8/10/12/15 countries). Tour must end with 0 (closed tour), got X.”
I searched the workspace and the string “must end with 0” doesn’t appear in unittests.py (only appears in the notebook itself). So it looks like there’s another checker being used that requires the tour to end with start, which would introduce a duplicate and fail is_valid_tour.
Question:
Which tour format is correct for submission?
-
Open tour:
[start, ..., last](unique nodes)
or -
Closed tour:
[start, ..., last, start]
And which test function/cell is the actual autograder using?
Any guidance from mentors/instructors would be hugely appreciated—right now the checks appear inconsistent.
Thanks!