Add DCP alghoritm, partial working test

This commit is contained in:
ilgeco
2026-04-07 22:05:39 +02:00
parent ef4743c986
commit ca56e3d4f1
17 changed files with 1313 additions and 33 deletions

View 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;
}