Commit 742619f4 authored by Johannes Leins's avatar Johannes Leins
Browse files

build emigration flows on first activation of population and keep it afterwards

emigration flows of inactive populations are kept (more memory) but runtime does not increase because only active populations are processed on update
parent aa444784
......@@ -424,35 +424,14 @@ void Population::init(Environment* environment, PopulationAtts* atts) {
}
void Population::resetEmigration(Environment *environment) {
if((atts->getDispersalType() != DISPERSAL && atts->getDispersalType() != BOTH) // if no dispersal is active OR
|| vitality == DEAD || vitality == ALIVE) { // if population already was DEAD/ALIVE nothing needs to be done
if(emigrationFlows.size() > 0 || // IF emigration flows were created before
(atts->getDispersalType() != DISPERSAL && atts->getDispersalType() != BOTH) // OR no dispersal is active
|| vitality == DEAD || vitality == ALIVE // OR population already was DEAD/ALIVE nothing needs to be done
)
{
return;
}
if(vitality == DIED) {
vector<Flow*> reducedFlows;
unordered_map<FlowType,vector<Flow*>> reducedFlowsByTyp;
for(auto flow : flows) {
for(auto emFlow : emigrationFlows) {
if(*flow == *emFlow) {
flow->getFrom()->removeOutput(emFlow);
if(emFlow->getTo()) {
flow->getTo()->removeInput(emFlow);
}
break;
}
if(emFlow == emigrationFlows.back()) {
reducedFlows.push_back(flow);
reducedFlowsByTyp[flow->getType()].push_back(flow);
}
}
}
flows = reducedFlows;
flowsByType = reducedFlowsByTyp;
// clear emigration flows
emigrationFlows.clear();
return;
}
// Otherwise the population was revived and the emigration edges need to be constructed
// Otherwise, migration to this population was activated for the first time and the emigration edges need to be constructed
// get neighborhood (full grid) of this population
unordered_map<Point, Population*> neighborhood = environment->getNeighborhood(neighborhoodID);
......
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