Skip to content

Commit

Permalink
more wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaspayette committed Jan 29, 2025
1 parent 619f377 commit 378bea7
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,25 @@

package uk.ac.ox.poseidon.agents.behaviours;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import uk.ac.ox.poseidon.agents.vessels.Vessel;

import java.time.Duration;
import java.time.LocalDateTime;
import java.util.function.Supplier;

@Getter
@AllArgsConstructor
@RequiredArgsConstructor
public class Waiting implements Behaviour {

private final Supplier<Duration> waitingDurationSupplier;
private final Supplier<Duration> durationSupplier;

@Override
public SteppableAction nextAction(
final Vessel vessel,
final LocalDateTime dateTime
) {
return new Action(vessel, dateTime, waitingDurationSupplier.get());
return new Action(vessel, dateTime, durationSupplier.get());
}

@ToString(callSuper = true)
Expand All @@ -58,5 +56,4 @@ public void complete(final LocalDateTime dateTime) {
getVessel().popBehaviour();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@AllArgsConstructor
public class WaitingBehaviourFactory extends BehaviourFactory<Waiting> {

private Factory<? extends Supplier<Duration>> durationSupplier;
Expand Down
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);
}
}
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();
}
}
}
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));
}
}

0 comments on commit 378bea7

Please sign in to comment.