matsim-org / matsim-code-examples

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

PT ridership calibration #725

Open mashrur93 opened 2 years ago

mashrur93 commented 2 years ago

Hi,

I am trying to calibrate my model for both traffic volume and PT ridership (at least alighting and boarding). I have prepared the count files for both contexts. I saw an example code for calibrating the car volume, but for PT there is none.

  1. My first question is if there is an additional module of PT calibration in the config file, like cadytsCar for Car. If so, what is the module's name?
  2. I found the necessary packages uploaded in the cadytsIntegration contrib for calibrating PT. However, there is no example code for running the cadyts for PT.

I am currently using cadyts for traffic volume only, which is as follows:

controler.addOverridingModule(new CadytsCarModule());

controler.setScoringFunctionFactory(new ScoringFunctionFactory() { @Inject CadytsContext cadytsContext; @Inject ScoringParametersForPerson parameters; @Override public ScoringFunction createNewScoringFunction(Person person) { final ScoringParameters params = parameters.getScoringParameters(person);

        SumScoringFunction scoringFunctionAccumulator = new SumScoringFunction();
        scoringFunctionAccumulator.addScoringFunction(new CharyparNagelLegScoring(params, controler.getScenario().getNetwork(), config.transit().getTransitModes()));
        scoringFunctionAccumulator.addScoringFunction(new CharyparNagelActivityScoring(params)) ;
        scoringFunctionAccumulator.addScoringFunction(new CharyparNagelAgentStuckScoring(params));

            final CadytsScoring<Link> scoringFunction = new CadytsScoring<>(person.getSelectedPlan(), config, cadytsContext);
        scoringFunction.setWeightOfCadytsCorrection(30. * config.planCalcScore().getBrainExpBeta()) ;
        scoringFunctionAccumulator.addScoringFunction(scoringFunction );

        return scoringFunctionAccumulator;
            }

If I want to modify the code for PT calibration, where do I have to make the changes? I have gone through https://github.com/matsim-org/matsim-code-examples/issues/187, but could not find any concluding remarks or ways to solve it. I would highly appreciate any guidance in this regard. Thanks

Janekdererste commented 2 years ago

The cadyts pt integration is can be found in here: https://github.com/matsim-org/matsim-libs/tree/master/contribs/cadytsIntegration/src/main/java/org/matsim/contrib/cadyts/pt

This package contains a package-info file I don't know how up to date or helpful the information is.

The contrib also contains an integration test, from which you could start looking around.

This contrib also contains

mashrur93 commented 2 years ago

Thanks, @Janekdererste for the quick response. The suggestions really helped. I have a question. While going through the codes, I saw current PT calibrates considering the occupancy files only, even though matsim requires all three files (alighting, boarding, and occupancy).

  1. I am a bit confused if the occupancy files refer to the passenger load on the respective station of the line or not.
  2. I have data from where I approximated the hourly boarding and alighting riders at the stations, but could not figure out how to calculate the hourly occupancies from them.

Any suggestions would be highly appreciated.

Janekdererste commented 2 years ago

Maybe @vsp-gleich can help with the occupancy files? I have never really worked with those files.

but could not figure out how to calculate the hourly occupancies from them.

This sounds like a addition and substraction exercise 🙃

mashrur93 commented 2 years ago

Thanks @Janekdererste. I was able to approximate the occupancies.

However, I am planning to do the pt calibration for daily aggregated occupancy counts, instead of hourly occupancy calibration (i.e., like we do for hourly traffic volume calibration). In doing so, I changed the "timeBinSize" attributes in the "CadytsCar" module to 86400 (24 hrs) instead of "3600". Kindly find the attached occupancy files I used.

<module name="cadytsCar" >
            .
            .
    <!-- Length of time bin for which counts are aggregated.  IN SECONDS!!!!  Default is 3600. -->
    <param name="timeBinSize" value="86400" />
            .
            .
</module>

However, I am getting errors as attached.

My question is: From the matsim manual, I understood, that each "h" value in the count file represents 1 hour (i.e., h = 6 means counts from 5 to 6hr). However, in the example config, the timeBinSize for this context was denoted as 3600. Therefore,

  1. How cadyts handle calibration against the aggregated hourly counts?
  2. When I am wanting to calibrate for daily ridership instead of hourly (that is, timeBinSize = 86400), a. Does it automatically merge the hours as needed (like adding occupancies from 6 to 24 for the attached count file) b. Or, do "h = 1" input in the count file then mean 0 to 24hr. In that case, I have the change the current count files.

    To sum up, are there any changes needed to be done in the counts file, if we want to calibrate daily ridership rather than default hourly ridership? and

I am also tagging @vsp-gleich for his thought.

I would highly appreciate any guidance in this regard. Thanks

ptCounts_occupancy.txt logfileWarningsErrors.log

vsp-gleich commented 2 years ago

Hello, I have to admit that I have never used the pt calibration code. It is rather old code and we usually lack data on vehicle capacity per departure and real world occupancy, so there is little use for us and no user experience I could share. Sorry. The occupancy file Cadyts is using is presumably the result of its CadytsPtOccupancyAnalyzer in the cadyts contrib. At least the comments suggest that no external code for occupancy analysis is to be used. CadytsPtOccupancyAnalyzer sets a hard-coded maximum time of 24 hours - 1 second (line 77), that could be part of the problem. This suggests that other values might be hard coded somewhere, too. Maybe the code was never used with a time bin size other than 1h. Typically matsim runs have more than 24 hours since some agents might return home only after midnight (effectively the simulation runs from hour 0 to hour 36 or similar). So there is likely a need to remap occupancy from the time after 24:00 hours to the early hours 24 hours earlier. At first glance it seems cadyts rather adds that demand to the last time slot, but maybe you could neglect these hours. If I was in your situation and had to get cadyts running for pt I would probably first try to get the current version with hourly counts to run with some test input and only later modify the cadyts code. I don't know what kind of input data you have, but I could be easier to somehow split up your daily counts into hourly slices in the cadyts format instead of manipulating the cadyts code straightaway. At the moment I have no time to dive deeper into that issue, sorry.