-
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.
flesh out epsilon-greedy destination supplier
and lots of things around it, notably the idea of Evaluator and Evaluation objects to generate values for possible choices
- Loading branch information
1 parent
bba9fb2
commit 0ecd426
Showing
20 changed files
with
471 additions
and
42 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...c/main/java/uk/ac/ox/poseidon/agents/behaviours/choices/AveragingOptionValuesFactory.java
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 |
---|---|---|
@@ -0,0 +1,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 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.poseidon.agents.behaviours.choices; | ||
|
||
import uk.ac.ox.poseidon.core.Factory; | ||
import uk.ac.ox.poseidon.core.Simulation; | ||
|
||
public class AveragingOptionValuesFactory<O> implements Factory<OptionValues<O>> { | ||
@Override | ||
public OptionValues<O> get(final Simulation simulation) { | ||
return new AveragingOptionValues<>(); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/choices/Evaluation.java
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* 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.poseidon.agents.behaviours.choices; | ||
|
||
@FunctionalInterface | ||
public interface Evaluation { | ||
double getResult(); | ||
} |
24 changes: 24 additions & 0 deletions
24
agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/choices/Evaluator.java
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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.poseidon.agents.behaviours.choices; | ||
|
||
public interface Evaluator<O> { | ||
Evaluation newEvaluation(O option); | ||
} |
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
64 changes: 64 additions & 0 deletions
64
...ac/ox/poseidon/agents/behaviours/destination/EpsilonGreedyDestinationSupplierFactory.java
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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.poseidon.agents.behaviours.destination; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import sim.util.Int2D; | ||
import uk.ac.ox.poseidon.agents.behaviours.choices.EpsilonGreedyChooser; | ||
import uk.ac.ox.poseidon.agents.behaviours.choices.Evaluator; | ||
import uk.ac.ox.poseidon.agents.behaviours.choices.OptionValues; | ||
import uk.ac.ox.poseidon.agents.vessels.Vessel; | ||
import uk.ac.ox.poseidon.agents.vessels.VesselScopeFactory; | ||
import uk.ac.ox.poseidon.core.Factory; | ||
import uk.ac.ox.poseidon.core.Simulation; | ||
import uk.ac.ox.poseidon.geography.bathymetry.BathymetricGrid; | ||
import uk.ac.ox.poseidon.geography.paths.PathFinder; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class EpsilonGreedyDestinationSupplierFactory extends VesselScopeFactory<DestinationSupplier> { | ||
|
||
private double epsilon; | ||
private Factory<? extends BathymetricGrid> bathymetricGrid; | ||
private Factory<? extends PathFinder<Int2D>> pathFinder; | ||
private Factory<? extends OptionValues<Int2D>> optionValues; | ||
private VesselScopeFactory<? extends Evaluator<Int2D>> destinationEvaluator; | ||
|
||
@Override | ||
protected DestinationSupplier newInstance( | ||
final Simulation simulation, | ||
final Vessel vessel | ||
) { | ||
return new EpsilonGreedyChooser<>( | ||
epsilon, | ||
bathymetricGrid | ||
.get(simulation) | ||
.getAccessibleCells(vessel.getCurrentCell(), pathFinder.get(simulation)), | ||
optionValues.get(simulation), | ||
destinationEvaluator.get(simulation, vessel), | ||
simulation.random | ||
)::get; | ||
} | ||
} |
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
68 changes: 68 additions & 0 deletions
68
...n/agents/behaviours/destination/TotalBiomassCaughtPerHourDestinationEvaluatorFactory.java
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* 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.poseidon.agents.behaviours.destination; | ||
|
||
import sim.util.Int2D; | ||
import uk.ac.ox.poseidon.agents.behaviours.Action; | ||
import uk.ac.ox.poseidon.agents.behaviours.choices.Evaluator; | ||
import uk.ac.ox.poseidon.agents.behaviours.fishing.FishingAction; | ||
import uk.ac.ox.poseidon.agents.vessels.Vessel; | ||
import uk.ac.ox.poseidon.agents.vessels.VesselScopeFactory; | ||
import uk.ac.ox.poseidon.core.Simulation; | ||
import uk.ac.ox.poseidon.core.events.CombiningEphemeralAccumulatingListener; | ||
|
||
public class TotalBiomassCaughtPerHourDestinationEvaluatorFactory | ||
extends VesselScopeFactory<Evaluator<Int2D>> { | ||
|
||
@Override | ||
protected Evaluator<Int2D> newInstance( | ||
final Simulation simulation, | ||
final Vessel vessel | ||
) { | ||
return option -> new Evaluation(vessel); | ||
} | ||
|
||
private static class Evaluation implements uk.ac.ox.poseidon.agents.behaviours.choices.Evaluation { | ||
|
||
private final CombiningEphemeralAccumulatingListener | ||
<FishingAction, Double, Action, Double, Double> listener; | ||
|
||
private Evaluation(final Vessel vessel) { | ||
listener = new CombiningEphemeralAccumulatingListener<>( | ||
vessel.getEventManager(), | ||
FishingAction.class, | ||
0.0, | ||
(caughtSoFar, fishingAction) -> caughtSoFar + fishingAction.getTotalBiomassCaught(), | ||
Action.class, | ||
0.0, | ||
(hoursSoFar, action) -> | ||
vessel.isAtPort() | ||
? hoursSoFar | ||
: hoursSoFar + action.getDuration().getSeconds() / 3600.0, | ||
(caught, hours) -> caught / hours | ||
); | ||
} | ||
|
||
@Override | ||
public double getResult() { | ||
return listener.get(); | ||
} | ||
} | ||
} |
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
39 changes: 39 additions & 0 deletions
39
agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/fishing/FishingAction.java
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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.poseidon.agents.behaviours.fishing; | ||
|
||
import uk.ac.ox.poseidon.agents.behaviours.Action; | ||
import uk.ac.ox.poseidon.agents.vessels.Vessel; | ||
|
||
import java.time.Duration; | ||
import java.time.LocalDateTime; | ||
|
||
public abstract class FishingAction extends Action { | ||
|
||
public FishingAction( | ||
final LocalDateTime start, | ||
final Duration duration, | ||
final Vessel vessel | ||
) { | ||
super(start, duration, vessel); | ||
} | ||
|
||
public abstract double getTotalBiomassCaught(); | ||
} |
Oops, something went wrong.