matsim-org / matsim-code-examples

A repository containing code examples around MATSim
GNU General Public License v3.0
83 stars 180 forks source link

Legs #104

Open SarahSie opened 5 years ago

SarahSie commented 5 years ago

Hello,

I have a question regarding the score for legs. how I can get the score only for one leg.

Thank you in advance.

kainagel commented 5 years ago

If you have a sufficiently new version, there is a config switch "writeExperiencedPlans", which writes a file "experienced_plans_scores.txt.gz", which contains new scores after score updates. It is probably a bit tricky to interpret, but there is then also "experienced_plans.xml.gz" which should help.

In general, there is no need for scores to go down during traveling: traveling is already penalized by the value of time as a resource, which means that you need to cut activities shorter when travel gets longer. In fact, in our own work we usually set the (direct) marginal disutility of traveling by car to zero. There is some info here .

SarahSie commented 5 years ago

Hello,

Thank you for your reply.

I have read in the MATSim book that the following formula is used for counting the score for leg.

Strav,q = Cmode(q) + B trav,mode(q) · ttrav,q + B m · Δmq +(Bd,mode(q) + Bm · d,mode(q)) · dtrav,q + Btransfer · xtransfer,q

I have evaluated the formula with writing code to test it. I have got the amount for each element in the formula. However, the score that I have got from the formula is not the same as the ones are in “0.experienced_plans_scores.txt”.(even with summing them up) I mean the score that I have got is correct for just the first leg, but for the rest is not the same. I think for the calculation of scores for legs, there are other scores as well. This scores which are based on events between the start and end of a leg does not seem to be in the formula.

Could you please help me to understand how the scores for legs and activities are counted? I mean which elements rather than the ones in the formula I should consider. is it depends on other type of events?

Thank you.

kainagel commented 5 years ago

I think that the experienced_plans_scores file is cumulative, so the first entry is at the end of the first leg, the next at the end of the following activity, etc. So differences between these scores are the individual score contributions. Note that there are also activity scores between the leg scores. (We recently also introduced "trip scoring"; I have no idea what the experienced_plans_scores does with that.) The last entry should correspond to the score that is finally also in the experienced_plans file.

If you can't figure it out, could you please present an example output of the experienced_plans_scores for one agent here, and include your own computations of what you think it should be. Thanks.

SarahSie commented 5 years ago

Hello, Please consider the following example. I have counted the score based on the formula which comes in the MATSim book.

Iteration PersonId Time OutTime EventType Leg C mode B trav,mode T trav B m Delta m B d mode Y d mode D trav B transfer X transfer score (Strav,q ) total score
0 1005064200 26458 7:20:58 leg transit_walk 1.172422111 -0.002226486 622 0.154123662 0 0 0 864.2517407 0 0 -0.212451961 -0.212451961
0 1005064200 27080 7:31:20 leg pt 1.27152021 -0.00171591 173 0.154123662 0 0 -5.70E-04 3567.904147 0 0 0.661225645 0.448773683
0 1005064200 27253 7:34:13 leg transit_walk 1.172422111 -0.002226486 0 0.154123662 0 0 0 0 0 0 1.172422111 1.621195794
0 1005064200 27253 7:34:13 leg pt 1.27152021 -0.00171591 1064 0.154123662 0 0 -5.70E-04 6371.450058 0 0 -1.11394313 0.507252664
0 1005064200 28317 7:51:57 leg transit_walk 1.172422111 -0.002226486 636 0.154123662 0 0 0 884.4380366 0 0 -0.24362276 0.263629904
0 1005064200 42658 11:50:58 leg walk 1.172422111 -0.002226486 156 0.154123662 0 0 0 216.7334553 0 0 0.82509035 1.088720254
0 1005064200 43258 12:00:58 leg walk 1.172422111 -0.002226486 156 0.154123662 0 0 0 216.7334553 0 0 0.82509035 1.913810604
0 1005064200 62458 17:20:58 leg transit_walk 1.172422111 -0.002226486 349 0.154123662 0 0 0 483.8987969 0 0 0.39537862 2.309189224
0 1005064200 62807 17:26:47 leg pt 1.27152021 -0.00171591 200 0.154123662 0 0 -5.70E-04 1375.277631 0 0 0.80751938 3.116708604
0 1005064200 63007 17:30:07 leg transit_walk 1.172422111 -0.002226486 6 0.154123662 0 0 0 7.35 0 0 1.159063197 4.275771801
0 1005064200 63013 17:30:13 leg pt 1.27152021 -0.00171591 870 0.154123662 0 0 -5.70E-04 8292.776051 0 0 -0.949845995 3.325925806
0 1005064200 63883 17:44:43 leg transit_walk 1.172422111 -0.002226486 623 0.154123662 0 0 0 864.2517407 0 0 -0.214678447 3.111247359

and this is the result from the "0.experienced_plans_scores": 1005064200 0.0 -0.21245196132666666 -0.21245196132666666 0.44975855212222005 0.44975855212222005 1.62218066302222 1.62218066302222 -1.7363465181112097 -1.7363465181112097 -1.9799692784912097 -1.9799692784912097 -1.1548789284712098 -1.1548789284712098 -0.3297885784512098 -0.3297885784512098 -0.3297885784512098 0.06559004176212346 0.06559004176212346 0.8740450467184422 0.8740450467184422 2.0331082437384422 2.0331082437384422 -1.1799850641428948 -1.1799850641428948 -1.3946635111162282 -1.3946635111162282 -1.3946635111162282

As you can see only the score of the first, second and thirds legs match in both files. However, the more legs come the more the score form formula get distance from the one in experienced_plans. Could you please write to me that what is missing in the formula? What I should consider. I think for the calculation of scores for legs, there are other scores as well. This scores which are based on events between the start and end of a leg does not seem to be in the formula. is it depends on another type of events?

Thank you.

kainagel commented 5 years ago

One issue is that the alternative-specific constant for pt (1.27152021) is counted only once per pt trip. This is to make it consistent with how normal choice models are evaluated.

I don't really know what happens with alternative-specific constants for walk (including transit_walk); we normally set them to zero.

It actually says roughly the correct thing in the config file comments: "[utils] alternative-specific constant. Normally per trip, but that is probably buggy for multi-leg trips."

Please let me know if that explains it or if there is something else.

SarahSie commented 5 years ago

So for the alternative-specific constant for pt, is it a problem that it counted only once? Besides, Can you please explain me that which elements should I change to set zero the alternative-specific constants for walk (including transit_walk)? In config file? Do you think by solving the issues that you have mentioned, therefore the score from formula will be the same as the score that I can get from running MATSim? I think that some events between leg start and end leg end may introduce some score changes, it is correct?