Add DCP alghoritm, partial working test
This commit is contained in:
49
src/PIM/Dialect/Spatial/DCPGraph/Task.cpp
Normal file
49
src/PIM/Dialect/Spatial/DCPGraph/Task.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <optional>
|
||||
|
||||
#include "Graph.hpp"
|
||||
#include "Task.hpp"
|
||||
#include "Uniqueworklist.hpp"
|
||||
|
||||
std::optional<Edge_t> TaskDCP::addChild(TaskDCP* child, Weight_t weight) {
|
||||
std::optional<Edge_t> oldEdge = std::nullopt;
|
||||
auto founded_element =
|
||||
std::find_if(childs.begin(), childs.end(), [child](Edge_t element) { return child == element.first; });
|
||||
if (founded_element != childs.end()) {
|
||||
oldEdge = *founded_element;
|
||||
fastRemove(childs, founded_element);
|
||||
}
|
||||
childs.emplace_back(child, weight);
|
||||
return oldEdge;
|
||||
}
|
||||
|
||||
std::optional<Edge_t> TaskDCP::addParent(TaskDCP* parent, Weight_t weight) {
|
||||
std::optional<Edge_t> oldEdge = std::nullopt;
|
||||
auto founded_element =
|
||||
std::find_if(parents.begin(), parents.end(), [parent](Edge_t element) { return parent == element.first; });
|
||||
if (founded_element != parents.end()) {
|
||||
oldEdge = *founded_element;
|
||||
fastRemove(parents, founded_element);
|
||||
}
|
||||
parents.emplace_back(parent, weight);
|
||||
return oldEdge;
|
||||
}
|
||||
|
||||
bool TaskDCP::hasDescendent(TaskDCP* child) {
|
||||
UniqueWorkList<std::vector<TaskDCP*>> worklist;
|
||||
worklist.reserve(32);
|
||||
worklist.push_back(this);
|
||||
while (!worklist.empty()) {
|
||||
TaskDCP* task = worklist.back();
|
||||
worklist.pop_back();
|
||||
if (task == child)
|
||||
return true;
|
||||
for (auto c : task->childs)
|
||||
worklist.push_back(c.first);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO fare qualcosa di sensato
|
||||
int TaskDCP::computeWeight(GraphDCP* graph, CPU cpu) {
|
||||
return orig_weight;
|
||||
}
|
||||
Reference in New Issue
Block a user