-
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.
add a standard biomass hold and a proportional discarding strategy
- Loading branch information
1 parent
aa50919
commit ffac9c2
Showing
14 changed files
with
482 additions
and
10 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
39 changes: 39 additions & 0 deletions
39
...s/src/main/java/uk/ac/ox/poseidon/agents/vessels/hold/OvercapacityDiscardingStrategy.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,39 @@ | ||
/* | ||
* 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.vessels.hold; | ||
|
||
import lombok.Data; | ||
import uk.ac.ox.poseidon.biology.Bucket; | ||
import uk.ac.ox.poseidon.biology.Content; | ||
|
||
public interface OvercapacityDiscardingStrategy<C extends Content<C>> { | ||
Result<C> discard( | ||
Bucket<C> contentToAdd, | ||
Bucket<C> currentHoldContent, | ||
double capacityInKg, | ||
double toleranceInKg | ||
); | ||
|
||
@Data | ||
class Result<C extends Content<C>> { | ||
public final Bucket<C> discarded; | ||
public final Bucket<C> updatedHoldContent; | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...ac/ox/poseidon/agents/vessels/hold/ProportionalBiomassOvercapacityDiscardingStrategy.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,54 @@ | ||
/* | ||
* 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.vessels.hold; | ||
|
||
import uk.ac.ox.poseidon.biology.Bucket; | ||
import uk.ac.ox.poseidon.biology.biomass.Biomass; | ||
|
||
public class ProportionalBiomassOvercapacityDiscardingStrategy | ||
implements OvercapacityDiscardingStrategy<Biomass> { | ||
@Override | ||
public Result<Biomass> discard( | ||
final Bucket<Biomass> contentToAdd, | ||
final Bucket<Biomass> currentHoldContent, | ||
final double capacityInKg, | ||
final double toleranceInKg | ||
) { | ||
final double contentToAddInKg = contentToAdd.getTotalBiomass().asKg(); | ||
final double currentContentInKg = currentHoldContent.getTotalBiomass().asKg(); | ||
final double availableCapacityInKg = capacityInKg - currentContentInKg; | ||
if (contentToAddInKg <= availableCapacityInKg) { | ||
return new Result<>( | ||
Bucket.empty(), | ||
currentHoldContent.add(contentToAdd) | ||
); | ||
} else { | ||
final double proportionToKeep = availableCapacityInKg / contentToAddInKg; | ||
final Bucket<Biomass> contentToKeep = | ||
contentToAdd.mapContent(biomass -> | ||
biomass.multiply(proportionToKeep) | ||
); | ||
return new Result<>( | ||
contentToAdd.subtract(contentToKeep), | ||
currentHoldContent.add(contentToKeep) | ||
); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...oseidon/agents/vessels/hold/ProportionalBiomassOvercapacityDiscardingStrategyFactory.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,35 @@ | ||
/* | ||
* 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.vessels.hold; | ||
|
||
import uk.ac.ox.poseidon.agents.vessels.Vessel; | ||
import uk.ac.ox.poseidon.agents.vessels.VesselScopeFactory; | ||
import uk.ac.ox.poseidon.core.Simulation; | ||
|
||
public class ProportionalBiomassOvercapacityDiscardingStrategyFactory | ||
extends VesselScopeFactory<ProportionalBiomassOvercapacityDiscardingStrategy> { | ||
@Override | ||
protected ProportionalBiomassOvercapacityDiscardingStrategy newInstance( | ||
final Simulation simulation, | ||
final Vessel vessel | ||
) { | ||
return new ProportionalBiomassOvercapacityDiscardingStrategy(); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
agents/src/main/java/uk/ac/ox/poseidon/agents/vessels/hold/StandardBiomassHold.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,67 @@ | ||
/* | ||
* 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.vessels.hold; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import uk.ac.ox.poseidon.agents.vessels.hold.OvercapacityDiscardingStrategy.Result; | ||
import uk.ac.ox.poseidon.biology.Bucket; | ||
import uk.ac.ox.poseidon.biology.biomass.Biomass; | ||
|
||
@RequiredArgsConstructor | ||
public class StandardBiomassHold implements Hold<Biomass> { | ||
|
||
private final double capacityInKg; | ||
private final double toleranceInKg; | ||
private final OvercapacityDiscardingStrategy<Biomass> overcapacityDiscardingStrategy; | ||
@Getter | ||
private Bucket<Biomass> content = Bucket.empty(); | ||
|
||
@Override | ||
public Bucket<Biomass> addContent(final Bucket<Biomass> contentToAdd) { | ||
final Bucket<Biomass> newContent = content.add(contentToAdd); | ||
if (newContent.getTotalBiomass().asKg() <= capacityInKg + toleranceInKg) { | ||
content = newContent; | ||
return Bucket.empty(); | ||
} else { | ||
final Result<Biomass> discardingResult = | ||
overcapacityDiscardingStrategy.discard( | ||
contentToAdd, | ||
content, | ||
capacityInKg, | ||
toleranceInKg | ||
); | ||
content = discardingResult.updatedHoldContent; | ||
return discardingResult.discarded; | ||
} | ||
} | ||
|
||
@Override | ||
public boolean isFull() { | ||
return content.getTotalBiomass().asKg() >= capacityInKg - toleranceInKg; | ||
} | ||
|
||
@Override | ||
public Bucket<Biomass> removeContent() { | ||
final Bucket<Biomass> removedContent = content; | ||
content = Bucket.empty(); | ||
return removedContent; | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
agents/src/main/java/uk/ac/ox/poseidon/agents/vessels/hold/StandardBiomassHoldFactory.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,60 @@ | ||
/* | ||
* 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.vessels.hold; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import uk.ac.ox.poseidon.agents.vessels.Vessel; | ||
import uk.ac.ox.poseidon.agents.vessels.VesselScopeFactory; | ||
import uk.ac.ox.poseidon.biology.biomass.Biomass; | ||
import uk.ac.ox.poseidon.core.Factory; | ||
import uk.ac.ox.poseidon.core.Simulation; | ||
|
||
import javax.measure.Quantity; | ||
import javax.measure.quantity.Mass; | ||
|
||
import static javax.measure.MetricPrefix.KILO; | ||
import static tech.units.indriya.unit.Units.GRAM; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class StandardBiomassHoldFactory extends VesselScopeFactory<StandardBiomassHold> { | ||
|
||
private Factory<? extends Quantity<Mass>> capacity; | ||
private Factory<? extends Quantity<Mass>> tolerance; | ||
private VesselScopeFactory<? extends OvercapacityDiscardingStrategy<Biomass>> | ||
overcapacityDiscardingStrategy; | ||
|
||
@Override | ||
protected StandardBiomassHold newInstance( | ||
final Simulation simulation, | ||
final Vessel vessel | ||
) { | ||
return new StandardBiomassHold( | ||
capacity.get(simulation).to(KILO(GRAM)).getValue().doubleValue(), | ||
tolerance.get(simulation).to(KILO(GRAM)).getValue().doubleValue(), | ||
overcapacityDiscardingStrategy.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
Oops, something went wrong.