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); } } }
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 ); } } }
/*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); }
assertNotNull(hh); assertEquals(id23, hh.getId()); assertEquals(3, hh.getMemberIds().size()); List<Id<Person>> hhmemberIds = new ArrayList<>(); hhmemberIds.addAll(hh.getMemberIds()); Collections.sort(hhmemberIds); assertEquals(pid23, hhmemberIds.get(0)); assertNotNull(hh); assertEquals(id24, hh.getId()); assertEquals(2, hh.getMemberIds().size()); assertEquals(pid44, hh.getMemberIds().get(0)); assertEquals(pid45, hh.getMemberIds().get(1)); assertNotNull(hh); assertEquals(id25, hh.getId()); assertEquals(0, hh.getMemberIds().size());