matsim-org/matsim-code-examples

Score function calculation

Opened this issue · 3 comments

I have following planscore configurations that I used from sioux-falls repository.

<module name="planCalcScore">
 	<param name="BrainExpBeta" value="1.0" />
 	
 	<param name="learningRate" value="1.0" />

 	<parameterset type="scoringParameters">
 	<param name="earlyDeparture" value="0.0" />
 	<param name="lateArrival" value="0.0" />
 	<param name="marginalUtilityOfMoney" value="0.062" />
 	<param name="performing" value="0.96" />
 	<param name="utilityOfLineSwitch" value="0.0"/>
 	<param name="waitingPt" value="-0.18" />

 	<parameterset type="modeParams">
 		<param name="mode" value="car"/>
 		<param name="marginalUtilityOfTraveling_util_hr" value="0.0" />
 		<param name="constant" value="-0.562"/>
 		<param name="monetaryDistanceRate" value="-0.0004"/>
                     <param name="dailyUtilityConstant" value="-0.0004"/>
 	</parameterset>
 	<parameterset type="modeParams">
 		<param name="mode" value="pt"/>
 		<param name="marginalUtilityOfTraveling_util_hr" value="-0.18" />
 		<param name="monetaryDistanceRate" value="0.0"/>
 		<param name="constant" value="-0.124"/>
 		<param name="dailyUtilityConstant" value="-0.0004"/>
 	</parameterset>
 	<parameterset type="modeParams">
 		<param name="mode" value="walk"/>
 		<param name="marginalUtilityOfTraveling_util_hr" value="-1.14" />
 		<param name="constant" value="0.0"/>
 		<param name="marginalUtilityOfDistance_util_m" value="0.0"/>
                     <param name="dailyUtilityConstant" value="-0.0004"/>
 	</parameterset>

 	<parameterset type="activityParams">
 		<param name="activityType"    value="home" /> <!-- home -->
 		<param name="priority"        value="1" />
 		<param name="typicalDuration" value="13:00:00" />
 		<param name="minimalDuration" value="01:00:00" />
 	</parameterset>
 	<parameterset type="activityParams">
 		<param name="activityType"            value="work" />
 		<param name="priority"        value="1" />
 		<param name="typicalDuration" value="09:00:00" />
 		<param name="minimalDuration" value="08:00:00" />
 		<param name="openingTime"     value="08:00:00" />
 		<param name="earliestEndTime" value="17:00:00" />
 		<param name="latestStartTime" value="09:00:00" />
 		<param name="closingTime"     value="18:00:00" />
 	</parameterset>

 	<parameterset type="activityParams">
 		<param name="activityType"            value="secondary" />
 		<param name="priority"        value="1" />
 		<param name="typicalDuration" value="01:00:00" />
 		<param name="minimalDuration" value="00:30:00" />
 		<param name="openingTime"     value="08:00:00" />
 		<param name="closingTime"     value="20:00:00" />
 	</parameterset>
 	</parameterset>
</module>

And the output plan of a particular agent in each iteration is provided as follows:

<!— ITERATION - 0 =========================================== -->

<person id="10006_1">
    <attributes>
        <attribute name="age" class="java.lang.Integer">32</attribute>
        <attribute name="carAvail" class="java.lang.String">always</attribute>
        <attribute name="employed" class="java.lang.Boolean">true</attribute>
        <attribute name="sex" class="java.lang.String">m</attribute>
        <attribute name="vehicles" class="org.matsim.vehicles.PersonVehicles">{"car":"10006_1"}</attribute>
    </attributes>
    <plan selected="yes">
        <activity type="home" facility="5810_18" x="686457.5027000001" y="4824397.363" end_time="07:27:08" >
        </activity>
        <leg mode="car" dep_time="07:27:08" trav_time="00:01:39">
            <attributes>
                <attribute name="routingMode" class="java.lang.String">car</attribute>
            </attributes>
            <route type="links" start_link="18_4" end_link="50_1" trav_time="00:01:39" distance="1835.3162857100572" vehicleRefId="null">18_4 55_1 55_2 55_3 50_1</route>
        </leg>
        <activity type="work" facility="21558_16" x="685234.5421000002" y="4823917.274599999" start_time="07:42:08" end_time="17:27:36" >
        </activity>
        <leg mode="car" dep_time="17:27:36" trav_time="00:03:16">
            <attributes>
                <attribute name="routingMode" class="java.lang.String">car</attribute>
            </attributes>
            <route type="links" start_link="50_1" end_link="18_4" trav_time="00:03:16" distance="4659.035988301946" vehicleRefId="null">50_1 50_2 50_3 54_1 54_2 54_3 54_4 18_1 18_2 18_3 18_4</route>
        </leg>
        <activity type="home" facility="5810_18" x="686457.5027000001" y="4824397.363" >
        </activity>
    </plan>

</person>

<!— ITERATION - 1 ========================================== -->

<person id="10006_1">
	<attributes>
		<attribute name="age" class="java.lang.Integer">32</attribute>
		<attribute name="carAvail" class="java.lang.String">always</attribute>
		<attribute name="employed" class="java.lang.Boolean">true</attribute>
		<attribute name="sex" class="java.lang.String">m</attribute>
		<attribute name="vehicles" class="org.matsim.vehicles.PersonVehicles">{"car":"10006_1"}</attribute>
	</attributes>
	<plan score="-36.43359107294678" selected="no">
		<activity type="home" facility="5810_18" x="686457.5027000001" y="4824397.363" end_time="07:27:08" >
		</activity>
		<leg mode="car" dep_time="07:27:08" trav_time="00:01:39">
			<attributes>
				<attribute name="routingMode" class="java.lang.String">car</attribute>
			</attributes>
			<route type="links" start_link="18_4" end_link="50_1" trav_time="00:01:39" distance="1835.3162857100572" vehicleRefId="10006_1">18_4 55_1 55_2 55_3 50_1</route>
		</leg>
		<activity type="work" facility="21558_16" x="685234.5421000002" y="4823917.274599999" start_time="07:42:08" end_time="17:27:36" >
		</activity>
		<leg mode="car" dep_time="17:27:36" trav_time="00:03:16">
			<attributes>
				<attribute name="routingMode" class="java.lang.String">car</attribute>
			</attributes>
			<route type="links" start_link="50_1" end_link="18_4" trav_time="00:03:16" distance="4659.035988301946" vehicleRefId="10006_1">50_1 50_2 50_3 54_1 54_2 54_3 54_4 18_1 18_2 18_3 18_4</route>
		</leg>
		<activity type="home" facility="5810_18" x="686457.5027000001" y="4824397.363" >
		</activity>
	</plan>

	<plan score="-36.43359107294678" selected="yes">
		<activity type="home" facility="5810_18" x="686457.5027000001" y="4824397.363" end_time="08:17:18" >
		</activity>
		<leg mode="car" dep_time="07:27:08" trav_time="00:01:39">
			<attributes>
				<attribute name="routingMode" class="java.lang.String">car</attribute>
			</attributes>
			<route type="links" start_link="18_4" end_link="50_1" trav_time="00:01:39" distance="1835.3162857100572" vehicleRefId="10006_1">18_4 55_1 55_2 55_3 50_1</route>
		</leg>
		<activity type="work" facility="21558_16" x="685234.5421000002" y="4823917.274599999" start_time="07:42:08" end_time="18:04:10" >
		</activity>
		<leg mode="car" dep_time="17:27:36" trav_time="00:03:16">
			<attributes>
				<attribute name="routingMode" class="java.lang.String">car</attribute>
			</attributes>
			<route type="links" start_link="50_1" end_link="18_4" trav_time="00:03:16" distance="4659.035988301946" vehicleRefId="10006_1">50_1 50_2 50_3 54_1 54_2 54_3 54_4 18_1 18_2 18_3 18_4</route>
		</leg>
		<activity type="home" facility="5810_18" x="686457.5027000001" y="4824397.363" >
		</activity>
	</plan>

</person>

<!— ITERATION -2 ========================================= -->

<person id="10006_1">
	<attributes>
		<attribute name="age" class="java.lang.Integer">32</attribute>
		<attribute name="carAvail" class="java.lang.String">always</attribute>
		<attribute name="employed" class="java.lang.Boolean">true</attribute>
		<attribute name="sex" class="java.lang.String">m</attribute>
		<attribute name="vehicles" class="org.matsim.vehicles.PersonVehicles">{"car":"10006_1"}</attribute>
	</attributes>
	<plan score="-36.43359107294678" selected="no">
		<activity type="home" facility="5810_18" x="686457.5027000001" y="4824397.363" end_time="07:27:08" >
		</activity>
		<leg mode="car" dep_time="07:27:08" trav_time="00:01:39">
			<attributes>
				<attribute name="routingMode" class="java.lang.String">car</attribute>
			</attributes>
			<route type="links" start_link="18_4" end_link="50_1" trav_time="00:01:39" distance="1835.3162857100572" vehicleRefId="10006_1">18_4 55_1 55_2 55_3 50_1</route>
		</leg>
		<activity type="work" facility="21558_16" x="685234.5421000002" y="4823917.274599999" start_time="07:42:08" end_time="17:27:36" >
		</activity>
		<leg mode="car" dep_time="17:27:36" trav_time="00:03:16">
			<attributes>
				<attribute name="routingMode" class="java.lang.String">car</attribute>
			</attributes>
			<route type="links" start_link="50_1" end_link="18_4" trav_time="00:03:16" distance="4659.035988301946" vehicleRefId="10006_1">50_1 50_2 50_3 54_1 54_2 54_3 54_4 18_1 18_2 18_3 18_4</route>
		</leg>
		<activity type="home" facility="5810_18" x="686457.5027000001" y="4824397.363" >
		</activity>
	</plan>

	<plan score="-43.53725366545754" selected="yes">
		<activity type="home" facility="5810_18" x="686457.5027000001" y="4824397.363" end_time="08:17:18" >
		</activity>
		<leg mode="car" dep_time="07:27:08" trav_time="00:01:39">
			<attributes>
				<attribute name="routingMode" class="java.lang.String">car</attribute>
			</attributes>
			<route type="links" start_link="18_4" end_link="50_1" trav_time="00:01:39" distance="1835.3162857100572" vehicleRefId="10006_1">18_4 55_1 55_2 55_3 50_1</route>
		</leg>
		<activity type="work" facility="21558_16" x="685234.5421000002" y="4823917.274599999" start_time="07:42:08" end_time="18:04:10" >
		</activity>
		<leg mode="car" dep_time="17:27:36" trav_time="00:03:16">
			<attributes>
				<attribute name="routingMode" class="java.lang.String">car</attribute>
			</attributes>
			<route type="links" start_link="50_1" end_link="18_4" trav_time="00:03:16" distance="4659.035988301946" vehicleRefId="10006_1">50_1 50_2 50_3 54_1 54_2 54_3 54_4 18_1 18_2 18_3 18_4</route>
		</leg>
		<activity type="home" facility="5810_18" x="686457.5027000001" y="4824397.363" >
		</activity>
	</plan>

</person>

<!— ITERATION -3 ========================================= -->

<person id="10006_1">
    <attributes>
        <attribute name="age" class="java.lang.Integer">32</attribute>
        <attribute name="carAvail" class="java.lang.String">always</attribute>
        <attribute name="employed" class="java.lang.Boolean">true</attribute>
        <attribute name="sex" class="java.lang.String">m</attribute>
        <attribute name="vehicles" class="org.matsim.vehicles.PersonVehicles">{"car":"10006_1"}</attribute>
    </attributes>
    <plan score="-36.43359107294678" selected="no">
        <activity type="home" facility="5810_18" x="686457.5027000001" y="4824397.363" end_time="07:27:08" >
        </activity>
        <leg mode="car" dep_time="07:27:08" trav_time="00:01:39">
            <attributes>
                <attribute name="routingMode" class="java.lang.String">car</attribute>
            </attributes>
            <route type="links" start_link="18_4" end_link="50_1" trav_time="00:01:39" distance="1835.3162857100572" vehicleRefId="10006_1">18_4 55_1 55_2 55_3 50_1</route>
        </leg>
        <activity type="work" facility="21558_16" x="685234.5421000002" y="4823917.274599999" start_time="07:42:08" end_time="17:27:36" >
        </activity>
        <leg mode="car" dep_time="17:27:36" trav_time="00:03:16">
            <attributes>
                <attribute name="routingMode" class="java.lang.String">car</attribute>
            </attributes>
            <route type="links" start_link="50_1" end_link="18_4" trav_time="00:03:16" distance="4659.035988301946" vehicleRefId="10006_1">50_1 50_2 50_3 54_1 54_2 54_3 54_4 18_1 18_2 18_3 18_4</route>
        </leg>
        <activity type="home" facility="5810_18" x="686457.5027000001" y="4824397.363" >
        </activity>
    </plan>

    <plan score="-43.53725366545754" selected="no">
        <activity type="home" facility="5810_18" x="686457.5027000001" y="4824397.363" end_time="08:17:18" >
        </activity>
        <leg mode="car" dep_time="07:27:08" trav_time="00:01:39">
            <attributes>
                <attribute name="routingMode" class="java.lang.String">car</attribute>
            </attributes>
            <route type="links" start_link="18_4" end_link="50_1" trav_time="00:01:39" distance="1835.3162857100572" vehicleRefId="10006_1">18_4 55_1 55_2 55_3 50_1</route>
        </leg>
        <activity type="work" facility="21558_16" x="685234.5421000002" y="4823917.274599999" start_time="07:42:08" end_time="18:04:10" >
        </activity>
        <leg mode="car" dep_time="17:27:36" trav_time="00:03:16">
            <attributes>
                <attribute name="routingMode" class="java.lang.String">car</attribute>
            </attributes>
            <route type="links" start_link="50_1" end_link="18_4" trav_time="00:03:16" distance="4659.035988301946" vehicleRefId="10006_1">50_1 50_2 50_3 54_1 54_2 54_3 54_4 18_1 18_2 18_3 18_4</route>
        </leg>
        <activity type="home" facility="5810_18" x="686457.5027000001" y="4824397.363" >
        </activity>
    </plan>

    <plan score="-43.53725366545754" selected="yes">
        <activity type="home" facility="5810_18" x="686457.5027000001" y="4824397.363" end_time="08:17:18" >
        </activity>
        <leg mode="walk" dep_time="08:17:18" trav_time="00:34:09">
            <attributes>
                <attribute name="routingMode" class="java.lang.String">walk</attribute>
            </attributes>
            <route type="generic" start_link="18_4" end_link="50_1" trav_time="00:34:09" distance="1707.9632831635238"></route>
        </leg>
        <activity type="work" facility="21558_16" x="685234.5421000002" y="4823917.274599999" start_time="07:42:08" end_time="18:04:10" >
        </activity>
        <leg mode="walk" dep_time="18:04:10" trav_time="00:34:09">
            <attributes>
                <attribute name="routingMode" class="java.lang.String">walk</attribute>
            </attributes>
            <route type="generic" start_link="50_1" end_link="18_4" trav_time="00:34:09" distance="1707.9632831635238"></route>
        </leg>
        <activity type="home" facility="5810_18" x="686457.5027000001" y="4824397.363" >
        </activity>
    </plan>

</person>

Now,
I am not able to understand how score = “-36.433, -43.53” is obtained in iteration 1 and iteration 2 respectively provided with the existing configurations and other time related informations. Can you tell me how this value is calculated using the formula ?

I found that the formula to calculate new score is :

new_score = (1-learningRate)*old_score + learningRate * score_from_mobsim.

But how the score_from_mobsim is calculated?

As per my understanding, it is calculated using Charypar-Nagel Utility function . But I am not able to calculate that value by using these available information. Can you please help me to understand how these particular score values are obtained?

Our user guide ch. 10 has an overview of the scoring in MATSim.

I went thoroughly through the documentation. But I was trying to put the values and calculate the score function manually and tally that score function value with the value obtained from MATSim.
Theoretically, I am clear about the concept but I wanted to know how the values are calculated inside program. I also tried to figure out from inside the code in this link, https://github.com/matsim-org/matsim-libs/blob/master/matsim/src/main/java/org/matsim/core/scoring/functions/CharyparNagelActivityScoring.java
So is it possible for you to show me with mathematical calculation upon provided the conditions mentioned above?

In the scoring config group, there is a switch writeExperiencedPlans. If you set this to "true" (in code or in the xml config), you should get an experienced_plans_scores.txt.gz in those iterations when plans files are written. In principle, this shows the different contributions to the overall score. I have never used it myself, but I know that it was written as response to questions such as yours. In principle, it should work; I am, however, not sure if it really catches all contributions to the score, or if there are newer additions to the scoring (like throwing score events) that are not included into that older code.

Could you please report how far that brings you? Thanks ...