Skip to content

Commit

Permalink
✨ Enable the usage of path finding algorithms on unclocked layouts in…
Browse files Browse the repository at this point in the history
… pyfiction
  • Loading branch information
marcelwa committed Nov 15, 2023
1 parent 48d15e6 commit a91f177
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ inline void a_star(pybind11::module& m)
detail::a_star<py_cartesian_obstruction_layout>(m);
detail::a_star<py_cartesian_gate_layout>(m);
detail::a_star<py_cartesian_clocked_layout>(m);
detail::a_star<py_cartesian_layout>(m);
detail::a_star<py_shifted_cartesian_obstruction_layout>(m);
detail::a_star<py_shifted_cartesian_gate_layout>(m);
detail::a_star<py_shifted_cartesian_clocked_layout>(m);
detail::a_star<py_shifted_cartesian_layout>(m);
detail::a_star<py_hexagonal_obstruction_layout>(m);
detail::a_star<py_hexagonal_gate_layout>(m);
detail::a_star<py_hexagonal_clocked_layout>(m);
detail::a_star<py_hexagonal_layout>(m);
}

} // namespace pyfiction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ void enumerate_all_paths(pybind11::module& m)

return paths;
},
"layout"_a, "source"_a, "target"_a, "params"_a = fiction::enumerate_all_paths_params{});
//, DOC(fiction_enumerate_all_paths));
"layout"_a, "source"_a, "target"_a, "params"_a = fiction::enumerate_all_paths_params{},
DOC(fiction_enumerate_all_paths));
}

} // namespace detail
Expand All @@ -54,11 +54,11 @@ inline void enumerate_all_paths(pybind11::module& m)
{
namespace py = pybind11;

py::class_<fiction::enumerate_all_paths_params>(m, "enumerate_all_paths_params")
//, DOC(fiction_enumerate_all_paths_params))
py::class_<fiction::enumerate_all_paths_params>(m, "enumerate_all_paths_params",
DOC(fiction_enumerate_all_paths_params))
.def(py::init<>())
.def_readwrite("crossings", &fiction::enumerate_all_paths_params::crossings)
//, DOC(fiction_enumerate_all_paths_params_crossings))
.def_readwrite("crossings", &fiction::enumerate_all_paths_params::crossings,
DOC(fiction_enumerate_all_paths_params_crossings))

;

Expand All @@ -67,12 +67,15 @@ inline void enumerate_all_paths(pybind11::module& m)
detail::enumerate_all_paths<py_cartesian_obstruction_layout>(m);
detail::enumerate_all_paths<py_cartesian_gate_layout>(m);
detail::enumerate_all_paths<py_cartesian_clocked_layout>(m);
detail::enumerate_all_paths<py_cartesian_layout>(m);
detail::enumerate_all_paths<py_shifted_cartesian_obstruction_layout>(m);
detail::enumerate_all_paths<py_shifted_cartesian_gate_layout>(m);
detail::enumerate_all_paths<py_shifted_cartesian_clocked_layout>(m);
detail::enumerate_all_paths<py_shifted_cartesian_layout>(m);
detail::enumerate_all_paths<py_hexagonal_obstruction_layout>(m);
detail::enumerate_all_paths<py_hexagonal_gate_layout>(m);
detail::enumerate_all_paths<py_hexagonal_clocked_layout>(m);
detail::enumerate_all_paths<py_hexagonal_layout>(m);
}

} // namespace pyfiction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,15 @@ inline void yen_k_shortest_paths(pybind11::module& m)
detail::yen_k_shortest_paths<py_cartesian_obstruction_layout>(m);
detail::yen_k_shortest_paths<py_cartesian_gate_layout>(m);
detail::yen_k_shortest_paths<py_cartesian_clocked_layout>(m);
detail::yen_k_shortest_paths<py_cartesian_layout>(m);
detail::yen_k_shortest_paths<py_shifted_cartesian_obstruction_layout>(m);
detail::yen_k_shortest_paths<py_shifted_cartesian_gate_layout>(m);
detail::yen_k_shortest_paths<py_shifted_cartesian_clocked_layout>(m);
detail::yen_k_shortest_paths<py_shifted_cartesian_layout>(m);
detail::yen_k_shortest_paths<py_hexagonal_obstruction_layout>(m);
detail::yen_k_shortest_paths<py_hexagonal_gate_layout>(m);
detail::yen_k_shortest_paths<py_hexagonal_clocked_layout>(m);
detail::yen_k_shortest_paths<py_hexagonal_layout>(m);
}

} // namespace pyfiction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@


class TestAStar(unittest.TestCase):
def test_path_finding(self):

def test_non_clocked_path_finding(self):
for lyt in [cartesian_layout((4, 4)), shifted_cartesian_layout((4, 4)), hexagonal_layout((4, 4))]:
self.assertListEqual(a_star(lyt, offset_coordinate(0, 0), offset_coordinate(0, 0)), [(0, 0)])

def test_clocked_path_finding(self):
for lyt in [clocked_cartesian_layout((4, 4), "2DDWave"), cartesian_gate_layout((4, 4), "2DDWave", "Layout"),
clocked_shifted_cartesian_layout((4, 4), "2DDWave"),
shifted_cartesian_gate_layout((4, 4), "2DDWave", "Layout"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@


class TestEnumerateAllPaths(unittest.TestCase):
def test_non_clocked_paths(self):
for lyt in [cartesian_layout((4, 4)), shifted_cartesian_layout((4, 4)), hexagonal_layout((4, 4))]:
self.assertListEqual(enumerate_all_paths(lyt, offset_coordinate(0, 0), offset_coordinate(0, 0)), [[(0, 0)]])

def test_clocking_paths(self):
for lyt in [clocked_cartesian_layout((4, 4), "2DDWave"), cartesian_gate_layout((4, 4), "2DDWave", "Layout"),
clocked_shifted_cartesian_layout((4, 4), "2DDWave"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@


class TestKShortestPaths(unittest.TestCase):
def test_yen(self):
def test_non_clocked_yen_paths(self):
for lyt in [cartesian_layout((4, 4)), shifted_cartesian_layout((4, 4)), hexagonal_layout((4, 4))]:
self.assertListEqual(yen_k_shortest_paths(lyt, offset_coordinate(0, 0), offset_coordinate(0, 0), 1),
[[(0, 0)]])

def test_clocked_yen_paths(self):
for lyt in [clocked_cartesian_layout((4, 4), "2DDWave"), cartesian_gate_layout((4, 4), "2DDWave", "Layout"),
clocked_shifted_cartesian_layout((4, 4), "2DDWave"),
shifted_cartesian_gate_layout((4, 4), "2DDWave", "Layout"),
clocked_hexagonal_layout((4, 4), "2DDWave"), hexagonal_gate_layout((4, 4), "2DDWave", "Layout")]:
self.assertEqual(yen_k_shortest_paths(lyt, offset_coordinate(0, 0), offset_coordinate(0, 0), 1), [[(0, 0)]])
self.assertEqual(yen_k_shortest_paths(lyt, offset_coordinate(0, 0), offset_coordinate(1, 0), 1), [[(0, 0), (1, 0)]])
self.assertEqual(yen_k_shortest_paths(lyt, offset_coordinate(0, 0), offset_coordinate(0, 1), 1), [[(0, 0), (0, 1)]])
self.assertEqual(yen_k_shortest_paths(lyt, offset_coordinate(0, 0), offset_coordinate(1, 0), 1),
[[(0, 0), (1, 0)]])
self.assertEqual(yen_k_shortest_paths(lyt, offset_coordinate(0, 0), offset_coordinate(0, 1), 1),
[[(0, 0), (0, 1)]])

paths = yen_k_shortest_paths(lyt, offset_coordinate(0, 0), offset_coordinate(1, 1), 2)

Expand Down

0 comments on commit a91f177

Please sign in to comment.