Skip to content

faq 29229070

Billy Charlton edited this page Sep 5, 2018 · 2 revisions

How to change the "employed" attribute of an agent?

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?

Comments: 4


Re: How to change the "employed" attribute of an agent?

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 PersonImpl class, and not in the Person.
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 PersonAttributes which has infinite possibilities. 
ObjectAttributes personAttributes = sc.getPopulation().getPersonAttributes();
 personAttributes.putAttribute(person.getId().toString(), "employed", false);

 

I hope that helps! 


Re: How to change the "employed" attribute of an agent?

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.


Re: How to change the "employed" attribute of an agent?

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.


Re: How to change the "employed" attribute of an agent?

by Joschka Bischoff on 2015-09-01 06:09:44

Though, one needs to check whether all code really supports PersonAttributes.
Especially SubTourModeChoice does not currently read PersonAttributes (or to be more precise

PermissibleModesCalculatorImpl), but relies on the values that are saved within PersonImpl.

 

 

Clone this wiki locally