faq 29229070 - matsim-org/matsim-code-examples GitHub Wiki
by Johan W. Joubert on 2015-06-01 16:16:00
Question asked by Tonny:
Could anyone kindly tell me how to change the “employed” attribute of agents.
By default it is set to “no”. I checked the API for person, there is not method such as "setEmployed()”.
Is it a must to revise the xml file afterwards?
by Johan W. Joubert on 2015-06-01 16:23:11
Tonny, there are two ways, the first being somewhat wrong.
- This was possible, but I see it has since been deprecated. The method you are looking for was available in the 
PersonImplclass, and not in thePerson. 
Scenario sc = ScenarioUtils.createScenario(ConfigUtils.createConfig());
 PopulationFactory pf = sc.getPopulation().getFactory();
 Person person = pf.createPerson(Id.createPersonId("1"));
 ((PersonImpl)person).setEmployed(false);
- 
The better approach would be to use the 
PersonAttributeswhich has infinite possibilities. 
ObjectAttributes personAttributes = sc.getPopulation().getPersonAttributes();
 personAttributes.putAttribute(person.getId().toString(), "employed", false);
I hope that helps!
by Johan W. Joubert on 2015-06-01 19:38:14
There is now a small code snippet in the main repository at tutorial.programming.personAttributes so that it can be refactored in the future as well.
by Johan W. Joubert on 2015-06-02 15:22:40
Hi Jiangshan Ma, please do not use deprecated code. It may be completely taken out at some future time. You've done the correct thing: the correct way is to use the ObjectAttributeXmlWriter and ignore the employed status in the population.xml file. As soon as the PopulationWriter is updated, it might not even write the employment status to the population.xml file.
by Joschka Bischoff on 2015-09-01 06:09:44
PermissibleModesCalculatorImpl), but relies on the values that are saved within PersonImpl.