Skip to content

Commit

Permalink
More plan class refinements and adaptation of those changes to the le…
Browse files Browse the repository at this point in the history
…sson classes
  • Loading branch information
shawnhatch committed Jun 27, 2024
1 parent c6acdc8 commit 6c23f16
Show file tree
Hide file tree
Showing 17 changed files with 286 additions and 165 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import gov.hhs.aspr.ms.gcm.lessons.plugins.model.PersonProperty;
import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorContext;
import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorPlan;
import gov.hhs.aspr.ms.gcm.simulation.nucleus.ConsumerActorPlan;
import gov.hhs.aspr.ms.gcm.simulation.nucleus.EventFilter;
import gov.hhs.aspr.ms.gcm.simulation.plugins.globalproperties.datamanagers.GlobalPropertiesDataManager;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.datamanagers.PeopleDataManager;
Expand Down Expand Up @@ -46,7 +47,7 @@ private void vaccinatePerson(PersonId personId) {
if (refusesVaccine) {
double planTime = actorContext.getTime() + randomGenerator.nextDouble() * vaccineAttemptInterval;

ActorPlan plan = new ActorPlan(planTime, (c) -> vaccinatePerson(personId));
ActorPlan plan = new ConsumerActorPlan(planTime, (c) -> vaccinatePerson(personId));
actorContext.addPlan(plan);
//record the plan for possible cancellation
actorPlans.put(personId, plan);
Expand Down Expand Up @@ -80,7 +81,7 @@ private void handleVaccineAcceptance(ActorContext actorContext,
/* start code_ref= person_properties_vaccinator_plan_vaccination|code_cap= Each unvaccinated person has a planned vaccination based on the VACCINE_ATTEMPT_INTERVAL global property. */
private void planVaccination(PersonId personId) {
double planTime = actorContext.getTime() + randomGenerator.nextDouble() * vaccineAttemptInterval;
ActorPlan plan = new ActorPlan(planTime, (c) -> vaccinatePerson(personId));
ActorPlan plan = new ConsumerActorPlan(planTime, (c) -> vaccinatePerson(personId));
actorContext.addPlan(plan);
//record the plan for possible cancellation
actorPlans.put(personId, plan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import gov.hhs.aspr.ms.gcm.lessons.plugins.model.support.SchoolStatus;
import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorContext;
import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorPlan;
import gov.hhs.aspr.ms.gcm.simulation.nucleus.ConsumerActorPlan;
import gov.hhs.aspr.ms.gcm.simulation.plugins.globalproperties.datamanagers.GlobalPropertiesDataManager;
import gov.hhs.aspr.ms.gcm.simulation.plugins.groups.datamanagers.GroupsDataManager;
import gov.hhs.aspr.ms.gcm.simulation.plugins.groups.support.GroupConstructionInfo;
Expand Down Expand Up @@ -41,7 +42,7 @@ public void init(ActorContext actorContext) {

private void planNextReview() {
double planTime = actorContext.getTime() + reviewInterval;
ActorPlan plan = new ActorPlan(planTime,false,this::reviewSchools);
ActorPlan plan = new ConsumerActorPlan(planTime,false,this::reviewSchools);
actorContext.addPlan(plan);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import gov.hhs.aspr.ms.gcm.lessons.plugins.model.support.PersonProperty;
import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorContext;
import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorPlan;
import gov.hhs.aspr.ms.gcm.simulation.nucleus.ConsumerActorPlan;
import gov.hhs.aspr.ms.gcm.simulation.plugins.globalproperties.datamanagers.GlobalPropertiesDataManager;
import gov.hhs.aspr.ms.gcm.simulation.plugins.groups.datamanagers.GroupsDataManager;
import gov.hhs.aspr.ms.gcm.simulation.plugins.groups.support.GroupId;
Expand All @@ -31,7 +32,7 @@ public void init(ActorContext actorContext) {

private void scheduleNextReview() {
double planTime = actorContext.getTime() + reviewInterval;
ActorPlan plan = new ActorPlan(planTime,false,this::reviewTeleworkStatus);
ActorPlan plan = new ConsumerActorPlan(planTime,false,this::reviewTeleworkStatus);
actorContext.addPlan(plan);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import gov.hhs.aspr.ms.gcm.lessons.plugins.model.support.PersonProperty;
import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorContext;
import gov.hhs.aspr.ms.gcm.simulation.nucleus.ActorPlan;
import gov.hhs.aspr.ms.gcm.simulation.nucleus.ConsumerActorPlan;
import gov.hhs.aspr.ms.gcm.simulation.nucleus.EventFilter;
import gov.hhs.aspr.ms.gcm.simulation.plugins.globalproperties.datamanagers.GlobalPropertiesDataManager;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.datamanagers.PeopleDataManager;
Expand Down Expand Up @@ -215,7 +216,7 @@ private void intializeCandidatesAndWeights() {
* vaccinator selects from maintained sub-populations.
*/
private void planNextVaccination() {
futurePlan = new ActorPlan(interVaccinationTime + actorContext.getTime(), this::vaccinatePerson);
futurePlan = new ConsumerActorPlan(interVaccinationTime + actorContext.getTime(), this::vaccinatePerson);
actorContext.addPlan(futurePlan);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public ConsumerActorPlan(double time, boolean active, long arrivalId, Consumer<A
*
*/
public ConsumerActorPlan(double time, Consumer<ActorContext> consumer) {
super(time, true, -1L);
super(time);
if (consumer == null) {
throw new ContractException(NucleusError.NULL_PLAN_CONSUMER);
}
Expand All @@ -60,7 +60,7 @@ public ConsumerActorPlan(double time, Consumer<ActorContext> consumer) {
*
*/
public ConsumerActorPlan(double time, boolean active, Consumer<ActorContext> consumer) {
super(time, active, -1L);
super(time, active);
if (consumer == null) {
throw new ContractException(NucleusError.NULL_PLAN_CONSUMER);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package gov.hhs.aspr.ms.gcm.simulation.nucleus;

import java.util.function.Consumer;

import gov.hhs.aspr.ms.util.errors.ContractException;

public class ConsumerDataManagerPlan extends DataManagerPlan {

private final Consumer<DataManagerContext> consumer;

/**
* Constructs the plan scheduled for the given time active status arrivalId and
* consumer
*
* @throw {@link ContractException}
* <ul>
* <li>{@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is
* null</li>
* </ul>
*
*/
public ConsumerDataManagerPlan(double time, boolean active, long arrivalId, Consumer<DataManagerContext> consumer) {
super(time, active, arrivalId);
if (consumer == null) {
throw new ContractException(NucleusError.NULL_PLAN_CONSUMER);
}

this.consumer = consumer;
}

/**
* Constructs the plan scheduled for the given time, active status and consumer.
* The arrival id is set to -1L indicating that this is a new, non-deserialized
* plan.
*
* @throw {@link ContractException}
* <ul>
* <li>{@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is
* null</li>
* </ul>
*
*/
public ConsumerDataManagerPlan(double time, boolean active, Consumer<DataManagerContext> consumer) {
super(time, active);
if (consumer == null) {
throw new ContractException(NucleusError.NULL_PLAN_CONSUMER);
}
this.consumer = consumer;
}

/**
* Constructs the plan scheduled for the given time and consumer. The plan will
* be active.The arrival id is set to -1L indicating that this is a new,
* non-deserialized plan.
*
* @throw {@link ContractException}
* <ul>
* <li>{@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is
* null</li>
* </ul>
*
*/
public ConsumerDataManagerPlan(double time, Consumer<DataManagerContext> consumer) {
super(time);
if (consumer == null) {
throw new ContractException(NucleusError.NULL_PLAN_CONSUMER);
}

this.consumer = consumer;
}

@Override
protected void execute(DataManagerContext context) {
this.consumer.accept(context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package gov.hhs.aspr.ms.gcm.simulation.nucleus;

import java.util.function.Consumer;

import gov.hhs.aspr.ms.util.errors.ContractException;

public class ConsumerReportPlan extends ReportPlan {

private final Consumer<ReportContext> consumer;

/**
* Constructs the plan scheduled for the given time, arrivalId and consumer.
* Report plans are always passive.
*
* @throw {@link ContractException}
* <ul>
* <li>{@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is
* null</li>
* </ul>
*
*/
public ConsumerReportPlan(double time, long arrivalId, Consumer<ReportContext> consumer) {
super(time, arrivalId);
if (consumer == null) {
throw new ContractException(NucleusError.NULL_PLAN_CONSUMER);
}
this.consumer = consumer;
}

/**
* Constructs the plan scheduled for the given time and consumer. Report plans
* are always passive.The arrival id is set to -1L indicating that this is a
* new, non-deserialized plan.
*
* @throw {@link ContractException}
* <ul>
* <li>{@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is
* null</li>
* </ul>
*
*/
public ConsumerReportPlan(double time, Consumer<ReportContext> consumer) {
super(time);
if (consumer == null) {
throw new ContractException(NucleusError.NULL_PLAN_CONSUMER);
}
this.consumer = consumer;
}

@Override
protected void execute(ReportContext context) {
this.consumer.accept(context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected DataManagerContext(DataManagerId dataManagerId, Simulation simulation)
*
*/
public void addPlan(final Consumer<DataManagerContext> consumer, final double planTime) {
simulation.addDataManagerPlan(dataManagerId, new DataManagerPlan(planTime, consumer));
simulation.addDataManagerPlan(dataManagerId, new ConsumerDataManagerPlan(planTime, consumer));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,77 +1,49 @@
package gov.hhs.aspr.ms.gcm.simulation.nucleus;

import java.util.function.Consumer;

import gov.hhs.aspr.ms.util.errors.ContractException;

public class DataManagerPlan extends Plan {
public abstract class DataManagerPlan extends Plan {
// The data manager id is used by the simulation via package access
DataManagerId dataManagerId;

private final Consumer<DataManagerContext> consumer;


/**
* Constructs the plan scheduled for the given time active status arrivalId and
* consumer
*
* @throw {@link ContractException}
* <ul>
* <li>{@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is
* null</li>
* </ul>
* Constructs the plan scheduled for the given time active status and arrivalId.
*
*/
public DataManagerPlan(double time, boolean active, long arrivalId, Consumer<DataManagerContext> consumer) {
public DataManagerPlan(double time, boolean active, long arrivalId) {
super(time, active, arrivalId, Planner.DATA_MANAGER);
if (consumer == null) {
throw new ContractException(NucleusError.NULL_PLAN_CONSUMER);
}

this.consumer = consumer;

}

/**
* Constructs the plan scheduled for the given time, active status and consumer.
* Constructs the plan scheduled for the given time and active status.
* The arrival id is set to -1L indicating that this is a new, non-deserialized
* plan.
*
* @throw {@link ContractException}
* <ul>
* <li>{@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is
* null</li>
* </ul>
*
*/
public DataManagerPlan(double time, boolean active, Consumer<DataManagerContext> consumer) {
public DataManagerPlan(double time, boolean active) {
super(time, active, -1L, Planner.DATA_MANAGER);
if (consumer == null) {
throw new ContractException(NucleusError.NULL_PLAN_CONSUMER);
}
this.consumer = consumer;

}

/**
* Constructs the plan scheduled for the given time and consumer. The plan will
* Constructs the plan scheduled for the given time. The plan will
* be active.The arrival id is set to -1L indicating that this is a new,
* non-deserialized plan.
*
* @throw {@link ContractException}
* <ul>
* <li>{@linkplain NucleusError#NULL_PLAN_CONSUMER} if the consumer is
* null</li>
* </ul>
*
*/
public DataManagerPlan(double time, Consumer<DataManagerContext> consumer) {
public DataManagerPlan(double time) {
super(time, true, -1L, Planner.DATA_MANAGER);
if (consumer == null) {
throw new ContractException(NucleusError.NULL_PLAN_CONSUMER);
}

this.consumer = consumer;
}

protected void execute(DataManagerContext context) {
this.consumer.accept(context);

}

/**
* Executes the data manager logic associated with the plan.
*/
protected abstract void execute(DataManagerContext context);

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected ReportContext(Simulation simulation) {
* </ul>
*/
public void addPlan(final Consumer<ReportContext> consumer, final double planTime) {
simulation.addReportPlan(new ReportPlan(planTime, consumer));
simulation.addReportPlan(new ConsumerReportPlan(planTime, consumer));
}

/**
Expand Down
Loading

0 comments on commit 6c23f16

Please sign in to comment.