diff --git a/POSEIDON/src/main/java/uk/ac/ox/oxfish/experiments/tuna/Runner.java b/POSEIDON/src/main/java/uk/ac/ox/oxfish/experiments/tuna/Runner.java index ed700eb61..eb2512b41 100644 --- a/POSEIDON/src/main/java/uk/ac/ox/oxfish/experiments/tuna/Runner.java +++ b/POSEIDON/src/main/java/uk/ac/ox/oxfish/experiments/tuna/Runner.java @@ -192,7 +192,7 @@ public void run( } public void run( - final int numYearsToRun, + final int numberOfYearsToRun, final int numberOfRunsPerPolicy, final AtomicInteger runCounter ) { @@ -202,7 +202,7 @@ public void run( : policies.stream()).forEach(policy -> { final int runNumber = runCounter.getAndIncrement(); logger.info(String.format("=== Starting run %d / %s ===", runNumber, numRuns)); - final State state = startRun(policy, runNumber, numRuns, numYearsToRun); + final State state = startRun(policy, runNumber, numRuns, numberOfYearsToRun); if (writeScenarioToFile) writeScenarioToFile(state); beforeStartConsumer.accept(state); state.model.start(); @@ -213,7 +213,7 @@ public void run( state.printStep(); state.model.schedule.step(state.model); afterStepConsumer.accept(state); - } while (state.model.getYear() < numYearsToRun); + } while (state.model.getYear() < numberOfYearsToRun); afterRunConsumer.accept(state); writeOutputs(runNumber, rowProviders, true); })); diff --git a/epo/src/main/java/uk/ac/ox/poseidon/epo/policies/PolicyRuns.java b/epo/src/main/java/uk/ac/ox/poseidon/epo/policies/PolicyRuns.java index d54118e94..5d4497b3a 100644 --- a/epo/src/main/java/uk/ac/ox/poseidon/epo/policies/PolicyRuns.java +++ b/epo/src/main/java/uk/ac/ox/poseidon/epo/policies/PolicyRuns.java @@ -16,6 +16,9 @@ package uk.ac.ox.poseidon.epo.policies; +import com.beust.jcommander.JCommander; +import com.beust.jcommander.Parameter; +import com.beust.jcommander.converters.PathConverter; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import uk.ac.ox.oxfish.experiments.tuna.Policy; @@ -28,6 +31,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; +import java.util.Map; import java.util.Map.Entry; import java.util.logging.Logger; import java.util.stream.IntStream; @@ -36,29 +40,46 @@ import static com.google.common.collect.ImmutableMap.toImmutableMap; import static java.util.stream.Collectors.toList; -public class PolicyRuns { +public class PolicyRuns implements Runnable { private static final Logger logger = Logger.getLogger(PolicyRuns.class.getName()); + @Parameter(names = "--output_folder", converter = PathConverter.class) + private final Path outputFolder = Paths.get( + System.getProperty("user.home"), "workspace", "epo_policy_runs", "runs" + ); + + @Parameter(names = "--scenario", converter = PathConverter.class) + private final Path scenarioFile = Paths.get( + System.getProperty("user.home"), "workspace", "epo_calibration_runs", "runs", + "2024-02-13", "cenv0729", "2024-02-17_06.26.53_local", + "calibrated_scenario_updated.yaml" + ); + + @Parameter(names = {"-r", "--runs_per_policy"}) + private final int numberOfRunsPerPolicy = 3; + + @Parameter(names = {"-y", "--years_to_run"}) + private final int numberOfYearsToRun = 3; + public static void main(final String[] args) { - final Path baseFolder = Paths.get( - System.getProperty("user.home"), "workspace", "epo_calibration_runs", "runs" - ); - final Path baseScenario = baseFolder.resolve(Paths.get( - "2024-02-13", "cenv0729", "2024-02-17_06.26.53_local", - "calibrated_scenario_updated.yaml" - )); + final Runnable policyRuns = new PolicyRuns(); + JCommander.newBuilder() + .addObject(policyRuns) + .build() + .parse(args); + policyRuns.run(); + } - final Path baseOutputFolder = Paths.get( - System.getProperty("user.home"), "workspace", "epo_policy_runs", "runs" - ); + private static Map>>> makePolicies() { final List yearsActive = ImmutableList.of(2023); - final ImmutableList proportions = ImmutableList.of(0.75, 0.50, 0.25, 0.10, 0.0); + final ImmutableList proportions = + ImmutableList.of(0.75, 0.50, 0.25, 0.10, 0.0); final ImmutableList fineProportions = IntStream.rangeClosed(1, 19) .mapToObj(i -> i * 0.05) .collect(toImmutableList()); - final ImmutableMap>>> policies = ImmutableMap.of( + return ImmutableMap.of( "global_object_set_limits", new GlobalObjectSetLimit( yearsActive, // 8729 FAD + 4003 OFS in 2022: @@ -97,14 +118,18 @@ public static void main(final String[] args) { Entry::getKey, entry -> entry.getValue().getWithDefault() )); + } + + @Override + public void run() { + final Map>>> policies = makePolicies(); - final int numberOfRunsPerPolicy = 1; final int numberOfPolicies = policies.values().stream().mapToInt(List::size).sum(); logger.info(String.format( "About to run %d policies %d times (%d total runs)", numberOfPolicies, - numberOfRunsPerPolicy, - numberOfPolicies * numberOfRunsPerPolicy + numberOfYearsToRun, + numberOfPolicies * numberOfYearsToRun )); policies @@ -113,9 +138,9 @@ public static void main(final String[] args) { .parallel() .forEach(entry -> { final String policyName = entry.getKey(); - final Path outputFolder = baseOutputFolder.resolve(policyName); + final Path outputFolder = this.outputFolder.resolve(policyName); final Runner runner = - new Runner<>(EpoPathPlannerAbundanceScenario.class, baseScenario, outputFolder) + new Runner<>(EpoPathPlannerAbundanceScenario.class, scenarioFile, outputFolder) .setPolicies(entry.getValue()) .setParallel(true) .setWriteScenarioToFile(true) @@ -127,7 +152,7 @@ public static void main(final String[] args) { .registerRowProvider("spatial_closures.csv", RectangularAreaExtractor::new) .registerRowProvider("sim_action_events.csv", PurseSeineActionsLogger::new); } - runner.run(3, numberOfRunsPerPolicy); + runner.run(numberOfYearsToRun, numberOfRunsPerPolicy); }); } }