Skip to content

Commit 42ac771

Browse files
further wip
1 parent 753c87f commit 42ac771

22 files changed

+492
-152
lines changed

agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/fishing/DefaultFishingBehaviourFactory.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public class DefaultFishingBehaviourFactory<C extends Content<C>>
4444
private VesselScopeFactory<? extends FishingGear<C>> fishingGear;
4545
private VesselScopeFactory<? extends Hold<C>> hold;
4646
private VesselScopeFactory<? extends Supplier<Fisheable<C>>> fisheableSupplier;
47-
private BehaviourFactory<?> afterFishingBehaviour;
4847

4948
@Override
5049
protected Fishing<C> newInstance(

agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/fishing/Fishing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public SteppableAction nextAction(
4848
final Vessel vessel,
4949
final LocalDateTime dateTime
5050
) {
51-
return new Action(vessel, dateTime, fishingGear.nextDuration());
51+
return new Action(vessel, dateTime, fishingGear.getDurationSupplier().get());
5252
}
5353

5454
@Getter

agents/src/main/java/uk/ac/ox/poseidon/agents/behaviours/strategy/ThereAndBackBehaviourFactory.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,33 @@
1919

2020
package uk.ac.ox.poseidon.agents.behaviours.strategy;
2121

22-
public class ThereAndBackBehaviourFactory {
22+
import lombok.AllArgsConstructor;
23+
import lombok.Getter;
24+
import lombok.NoArgsConstructor;
25+
import lombok.Setter;
26+
import uk.ac.ox.poseidon.agents.behaviours.BehaviourFactory;
27+
import uk.ac.ox.poseidon.agents.vessels.Vessel;
28+
import uk.ac.ox.poseidon.core.Simulation;
29+
30+
@Getter
31+
@Setter
32+
@NoArgsConstructor
33+
@AllArgsConstructor
34+
public class ThereAndBackBehaviourFactory extends BehaviourFactory<ThereAndBack> {
35+
36+
private BehaviourFactory<?> fishingDestinationBehaviour;
37+
private BehaviourFactory<?> fishingBehaviour;
38+
private BehaviourFactory<?> travellingBehaviour;
39+
40+
@Override
41+
protected ThereAndBack newInstance(
42+
final Simulation simulation,
43+
final Vessel vessel
44+
) {
45+
return new ThereAndBack(
46+
fishingDestinationBehaviour.get(simulation, vessel),
47+
fishingBehaviour.get(simulation, vessel),
48+
travellingBehaviour.get(simulation, vessel)
49+
);
50+
}
2351
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* POSEIDON: an agent-based model of fisheries
3+
* Copyright (c) 2025 CoHESyS Lab [email protected]
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
20+
package uk.ac.ox.poseidon.agents.vessels;
21+
22+
import lombok.AllArgsConstructor;
23+
import lombok.Getter;
24+
import lombok.NoArgsConstructor;
25+
import lombok.Setter;
26+
import uk.ac.ox.poseidon.core.Factory;
27+
import uk.ac.ox.poseidon.core.Simulation;
28+
29+
@Getter
30+
@Setter
31+
@NoArgsConstructor
32+
@AllArgsConstructor
33+
public class VesselScopeFactoryDecorator<C> extends VesselScopeFactory<C> {
34+
private Factory<C> delegate;
35+
36+
@Override
37+
protected C newInstance(
38+
final Simulation simulation,
39+
final Vessel vessel
40+
) {
41+
return delegate.get(simulation);
42+
}
43+
}

agents/src/main/java/uk/ac/ox/poseidon/agents/vessels/gears/FishingGear.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@
2424
import uk.ac.ox.poseidon.biology.Fisheable;
2525

2626
import java.time.Duration;
27+
import java.util.function.Supplier;
2728

2829
public interface FishingGear<C extends Content<C>> {
2930

30-
Duration nextDuration();
31+
Supplier<Duration> getDurationSupplier();
3132

3233
Bucket<C> fish(Fisheable<C> fisheable);
3334

agents/src/main/java/uk/ac/ox/poseidon/agents/vessels/gears/FixedBiomassProportionGear.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,28 @@
1919

2020
package uk.ac.ox.poseidon.agents.vessels.gears;
2121

22+
import lombok.Getter;
2223
import uk.ac.ox.poseidon.biology.Bucket;
2324
import uk.ac.ox.poseidon.biology.Fisheable;
2425
import uk.ac.ox.poseidon.biology.biomass.Biomass;
2526

2627
import java.time.Duration;
28+
import java.util.function.Supplier;
2729

2830
import static uk.ac.ox.poseidon.core.utils.Preconditions.checkUnitRange;
2931

32+
@Getter
3033
public class FixedBiomassProportionGear implements FishingGear<Biomass> {
3134

3235
private final double proportion;
33-
private final Duration duration;
36+
private final Supplier<Duration> durationSupplier;
3437

3538
public FixedBiomassProportionGear(
3639
final double proportion,
37-
final Duration duration
40+
final Supplier<Duration> durationSupplier
3841
) {
3942
this.proportion = checkUnitRange(proportion, "proportion");
40-
this.duration = duration;
41-
}
42-
43-
@Override
44-
public Duration nextDuration() {
45-
return duration;
43+
this.durationSupplier = durationSupplier;
4644
}
4745

4846
@Override

agents/src/main/java/uk/ac/ox/poseidon/agents/vessels/gears/FixedBiomassProportionGearFactory.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,29 @@
2323
import lombok.Getter;
2424
import lombok.NoArgsConstructor;
2525
import lombok.Setter;
26+
import uk.ac.ox.poseidon.agents.vessels.Vessel;
27+
import uk.ac.ox.poseidon.agents.vessels.VesselScopeFactory;
2628
import uk.ac.ox.poseidon.core.Factory;
27-
import uk.ac.ox.poseidon.core.GlobalScopeFactory;
2829
import uk.ac.ox.poseidon.core.Simulation;
2930

3031
import java.time.Duration;
32+
import java.util.function.Supplier;
3133

3234
@Getter
3335
@Setter
3436
@AllArgsConstructor
3537
@NoArgsConstructor
3638
public class FixedBiomassProportionGearFactory
37-
extends GlobalScopeFactory<FixedBiomassProportionGear> {
39+
extends VesselScopeFactory<FixedBiomassProportionGear> {
3840

3941
private double proportion;
40-
private Factory<? extends Duration> duration;
42+
private Factory<? extends Supplier<Duration>> durationSupplier;
4143

4244
@Override
43-
protected FixedBiomassProportionGear newInstance(final Simulation simulation) {
44-
return new FixedBiomassProportionGear(proportion, duration.get(simulation));
45+
protected FixedBiomassProportionGear newInstance(
46+
final Simulation simulation,
47+
final Vessel vessel
48+
) {
49+
return new FixedBiomassProportionGear(proportion, durationSupplier.get(simulation));
4550
}
4651
}

agents/src/main/java/uk/ac/ox/poseidon/agents/vessels/hold/InfiniteHoldFactory.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@
1919

2020
package uk.ac.ox.poseidon.agents.vessels.hold;
2121

22+
import uk.ac.ox.poseidon.agents.vessels.Vessel;
23+
import uk.ac.ox.poseidon.agents.vessels.VesselScopeFactory;
2224
import uk.ac.ox.poseidon.biology.Content;
23-
import uk.ac.ox.poseidon.core.Factory;
2425
import uk.ac.ox.poseidon.core.Simulation;
2526

26-
public class InfiniteHoldFactory<C extends Content<C>> implements Factory<InfiniteHold<C>> {
27+
public class InfiniteHoldFactory<C extends Content<C>> extends VesselScopeFactory<InfiniteHold<C>> {
2728
@Override
28-
public InfiniteHold<C> get(final Simulation simulation) {
29+
protected InfiniteHold<C> newInstance(
30+
final Simulation simulation,
31+
final Vessel vessel
32+
) {
2933
return new InfiniteHold<>();
3034
}
3135
}

agents/src/main/java/uk/ac/ox/poseidon/agents/vessels/hold/VoidHoldFactory.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@
1919

2020
package uk.ac.ox.poseidon.agents.vessels.hold;
2121

22+
import uk.ac.ox.poseidon.agents.vessels.Vessel;
23+
import uk.ac.ox.poseidon.agents.vessels.VesselScopeFactory;
2224
import uk.ac.ox.poseidon.biology.Content;
23-
import uk.ac.ox.poseidon.core.Factory;
2425
import uk.ac.ox.poseidon.core.Simulation;
2526

26-
public class VoidHoldFactory<C extends Content<C>> implements Factory<VoidHold<C>> {
27+
public class VoidHoldFactory<C extends Content<C>> extends VesselScopeFactory<VoidHold<C>> {
2728
@Override
28-
public VoidHold<C> get(final Simulation simulation) {
29+
protected VoidHold<C> newInstance(
30+
final Simulation simulation,
31+
final Vessel vessel
32+
) {
2933
return new VoidHold<>();
3034
}
3135
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* POSEIDON: an agent-based model of fisheries
3+
* Copyright (c) 2024 CoHESyS Lab [email protected]
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
20+
package uk.ac.ox.poseidon.core.suppliers;
21+
22+
import lombok.AllArgsConstructor;
23+
import lombok.Getter;
24+
import lombok.NoArgsConstructor;
25+
import lombok.Setter;
26+
import uk.ac.ox.poseidon.core.GlobalScopeFactory;
27+
import uk.ac.ox.poseidon.core.Simulation;
28+
29+
import java.util.function.BooleanSupplier;
30+
31+
@Getter
32+
@Setter
33+
@NoArgsConstructor
34+
@AllArgsConstructor
35+
public class ConstantBooleanSupplierFactory extends GlobalScopeFactory<BooleanSupplier> {
36+
37+
public static final ConstantBooleanSupplierFactory ALWAYS_TRUE =
38+
new ConstantBooleanSupplierFactory(true);
39+
40+
public static final ConstantBooleanSupplierFactory ALWAYS_FALSE =
41+
new ConstantBooleanSupplierFactory(false);
42+
43+
private boolean value;
44+
45+
@Override
46+
protected BooleanSupplier newInstance(final Simulation simulation) {
47+
return () -> value;
48+
}
49+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* POSEIDON: an agent-based model of fisheries
3+
* Copyright (c) 2025 CoHESyS Lab [email protected]
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
20+
package uk.ac.ox.poseidon.core.suppliers;
21+
22+
import uk.ac.ox.poseidon.core.Factory;
23+
import uk.ac.ox.poseidon.core.time.DurationFactory;
24+
import uk.ac.ox.poseidon.core.utils.ConstantSupplierFactory;
25+
26+
import java.time.Duration;
27+
import java.util.function.Supplier;
28+
29+
public class ConstantDurationSuppliers {
30+
public static final Factory<Supplier<Duration>> ONE_DAY_DURATION_SUPPLIER =
31+
new ConstantSupplierFactory<>(new DurationFactory(1, 0, 0, 0));
32+
public static final Factory<Supplier<Duration>> ONE_HOUR_DURATION_SUPPLIER =
33+
new ConstantSupplierFactory<>(new DurationFactory(1, 0, 0, 0));
34+
}

core/src/main/java/uk/ac/ox/poseidon/core/suppliers/FixedIntSupplierFactory.java renamed to core/src/main/java/uk/ac/ox/poseidon/core/suppliers/ConstantIntSupplierFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
@Setter
3333
@NoArgsConstructor
3434
@AllArgsConstructor
35-
public class FixedIntSupplierFactory extends GlobalScopeFactory<IntSupplier> {
35+
public class ConstantIntSupplierFactory extends GlobalScopeFactory<IntSupplier> {
3636

3737
private int value;
3838

Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* POSEIDON: an agent-based model of fisheries
3-
* Copyright (c) 2024 CoHESyS Lab [email protected]
3+
* Copyright (c) 2025 CoHESyS Lab [email protected]
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU General Public License as published by
@@ -17,21 +17,18 @@
1717
*
1818
*/
1919

20-
package uk.ac.ox.poseidon.core.time;
20+
package uk.ac.ox.poseidon.core.suppliers;
2121

2222
import lombok.RequiredArgsConstructor;
2323

24-
import java.time.Duration;
2524
import java.util.function.Supplier;
2625

2726
@RequiredArgsConstructor
28-
public class DurationSupplier implements Supplier<Duration> {
29-
30-
private final Supplier<Long> secondsSupplier;
27+
public class ConstantSupplier<T> implements Supplier<T> {
28+
private final T value;
3129

3230
@Override
33-
public Duration get() {
34-
return Duration.ofSeconds(secondsSupplier.get());
31+
public T get() {
32+
return null;
3533
}
36-
3734
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* POSEIDON: an agent-based model of fisheries
3+
* Copyright (c) 2025 CoHESyS Lab [email protected]
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
*/
19+
20+
package uk.ac.ox.poseidon.core.suppliers;
21+
22+
import lombok.AllArgsConstructor;
23+
import lombok.Getter;
24+
import lombok.NoArgsConstructor;
25+
import lombok.Setter;
26+
import uk.ac.ox.poseidon.core.Factory;
27+
import uk.ac.ox.poseidon.core.GlobalScopeFactory;
28+
import uk.ac.ox.poseidon.core.Simulation;
29+
30+
@Getter
31+
@Setter
32+
@NoArgsConstructor
33+
@AllArgsConstructor
34+
public class ConstantSupplierFactory<T> extends GlobalScopeFactory<ConstantSupplier<T>> {
35+
36+
private Factory<T> value;
37+
38+
@Override
39+
protected ConstantSupplier<T> newInstance(final Simulation simulation) {
40+
return new ConstantSupplier<>(value.get(simulation));
41+
}
42+
}

0 commit comments

Comments
 (0)