/** * Adds the household to the container. If streaming is set, the household * is added, the algorithms are run on the household, and it is subsequently * removed. If not, the household is added incrementally to the container. * @param household * @throws IllegalArgumentException if the container already includes the * {@link Id} of the household being added. */ public final void addHousehold(final Household household){ /* Validate that a household with the same Id does not exist yet. */ if(this.getHouseholds().containsKey(household.getId())){ throw new IllegalArgumentException("Household with Id " + household.getId() + " already exisits."); } this.households.put(household.getId(), household); }
public void runAlgorithms(Household h){ for(HouseholdAlgorithm algorithm : this.householdAlgorithms){ log.info("Running algorithm " + algorithm.getClass().getName() + " on household " + h.getId()); algorithm.run(h); } }
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 ); } } }
/*package*/ void writeHousehold(Household h) throws UncheckedIOException { this.atts.clear(); atts.add(createTuple(HouseholdsSchemaV10Names.ID, h.getId().toString())); this.writeStartTag(HouseholdsSchemaV10Names.HOUSEHOLD, atts); if ((h.getMemberIds() != null) && !h.getMemberIds().isEmpty()){ this.writeMembers(h.getMemberIds()); } if ((h.getVehicleIds() != null) && !h.getVehicleIds().isEmpty()) { this.writeStartTag(HouseholdsSchemaV10Names.VEHICLES, null); for (Id<Vehicle> id : h.getVehicleIds()){ atts.clear(); atts.add(createTuple(HouseholdsSchemaV10Names.REFID, id.toString())); this.writeStartTag(HouseholdsSchemaV10Names.VEHICLEDEFINITIONID, atts, true); } this.writeEndTag(HouseholdsSchemaV10Names.VEHICLES); } if (h.getIncome() != null){ this.writeIncome(h.getIncome()); } AttributesXmlWriterDelegate attributesWriter = new AttributesXmlWriterDelegate(); attributesWriter.putAttributeConverters(this.attributeConverters); try { this.writer.write(NL); } catch (IOException e) { e.printStackTrace(); } attributesWriter.writeAttributes( "\t\t" , this.writer , h.getAttributes() ); this.writeEndTag(HouseholdsSchemaV10Names.HOUSEHOLD); }
/** * Test that households with the same {@link Id} are not accepted. */ public void testAddHousehold_DuplicateId(){ HouseholdsImpl hhs = new HouseholdsImpl(); Household hh1 = new HouseholdImpl(Id.create("1", Household.class)); Household hh2 = new HouseholdImpl(Id.create("1", Household.class)); assertEquals("Shouldn't have a household.", 0, hhs.getHouseholds().size()); hhs.addHousehold(hh1); assertEquals("Didn't add the household.", 1, hhs.getHouseholds().size()); assertEquals("Should have added the household.", hh1, hhs.getHouseholds().get(hh1.getId())); try{ hhs.addHousehold(hh2); fail("Should not have accepted household with similar Id."); } catch (IllegalArgumentException e){ } }
Household hh = households.getHouseholds().get(id23); assertNotNull(hh); assertEquals(id23, hh.getId()); assertEquals(3, hh.getMemberIds().size()); List<Id<Person>> hhmemberIds = new ArrayList<>(); assertEquals(id24, hh.getId()); assertEquals(2, hh.getMemberIds().size()); assertEquals(pid44, hh.getMemberIds().get(0)); assertEquals(id25, hh.getId()); assertEquals(0, hh.getMemberIds().size());