Commit 554760f8 authored by Sonja Happ's avatar Sonja Happ

skip execution of forwad and backward sweep methods for agents thate are already finished

parent 3c797eb2
......@@ -1570,17 +1570,24 @@ void Model::do_backward_sweep() {
IO->log_info("now in backward sweep");
int counter= 0;
uint have_backward_sweeped = 0;
std::vector<bool> state(agents_scheduling.size(), false);
while(!backward_sweep_finished) {
if(have_backward_sweeped < agents_scheduling.size()){
//perform backward sweep for all node agents if not all node agents have finished backward sweeping
int index = 0;
for(auto i : agents_scheduling){ // iterate forward
bool done_something = false;
done_something = i->do_backward_sweep(agent_network_elec);
if(done_something){
have_backward_sweeped++;
}
IO->log_info("Backward sweep for AgentID " + std::to_string(i->getId().id()) + " done_something=" + std::to_string(done_something) + " (iterating forward)");
if(state[index] == false){
state[index] = i->do_backward_sweep(agent_network_elec);
if(state[index]){
have_backward_sweeped++;
}
IO->log_info("Backward sweep for AgentID " + std::to_string(i->getId().id()) + " state=" + std::to_string(state[index]));
} else {
IO->log_info("Skipping AgentID " + std::to_string(i->getId().id()));
}
index++;
}
} else {
IO->log_info("Skipping ...");
......@@ -1623,37 +1630,48 @@ void Model::do_forward_sweep() {
int counter = 0;
bool started_convergence_check = false;
uint checked_convergence = 0;
std::vector<uint> state(agents_scheduling.size(), DONE_NOTHING);
while(!forward_sweep_finished){
if(checked_convergence < agents_scheduling.size()){
if(!started_convergence_check) {
//perform forward sweep for all node agents
for (unsigned long i = agents_scheduling.size(); i > 0; i--) { // iterate backwards...
uint answer = agents_scheduling[i-1]->do_forward_sweep(agent_network_elec);
IO->log_info("Forward sweep for AgentID " + std::to_string(agents_scheduling[i-1]->getId().id()) + "answer=" + std::to_string(answer));
if (answer == DONE_CONVERGENCE_CHECK){
started_convergence_check = true;
checked_convergence++;
} else{
started_convergence_check = false;
if(state[i-1] == DONE_NOTHING){
state[i-1] = agents_scheduling[i-1]->do_forward_sweep(agent_network_elec);
IO->log_info("Forward sweep for AgentID " + std::to_string(agents_scheduling[i-1]->getId().id()) + " state=" + std::to_string(state[i-1]));
if (state[i-1] == DONE_CONVERGENCE_CHECK){
started_convergence_check = true;
checked_convergence++;
} else{
started_convergence_check = false;
}
if (state[i-1] == DONE_NOTHING){
break; // stop iteration if one agent could not complete forward sweep because previous agents have not completed yet
}
} else {
IO->log_info("Skipping AgentID " + std::to_string(agents_scheduling[i-1]->getId().id()));
}
if (answer == DONE_NOTHING){
break; // stop iteration if one agent could not complete forward sweep because previous agents have not completed yet
}
}
}
else{
//perform convergence check for all node agents
int index = 0;
for (auto i : agents_scheduling) { // iterate forward...
uint answer = i->do_forward_sweep(agent_network_elec);
IO->log_info("Convergence check for Agent ID " + std::to_string(i->getId().id()) + " answer="+ std::to_string(answer));
if(answer == DONE_CONVERGENCE_CHECK){
checked_convergence++;
}
if (answer == DONE_NOTHING){
break; // stop iteration if one agent could to nothing because it is likely that the following agents cannot to anything either
if(state[index] == DONE_FORWARD_SWEEP){
state[index] = i->do_forward_sweep(agent_network_elec);
IO->log_info("Convergence check for Agent ID " + std::to_string(i->getId().id()) + " state="+ std::to_string(state[index]));
if(state[index] == DONE_CONVERGENCE_CHECK){
checked_convergence++;
}
if (state[index] == DONE_NOTHING){
break; // stop iteration if one agent could to nothing because it is likely that the following agents cannot to anything either
}
} else {
IO->log_info("Skipping AgentID " + std::to_string(i->getId().id()));
}
}
index++;
}
}
} else {
IO->log_info("Skipping ...");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment