|
@@ -40,20 +40,34 @@ namespace mdd {
|
|
state ProcessorStandard::update() {
|
|
state ProcessorStandard::update() {
|
|
if (priorityEvaluation != MANUAL)
|
|
if (priorityEvaluation != MANUAL)
|
|
{
|
|
{
|
|
- //sort by connections
|
|
|
|
|
|
+ //update priorities
|
|
for (auto it = _priority_list.begin(); it != _priority_list.end(); ++it) {
|
|
for (auto it = _priority_list.begin(); it != _priority_list.end(); ++it) {
|
|
- auto connections = it->module_ptr->getConnections();
|
|
|
|
- it->connectionCounter = 0;
|
|
|
|
- for (auto it_c = connections.begin(); it_c != connections.end(); ++it_c) {
|
|
|
|
|
|
+ //collect connected inputs
|
|
|
|
+ auto input_connections = it->module_ptr->getInputConnections();
|
|
|
|
+ it->inputCounter = 0;
|
|
|
|
+ for (auto it_c = input_connections.begin(); it_c != input_connections.end(); ++it_c) {
|
|
if ((*it_c) != nullptr)
|
|
if ((*it_c) != nullptr)
|
|
{
|
|
{
|
|
- ++(it->connectionCounter);
|
|
|
|
|
|
+ ++(it->inputCounter);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //collect connected outputs
|
|
|
|
+ auto output_connections = it->module_ptr->getOutputConnections();
|
|
|
|
+ it->outputCounter = 0;
|
|
|
|
+ for (auto it_c = output_connections.begin(); it_c != output_connections.end(); ++it_c) {
|
|
|
|
+ if (!(*it_c).empty())
|
|
|
|
+ {
|
|
|
|
+ ++(it->outputCounter);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//sort by connections
|
|
//sort by connections
|
|
std::sort(_priority_list.begin(), _priority_list.end(), [](module_priority a, module_priority b) {
|
|
std::sort(_priority_list.begin(), _priority_list.end(), [](module_priority a, module_priority b) {
|
|
- return a.connectionCounter < b.connectionCounter;
|
|
|
|
|
|
+ if (a.inputCounter == b.inputCounter)
|
|
|
|
+ {
|
|
|
|
+ return a.outputCounter > b.outputCounter;
|
|
|
|
+ }
|
|
|
|
+ return a.inputCounter < b.inputCounter;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
@@ -61,21 +75,30 @@ namespace mdd {
|
|
//update
|
|
//update
|
|
state ret = state::UNCHANGED;
|
|
state ret = state::UNCHANGED;
|
|
state group_state = state::CHANGED;
|
|
state group_state = state::CHANGED;
|
|
|
|
+ size_t restart = 0;
|
|
while (group_state == state::CHANGED) {
|
|
while (group_state == state::CHANGED) {
|
|
getProcessorOutput(0)->getValueInternal()["value"] = getProcessorOutput(0)->getValue()["value"].get<int>() + 1;
|
|
getProcessorOutput(0)->getValueInternal()["value"] = getProcessorOutput(0)->getValue()["value"].get<int>() + 1;
|
|
group_state = state::UNCHANGED;
|
|
group_state = state::UNCHANGED;
|
|
- for (int i = 0; i < _priority_list.size(); ++i) {
|
|
|
|
|
|
+ for (int i = restart; i < _priority_list.size(); ++i) {
|
|
auto t_start = Time::now();
|
|
auto t_start = Time::now();
|
|
state module_state = _priority_list[i].module_ptr->update();
|
|
state module_state = _priority_list[i].module_ptr->update();
|
|
auto t_end = Time::now();
|
|
auto t_end = Time::now();
|
|
- _priority_list[i].runtime = std::chrono::duration_cast<std::chrono::milliseconds>(t_end - t_start);
|
|
|
|
|
|
+ if (priorityEvaluation == TIME)
|
|
|
|
+ {
|
|
|
|
+ _priority_list[i].time_priority = std::round(std::log10(std::chrono::duration_cast<std::chrono::milliseconds>(t_end - t_start).count()));
|
|
|
|
+ }
|
|
if (module_state == state::CHANGED) {
|
|
if (module_state == state::CHANGED) {
|
|
group_state = state::CHANGED;
|
|
group_state = state::CHANGED;
|
|
ret = state::CHANGED;
|
|
ret = state::CHANGED;
|
|
}
|
|
}
|
|
- if (priorityEvaluation == DYNAMIC || priorityEvaluation == TIME) {
|
|
|
|
- if (_priority_list[i + 1].connectionCounter == _priority_list[i].connectionCounter)
|
|
|
|
|
|
+ // ignore modules which have to initilize once in the future
|
|
|
|
+ if (_priority_list[i].inputCounter == 0 && priorityEvaluation != MANUAL) {
|
|
|
|
+ restart = i;
|
|
|
|
+ }
|
|
|
|
+ if ((priorityEvaluation == DYNAMIC || priorityEvaluation == TIME) && _priority_list.size() < i+1) {
|
|
|
|
+ if (_priority_list[i + 1].inputCounter == _priority_list[i].inputCounter && _priority_list[i + 1].inputCounter != 0)
|
|
{
|
|
{
|
|
|
|
+ //collect changes
|
|
for (auto it = _priority_list.begin() + i + 1; it != _priority_list.end(); ++it) {
|
|
for (auto it = _priority_list.begin() + i + 1; it != _priority_list.end(); ++it) {
|
|
auto input_states = it->module_ptr->getInputStates();
|
|
auto input_states = it->module_ptr->getInputStates();
|
|
it->changeCounter = 0;
|
|
it->changeCounter = 0;
|
|
@@ -87,10 +110,24 @@ namespace mdd {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
std::sort(_priority_list.begin() + i + 1, _priority_list.end(), [](module_priority a, module_priority b) {
|
|
std::sort(_priority_list.begin() + i + 1, _priority_list.end(), [](module_priority a, module_priority b) {
|
|
- return (a.connectionCounter - a.changeCounter) < (b.connectionCounter - b.changeCounter);
|
|
|
|
|
|
+ if (a.inputCounter == b.inputCounter)
|
|
|
|
+ {
|
|
|
|
+ if (a.time_priority == b.time_priority)
|
|
|
|
+ {
|
|
|
|
+ if ((a.inputCounter - a.changeCounter) == (b.inputCounter - b.changeCounter)) {
|
|
|
|
+ if (a.changeCounter == b.changeCounter) {
|
|
|
|
+ return a.outputCounter > b.outputCounter;
|
|
|
|
+ }
|
|
|
|
+ return a.changeCounter > b.changeCounter;
|
|
|
|
+ }
|
|
|
|
+ return (a.inputCounter - a.changeCounter) < (b.inputCounter - b.changeCounter);
|
|
|
|
+ }
|
|
|
|
+ return a.time_priority < b.time_priority;
|
|
|
|
+ }
|
|
|
|
+ return a.inputCounter < b.inputCounter;
|
|
|
|
+
|
|
});
|
|
});
|
|
}
|
|
}
|
|
- //optimize by computational time
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if (maxIterations != -1 && getProcessorOutput(0)->getValueInternal()["value"].get<int>() >= maxIterations)
|
|
if (maxIterations != -1 && getProcessorOutput(0)->getValueInternal()["value"].get<int>() >= maxIterations)
|
|
@@ -104,10 +141,12 @@ namespace mdd {
|
|
std::shared_ptr<IOutput> ProcessorStandard::getIteration(){
|
|
std::shared_ptr<IOutput> ProcessorStandard::getIteration(){
|
|
return getProcessorOutput(0);
|
|
return getProcessorOutput(0);
|
|
}
|
|
}
|
|
- ProcessorStandard::module_priority::module_priority(std::shared_ptr<IModule> module, size_t connection, size_t change)
|
|
|
|
|
|
+ ProcessorStandard::module_priority::module_priority(std::shared_ptr<IModule> module, size_t inputs, size_t outputs, size_t change)
|
|
{
|
|
{
|
|
module_ptr = module;
|
|
module_ptr = module;
|
|
- connectionCounter = connection;
|
|
|
|
|
|
+ inputCounter = inputs;
|
|
|
|
+ outputCounter = outputs;
|
|
changeCounter = change;
|
|
changeCounter = change;
|
|
|
|
+ time_priority = 0;
|
|
}
|
|
}
|
|
}
|
|
}
|