Skip to content

Commit

Permalink
Moving people container classes (#229)
Browse files Browse the repository at this point in the history
* Added people containers to the people plugin

* Removed people containers from the partitions plugin and adapted the plugin to use the people containers in the people plugin
  • Loading branch information
shawnhatch authored Apr 25, 2024
1 parent 0829acc commit 02cbc82
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import org.apache.commons.math3.random.RandomGenerator;

import gov.hhs.aspr.ms.gcm.simulation.nucleus.Event;
import gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.containers.BasePeopleContainer;
import gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.containers.PeopleContainer;
import gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.filters.Filter;
import gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.filters.TrueFilter;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.datamanagers.PeopleDataManager;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.PersonId;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.containers.BasePeopleContainer;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.containers.PeopleContainer;
import gov.hhs.aspr.ms.gcm.simulation.plugins.stochastics.datamanagers.StochasticsDataManager;
import gov.hhs.aspr.ms.gcm.simulation.plugins.stochastics.support.RandomNumberGeneratorId;
import gov.hhs.aspr.ms.util.errors.ContractException;
Expand Down Expand Up @@ -67,10 +67,11 @@ public DegeneratePopulationPartitionImpl(final PartitionsContext partitionsConte
}
list.add(filterSensitivity);
}

peopleContainer = new BasePeopleContainer(partitionsContext, supportRunContinuity);


final PeopleDataManager peopleDataManager = partitionsContext.getDataManager(PeopleDataManager.class);
peopleContainer = new BasePeopleContainer(peopleDataManager, supportRunContinuity);


final int personIdLimit = peopleDataManager.getPersonIdLimit();
for (int i = 0; i < personIdLimit; i++) {
if (peopleDataManager.personIndexExists(i)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

import gov.hhs.aspr.ms.gcm.simulation.nucleus.Event;
import gov.hhs.aspr.ms.gcm.simulation.nucleus.NucleusError;
import gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.containers.BasePeopleContainer;
import gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.containers.PeopleContainer;
import gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.filters.Filter;
import gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.filters.TrueFilter;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.datamanagers.PeopleDataManager;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.PersonId;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.containers.BasePeopleContainer;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.containers.PeopleContainer;
import gov.hhs.aspr.ms.gcm.simulation.plugins.stochastics.datamanagers.StochasticsDataManager;
import gov.hhs.aspr.ms.gcm.simulation.plugins.stochastics.support.RandomNumberGeneratorId;
import gov.hhs.aspr.ms.util.combinatorics.TupleGenerator;
Expand Down Expand Up @@ -426,7 +426,8 @@ private void addPerson(final PersonId personId) {
cleanedKey = new Key(key);
cleanedKey.calculateHashCode();
keyMap.put(cleanedKey, cleanedKey);
final BasePeopleContainer basePeopleContainer = new BasePeopleContainer(partitionsContext,

final BasePeopleContainer basePeopleContainer = new BasePeopleContainer(peopleDataManager,
supportRunContinuity);
keyToPeopleMap.put(cleanedKey, basePeopleContainer);
final LabelSet labelSet = getLabelSet(cleanedKey);
Expand Down Expand Up @@ -1020,7 +1021,7 @@ private void move(final Key currentKey, final Key newKey, final PersonId personI
if (cleanedNewKey == null) {
cleanedNewKey = newKey;
keyMap.put(cleanedNewKey, cleanedNewKey);
keyToPeopleMap.put(cleanedNewKey, new BasePeopleContainer(partitionsContext, supportRunContinuity));
keyToPeopleMap.put(cleanedNewKey, new BasePeopleContainer(peopleDataManager, supportRunContinuity));
final LabelSet labelSet = getLabelSet(cleanedNewKey);
labelSetInfoMap.put(cleanedNewKey, labelSet);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public enum PersonError implements ContractError {
NULL_PERSON_RANGE("Null person range"),//
PERSON_ASSIGNMENT_TIME_IN_FUTURE("The person assignment time from the plugin data is greater than the current time in the simulation"),//
UNKNOWN_PERSON_ID("Unknown person id"),//

NULL_PEOPLE_DATA_MANAGER("Null people data manager"),//
;

private final String description;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.containers;
package gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.containers;

import java.util.List;

import org.apache.commons.math3.random.RandomGenerator;

import gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.PartitionsContext;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.datamanagers.PeopleDataManager;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.PersonId;

Expand Down Expand Up @@ -32,8 +31,8 @@ private static enum PeopleContainerMode {

private final boolean supportRunContinuity;

public BasePeopleContainer(PartitionsContext partitionsContext, boolean supportRunContinuity) {
this.peopleDataManager = partitionsContext.getDataManager(PeopleDataManager.class);
public BasePeopleContainer(PeopleDataManager peopleDataManager, boolean supportRunContinuity) {
this.peopleDataManager = peopleDataManager;
this.supportRunContinuity = supportRunContinuity;

if (supportRunContinuity) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.containers;
package gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.containers;

import java.util.ArrayList;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.containers;
package gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.containers;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.containers;
package gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.containers;

import java.util.ArrayList;
import java.util.BitSet;
Expand All @@ -7,8 +7,8 @@
import org.apache.commons.math3.random.RandomGenerator;
import org.apache.commons.math3.util.FastMath;

import gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.PartitionError;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.datamanagers.PeopleDataManager;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.PersonError;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.PersonId;
import gov.hhs.aspr.ms.util.errors.ContractException;

Expand Down Expand Up @@ -43,7 +43,7 @@ public class TreeBitSetPeopleContainer implements PeopleContainer {
*/
public TreeBitSetPeopleContainer(PeopleDataManager personDataManger) {
if (personDataManger == null) {
throw new ContractException(PartitionError.NULL_PEOPLE_DATA_MANAGER);
throw new ContractException(PersonError.NULL_PEOPLE_DATA_MANAGER);
}
blockSize = 63;
this.peopleDataManager = personDataManger;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.containers;
package gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.containers;

import org.apache.commons.math3.random.RandomGenerator;
import org.junit.jupiter.api.Test;

import gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.PartitionsContext;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.datamanagers.PeopleDataManager;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.PersonId;
import gov.hhs.aspr.ms.util.annotations.UnitTestConstructor;
import gov.hhs.aspr.ms.util.annotations.UnitTestMethod;

public class AT_BasePeopleContainer {

private PeopleContainer getPeopleContainer(PartitionsContext partitionsContext) {
return new BasePeopleContainer(partitionsContext,false);
private PeopleContainer getPeopleContainer(PeopleDataManager peopleDataManager) {
return new BasePeopleContainer(peopleDataManager,false);
}

@Test
@UnitTestConstructor(target = BasePeopleContainer.class, args = { PartitionsContext.class, boolean.class})
@UnitTestConstructor(target = BasePeopleContainer.class, args = { PeopleDataManager.class, boolean.class})
public void testConstructor() {
// nothing to test
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.containers;
package gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.containers;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.apache.commons.math3.random.RandomGenerator;
import org.junit.jupiter.api.Test;

import gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.PartitionsContext;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.datamanagers.PeopleDataManager;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.PersonId;
import gov.hhs.aspr.ms.util.annotations.UnitTestConstructor;
import gov.hhs.aspr.ms.util.annotations.UnitTestField;
Expand All @@ -20,7 +20,7 @@ public void testDefaultTargetDepth() {
assertEquals(80, IntSetPeopleContainer.DEFAULT_TARGET_DEPTH);
}

private PeopleContainer getPeopleContainer(PartitionsContext context) {
private PeopleContainer getPeopleContainer(PeopleDataManager peopleDataManager) {
return new IntSetPeopleContainer();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.containers;
package gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.containers;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.apache.commons.math3.random.RandomGenerator;
import org.junit.jupiter.api.Test;

import gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.PartitionError;
import gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.PartitionsContext;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.datamanagers.PeopleDataManager;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.PersonError;
import gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.PersonId;
import gov.hhs.aspr.ms.util.annotations.UnitTestConstructor;
import gov.hhs.aspr.ms.util.annotations.UnitTestMethod;
Expand All @@ -18,15 +17,15 @@
public class AT_TreeBitSetPeopleContainer {


private PeopleContainer getPeopleContainer(PartitionsContext context) {
return new TreeBitSetPeopleContainer(context.getDataManager(PeopleDataManager.class));
private PeopleContainer getPeopleContainer(PeopleDataManager peopleDataManager) {
return new TreeBitSetPeopleContainer(peopleDataManager);
}

@Test
@UnitTestConstructor(target = TreeBitSetPeopleContainer.class,args = {PeopleDataManager.class})
public void testConstructor() {
ContractException contractException = assertThrows(ContractException.class,()->new TreeBitSetPeopleContainer(null));
assertEquals(PartitionError.NULL_PEOPLE_DATA_MANAGER, contractException.getErrorType());
assertEquals(PersonError.NULL_PEOPLE_DATA_MANAGER, contractException.getErrorType());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gov.hhs.aspr.ms.gcm.simulation.plugins.partitions.support.containers;
package gov.hhs.aspr.ms.gcm.simulation.plugins.people.support.containers;

/*
* Manual performance tuning test turned off until adoption of JOL or another memory assessment tool for post-8 java
Expand Down
Loading

0 comments on commit 02cbc82

Please sign in to comment.