-
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
619f377
commit 378bea7
Showing
5 changed files
with
174 additions
and
8 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
58 changes: 58 additions & 0 deletions
58
agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/port/AtPort.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,58 @@ | ||
/* | ||
* 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.RequiredArgsConstructor; | ||
import uk.ac.ox.poseidon.agents.behaviours.Behaviour; | ||
import uk.ac.ox.poseidon.agents.behaviours.SteppableAction; | ||
import uk.ac.ox.poseidon.agents.vessels.Vessel; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.function.BooleanSupplier; | ||
|
||
import static com.google.common.base.Preconditions.checkState; | ||
|
||
@RequiredArgsConstructor | ||
public class AtPort implements Behaviour { | ||
|
||
// TODO: handle hold emptying | ||
|
||
private final BooleanSupplier isReady; | ||
private final Behaviour dockingBehaviour; | ||
private final Behaviour behaviourIfReady; | ||
private final Behaviour behaviourIfNotReady; | ||
|
||
@Override | ||
public SteppableAction nextAction( | ||
final Vessel vessel, | ||
final LocalDateTime dateTime | ||
) { | ||
checkState(vessel.isAtPort()); | ||
final Behaviour nextBehaviour; | ||
if (vessel.getCurrentDestination() != null) | ||
nextBehaviour = dockingBehaviour; | ||
else if (isReady.getAsBoolean()) | ||
nextBehaviour = behaviourIfReady; | ||
else | ||
nextBehaviour = behaviourIfNotReady; | ||
vessel.pushBehaviour(nextBehaviour); | ||
return nextBehaviour.nextAction(vessel, dateTime); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/port/Docking.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,62 @@ | ||
/* | ||
* 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.RequiredArgsConstructor; | ||
import lombok.ToString; | ||
import uk.ac.ox.poseidon.agents.behaviours.Behaviour; | ||
import uk.ac.ox.poseidon.agents.behaviours.SteppableAction; | ||
import uk.ac.ox.poseidon.agents.vessels.Vessel; | ||
|
||
import java.time.Duration; | ||
import java.time.LocalDateTime; | ||
import java.util.function.Supplier; | ||
|
||
@RequiredArgsConstructor | ||
public class Docking implements Behaviour { | ||
|
||
private final Supplier<Duration> durationSupplier; | ||
|
||
@Override | ||
public SteppableAction nextAction( | ||
final Vessel vessel, | ||
final LocalDateTime dateTime | ||
) { | ||
return new Action(vessel, dateTime, durationSupplier.get()); | ||
} | ||
|
||
@ToString(callSuper = true) | ||
private static class Action extends SteppableAction { | ||
|
||
private Action( | ||
final Vessel vessel, | ||
final LocalDateTime start, | ||
final Duration duration | ||
) { | ||
super(vessel, start, duration); | ||
} | ||
|
||
@Override | ||
public void complete(final LocalDateTime dateTime) { | ||
getVessel().setCurrentDestination(null); | ||
getVessel().popBehaviour(); | ||
} | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/port/DockingBehaviourFactory.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,49 @@ | ||
/* | ||
* 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.core.Factory; | ||
import uk.ac.ox.poseidon.core.Simulation; | ||
|
||
import java.time.Duration; | ||
import java.util.function.Supplier; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class DockingBehaviourFactory extends BehaviourFactory<Docking> { | ||
|
||
private Factory<? extends Supplier<Duration>> durationSupplier; | ||
|
||
@Override | ||
protected Docking newInstance( | ||
final Simulation simulation, | ||
final Vessel vessel | ||
) { | ||
return new Docking(durationSupplier.get(simulation)); | ||
} | ||
} |