-
Notifications
You must be signed in to change notification settings - Fork 179
faq 301596674
by Nirmeen on 2018-07-11 15:30:11
I would like to add custom attribute(s) to person object and be able to read/access it.
I added "income" as an attribute to population_v6,dtd and plans.xml as shown below, however i am not sure what is the correct way to define and read/access it. Can you please advise.
<!ELEMENT person (attributes?,plan*)>
<!ATTLIST person
id CDATA #REQUIRED
car_avail (always|never|sometimes) #IMPLIED
employed (yes|no) #IMPLIED
income CDATA #IMPLIED>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE population SYSTEM "resources\dtd\population_v6.dtd">
<population>
<!-- ====================================================================== -->
<person id="1" car_avail="always" employed="yes" income="1750">
<plan score="104.84298221603848" selected="yes">
<activity type="h" link="263254491_34027699" x="4625652.386267886" y="5830739.079902429" end_time="13:33:00" >
</activity>
<leg mode="pt" dep_time="13:33:00" trav_time="01:24:13">
<route type="generic" start_link="263254491_34027699" end_link="29364027_29364041" trav_time="01:24:13" distance="32390.67598449947"></route>
</leg>
</plan>
</person>
<!-- ====================================================================== -->
</population>
by Johan W. Joubert on 2018-07-11 15:44:17
Hi Nirmeen, I'm not quite sure what the first snippet is you supplied. You cannot (or should not) change the dtd
file. That's fixed. It indicates that a Person
may (but need not, hence the ?
) have one or more attributes
.
In my mind the correct way of giving a person attributes - depending on what version of MATSim you're using - is something along the following lines (programatically).
Scenario sc = ScenarioUtils.createScenario(ConfigUtils.createConfig());
Person person = sc.getPopulation().getFactory().createPerson(Id.createPersonId("1"));
person.getAttributes().putAttribute("car_avail", "always");
person.getAttributes().putAttribute("employed", "yes");
person.getAttributes().putAttribute("income", 1750);
sc.getPopulation().addPerson(person);
If you write that population out, you should be able to see what the XML
version of the attributes look like.
by Nirmeen on 2018-07-11 15:53:13
Hi Johan,
Thank you for your response.
The version in pom.xml is 0.11.0-SNAPSHOT.
I was wondering, if there is a way to read it directly from plans.xml file.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE population SYSTEM "\resources\dtd\population_v6.dtd">
<population>
<!-- ====================================================================== -->
<person id="1" car_avail="always" employed="yes" income="1750">
<plan score="104.84298221603848" selected="yes">
<activity type="h" link="263254491_34027699" x="4625652.386267886" y="5830739.079902429" end_time="13:33:00" >
</activity>
<leg mode="pt" dep_time="13:33:00" trav_time="01:24:13">
<route type="generic" start_link="263254491_34027699" end_link="29364027_29364041" trav_time="01:24:13" distance="32390.67598449947"></route>
</leg>
</plan>
</person>
<!-- ====================================================================== -->
</population>
by Nirmeen on 2018-07-11 16:08:04
Thank you for your response.
The MATSim version is 0.11.0-SNAPSHOT.
I was wondering if there is a way to read it directly from plans.xml, since there will be multiple person objects in the population
by Nirmeen on 2018-07-11 16:23:44
Thank you for your response.
The MATSim version is 0.11.0-SNAPSHOT.
I am a bit confused in which class should this initialization be done. i was also wondering if we can read the person object directly from plans.xml file since there might be multiple person objects.
You are viewing an archive of the previous MATSim Q&A site. The real site is now at https://matsim.org/faq