diff --git a/src/faebryk/core/cpp/__init__.pyi b/src/faebryk/core/cpp/__init__.pyi index 40d406c8..12157da8 100644 --- a/src/faebryk/core/cpp/__init__.pyi +++ b/src/faebryk/core/cpp/__init__.pyi @@ -8,6 +8,28 @@ import enum from collections.abc import Callable, Sequence, Set from typing import overload +class Counter: + @property + def in_cnt(self) -> int: ... + @property + def weak_in_cnt(self) -> int: ... + @property + def out_weaker(self) -> int: ... + @property + def out_stronger(self) -> int: ... + @property + def out_cnt(self) -> int: ... + @property + def time_spent_s(self) -> float: ... + @property + def hide(self) -> bool: ... + @property + def name(self) -> str: ... + @property + def multi(self) -> bool: ... + @property + def total_counter(self) -> bool: ... + class Graph: def __init__(self) -> None: ... def get_edges(self, arg: GraphInterface, /) -> dict[GraphInterface, Link]: ... @@ -149,5 +171,8 @@ def add(i: int, j: int = 1) -> int: """A function that adds two numbers""" def call_python_function(func: Callable[[], int]) -> int: ... +def find_paths( + src: Node, dst: Sequence[Node] +) -> tuple[list[list[GraphInterface]], list[Counter]]: ... def print_obj(obj: object) -> None: ... def set_leak_warnings(value: bool) -> None: ... diff --git a/src/faebryk/core/cpp/include/pathfinder/pathfinder.hpp b/src/faebryk/core/cpp/include/pathfinder/pathfinder.hpp index 6d0aa89f..fd35f990 100644 --- a/src/faebryk/core/cpp/include/pathfinder/pathfinder.hpp +++ b/src/faebryk/core/cpp/include/pathfinder/pathfinder.hpp @@ -5,6 +5,7 @@ #pragma once #include "graph/graph.hpp" +#include "pathfinder/bfs.hpp" #include "pathfinder/pathcounter.hpp" #include "perf.hpp" #include @@ -27,7 +28,6 @@ struct Filter { }; class PathFinder { - Graph &g; std::vector multi_paths; size_t path_cnt = 0; @@ -44,7 +44,7 @@ class PathFinder { std::vector _filter_paths_by_split_join(std::vector &paths); public: - PathFinder(Graph &g); + PathFinder(); std::vector filters; bool run_filters(BFSPath &p); diff --git a/src/faebryk/core/cpp/src/main.cpp b/src/faebryk/core/cpp/src/main.cpp index c8cffcef..c82208a4 100644 --- a/src/faebryk/core/cpp/src/main.cpp +++ b/src/faebryk/core/cpp/src/main.cpp @@ -6,6 +6,7 @@ #include "graph/graphinterfaces.hpp" #include "graph/links.hpp" #include "nano.hpp" +#include "pathfinder/pathfinder.hpp" #include // check if c++20 is used @@ -46,6 +47,17 @@ void print_obj_pyptr(PyObject *pyobj) { print_obj(obj); } +std::pair, std::vector> +find_paths(Node_ref src, std::vector dst) { + PerfCounter pc; + + PathFinder pf; + auto res = pf.find_paths(src, dst); + + printf("TIME: %3.2lf ms C++ find paths\n", pc.ms()); + return res; +} + PYMOD(m) { m.doc() = "faebryk core c++ module"; @@ -54,6 +66,8 @@ PYMOD(m) { m.def("set_leak_warnings", &nb::set_leak_warnings, "value"_a); m.def("print_obj", &print_obj, "obj"_a); + m.def("find_paths", &find_paths, "src"_a, "dst"_a); + // Graph using GI = GraphInterface; @@ -158,4 +172,17 @@ PYMOD(m) { nb::exception(m, "NodeException"); nb::exception(m, "NodeNoParent"); + + // Pathfinder + nb::class_(m, "Counter") + .def_ro("in_cnt", &Counter::in_cnt) + .def_ro("weak_in_cnt", &Counter::weak_in_cnt) + .def_ro("out_weaker", &Counter::out_weaker) + .def_ro("out_stronger", &Counter::out_stronger) + .def_ro("out_cnt", &Counter::out_cnt) + .def_ro("time_spent_s", &Counter::time_spent_s) + .def_ro("hide", &Counter::hide) + .def_ro("name", &Counter::name) + .def_ro("multi", &Counter::multi) + .def_ro("total_counter", &Counter::total_counter); } diff --git a/src/faebryk/core/cpp/src/pathfinder/pathfinder.cpp b/src/faebryk/core/cpp/src/pathfinder/pathfinder.cpp index 71fa2dcb..47dac73b 100644 --- a/src/faebryk/core/cpp/src/pathfinder/pathfinder.cpp +++ b/src/faebryk/core/cpp/src/pathfinder/pathfinder.cpp @@ -10,9 +10,8 @@ #include // PathFinder implementations -PathFinder::PathFinder(Graph &g) - : g(g) { - filters = { +PathFinder::PathFinder() + : filters{ Filter{ .filter = &PathFinder::_count, .discovery = true, @@ -85,7 +84,7 @@ PathFinder::PathFinder(Graph &g) .name = "stack", }, }, - }; + } { } // Filter implementations