-
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.
yep more wip on Behaviour refactoring (getting there, though)
- Loading branch information
1 parent
378bea7
commit 753c87f
Showing
27 changed files
with
602 additions
and
68 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/BranchingBehaviour.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,52 @@ | ||
/* | ||
* POSEIDON: an agent-based model of fisheries | ||
* Copyright (c) 2025 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; | ||
|
||
import uk.ac.ox.poseidon.agents.vessels.Vessel; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.Optional; | ||
|
||
public abstract class BranchingBehaviour implements Behaviour { | ||
@Override | ||
public final SteppableAction nextAction( | ||
final Vessel vessel, | ||
final LocalDateTime dateTime | ||
) { | ||
return Optional | ||
.ofNullable(nextBehaviour(vessel, dateTime)) | ||
.map(behaviour -> { | ||
vessel.pushBehaviour(behaviour); | ||
return behaviour.nextAction(vessel, dateTime); | ||
}) | ||
.or(() -> { | ||
vessel.popBehaviour(); | ||
return Optional | ||
.ofNullable(vessel.currentBehaviour()) | ||
.map(behaviour -> behaviour.nextAction(vessel, dateTime)); | ||
}) | ||
.orElse(null); | ||
} | ||
|
||
protected abstract Behaviour nextBehaviour( | ||
final Vessel vessel, | ||
final LocalDateTime dateTime | ||
); | ||
} |
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
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
65 changes: 65 additions & 0 deletions
65
agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/port/HomeBehaviourFactory.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,65 @@ | ||
/* | ||
* POSEIDON: an agent-based model of fisheries | ||
* Copyright (c) 2025 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.port; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import uk.ac.ox.poseidon.agents.behaviours.BehaviourFactory; | ||
import uk.ac.ox.poseidon.agents.vessels.Vessel; | ||
import uk.ac.ox.poseidon.agents.vessels.VesselScopeFactory; | ||
import uk.ac.ox.poseidon.agents.vessels.hold.Hold; | ||
import uk.ac.ox.poseidon.core.Factory; | ||
import uk.ac.ox.poseidon.core.Simulation; | ||
import uk.ac.ox.poseidon.geography.ports.PortGrid; | ||
|
||
import java.util.function.BooleanSupplier; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class HomeBehaviourFactory extends BehaviourFactory<Home> { | ||
|
||
private Factory<? extends PortGrid> portGrid; | ||
private VesselScopeFactory<? extends Hold<?>> hold; | ||
private VesselScopeFactory<? extends BooleanSupplier> readinessSupplier; | ||
private BehaviourFactory<?> travelBehaviour; | ||
private BehaviourFactory<?> landingBehaviour; | ||
private BehaviourFactory<?> behaviourIfReady; | ||
private BehaviourFactory<?> behaviourIfNotReady; | ||
|
||
@Override | ||
protected Home newInstance( | ||
final Simulation simulation, | ||
final Vessel vessel | ||
) { | ||
return new Home( | ||
portGrid.get(simulation), | ||
hold.get(simulation, vessel), | ||
readinessSupplier.get(simulation, vessel), | ||
travelBehaviour.get(simulation, vessel), | ||
landingBehaviour.get(simulation, vessel), | ||
behaviourIfReady.get(simulation, vessel), | ||
behaviourIfNotReady.get(simulation, vessel) | ||
); | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/strategy/ThereAndBack.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) 2025 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.strategy; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import uk.ac.ox.poseidon.agents.behaviours.Behaviour; | ||
import uk.ac.ox.poseidon.agents.behaviours.BranchingBehaviour; | ||
import uk.ac.ox.poseidon.agents.vessels.Vessel; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@RequiredArgsConstructor | ||
public class ThereAndBack extends BranchingBehaviour { | ||
|
||
private final Behaviour fishingDestinationBehaviour; | ||
private final Behaviour fishingBehaviour; | ||
private final Behaviour travellingBehaviour; | ||
|
||
private boolean done = false; | ||
|
||
@Override | ||
protected Behaviour nextBehaviour( | ||
final Vessel vessel, | ||
final LocalDateTime dateTime | ||
) { | ||
if (done) { | ||
return null; | ||
} else if (vessel.isAtPort()) { | ||
return fishingDestinationBehaviour; | ||
} else if (vessel.isAtCurrentDestination()) { | ||
done = true; | ||
return fishingBehaviour; | ||
} else { | ||
return travellingBehaviour; | ||
} | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
.../main/java/uk/ac/ox/poseidon/agents/behaviours/strategy/ThereAndBackBehaviourFactory.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,23 @@ | ||
/* | ||
* POSEIDON: an agent-based model of fisheries | ||
* Copyright (c) 2025 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.strategy; | ||
|
||
public class ThereAndBackBehaviourFactory { | ||
} |
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
Oops, something went wrong.