private void fillHousehold() { ((HouseholdImpl) this.currentHousehold).setMemberIds(this.currentmembers); ((HouseholdImpl) this.currentHousehold).setVehicleIds(this.currentVehicleIds); this.currentHousehold.setIncome(this.currentincome); this.currentHhId = null; this.currentVehicleIds = null; this.currentincome = null; this.currentmembers = null; this.currentIncomePeriod = null; this.currentincomeCurrency = null; }
/*package*/ Household createHousehold() { Household hh = this.builder.createHousehold(this.currentHhId); ((HouseholdImpl) hh).setMemberIds(this.currentmembers); ((HouseholdImpl) hh).setVehicleIds(this.currentVehicleIds); hh.setIncome(this.currentincome); this.currentHhId = null; this.currentVehicleIds = null; this.currentincome = null; this.currentmembers = null; this.currentIncomePeriod = null; this.currentincomeCurrency = null; return hh; }
@Override public Income createIncome(double income, IncomePeriod period) { return new IncomeImpl(income, period); } }
public void testBasicReaderWriter() throws IOException { Households households = new HouseholdsImpl(); HouseholdsReaderV10 reader = new HouseholdsReaderV10(households); reader.readFile(this.getPackageInputDirectory() + TESTHOUSEHOLDSINPUT); checkContent(households); HouseholdsWriterV10 writer = new HouseholdsWriterV10(households); String outfilename = this.getOutputDirectory() + TESTXMLOUTPUT; writer.writeFile(outfilename); File outFile = new File(outfilename); assertTrue(outFile.exists()); //read it again to check if the same is read as at the very first beginning of test households = new HouseholdsImpl(); reader = new HouseholdsReaderV10(households); reader.readFile(outfilename); checkContent(households); }
/** * 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){ } }
private void writeIncome(Income income) throws UncheckedIOException { atts.clear(); if (income.getCurrency() != null) { atts.add(createTuple(HouseholdsSchemaV10Names.CURRENCY,income.getCurrency())); } atts.add(createTuple(HouseholdsSchemaV10Names.PERIOD, income.getIncomePeriod().toString())); this.writeStartTag(HouseholdsSchemaV10Names.INCOME, atts); this.writeContent(Double.toString(income.getIncome()), true); this.writeEndTag(HouseholdsSchemaV10Names.INCOME); }
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 ); } } }
/** * Test that households are accumulated if streaming is off. */ public void testAddHousehold_NoStreaming(){ HouseholdsImpl hhs = new HouseholdsImpl(); Household hh1 = new HouseholdImpl(Id.create("1", Household.class)); Household hh2 = new HouseholdImpl(Id.create("2", Household.class)); hhs.addHousehold(hh1); assertEquals("Should have the first household added.", 1, hhs.getHouseholds().size()); assertTrue("First household not present.", hhs.getHouseholds().containsValue(hh1)); hhs.addHousehold(hh2); assertEquals("Should have the first AND second household added.", 2, hhs.getHouseholds().size()); assertTrue("First household not present.", hhs.getHouseholds().containsValue(hh1)); assertTrue("Second household not present.", hhs.getHouseholds().containsValue(hh2)); }
@Override public int compare(Household o1, Household o2) { if (o1.getIncome().getIncomePeriod() != o2.getIncome().getIncomePeriod()){ throw new IllegalArgumentException("Can only compare Households with incomes in " + " same income period"); } if (o1.getIncome().getIncome() < o2.getIncome().getIncome()){ return -1; } else if (o1.getIncome().getIncome() > o2.getIncome().getIncome()){ return 1; } return 0; }
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); } } }
@Override public HouseholdImpl createHousehold(Id<Household> householdId) { HouseholdImpl hh = new HouseholdImpl(householdId); hh.setMemberIds(new ArrayList<Id<Person>>()); hh.setVehicleIds(new ArrayList<Id<Vehicle>>()); return hh; }
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(); }
/*package*/ void openFileAndWritePreamble(String filename){ this.openFile(filename); this.writeXmlHead(); this.writeHeader(); }
@Override public void endTag(String name, String content, Stack<String> context) { if (HouseholdsSchemaV10Names.HOUSEHOLD.equalsIgnoreCase(name)) { Household household = createHousehold(); this.algoRunner.runAlgorithms(household); this.hhWriter.writeHousehold(household); counter.incCounter(); } }
/*package*/ void writeEndAndCloseFile(){ this.writeEndTag(HouseholdsSchemaV10Names.HOUSEHOLDS); this.close(); }
public HouseholdsStreamingReaderV10(HouseholdsAlgorithmRunner algoRunner){ super(new HouseholdsImpl()); this.algoRunner = algoRunner; }
private void writeHeader(){ atts.clear(); atts.add(createTuple(XMLNS, MatsimXmlWriter.MATSIM_NAMESPACE)); atts.add(createTuple(XMLNS + ":xsi", DEFAULTSCHEMANAMESPACELOCATION)); atts.add(createTuple("xsi:schemaLocation", MATSIM_NAMESPACE + " " + DEFAULT_DTD_LOCATION + "households_v1.0.xsd")); this.writeStartTag(HouseholdsSchemaV10Names.HOUSEHOLDS, atts); }
@Override public void run(Household household) { writeHousehold(household); }
public PersonHouseholdMapping(Households hhs) { this.reinitialize(hhs); }
public AbstractHouseholdsReaderV10(Households households) { if (households == null) { throw new IllegalArgumentException("Container for households must not be null!"); } this.households = households; this.builder = households.getFactory(); }