public void reinitialize(Households hhs) { this.phMap.clear(); for (Household h : hhs.getHouseholds().values()){ for (Id<Person> member : h.getMemberIds()){ this.phMap.put(member, h); } } }
public AbstractHouseholdsReaderV10(Households households) { if (households == null) { throw new IllegalArgumentException("Container for households must not be null!"); } this.households = households; this.builder = households.getFactory(); }
private void loadHouseholds() { if ( (this.config.households() != null) && (this.config.households().getInputFile() != null) ) { URL householdsFile = this.config.households().getInputFileURL(this.config.getContext()); log.info("loading households from " + householdsFile); new HouseholdsReaderV10(this.scenario.getHouseholds()).parse(householdsFile); log.info("households loaded."); } else { log.info("no households file set in config, not loading households"); } final String fn = this.config.households().getInputHouseholdAttributesFile(); if ((this.config.households() != null) && ( fn != null)) { URL householdAttributesFileName = ConfigGroup.getInputFileURL(this.config.getContext(), fn ) ; log.info("loading household attributes from " + householdAttributesFileName); ObjectAttributesXmlReader reader = new ObjectAttributesXmlReader(this.scenario.getHouseholds().getHouseholdAttributes()); reader.putAttributeConverters( attributeConverters ); reader.parse(householdAttributesFileName); } else { log.info("no household-attributes file set in config, not loading any household attributes"); } }
@Test public void testLoadScenario_loadHouseholdAttributes() { Config config = ConfigUtils.loadConfig(IOUtils.newUrl(this.util.classInputResourcePath(), "householdAttributesConfig.xml")); config.households().addParam("inputHouseholdAttributesFile", "householdAttributes.xml"); Scenario scenario = ScenarioUtils.loadScenario(config); Assert.assertEquals("world", scenario.getHouseholds().getHouseholdAttributes().getAttribute("1", "hello")); } }
private static Collection<? extends Collection<Id<Person>>> extractGroups( final Households households) { final List<List<Id<Person>>> groups = new ArrayList<>(); for ( Household hh : households.getHouseholds().values() ) { groups.add( hh.getMemberIds() ); } return groups; }
@Override public Set<Id<Vehicle>> identifyVehiclesUsableForAgent(final Id<Person> person) { // we can't simply remember an agent->hh mapping at construction, // as the households container is mutable. It would not make any sense // to modify it, but one is never too prudent. final Id<Household> hhId = agent2hh.get( person ); if ( hhId == null ) throw new RuntimeException( "no household known for "+person ); final Household hh = households.getHouseholds().get( hhId ); if ( hh == null ) throw new RuntimeException( "household "+hhId+" vanished!" ); if ( !hh.getMemberIds().contains( person ) ) throw new RuntimeException( "household "+hhId+" does not contain "+person ); return new HashSet<Id<Vehicle>>( hh.getVehicleIds() ); } }
public HouseholdBasedVehicleRessources( final Households hhs) { this.households = hhs; for (Household hh : hhs.getHouseholds().values()) { final Id hhId = hh.getId(); for (Id agentId : hh.getMemberIds()) { agent2hh.put( agentId , hhId ); } } }
public final void run(final Households households) { log.info("Running " + this.getClass().getName() + " algorithm..."); Counter counter = new Counter(" household # "); for(Household h : households.getHouseholds().values()) { this.run(h); counter.incCounter(); } counter.printCounter(); log.info("Done running algorithm."); }
/** * Run all the algorithms added to the container. */ public final void runAlgorithms(Households hh){ for(int i = 0; i < this.householdAlgorithms.size(); i++){ HouseholdAlgorithm algorithm = this.householdAlgorithms.get(i); log.info("Running algorithm " + algorithm.getClass().getName()); Counter c = new Counter (" household # "); for(Household household : hh.getHouseholds().values()){ algorithm.run(household); c.incCounter(); } c.printCounter(); log.info("Done running algorithm."); } }
private void writeHouseholds(Households basicHouseholds) throws UncheckedIOException { Counter counter = new Counter("[HouseholdsWriter] wrote household # "); for (Household h : basicHouseholds.getHouseholds().values()) { this.writeHousehold(h); counter.incCounter(); } counter.printCounter(); }
private void checkContent(Households households) { assertEquals(3, households.getHouseholds().size()); Household hh = households.getHouseholds().get(id23); assertNotNull(hh); assertEquals(id23, hh.getId()); assertEquals("customValue1", customContent); hh = households.getHouseholds().get(id24); assertNotNull(hh); assertEquals(id24, hh.getId()); hh = households.getHouseholds().get(id25); assertNotNull(hh); assertEquals(id25, hh.getId());