-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use action override in EPO policy runs
- Loading branch information
1 parent
b8b671b
commit 0a69cf6
Showing
6 changed files
with
135 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,17 @@ | ||
/* | ||
* POSEIDON, an agent-based model of fisheries | ||
* Copyright (C) 2022 CoHESyS Lab [email protected] | ||
* POSEIDON, an agent-based model of fisheries | ||
* Copyright (C) 2024 CoHESyS Lab [email protected] | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* This program is free software: you can redistribute it and/or modify it under the terms of the | ||
* GNU General Public License as published by the Free Software Foundation, either version 3 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with this program. | ||
* If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package uk.ac.ox.oxfish.fisher.purseseiner.planner; | ||
|
@@ -70,7 +66,6 @@ public class PlannedStrategy implements DestinationStrategy, FishingStrategy { | |
// these get activated when we are at location and are performing whatever we said we were going to perform | ||
private Action[] actionQueueInProgress; | ||
private int actionQueueIndex = -1; | ||
|
||
public PlannedStrategy( | ||
final DrawThenCheapestInsertionPlanner planner, | ||
final double planningHorizonInHours, | ||
|
@@ -81,6 +76,10 @@ public PlannedStrategy( | |
this.minimumValueOfSetOnOwnFad = minimumValueOfSetOnOwnFad; | ||
} | ||
|
||
public DrawThenCheapestInsertionPlanner getPlanner() { | ||
return planner; | ||
} | ||
|
||
@Override | ||
public void start( | ||
final FishState model, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
/* | ||
* POSEIDON, an agent-based model of fisheries | ||
* Copyright (C) 2024 CoHESyS Lab [email protected] | ||
* | ||
* This program is free software: you can redistribute it and/or modify it under the terms of the | ||
* GNU General Public License as published by the Free Software Foundation, either version 3 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along with this program. | ||
* If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package uk.ac.ox.oxfish.fisher.purseseiner.planner; | ||
|
||
import ec.util.MersenneTwisterFast; | ||
|
@@ -195,6 +210,10 @@ public PlannedStrategyProxy( | |
this.noaSetsRangeInSeaTiles = noaSetsRangeInSeaTiles; | ||
} | ||
|
||
public PlannedStrategy getDelegate() { | ||
return delegate; | ||
} | ||
|
||
@SuppressWarnings("rawtypes") | ||
@Override | ||
public void start( | ||
|
Submodule epo_inputs
updated
from a365ea to 5b25ae
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,25 +2,30 @@ | |
* POSEIDON, an agent-based model of fisheries | ||
* Copyright (C) 2024 CoHESyS Lab [email protected] | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* This program is free software: you can redistribute it and/or modify it under the terms of the | ||
* GNU General Public License as published by the Free Software Foundation, either version 3 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
* See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* You should have received a copy of the GNU General Public License along with this program. | ||
* If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package uk.ac.ox.poseidon.epo.policies; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import uk.ac.ox.oxfish.experiments.tuna.Policy; | ||
import uk.ac.ox.oxfish.fisher.Fisher; | ||
import uk.ac.ox.oxfish.fisher.purseseiner.planner.ActionType; | ||
import uk.ac.ox.oxfish.fisher.purseseiner.planner.PlannedStrategy; | ||
import uk.ac.ox.oxfish.fisher.purseseiner.planner.PlannedStrategyProxy; | ||
import uk.ac.ox.oxfish.fisher.purseseiner.regulations.ActiveFadLimitsFactory; | ||
import uk.ac.ox.oxfish.model.FishState; | ||
import uk.ac.ox.oxfish.model.StepOrder; | ||
import uk.ac.ox.poseidon.epo.scenarios.EpoScenario; | ||
import uk.ac.ox.poseidon.regulations.core.NamedRegulationsFactory; | ||
|
||
|
@@ -37,14 +42,18 @@ public class ActiveFadLimitsPolicies extends PolicySupplier { | |
private final int referenceYear; | ||
private final List<Double> proportionsOfCurrentLimits; | ||
|
||
private final boolean addActionOverride; | ||
|
||
ActiveFadLimitsPolicies( | ||
final List<Integer> yearsActive, | ||
final int referenceYear, | ||
final List<Double> proportionsOfCurrentLimits | ||
final List<Double> proportionsOfCurrentLimits, | ||
final boolean addActionOverride | ||
) { | ||
super(yearsActive); | ||
this.referenceYear = referenceYear; | ||
this.proportionsOfCurrentLimits = proportionsOfCurrentLimits; | ||
this.addActionOverride = addActionOverride; | ||
} | ||
|
||
@Override | ||
|
@@ -57,27 +66,71 @@ public List<Policy<EpoScenario<?>>> get() { | |
"%02d%% of regular active FAD limits", | ||
(int) (proportion * 100) | ||
), | ||
scenario -> | ||
((NamedRegulationsFactory) scenario.getRegulations()).modify( | ||
"Active-FAD limits", | ||
() -> { | ||
final ImmutableMap<String, Integer> newLimits = ACTIVE_FAD_LIMITS | ||
.get(referenceYear) | ||
.entrySet() | ||
.stream() | ||
.collect(toImmutableMap( | ||
Entry::getKey, | ||
entry -> (int) (entry.getValue() * proportion) | ||
)); | ||
final ImmutableMap.Builder<Integer, Map<String, Integer>> builder = | ||
ImmutableMap.<Integer, Map<String, Integer>>builder() | ||
.putAll(ACTIVE_FAD_LIMITS); | ||
getYearsActive().forEach(year -> builder.put(year, newLimits)); | ||
return new ActiveFadLimitsFactory(builder.buildKeepingLast()); | ||
} | ||
) | ||
scenario -> { | ||
modifyActiveFadsLimit(proportion, scenario); | ||
if (addActionOverride) { | ||
addActionOverride(scenario); | ||
} | ||
} | ||
|
||
) | ||
) | ||
.collect(toImmutableList()); | ||
} | ||
|
||
private void modifyActiveFadsLimit( | ||
final Double proportion, | ||
final EpoScenario<?> scenario | ||
) { | ||
((NamedRegulationsFactory) scenario.getRegulations()).modify( | ||
"Active-FAD limits", | ||
() -> { | ||
final ImmutableMap<String, Integer> newLimits = ACTIVE_FAD_LIMITS | ||
.get(referenceYear) | ||
.entrySet() | ||
.stream() | ||
.collect(toImmutableMap( | ||
Entry::getKey, | ||
entry -> (int) (entry.getValue() * proportion) | ||
)); | ||
final ImmutableMap.Builder<Integer, Map<String, Integer>> builder = | ||
ImmutableMap.<Integer, Map<String, Integer>>builder() | ||
.putAll(ACTIVE_FAD_LIMITS); | ||
getYearsActive().forEach(year -> builder.put(year, newLimits)); | ||
return new ActiveFadLimitsFactory(builder.buildKeepingLast()); | ||
} | ||
); | ||
} | ||
|
||
private void addActionOverride( | ||
final EpoScenario<?> scenario | ||
) { | ||
scenario.getAdditionalStartables().put( | ||
"FAD deployment action override", | ||
// Those lambdas are crazy, but we: | ||
fishState1 -> // create an algorithm factory | ||
fishState2 -> // that creates a startable | ||
fishState2.scheduleOnceInXDays( | ||
simState -> { // that schedules a steppable... | ||
final ImmutableList<ActionType> overrides = | ||
ImmutableList.of(ActionType.DeploymentAction); | ||
((FishState) simState) | ||
.getFishers() | ||
.stream() | ||
.map(Fisher::getDestinationStrategy) | ||
.filter(PlannedStrategyProxy.class::isInstance) | ||
.map(PlannedStrategyProxy.class::cast) | ||
.map(PlannedStrategyProxy::getDelegate) | ||
.map(PlannedStrategy::getPlanner) | ||
// some vessels (mostly dolphin-setters) have zero empirical deployments | ||
// and thus no "plan module" with deployment location preferences, so | ||
// we exclude those from the "deploy as much as possible" variation | ||
.filter(planner -> planner.getPlanModules().containsKey(ActionType.DeploymentAction)) | ||
.forEach(planner -> planner.setActionPreferenceOverrides(overrides)); | ||
}, | ||
StepOrder.DAWN, | ||
(365 * 2) + 1 // Jan. 1st of the third year | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters