diff --git a/include/aidge/graph/GraphView.hpp b/include/aidge/graph/GraphView.hpp index eaf23d88efa0dd367047d5fd3881a0f52240f3ee..62f6ac11cdcd2fc8c321d38e72653b3b90f372be 100644 --- a/include/aidge/graph/GraphView.hpp +++ b/include/aidge/graph/GraphView.hpp @@ -54,22 +54,6 @@ public: // ctor } - /** - * Construct a GraphView from a set of nodes. The startNode parameters - * allows to define a default inputs/ouputs order relative to this node. - * For two topologically identical graphs, using the same topological node - * as starting node will lead to the same topologically ordered inputs/outputs list. - * Otherwise, inputs/outputs order will be arbitrary. - */ - GraphView(std::set<NodePtr> nodes, NodePtr startNode = nullptr, std::string name="") - : mName(name) - { - if (startNode != nullptr) { - add(startNode, false); - } - add(nodes); - } - bool operator==(const GraphView &gv) const { return mNodes == gv.mNodes; diff --git a/src/graph/Connector.cpp b/src/graph/Connector.cpp index cf3b18dc5f17a4213a32066a3d244d5bed6f77e5..cd2ceff8b58076a5054269e4676120b94c8b5beb 100644 --- a/src/graph/Connector.cpp +++ b/src/graph/Connector.cpp @@ -26,15 +26,7 @@ Aidge::Connector::Connector(std::shared_ptr<Aidge::Node> node) { Aidge::IOIndex_t Aidge::Connector::size() const { return mNode->nbOutputs(); } -std::shared_ptr<Aidge::GraphView> Aidge::generateGraph(std::vector<Connector> ctors) { - std::set<NodePtr> nodesToAdd; - for (const Connector& ctor : ctors) { - nodesToAdd.insert(ctor.node()); - } - return std::make_shared<GraphView>(nodesToAdd, ctors.back().node()); - - // TODO: FIXME: don't understand the following code! -/* +std::shared_ptr<Aidge::GraphView> Aidge::generateGraph(std::vector<Connector> ctors) { std::shared_ptr<GraphView> graph = std::make_shared<GraphView>(); std::vector<std::shared_ptr<Node>> nodesToAdd = std::vector<std::shared_ptr<Node>>(); for (const Connector& ctor : ctors) { @@ -59,5 +51,4 @@ std::shared_ptr<Aidge::GraphView> Aidge::generateGraph(std::vector<Connector> ct buffer = {}; } return graph; -*/ } \ No newline at end of file diff --git a/src/graph/GraphView.cpp b/src/graph/GraphView.cpp index 3c6a39921a3eb326a1c276ea4733f2e99b88f2e4..2714484eb29303a5d7d2f1927836207b48324371 100644 --- a/src/graph/GraphView.cpp +++ b/src/graph/GraphView.cpp @@ -107,7 +107,7 @@ void Aidge::GraphView::save(std::string path, bool verbose) const { /////////////////////////////////////////////////////// void Aidge::GraphView::setOrderedInputs(const std::vector<std::pair<NodePtr, IOIndex_t>>& inputs) { - AIDGE_ASSERT(inputs.size() > mInputNodes.size(), "too many specified number of inputs"); + AIDGE_ASSERT(inputs.size() <= mInputNodes.size(), "too many specified number of inputs"); std::vector<std::pair<NodePtr, IOIndex_t>> ignoredInputs(mInputNodes); for (auto input : inputs) { @@ -121,7 +121,7 @@ void Aidge::GraphView::setOrderedInputs(const std::vector<std::pair<NodePtr, IOI } void Aidge::GraphView::setOrderedOutputs(const std::vector<std::pair<NodePtr, IOIndex_t>>& outputs) { - AIDGE_ASSERT(outputs.size() > mOutputNodes.size(), "too many specified number of outputs"); + AIDGE_ASSERT(outputs.size() <= mOutputNodes.size(), "too many specified number of outputs"); std::vector<std::pair<NodePtr, IOIndex_t>> ignoredOutputs(mOutputNodes); for (auto output : outputs) { @@ -832,8 +832,9 @@ void Aidge::GraphView::updateInputsOutputsNew(std::shared_ptr<Node> newNode) { (mNodes.find(pa_ptr) == mNodes.end())) { // Parent doesn't exist || Parent not in the graph const auto val = std::make_pair(newNode, inputIdx); - AIDGE_INTERNAL_ASSERT(std::find(mInputNodes.begin(), mInputNodes.end(), val) == mInputNodes.end()); - newInputsInsertionPoint = mInputNodes.insert(newInputsInsertionPoint, val); + if (std::find(mInputNodes.begin(), mInputNodes.end(), val) == mInputNodes.end()) { + newInputsInsertionPoint = mInputNodes.insert(newInputsInsertionPoint, val); + } } ++inputIdx; } @@ -1166,10 +1167,16 @@ std::shared_ptr<Aidge::GraphView> Aidge::GraphView::cloneCallback(NodePtr(*clone } if (!found) { - it = newInputNodes.erase(it); break; } } + + if (oldToNewNodes[it->first] == nullptr) { + it = newInputNodes.erase(it); + } + else { + it->first = oldToNewNodes[it->first]; + } } newGraph->setOrderedInputs(newInputNodes); @@ -1185,10 +1192,16 @@ std::shared_ptr<Aidge::GraphView> Aidge::GraphView::cloneCallback(NodePtr(*clone *it = parents[0]; } else { - it = newOutputNodes.erase(it); break; } } + + if (oldToNewNodes[it->first] == nullptr) { + it = newOutputNodes.erase(it); + } + else { + it->first = oldToNewNodes[it->first]; + } } newGraph->setOrderedOutputs(newOutputNodes); diff --git a/unit_tests/graph/Test_GraphView.cpp b/unit_tests/graph/Test_GraphView.cpp index 7da7cf164bd1dfdcd12a7788d7904b33d07187f2..75f9a47fe48065b2a84b0f284777941d063af0be 100644 --- a/unit_tests/graph/Test_GraphView.cpp +++ b/unit_tests/graph/Test_GraphView.cpp @@ -55,7 +55,8 @@ std::set<NodePtr> genRandomDAG(size_t nbNodes, float density = 0.5, size_t maxIn TEST_CASE("genRandomDAG") { - auto g = std::make_shared<GraphView>(genRandomDAG(10)); + auto g = std::make_shared<GraphView>(); + g->add(genRandomDAG(10)); REQUIRE(g->getNodes().size() == 10); g->save("./genRandomDAG"); }