Skip to content
Snippets Groups Projects
Commit bea47f03 authored by Martin Hanzik's avatar Martin Hanzik Committed by Jan Trávníček
Browse files

Fixes

parent cc83a1e5
No related branches found
No related tags found
No related merge requests found
...@@ -12,32 +12,18 @@ ...@@ -12,32 +12,18 @@
   
std::shared_ptr<abstraction::OperationAbstraction> ParallelExecutor::execute(OutputModelBox* output) { std::shared_ptr<abstraction::OperationAbstraction> ParallelExecutor::execute(OutputModelBox* output) {
   
for (auto* box: ModelBox::getAllModelBoxes()) { const std::vector<ModelBox*>& boxes = ModelBox::getAllModelBoxes();
box->id = static_cast<size_t>(-1);
box->level = static_cast<size_t>(-1);
box->clearCachedResult();
}
// collect all boxes leading to the output box
std::vector<ModelBox*> boxes;
boxes.push_back(output);
   
for (size_t i = 0; i < boxes.size(); ++i) { for (size_t i = 0; i < boxes.size(); ++i) {
ModelBox* box = boxes[i]; auto* box = boxes[i];
if (box->id != static_cast<size_t>(-1)) { for (auto* input: box->inputs) {
// cycle detected if (!input) {
throw exception::CommonException { "Connection graph contains a cycle." };
}
box->id = i;
for (auto* b: box->inputs) {
if (!b) {
// unconnected input
// TODO check this earlier
throw exception::CommonException { "Connection graph contains an unconnected input." }; throw exception::CommonException { "Connection graph contains an unconnected input." };
} }
boxes.push_back(b);
} }
box->id = i;
box->level = static_cast<size_t>(-1);
box->clearCachedResult();
} }
   
std::vector<std::vector<size_t>> M; std::vector<std::vector<size_t>> M;
...@@ -50,6 +36,9 @@ std::shared_ptr<abstraction::OperationAbstraction> ParallelExecutor::execute(Out ...@@ -50,6 +36,9 @@ std::shared_ptr<abstraction::OperationAbstraction> ParallelExecutor::execute(Out
for (size_t i = 0; i < N; ++i) { for (size_t i = 0; i < N; ++i) {
ModelBox* b = boxes[i]; ModelBox* b = boxes[i];
for (const auto& neighbour: b->outputs) { for (const auto& neighbour: b->outputs) {
if (b == neighbour.first) {
throw exception::CommonException { "Connection graph contains a loop." };
}
M[b->id][neighbour.first->id] = 1; M[b->id][neighbour.first->id] = 1;
} }
} }
...@@ -122,7 +111,9 @@ std::shared_ptr<abstraction::OperationAbstraction> ParallelExecutor::execute(Out ...@@ -122,7 +111,9 @@ std::shared_ptr<abstraction::OperationAbstraction> ParallelExecutor::execute(Out
   
for (size_t i = 0; i < N; ++i) { for (size_t i = 0; i < N; ++i) {
for (size_t j = 0; j < N; ++j) { for (size_t j = 0; j < N; ++j) {
Q_ASSERT(!M[i][j]); if (M[i][j]) {
throw exception::CommonException { "Connection graph contains a cycle." };
}
} }
} }
   
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment