-
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.
- Loading branch information
1 parent
964a156
commit b30acc5
Showing
8 changed files
with
251 additions
and
9 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
.../main/java/uk/ac/ox/poseidon/agents/behaviours/destination/NeighbourhoodGridExplorer.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,51 @@ | ||
/* | ||
* 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 ec.util.MersenneTwisterFast; | ||
import lombok.RequiredArgsConstructor; | ||
import sim.util.Int2D; | ||
import uk.ac.ox.poseidon.agents.behaviours.choices.Explorer; | ||
import uk.ac.ox.poseidon.agents.vessels.Vessel; | ||
import uk.ac.ox.poseidon.geography.paths.GridPathFinder; | ||
|
||
import java.util.function.IntSupplier; | ||
|
||
import static uk.ac.ox.poseidon.core.MasonUtils.oneOf; | ||
|
||
@RequiredArgsConstructor | ||
public class NeighbourhoodGridExplorer implements Explorer<Int2D> { | ||
|
||
private final Vessel vessel; | ||
private final GridPathFinder pathFinder; | ||
private final IntSupplier neighbourhoodSizeSupplier; | ||
private final MersenneTwisterFast rng; | ||
|
||
@Override | ||
public Int2D explore(final Int2D currentCell) { | ||
return oneOf( | ||
pathFinder.getAccessibleWaterNeighbours( | ||
currentCell == null ? vessel.getCurrentCell() : currentCell, | ||
neighbourhoodSizeSupplier.getAsInt() | ||
), | ||
rng | ||
); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...ava/uk/ac/ox/poseidon/agents/behaviours/destination/NeighbourhoodGridExplorerFactory.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,55 @@ | ||
/* | ||
* 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 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.paths.GridPathFinder; | ||
|
||
import java.util.function.IntSupplier; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class NeighbourhoodGridExplorerFactory extends VesselScopeFactory<NeighbourhoodGridExplorer> { | ||
|
||
private Factory<? extends GridPathFinder> pathFinder; | ||
private Factory<? extends IntSupplier> neighbourhoodSizeSupplier; | ||
|
||
@Override | ||
protected NeighbourhoodGridExplorer newInstance( | ||
final Simulation simulation, | ||
final Vessel vessel | ||
) { | ||
return new NeighbourhoodGridExplorer( | ||
vessel, | ||
pathFinder.get(simulation), | ||
neighbourhoodSizeSupplier.get(simulation), | ||
simulation.random | ||
); | ||
} | ||
} |
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
43 changes: 43 additions & 0 deletions
43
core/src/main/java/uk/ac/ox/poseidon/core/suppliers/FixedIntSupplierFactory.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,43 @@ | ||
/* | ||
* 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.core.suppliers; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import uk.ac.ox.poseidon.core.GlobalScopeFactory; | ||
import uk.ac.ox.poseidon.core.Simulation; | ||
|
||
import java.util.function.IntSupplier; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class FixedIntSupplierFactory extends GlobalScopeFactory<IntSupplier> { | ||
|
||
private int value; | ||
|
||
@Override | ||
protected IntSupplier newInstance(final Simulation simulation) { | ||
return () -> value; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
core/src/main/java/uk/ac/ox/poseidon/core/suppliers/PoissonIntSupplierFactory.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,45 @@ | ||
/* | ||
* 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.core.suppliers; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import sim.util.distribution.Poisson; | ||
import uk.ac.ox.poseidon.core.Simulation; | ||
import uk.ac.ox.poseidon.core.SimulationScopeFactory; | ||
|
||
import java.util.function.IntSupplier; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class PoissonIntSupplierFactory extends SimulationScopeFactory<IntSupplier> { | ||
|
||
private double mean; | ||
|
||
@Override | ||
protected IntSupplier newInstance(final Simulation simulation) { | ||
final Poisson poisson = new Poisson(mean, simulation.random); | ||
return poisson::nextInt; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
core/src/main/java/uk/ac/ox/poseidon/core/suppliers/ShiftedIntSupplierFactory.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,46 @@ | ||
/* | ||
* 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.core.suppliers; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import uk.ac.ox.poseidon.core.Factory; | ||
import uk.ac.ox.poseidon.core.GlobalScopeFactory; | ||
import uk.ac.ox.poseidon.core.Simulation; | ||
|
||
import java.util.function.IntSupplier; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ShiftedIntSupplierFactory extends GlobalScopeFactory<IntSupplier> { | ||
|
||
private Factory<? extends IntSupplier> intSupplier; | ||
private int shift; | ||
|
||
@Override | ||
protected IntSupplier newInstance(final Simulation simulation) { | ||
final IntSupplier intSupplier = this.intSupplier.get(simulation); | ||
return () -> intSupplier.getAsInt() + shift; | ||
} | ||
} |
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