diff --git a/src/GraphCtrl/GraphElement/GElement.cpp b/src/GraphCtrl/GraphElement/GElement.cpp index ca63a5dc..61f26979 100644 --- a/src/GraphCtrl/GraphElement/GElement.cpp +++ b/src/GraphCtrl/GraphElement/GElement.cpp @@ -344,6 +344,7 @@ CBool GElement::isMacro() const { CStatus GElement::crashed(const CException& ex) { + (void)(this); return CStatus(internal::STATUS_CRASH, ex.what()); } @@ -375,6 +376,7 @@ CVoid GElement::dump(std::ostream& oss) { CVoid GElement::dumpEdge(std::ostream& oss, GElementPtr src, GElementPtr dst, const std::string& label) { + (void)(this); if (src->isGGroup() && dst->isGGroup()) { // 在group的逻辑中,添加 cluster_ 的信息 oss << 'p' << src << " -> p" << dst << label << "[ltail=cluster_p" << src << " lhead=cluster_p" << dst << "]"; diff --git a/src/GraphCtrl/GraphElement/GGroup/GGroup.cpp b/src/GraphCtrl/GraphElement/GGroup/GGroup.cpp index 992c8ed9..e0234260 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GGroup.cpp +++ b/src/GraphCtrl/GraphElement/GGroup/GGroup.cpp @@ -72,6 +72,7 @@ CVoid GGroup::dumpGroupLabelBegin(std::ostream& oss) { CVoid GGroup::dumpGroupLabelEnd(std::ostream& oss) { + (void)(this); oss << "}\n"; } @@ -109,4 +110,9 @@ CBool GGroup::isSeparate(GElementCPtr a, GElementCPtr b) const { return false; } + +CSize GGroup::trim() const { + return 0; +} + CGRAPH_NAMESPACE_END \ No newline at end of file diff --git a/src/GraphCtrl/GraphElement/GGroup/GGroup.h b/src/GraphCtrl/GraphElement/GGroup/GGroup.h index 07c54a46..0a3f63da 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GGroup.h +++ b/src/GraphCtrl/GraphElement/GGroup/GGroup.h @@ -61,6 +61,12 @@ class GGroup : public GElement { */ virtual CBool isSeparate(GElementCPtr a, GElementCPtr b) const; + /** + * 剪裁逻辑 + * @return + */ + virtual CSize trim() const; + private: GElementPtrArr group_elements_arr_; // 存放 element的数组 @@ -71,6 +77,7 @@ class GGroup : public GElement { friend class GMutable; template friend class GMultiCondition; template friend class GSome; + friend class GTrimOptimizer; }; using GGroupPtr = GGroup *; diff --git a/src/GraphCtrl/GraphElement/GGroup/GRegion/GRegion.cpp b/src/GraphCtrl/GraphElement/GGroup/GRegion/GRegion.cpp index beb26e66..d342e5fb 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GRegion/GRegion.cpp +++ b/src/GraphCtrl/GraphElement/GGroup/GRegion/GRegion.cpp @@ -124,4 +124,13 @@ CBool GRegion::isSeparate(GElementCPtr a, GElementCPtr b) const { return GSeparateOptimizer::checkSeparate(manager_->manager_elements_, a, b); } + +CSize GRegion::trim() const { + CSize result = 0; + if (manager_) { + result = GTrimOptimizer::trim(manager_->manager_elements_); + } + return result; +} + CGRAPH_NAMESPACE_END \ No newline at end of file diff --git a/src/GraphCtrl/GraphElement/GGroup/GRegion/GRegion.h b/src/GraphCtrl/GraphElement/GGroup/GRegion/GRegion.h index cf55aaf0..f3b4835c 100644 --- a/src/GraphCtrl/GraphElement/GGroup/GRegion/GRegion.h +++ b/src/GraphCtrl/GraphElement/GGroup/GRegion/GRegion.h @@ -44,6 +44,8 @@ class GRegion : public GGroup { CBool isSeparate(GElementCPtr a, GElementCPtr b) const final; + CSize trim() const override; + private: GElementManagerPtr manager_ = nullptr; // region 内部通过 manager来管理其中的 element 信息 @@ -51,6 +53,7 @@ class GRegion : public GGroup { friend class GPipeline; friend class UAllocator; + friend class GTrimOptimizer; }; using GRegionPtr = GRegion *; diff --git a/src/GraphCtrl/GraphElement/_GOptimizer/GOptimizer.h b/src/GraphCtrl/GraphElement/_GOptimizer/GOptimizer.h index b03d4831..6aeb9a91 100644 --- a/src/GraphCtrl/GraphElement/_GOptimizer/GOptimizer.h +++ b/src/GraphCtrl/GraphElement/_GOptimizer/GOptimizer.h @@ -70,12 +70,16 @@ class GOptimizer : public GElementObject { int father, int son, int unlink) { const CSize size = elements.size(); std::vector> graph(size, std::vector(size, unlink)); - for (auto& path : paths) { - for (int i = 0; i < path.size() - 1; i++) { + if (0 == size || 0 == paths.size()) { + return graph; + } + + for (const auto& path : paths) { + for (CSize i = 0; i < path.size(); i++) { // 这里的 find是一定能找到的。因为path的数据,是从elements中记录的 - int height = (int)std::distance(elements.begin(), elements.find(path[i])); - for (int j = i + 1; j < path.size(); j++) { - int column = (int)std::distance(elements.begin(), elements.find(path[j])); + CSize height = std::distance(elements.begin(), elements.find(path[i])); + for (CSize j = i + 1; j < path.size(); j++) { + CSize column = std::distance(elements.begin(), elements.find(path[j])); graph[height][column] = father; graph[column][height] = son; } diff --git a/src/GraphCtrl/GraphElement/_GOptimizer/GTrimOptimizer.h b/src/GraphCtrl/GraphElement/_GOptimizer/GTrimOptimizer.h index f092da2b..7edc9dfa 100644 --- a/src/GraphCtrl/GraphElement/_GOptimizer/GTrimOptimizer.h +++ b/src/GraphCtrl/GraphElement/_GOptimizer/GTrimOptimizer.h @@ -13,6 +13,7 @@ #include #include "GOptimizer.h" +#include "../GGroup/GGroupInclude.h" CGRAPH_NAMESPACE_BEGIN @@ -28,12 +29,13 @@ class GTrimOptimizer : public GOptimizer { auto graph = buildGraph(elements, paths, 1, 0, 0); for (auto* cur : elements) { - int idx = (int)std::distance(elements.begin(), elements.find(cur)); + CSize idx = std::distance(elements.begin(), elements.find(cur)); GElementPtrArr candidates; - for (int i = 0; i < (int)cur->dependence_.size(); i++) { - int x = (int)std::distance(elements.begin(), elements.find(cur->dependence_[i])); - for (int j = i; j < (int)cur->dependence_.size(); j++) { - int y = (int)std::distance(elements.begin(), elements.find(cur->dependence_[j])); + for (CSize i = 0; i < cur->dependence_.size(); i++) { + CSize x = std::distance(elements.begin(), elements.find(cur->dependence_[i])); + for (CSize j = 0; j < cur->dependence_.size(); j++) { + // 这里必须是 n^2 的循环 + CSize y = std::distance(elements.begin(), elements.find(cur->dependence_[j])); if (1 == graph[x][y]) { graph[x][idx] = 0; candidates.push_back(cur->dependence_[i]); @@ -46,12 +48,17 @@ class GTrimOptimizer : public GOptimizer { trimNum++; } } + + if (cur->isGGroup()) { + trimNum += ((GGroupPtr)cur)->trim(); + } } return trimNum; } friend class GElementManager; + friend class GRegion; }; CGRAPH_NAMESPACE_END