/** * convenience method for often used demographic attribute */ public static String getSex(Person person) { return (String) person.getAttributes().getAttribute(SEX_ATTRIBUTE); }
/** * convenience method for often used demographic attribute */ public static Boolean isEmployed(Person person) { return (Boolean) person.getAttributes().getAttribute(EMPLOYED); }
/** * convenience method for often used demographic attribute */ public static Integer getAge(Person person) { return (Integer) person.getAttributes().getAttribute(AGE); }
/** * convenience method for often used demographic attribute */ public static String getCarAvail(Person person) { return (String) person.getAttributes().getAttribute(CAR_AVAIL); }
/** * convenience method for often used demographic attribute */ public static String getLicense(Person person) { return (String) person.getAttributes().getAttribute(HAS_LICENSE); }
private void startPerson(final Person person, final BufferedWriter out) throws IOException { out.write("\t<person id=\""); out.write(person.getId().toString()); out.write("\""); out.write(">\n"); this.attributesWriter.writeAttributes( "\t\t" , out , person.getAttributes() ); }
/** * convenience method for often used demographic attribute */ public static void setAge(Person person, final Integer age) { if (age!=null){ person.getCustomAttributes().put(AGE, age); person.getAttributes().putAttribute(AGE,age ) ; } }
/** * convenience method for often used demographic attribute */ public static void setLicence(Person person, final String licence) { if (licence!=null){ person.getCustomAttributes().put(HAS_LICENSE, licence); person.getAttributes().putAttribute(HAS_LICENSE, licence ) ; } }
/** * convenience method for often used demographic attribute */ public static void setCarAvail(Person person, final String carAvail) { if (carAvail!=null){ person.getCustomAttributes().put(CAR_AVAIL, carAvail); person.getAttributes().putAttribute(CAR_AVAIL,carAvail ) ; } }
/** * convenience method for often used demographic attribute */ public static void setEmployed(Person person, final Boolean employed) { if (employed!=null){ person.getCustomAttributes().put(EMPLOYED, employed); person.getAttributes().putAttribute(EMPLOYED,employed ) ; } }
/** * convenience method for often used demographic attribute */ public static void setSex(Person person, final String sex) { if (sex!=null){ person.getCustomAttributes().put(SEX_ATTRIBUTE, sex); person.getAttributes().putAttribute( SEX_ATTRIBUTE, sex ) ; } }
String args = person.getAttributes().toString(); List<String[]> initArgs = new ArrayList<>(); Pattern logEntry = Pattern.compile("\\{\\s*key\\s*=\\s*(.*?)\\s*;\\s*object\\s*=\\s*(.*?)\\s*\\}");
public static void populationWithBDIAttributeExample() { { Config config = ConfigUtils.createConfig() ; Scenario scenario = ScenarioUtils.createScenario( config ) ; Population pop = scenario.getPopulation() ; PopulationFactory pf = pop.getFactory() ; for ( int ii=0 ; ii<10 ; ii++ ) { Person person = pf.createPerson( Id.createPersonId(ii)) ; person.getAttributes().putAttribute("isBDIAgent", true ) ; pop.addPerson(person); } PopulationUtils.writePopulation(pop, "pop.xml"); } { Config config = ConfigUtils.createConfig() ; config.plans().setInputFile("pop.xml"); Scenario scenario = ScenarioUtils.loadScenario( config ) ; for ( Person person : scenario.getPopulation().getPersons().values() ) { final String attribute = (String) person.getAttributes().getAttribute("isBDIAgent"); System.out.println( "id=" + person.getId() + "; isBdi=" + attribute ) ; } } }
@Test public void testPersonAttributesIO() { final Population population = PopulationUtils.createPopulation(ConfigUtils.createConfig() ); final Person person = population.getFactory().createPerson(Id.createPersonId( "Donald Trump")); population.addPerson( person ); person.getAttributes().putAttribute( "brain" , false ); person.getAttributes().putAttribute( "party" , "republican" ); final String file = utils.getOutputDirectory()+"/population.xml"; new PopulationWriter( population ).writeV6( file ); final Scenario readScenario = ScenarioUtils.createScenario( ConfigUtils.createConfig() ); new PopulationReader( readScenario ).readFile( file ); final Person readPerson = readScenario.getPopulation().getPersons().get( Id.createPersonId( "Donald Trump" ) ); Assert.assertEquals( "Unexpected boolean attribute in " + readPerson.getAttributes(), person.getAttributes().getAttribute( "brain" ) , readPerson.getAttributes().getAttribute( "brain" ) ); Assert.assertEquals( "Unexpected String attribute in " + readPerson.getAttributes(), person.getAttributes().getAttribute( "party" ) , readPerson.getAttributes().getAttribute( "party" ) ); }
break; case PERSON: currAttributes = currperson.getAttributes(); break; case PLAN:
double logNormalRnd = (double) person.getAttributes().getAttribute("logNormalRnd");
.getPersons() .get( Id.createPersonId( 1 ) ) .getAttributes() .getAttribute( "otherAttribute" );
sc.getPopulation().getPersonAttributes().putAttribute( "1" , "stupidAttribute" , new StupidClass() ); person.getAttributes().putAttribute( "otherAttribute" , new StupidClass() );