-
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.
wip on behaviour classes refactoring
- Loading branch information
1 parent
ed4ae35
commit 619f377
Showing
38 changed files
with
501 additions
and
20,820 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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/AbstractAction.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,53 @@ | ||
/* | ||
* 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 edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import lombok.Data; | ||
import uk.ac.ox.poseidon.agents.vessels.Vessel; | ||
|
||
import java.time.Duration; | ||
import java.time.LocalDateTime; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
@Data | ||
public abstract class AbstractAction implements Action { | ||
protected final Vessel vessel; | ||
protected final LocalDateTime start; | ||
protected final Duration duration; | ||
|
||
@SuppressFBWarnings("EI_EXPOSE_REP2") | ||
public AbstractAction( | ||
final Vessel vessel, | ||
final LocalDateTime start, | ||
final Duration duration | ||
) { | ||
checkArgument( | ||
duration.isPositive(), | ||
"Duration must be positive but was %s.", | ||
duration | ||
); | ||
this.start = checkNotNull(start); | ||
this.duration = checkNotNull(duration); | ||
this.vessel = checkNotNull(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* | ||
* POSEIDON: an agent-based model of fisheries | ||
* Copyright (c) 2024 CoHESyS Lab [email protected] | ||
* 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 | ||
|
@@ -19,59 +19,20 @@ | |
|
||
package uk.ac.ox.poseidon.agents.behaviours; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import lombok.Data; | ||
import sim.engine.SimState; | ||
import sim.engine.Steppable; | ||
import uk.ac.ox.poseidon.agents.vessels.Vessel; | ||
import uk.ac.ox.poseidon.core.schedule.TemporalSchedule; | ||
|
||
import java.time.Duration; | ||
import java.time.LocalDateTime; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.base.Preconditions.checkNotNull; | ||
public interface Action { | ||
|
||
@Data | ||
public abstract class Action implements Steppable { | ||
|
||
private final LocalDateTime start; | ||
private final Duration duration; | ||
private final Vessel vessel; | ||
|
||
@SuppressFBWarnings("EI_EXPOSE_REP2") | ||
public Action( | ||
final LocalDateTime start, | ||
final Duration duration, | ||
final Vessel vessel | ||
) { | ||
checkArgument( | ||
duration.isPositive(), | ||
"Duration must be positive but was %s.", | ||
duration | ||
); | ||
this.start = checkNotNull(start); | ||
this.duration = checkNotNull(duration); | ||
this.vessel = checkNotNull(vessel); | ||
default LocalDateTime getEnd() { | ||
return getStart().plus(getDuration()); | ||
} | ||
|
||
@Override | ||
public final void step(final SimState simState) { | ||
checkArgument(simState.schedule instanceof TemporalSchedule); | ||
final var schedule = (TemporalSchedule) simState.schedule; | ||
final var nextAction = complete(schedule.getDateTime()); | ||
vessel.getEventManager().broadcast(this); | ||
if (nextAction != null) { | ||
schedule.scheduleOnceIn(nextAction.getDuration(), nextAction); | ||
} | ||
} | ||
Vessel getVessel(); | ||
|
||
protected abstract Action complete( | ||
LocalDateTime dateTime | ||
); | ||
|
||
public LocalDateTime getEnd() { | ||
return start.plus(duration); | ||
} | ||
LocalDateTime getStart(); | ||
|
||
Duration getDuration(); | ||
} |
34 changes: 0 additions & 34 deletions
34
agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/BackToInitialBehaviourFactory.java
This file was deleted.
Oops, something went wrong.
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
34 changes: 0 additions & 34 deletions
34
agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/DoNothingBehaviour.java
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/DoNothingBehaviourFactory.java
This file was deleted.
Oops, something went wrong.
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,6 +1,6 @@ | ||
/* | ||
* POSEIDON: an agent-based model of fisheries | ||
* Copyright (c) 2024 CoHESyS Lab [email protected] | ||
* 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 | ||
|
@@ -19,29 +19,8 @@ | |
|
||
package uk.ac.ox.poseidon.agents.behaviours; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import lombok.Getter; | ||
import sim.util.Int2D; | ||
import uk.ac.ox.poseidon.agents.vessels.Vessel; | ||
|
||
import java.time.Duration; | ||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
public abstract class GridAction extends Action { | ||
private final Int2D cell; | ||
|
||
@SuppressFBWarnings( | ||
value = "EI2", | ||
justification = "Int2D is immutable even if SpotBugs thinks otherwise." | ||
) | ||
public GridAction( | ||
final LocalDateTime start, | ||
final Duration duration, | ||
final Vessel vessel, | ||
final Int2D cell | ||
) { | ||
super(start, duration, vessel); | ||
this.cell = cell; | ||
} | ||
public interface GridAction extends Action { | ||
Int2D getCell(); | ||
} |
57 changes: 57 additions & 0 deletions
57
agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/SteppableAction.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,57 @@ | ||
/* | ||
* 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; | ||
|
||
import sim.engine.SimState; | ||
import sim.engine.Steppable; | ||
import uk.ac.ox.poseidon.agents.vessels.Vessel; | ||
import uk.ac.ox.poseidon.core.schedule.TemporalSchedule; | ||
|
||
import java.time.Duration; | ||
import java.time.LocalDateTime; | ||
|
||
public abstract class SteppableAction extends AbstractAction implements Steppable { | ||
|
||
public SteppableAction( | ||
final Vessel vessel, | ||
final LocalDateTime start, | ||
final Duration duration | ||
) { | ||
super(vessel, start, duration); | ||
} | ||
|
||
public void init() {} | ||
|
||
protected abstract void complete( | ||
LocalDateTime dateTime | ||
); | ||
|
||
@Override | ||
public final void step(final SimState simState) { | ||
if (simState.schedule instanceof final TemporalSchedule schedule) { | ||
complete(schedule.getDateTime()); | ||
vessel.getEventManager().broadcast(this); | ||
vessel.scheduleNextAction(schedule); | ||
} else throw new IllegalStateException( | ||
"Simulation schedule type must be " + TemporalSchedule.class.getName() | ||
); | ||
} | ||
|
||
} |
Oops, something went wrong.