Skip to content

Commit

Permalink
don't check for cell accessibility in the imitating picker
Browse files Browse the repository at this point in the history
This should be checked upstream, when choosing who to potentially
imitate. It should make things a bit faster, and also makes the
picker more general.
  • Loading branch information
nicolaspayette committed Nov 19, 2024
1 parent 66d969c commit 23e5a58
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@

import ec.util.MersenneTwisterFast;
import lombok.RequiredArgsConstructor;
import sim.util.Int2D;
import uk.ac.ox.poseidon.agents.behaviours.choices.OptionValues;
import uk.ac.ox.poseidon.agents.behaviours.choices.Picker;
import uk.ac.ox.poseidon.agents.registers.Register;
import uk.ac.ox.poseidon.agents.vessels.Vessel;
import uk.ac.ox.poseidon.geography.paths.GridPathFinder;

import java.util.List;
import java.util.Map.Entry;
Expand All @@ -50,28 +47,25 @@
* option in a chain of explorers; it needs another one to fall back on.
*/
@RequiredArgsConstructor
public class ImitatingCellPicker implements Picker<Int2D> {
public class ImitatingPicker<O> implements Picker<O> {

private final Vessel vessel;
private final OptionValues<Int2D> optionValues;
private final Register<Entry<Int2D, Double>> candidateRegister;
private final GridPathFinder pathFinder;
private final OptionValues<O> optionValues;
private final Register<Entry<O, Double>> candidateRegister;
private final MersenneTwisterFast rng;

@Override
public Optional<Int2D> pick() {
public Optional<O> pick() {

final Optional<Entry<Int2D, Double>> currentBestEntry =
final Optional<Entry<O, Double>> currentBestEntry =
optionValues.getBestEntry(rng);

final double currentBestValue =
currentBestEntry.map(Entry::getValue).orElse(NEGATIVE_INFINITY);

final List<Int2D> candidates = candidateRegister
final List<O> candidates = candidateRegister
.getAllEntries()
.map(Entry::getValue)
.filter(entry -> entry.getValue() > currentBestValue)
.filter(entry -> pathFinder.isAccessible(vessel.getCurrentCell(), entry.getKey()))
.collect(maxAll(comparingByValue(), mapping(Entry::getKey, toList())));

return upToOneOf(candidates, rng)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,32 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import sim.util.Int2D;
import uk.ac.ox.poseidon.agents.behaviours.choices.OptionValues;
import uk.ac.ox.poseidon.agents.registers.Register;
import uk.ac.ox.poseidon.agents.vessels.Vessel;
import uk.ac.ox.poseidon.agents.vessels.VesselScopeFactory;
import uk.ac.ox.poseidon.core.Factory;
import uk.ac.ox.poseidon.core.Simulation;
import uk.ac.ox.poseidon.geography.paths.GridPathFinder;

import java.util.Map.Entry;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class ImitatingCellPickerFactory extends VesselScopeFactory<ImitatingCellPicker> {
public class ImitatingPickerFactory<O> extends VesselScopeFactory<ImitatingPicker<O>> {

private VesselScopeFactory<? extends OptionValues<Int2D>> optionValues;
private Factory<? extends Register<Entry<Int2D, Double>>> candidateRegister;
private Factory<? extends GridPathFinder> pathFinder;
private VesselScopeFactory<? extends OptionValues<O>> optionValues;
private Factory<? extends Register<Entry<O, Double>>> candidateRegister;

@Override
protected ImitatingCellPicker newInstance(
protected ImitatingPicker<O> newInstance(
final Simulation simulation,
final Vessel vessel
) {
return new ImitatingCellPicker(
vessel,
return new ImitatingPicker<>(
optionValues.get(simulation, vessel),
candidateRegister.get(simulation),
pathFinder.get(simulation),
simulation.random
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,11 @@ public class BasicScenario extends Scenario {
1
)
),
new ImitatingCellPickerFactory(
new ImitatingPickerFactory<>(
optionValues,
new BestOptionsRegisterFactory<>(
optionValuesRegister
),
pathFinder
)
),
new TotalBiomassCaughtPerHourDestinationEvaluatorFactory()
),
Expand Down

0 comments on commit 23e5a58

Please sign in to comment.