-
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 predicate operators for regulations
- Loading branch information
1 parent
98535b5
commit bf1f0df
Showing
15 changed files
with
940 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
agents/src/main/java/uk/ac/ox/poseidon/agents/regulations/PermittedIf.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,36 @@ | ||
/* | ||
* 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.regulations; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import uk.ac.ox.poseidon.agents.behaviours.Action; | ||
|
||
import java.util.function.Predicate; | ||
|
||
@RequiredArgsConstructor | ||
public class PermittedIf implements Regulations { | ||
|
||
private final Predicate<Action> actionPredicate; | ||
|
||
@Override | ||
public boolean isPermitted(final Action action) { | ||
return actionPredicate.test(action); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
agents/src/main/java/uk/ac/ox/poseidon/agents/regulations/PermittedIfFactory.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,44 @@ | ||
/* | ||
* 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.regulations; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import uk.ac.ox.poseidon.agents.behaviours.Action; | ||
import uk.ac.ox.poseidon.core.GlobalScopeFactory; | ||
import uk.ac.ox.poseidon.core.Simulation; | ||
|
||
import java.util.function.Predicate; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class PermittedIfFactory extends GlobalScopeFactory<PermittedIf> { | ||
|
||
private GlobalScopeFactory<? extends Predicate<Action>> actionPredicate; | ||
|
||
@Override | ||
protected PermittedIf newInstance(final Simulation simulation) { | ||
return new PermittedIf(actionPredicate.get(simulation)); | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
agents/src/main/java/uk/ac/ox/poseidon/agents/regulations/predicates/operators/AllOf.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,41 @@ | ||
/* | ||
* 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.regulations.predicates.operators; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import uk.ac.ox.poseidon.agents.behaviours.Action; | ||
|
||
import java.util.function.Predicate; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class AllOf implements Predicate<Action> { | ||
|
||
@NonNull | ||
private final ImmutableList<Predicate<Action>> predicates; | ||
|
||
@Override | ||
public boolean test(final Action action) { | ||
return predicates.stream().allMatch(predicate -> predicate.test(action)); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...src/main/java/uk/ac/ox/poseidon/agents/regulations/predicates/operators/AllOfFactory.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.regulations.predicates.operators; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import uk.ac.ox.poseidon.agents.behaviours.Action; | ||
import uk.ac.ox.poseidon.core.Factory; | ||
import uk.ac.ox.poseidon.core.GlobalScopeFactory; | ||
import uk.ac.ox.poseidon.core.Simulation; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import static com.google.common.collect.ImmutableList.toImmutableList; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class AllOfFactory extends GlobalScopeFactory<AllOf> { | ||
|
||
List<Factory<? extends Predicate<Action>>> predicates; | ||
|
||
@Override | ||
protected AllOf newInstance(final Simulation simulation) { | ||
return new AllOf( | ||
predicates | ||
.stream() | ||
.map(p -> p.get(simulation)) | ||
.collect(toImmutableList()) | ||
); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
agents/src/main/java/uk/ac/ox/poseidon/agents/regulations/predicates/operators/AnyOf.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,41 @@ | ||
/* | ||
* 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.regulations.predicates.operators; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import uk.ac.ox.poseidon.agents.behaviours.Action; | ||
|
||
import java.util.function.Predicate; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class AnyOf implements Predicate<Action> { | ||
|
||
@NonNull | ||
private final ImmutableList<Predicate<Action>> predicates; | ||
|
||
@Override | ||
public boolean test(final Action action) { | ||
return predicates.stream().anyMatch(predicate -> predicate.test(action)); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...src/main/java/uk/ac/ox/poseidon/agents/regulations/predicates/operators/AnyOfFactory.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.regulations.predicates.operators; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import uk.ac.ox.poseidon.agents.behaviours.Action; | ||
import uk.ac.ox.poseidon.core.Factory; | ||
import uk.ac.ox.poseidon.core.GlobalScopeFactory; | ||
import uk.ac.ox.poseidon.core.Simulation; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
import static com.google.common.collect.ImmutableList.toImmutableList; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class AnyOfFactory extends GlobalScopeFactory<AnyOf> { | ||
|
||
List<Factory<? extends Predicate<Action>>> predicates; | ||
|
||
@Override | ||
protected AnyOf newInstance(final Simulation simulation) { | ||
return new AnyOf( | ||
predicates | ||
.stream() | ||
.map(p -> p.get(simulation)) | ||
.collect(toImmutableList()) | ||
); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
agents/src/main/java/uk/ac/ox/poseidon/agents/regulations/predicates/operators/Not.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,40 @@ | ||
/* | ||
* 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.regulations.predicates.operators; | ||
|
||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import uk.ac.ox.poseidon.agents.behaviours.Action; | ||
|
||
import java.util.function.Predicate; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class Not implements Predicate<Action> { | ||
|
||
@NonNull | ||
private final Predicate<Action> predicate; | ||
|
||
@Override | ||
public boolean test(final Action action) { | ||
return !predicate.test(action); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...s/src/main/java/uk/ac/ox/poseidon/agents/regulations/predicates/operators/NotFactory.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,45 @@ | ||
/* | ||
* 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.regulations.predicates.operators; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import uk.ac.ox.poseidon.agents.behaviours.Action; | ||
import uk.ac.ox.poseidon.core.Factory; | ||
import uk.ac.ox.poseidon.core.GlobalScopeFactory; | ||
import uk.ac.ox.poseidon.core.Simulation; | ||
|
||
import java.util.function.Predicate; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class NotFactory extends GlobalScopeFactory<Not> { | ||
|
||
private Factory<? extends Predicate<Action>> predicate; | ||
|
||
@Override | ||
protected Not newInstance(final Simulation simulation) { | ||
return new Not(predicate.get(simulation)); | ||
} | ||
} |
Oops, something went wrong.