change old DAG implementation to pass unit tests
This commit is contained in:
parent
6105ea7a69
commit
72c7a8ab00
|
@ -1965,42 +1965,6 @@ int Document::recompute()
|
|||
|
||||
#else //ifdef USE_OLD_DAG
|
||||
|
||||
std::vector<App::DocumentObject*> Document::topologicalSort() const
|
||||
{
|
||||
// topological sort algorithm described here:
|
||||
// https://de.wikipedia.org/wiki/Topologische_Sortierung#Algorithmus_f.C3.BCr_das_Topologische_Sortieren
|
||||
vector < App::DocumentObject* > ret;
|
||||
ret.reserve(d->objectArray.size());
|
||||
map < App::DocumentObject*,int > countMap;
|
||||
|
||||
for (auto objectIt : d->objectArray)
|
||||
countMap[objectIt] = objectIt->getInList().size();
|
||||
|
||||
auto rootObjeIt = find_if(countMap.begin(), countMap.end(), [](pair < App::DocumentObject*, int > count)->bool {
|
||||
return count.second == 0;
|
||||
});
|
||||
|
||||
if (rootObjeIt == countMap.end()){
|
||||
cerr << "Document::topologicalSort: cyclic dependency detected (no root object)" << endl;
|
||||
return ret;
|
||||
}
|
||||
|
||||
while (rootObjeIt != countMap.end()){
|
||||
rootObjeIt->second = rootObjeIt->second - 1;
|
||||
for (auto outListIt : rootObjeIt->first->getOutList()){
|
||||
auto outListMapIt = countMap.find(outListIt);
|
||||
outListMapIt->second = outListMapIt->second - 1;
|
||||
}
|
||||
ret.push_back(rootObjeIt->first);
|
||||
|
||||
rootObjeIt = find_if(countMap.begin(), countMap.end(), [](pair < App::DocumentObject*, int > count)->bool {
|
||||
return count.second == 0;
|
||||
});
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int Document::recompute()
|
||||
{
|
||||
int objectCount = 0;
|
||||
|
@ -2047,6 +2011,42 @@ int Document::recompute()
|
|||
|
||||
#endif // USE_OLD_DAG
|
||||
|
||||
std::vector<App::DocumentObject*> Document::topologicalSort() const
|
||||
{
|
||||
// topological sort algorithm described here:
|
||||
// https://de.wikipedia.org/wiki/Topologische_Sortierung#Algorithmus_f.C3.BCr_das_Topologische_Sortieren
|
||||
vector < App::DocumentObject* > ret;
|
||||
ret.reserve(d->objectArray.size());
|
||||
map < App::DocumentObject*,int > countMap;
|
||||
|
||||
for (auto objectIt : d->objectArray)
|
||||
countMap[objectIt] = objectIt->getInList().size();
|
||||
|
||||
auto rootObjeIt = find_if(countMap.begin(), countMap.end(), [](pair < App::DocumentObject*, int > count)->bool {
|
||||
return count.second == 0;
|
||||
});
|
||||
|
||||
if (rootObjeIt == countMap.end()){
|
||||
cerr << "Document::topologicalSort: cyclic dependency detected (no root object)" << endl;
|
||||
return ret;
|
||||
}
|
||||
|
||||
while (rootObjeIt != countMap.end()){
|
||||
rootObjeIt->second = rootObjeIt->second - 1;
|
||||
for (auto outListIt : rootObjeIt->first->getOutList()){
|
||||
auto outListMapIt = countMap.find(outListIt);
|
||||
outListMapIt->second = outListMapIt->second - 1;
|
||||
}
|
||||
ret.push_back(rootObjeIt->first);
|
||||
|
||||
rootObjeIt = find_if(countMap.begin(), countMap.end(), [](pair < App::DocumentObject*, int > count)->bool {
|
||||
return count.second == 0;
|
||||
});
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char * Document::getErrorDescription(const App::DocumentObject*Obj) const
|
||||
{
|
||||
for (std::vector<App::DocumentObjectExecReturn*>::const_iterator it=_RecomputeLog.begin();it!=_RecomputeLog.end();++it)
|
||||
|
|
|
@ -492,7 +492,6 @@ Py::List DocumentPy::getObjects(void) const
|
|||
|
||||
Py::List DocumentPy::getToplogicalSortedObjects(void) const
|
||||
{
|
||||
#ifndef USE_OLD_DAG
|
||||
std::vector<DocumentObject*> objs = getDocumentPtr()->topologicalSort();
|
||||
Py::List res;
|
||||
|
||||
|
@ -501,9 +500,6 @@ Py::List DocumentPy::getToplogicalSortedObjects(void) const
|
|||
res.append(Py::Object((*It)->getPyObject(), true));
|
||||
|
||||
return res;
|
||||
#else
|
||||
return Py::List();
|
||||
#endif
|
||||
}
|
||||
|
||||
Py::List DocumentPy::getRootObjects(void) const
|
||||
|
|
Loading…
Reference in New Issue
Block a user