matsim-org / matsim-code-examples

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

Issue with using ParameterSet for scoringParameters #83

Closed alexdawn closed 5 years ago

alexdawn commented 5 years ago

Hi I am trying to get subpopulations to work (see https://github.com/matsim-org/matsim-code-examples/issues/76), using the example project in equilibrium extended I tried restructuring my planCalcScore module to have the same parameter sets because I was getting inexplicable errors using the config format without the parameter sets

My config is here with most of the features transit, subpopulation, modechoice turned off while I try and get the planCalcScore working:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE config SYSTEM "./dtd/config_v2.dtd"[
    <!ENTITY frac "0.1">
    <!ENTITY scale "10.0">]>

<config>
    <module name="global">
        <!--Matsim requires a flat projection, so we are using National Grid OSGB 1936 -->
        <param name="coordinateSystem" value="EPSG:27700" />
    </module>

    <module name="network">
        <param name="inputNetworkFile" value="network.xml" />
    </module>

    <module name="plans">
        <param name="inputPlansFile" value="jtw_with_nts_agents.xml" />
        <!--<param name="inputPersonAttributesFile" value="personAttributes.xml" />-->
        <!--<param name="subpopulationAttributeName" value="subpopulation" />-->
    </module>

    <module name="controler">
        <param name="runId" value="v0.3"/>
        <param name="outputDirectory" value="./output" />
        <param name="firstIteration" value="0" />
        <param name="lastIteration" value="50" />
        <param name="snapshotFormat" value="googleearth"/>
        <param name="writeEventsInterval" value="50"/>
        <param name="writePlansInterval" value="50"/>
        <param name="writeSnapshotsInterval" value="50"/>
        <param name="routingAlgorithmType" value="AStarLandmarks" />
    </module>

    <module name="qsim">
        <param name="vehiclesSource" value="modeVehicleTypesFromVehiclesData" />
        <param name="mainMode" value="car,lgv,hgv" />
        <param name="startTime" value="00:00:00" />
        <param name="endTime" value="24:00:00" />

        <param name = "snapshotperiod"  value = "00:00:00"/>
        <!-- Boolean. `true': stuck vehicles are removed, aborting the plan; `false': stuck vehicles are forced into the next link. `false' is probably the better choice. -->
        <param name="removeStuckVehicles" value="false" />

        <!-- time in seconds.  Time after which the frontmost vehicle on a link is called `stuck' if it does not move. -->
        <param name="stuckTime" value="2.0" />
        <param name="timeStepSize" value="00:00:01" />

        <param name="flowCapacityFactor" value="&frac;" />
        <param name="storageCapacityFactor" value="&frac;" />

        <param name="vehicleBehavior" value="wait"/> <!-- once we add in vehicle sharing agents have to wait till vehicle is avaiable -->
    </module>

    <module name="planCalcScore">
        <param name="learningRate" value="1.0" />
        <param name="BrainExpBeta" value="2.0" />
        <parameterset type="scoringParameters">
            <param name="subpopulation" value="null" />
            <param name="lateArrival" value="-0" />
            <param name="earlyDeparture" value="-0" />
            <param name="performing" value="+2" />
            <param name="waiting" value="-0" />
            <parameterset type="modeParams" >
                <param name="constant" value="0.0" />
                <param name="marginalUtilityOfDistance_util_m" value="0.0" />
                <param name="marginalUtilityOfTraveling_util_hr" value="-6.0" />
                <param name="mode" value="car" />
                <param name="monetaryDistanceRate" value="0.0" />
            </parameterset>
            <parameterset type="modeParams" >
                <param name="constant" value="0.0" />
                <param name="marginalUtilityOfDistance_util_m" value="0.0" />
                <param name="marginalUtilityOfTraveling_util_hr" value="-6.0" />
                <param name="mode" value="motorbike" />
                <param name="monetaryDistanceRate" value="0.0" />
            </parameterset>
            <parameterset type="modeParams" >
                <param name="constant" value="0.0" />
                <param name="marginalUtilityOfDistance_util_m" value="0.0" />
                <param name="marginalUtilityOfTraveling_util_hr" value="-6.0" />
                <param name="mode" value="lgv" />
                <param name="monetaryDistanceRate" value="0.0" />
            </parameterset>
            <parameterset type="modeParams" >
                <param name="constant" value="0.0" />
                <param name="marginalUtilityOfDistance_util_m" value="0.0" />
                <param name="marginalUtilityOfTraveling_util_hr" value="-6.0" />
                <param name="mode" value="hgv" />
                <param name="monetaryDistanceRate" value="0.0" />
            </parameterset>
            <parameterset type="activityParams" >
                <param name="activityType"            value="h" /> <!-- home -->
                <param name="priority"        value="1" />
                <param name="typicalDuration" value="12:00:00" />
                <param name="minimalDuration" value="01:00:00" />
            </parameterset>
            <parameterset type="activityParams" >
                <param name="activityType"            value="w" /> <!-- work -->
                <param name="priority"        value="1" />
                <param name="typicalDuration" value="08:00:00" />
                <param name="minimalDuration" value="04:00:00" />
            </parameterset>
            <parameterset type="activityParams" >
                <param name="activityType"            value="b" /> <!-- business -->
                <param name="priority"        value="1" />
                <param name="typicalDuration" value="03:00:00" />
                <param name="minimalDuration" value="01:00:00" />
            </parameterset>
        </parameterset>
    </module>

    <module name="strategy">
        <param name="maxAgentPlanMemorySize" value="5" /> <!-- 0 would mean unlimited, bad idea for your RAM! -->
        <!--gradually phase out options, last 10 iterations are just selecting from existing plans -->
        <parameterset type="strategysettings" >
            <param name="strategyName" value="BestScore" /> <!-- changes plan weighted towards the best option  (ChangeExpBeta) -->
            <!--<param name="subpopulation" value="agent,freightdriver" />-->
            <param name="weight" value="0.6" />
        </parameterset>
        <parameterset type="strategysettings" >
            <param name="disableAfterIteration" value="45" />
            <param name="strategyName" value="ReRoute" />
            <!--<param name="subpopulation" value="agent,freightdriver" />-->
            <param name="weight" value="0.2" />
        </parameterset>
        <parameterset type="strategysettings" >
            <param name="disableAfterIteration" value="40" />
            <param name="strategyName" value="TimeAllocationMutator_ReRoute" />
            <!--<param name="subpopulation" value="agent" />-->
            <param name="weight" value="0.1" />
        </parameterset>
        <!--<parameterset type="strategysettings" >
            <param name="disableAfterIteration" value="25" />
            <param name="strategyName" value="SubtourModeChoice" />
            <param name="subpopulation" value="agent" />
            <param name="weight" value="0.1" />
        </parameterset>-->
    </module>

    <module name="planscalcroute" >
        <param name="networkModes" value="car,lgv,hgv" />
        <parameterset type="teleportedModeParameters" >
            <param name="beelineDistanceFactor" value="1.3" />
            <param name="mode" value="bike" />
            <param name="teleportedModeSpeed" value="4.166666666666667" />
        </parameterset>
        <parameterset type="teleportedModeParameters" >
            <param name="beelineDistanceFactor" value="1.3" />
            <param name="mode" value="walk" />
            <param name="teleportedModeSpeed" value="0.8333333333333333" />
        </parameterset>
        <parameterset type="teleportedModeParameters">
            <param name="mode" value="ride"/>
            <param name="teleportedModeFreespeedFactor" value="1.0"/><!-- multiplyer on car free speeds -->
        </parameterset>
        <parameterset type="teleportedModeParameters">
            <param name="mode" value="motorbike"/>
            <param name="teleportedModeFreespeedFactor" value="1.0"/><!-- multiplyer on car free speeds -->
        </parameterset>
    </module>

    <module name="households">
        <param name="inputFile" value="null"/>
        <param name="inputHouseholdAttributesFile" value="null"/>
    </module>

    <module name="vehicles" >
        <param name="vehiclesFile" value="mode-vehicles.xml" />
    </module>

    <module name="TimeAllocationMutator" >
        <param name="mutationRange" value="9000.00" /> <!-- module currently randomly shifts by up to 2.5hrs -->
    </module>

    <module name="travelTimeCalculator" >
        <param name="analyzedModes" value="car,ride,walk,bike,motorbike,lgv,hgv" />
        <param name="separateModes" value="true" />
    </module>

    <module name="counts" >
        <param name="inputCountsFile" value="counts.xml" />
        <param name="outputformat" value="txt, html, kml" />
        <param name="countsScaleFactor" value="&scale;" />
    </module>

    <!--<module name="transit">
        <param name="useTransit" value="true" />
        <param name="transitScheduleFile" value="transitSchedule.xml" />
        <param name="vehiclesFile" value="transitVehicles.xml" />
        <param name="transitModes" value="pt" />
    </module>--> <!--this properly recognises train etc...-->

    <!--<module name="subtourModeChoice">
        <param name="chainBasedModes" value="car,bike,motorbike" />
        <param name="modes" value="car,ride,walk,bike,motorbike" />
        <param name="considerCarAvailability" value="false"/>
    </module>-->
</config>

the error is:


2019-02-06 12:22:04,175 ERROR MatsimRuntimeModifications:63 Shutdown possibly caused by the following Exception:
java.lang.NullPointerException
        at org.matsim.core.config.groups.PlanCalcScoreConfigGroup$ScoringParameterSet.getMarginalUtlOfWaitingPt_utils_hr(PlanCalcScoreConfigGroup.java:1183)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.matsim.core.config.ReflectiveConfigGroup.getValue(ReflectiveConfigGroup.java:350)
        at org.matsim.core.config.ConfigGroup.addParameterToMap(ConfigGroup.java:79)
        at org.matsim.core.config.ReflectiveConfigGroup.getParams(ReflectiveConfigGroup.java:408)
        at org.matsim.core.config.ConfigWriterHandlerImplV2.writeModule(ConfigWriterHandlerImplV2.java:61)
        at org.matsim.core.config.ConfigWriterHandlerImplV2.writeModule(ConfigWriterHandlerImplV2.java:106)
        at org.matsim.core.config.ConfigWriterHandlerImplV2.writeModule(ConfigWriterHandlerImplV2.java:157)
        at org.matsim.core.config.ConfigWriter.write(ConfigWriter.java:111)
        at org.matsim.core.config.ConfigWriter.writeStream(ConfigWriter.java:75)
        at org.matsim.core.controler.ControlerUtils.checkConfigConsistencyAndWriteToLog(ControlerUtils.java:61)
        at org.matsim.core.controler.AbstractController$1.run(AbstractController.java:82)
        at org.matsim.core.controler.MatsimRuntimeModifications.run(MatsimRuntimeModifications.java:48)
        at org.matsim.core.controler.MatsimRuntimeModifications.run(MatsimRuntimeModifications.java:31)
        at org.matsim.core.controler.AbstractController.run(AbstractController.java:92)
        at org.matsim.core.controler.NewControler.run(NewControler.java:75)
        at org.matsim.core.controler.Controler.run(Controler.java:202)
        at org.matsim.run.Controler.run(Controler.java:56)
        at org.matsim.run.Controler.main(Controler.java:60)
alexdawn commented 5 years ago

have avoided this error in the mean time by not using <parameterset type="modeParams" >

kainagel commented 5 years ago

Although this issue has been closed:

I know that there is some ugly mechanics involved here that is confusing and that we need to clean up. It has to do with backwards compatibility that we wanted to keep when this was introduced.

In that sense: The fact that it now runs without errors unfortunately does not mean that it does what it should.

Please be careful.

tduberne commented 5 years ago

Although what @kainagel said is true (be careful when mixing "nested" and "flat" config formats), my feeling here is that this is actually a bug that was missed by the unit tests.

Looking at the stack trace and the code for getMarginalUtlOfWaitingPt_utils_hr, this seems to be a mess-up in the two backward-compatibility layers, which seems to fire only when there is no "pt" mode defined.

Thank you for the report!