matsim-org / matsim-code-examples

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

Cadyts PT and MIT calibration in a combined way #187

Closed ChristophTraf closed 4 years ago

ChristophTraf commented 5 years ago

Since a calibration of the PT affects MIT simulation count data, and vice versa the MIT calibration has an influence on the PT, we would like to calibrate PT and MIT in a combined way. Is such a calibration possible with Cadyts?

If both modules (CadytsPtModule and CadytsCarModule) are added to the controler at the same time, we get a null point exception.

controler.addOverridingModule(new CadytsPtModule()); controler.addOverridingModule(new CadytsCarModule());

kainagel commented 4 years ago

Sorry for the delay. From a conceptual point of view it should work. However, there are presumably implementation issues; e.g. the cadyts car module may not know what to do with buses. If you could make available via github some code that has that null pointer exception, that would be great.

ChristophTraf commented 4 years ago

Hi, thank you for your response. I put the code on the repo "https://github.com/ChristophTraf/CadytsTests.git". In the method “testCalibrationAsScoringPTwithMIT” under “test/java/” I tried to perform a combined calibration.

Thank you

kainagel commented 4 years ago

Hello, thanks. I just looked at it. It is (evidently) not running since the input files are missing. Could you please either add an illustrative scenario that shows the same error, or make the scenario available to me? The first is preferred; but if it is not possible you could make the scenario files available to me privately. All the best ...

ChristophTraf commented 4 years ago

Hello Kai!

I've added test input files to the repo "https://github.com/ChristophTraf/CadytsTests.git". Thank you!!!

LG Christoph

kainagel commented 4 years ago

Status update: I think what is happening is the following: there is a config setting that sets the "calibrated items". For your application, this would have to exist once for pt and once for car. Unfortunately, it does not. So you first fill it with the pt lines. Later the code itself fills it with the car links, which effectively over-writes the pt lines setting. Later in the code it thus uses the car links and tries to find corresponding pt lines, which evidently do not exist.

Just wanted to let you know where I stand; I don't have any more time right now. My intuition to move forward would be to just get rid of that config setting; after all, we can just assume that all items for which we register counts will also be used for calibration. But I need to try around to find out about resulting complications. I don't think that there is anything simple you can do from the user side.

whizkid-25 commented 4 years ago

Hi @ChristophTraf , @kainagel

Did you come up with any solution. I am facing the same problem. I have explained my issue in the following link https://github.com/matsim-org/matsim-code-examples. It would be really helpful if you can have a look!

ChristophTraf commented 4 years ago

Hey @whizkid-25

No, I could not find any solution. I tried to perform a separate calibration of car and then pt while first calibrating cars and then removed the car mode from the changeModes and subtourModeChoice parameters for the calibration of pt. Since this changes the use of pt, the modal split of pt and car also changes. It would be great if such a combined calibration would work.

whizkid-25 commented 4 years ago

Hi @ChristophTraf ,

Thanks for replying back. I have tried to calibrate the car. However, while trying to calibrate pt there's an error which shuts down my simulation. Can you please share the PT module you have used in your config. file? Do I need a separate count file for transit as well?

Looking forward to your answer. Thanks again.

ChristophTraf commented 4 years ago

You can find examples in the contribs->cadytsIntegration (https://github.com/matsim-org/matsim/tree/master/contribs/cadytsIntegration)

whizkid-25 commented 4 years ago

Yeah I didn't find an example config.xml file though.

ChristophTraf commented 4 years ago

run for example the testInitialization in https://github.com/matsim-org/matsim/blob/master/contribs/cadytsIntegration/src/test/java/org/matsim/contrib/cadyts/pt/CadytsPtIT.java. It creates a config

whizkid-25 commented 4 years ago

Hi @ChristophTraf Can you please paste the example config. file here. For some reasons I cannot retrieve it from the testinitialization. I have uploaded mine below.

whizkid-25 commented 4 years ago

Hi Christoph

Can you please see the attached config. file that I have prepared and tell me if this will work? Also, can you please send me the example config. xml file here? Thanks a lot.

Syed Ahnaf Morshed,PhD Candidate Lehman Center for Transportation Research Civil and Environmental Engineering College of Engineering and Computing 10555 W. Flagler Street, Miami, FL 33174 (337)-446-9308 smors005@fiu.edu smors005@fiu.edu

On Thu, Feb 13, 2020 at 3:07 AM ChristophTraf notifications@github.com wrote:

run for example the testInitialization in https://github.com/matsim-org/matsim/blob/master/contribs/cadytsIntegration/src/test/java/org/matsim/contrib/cadyts/pt/CadytsPtIT.java. It creates a config

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/matsim-org/matsim-code-examples/issues/187?email_source=notifications&email_token=AOLKTRY2S3O6SMZWESQJCD3RCT5SRA5CNFSM4ILAXNJKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOELTZICQ#issuecomment-585602058, or unsubscribe https://github.com/notifications/unsubscribe-auth/AOLKTR3CAOQMCVCLUDLGGGTRCT5SRANCNFSM4ILAXNJA .

<?xml version="1.0" ?> <!DOCTYPE config SYSTEM "http://www.matsim.org/files/dtd/config_v2.dtd">

<
whizkid-25 commented 4 years ago

Hi @ChristophTraf, Can you please attach the example config. file here.

kainagel commented 4 years ago

At least purely technically, the matsim head now will allow to calibrate simultaneously against car and pt counts. It is currently in the regression testing, if all goes well, it will merge automatically in the next couple of hours.

When I run the testCalibrationAsScoringPTwithMIT, it fails with some problems with coordinates. I switched on autogeneration of facilities, and together with some fixes there (also still to be merged into matsim master), the code now runs iterations. If they are going anywhere reasonable, I cannot say.

whizkid-25 commented 4 years ago

@kainagel Hi, Do you have a sample module for PT Cadyts that I can refer to in the config. file?

kainagel commented 4 years ago

@whizkid-25 : could you please ask your questions in a separate thread? thanks

JackyAsp commented 4 years ago

Hi! I have seen that there are some test scenarios for pt calibration and car calibration (matsim/contribs/cadytsIntegration/src/test/java/org/matsim/contrib/cadyts/)? Does there already exist a test scenario to run combined PT and MIT calibration?

ChristophTraf commented 4 years ago

Hi Kai!

That’s great, thank you very much. Do I need to define a weekly build version in my pom.xml instead of the 12.0-Snapshot to obtain the new functionality via maven? The CadytsPtContext.java and all other files were not update (just in the git repo).

Thank you!

kainagel commented 4 years ago

Arrgghh, glad that you caught this. Both the snapshots and the weekly builds are generated by jenkins, see http://ci.matsim.org:8080 . Unfortunately, the contribs have been failing the last couple of days, see here: http://ci.matsim.org:8080/job/MATSim_contrib_M2/ . Meaning that the necessary code is deployed neither by snapshot nor by weekly build. -- Actually, turns out that they are failing because of one of my changes, which was accepted by the travis build server (which certifies the github merge), but not by jenkins. :-(. Will fix it ASAP.

kainagel commented 4 years ago

The build server http://ci.matsim.org:8080/job/MATSim_contrib_M2/7078/ has now run through so 12.0-SNAPSHOT with the new material should be there. You may have to force-update maven, or wait 24hrs. I don't know when the next weekly build will be.

ChristophTraf commented 4 years ago

Now everything looks fine and all changes are included in the 12.0-SNAPSHOT. Thank you!

kainagel commented 4 years ago

Glad to hear that. I think that I made it clear that the setup so it was in your repo last time I looked at it by itself will not do anything. One issue is that the corrected pt scoring was nowhere inserted last time I looked at it. Let us know how it goes. I will now close this; please re-open if you think that that is warranted.

andyb87 commented 3 years ago

Dear MATSim community,

I am also trying to run the Cadyts calibration for MIT and PT at the same time in my scenario. I am using the latest Weekly for this (14.0-2021w32) and have built a RunMatsim script following the examples above.

public class RunCadyts {

    public static void main(String[] args) {
        final Config config = ConfigUtils.loadConfig( args[0], new CadytsConfigGroup() );

        final Scenario scenario = ScenarioUtils.loadScenario(config);

        // ---

        final Controler controler = new Controler( scenario );

        controler.addOverridingModule(new CadytsCarModule());
        controler.addOverridingModule(new CadytsPtModule());

        // include cadyts into the plan scoring (this will add the cadyts corrections to the scores):

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

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

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

                return scoringFunctionAccumulator;
            }
        }) ;

        controler.run();

    }

}

At first sight everything works fine and the simulation runs without problems. However, I noticed that only one Cadyts module does the calibration work, depending on the order the addOverridingModule is added in the script. In my example above, only CadytsPtModule would calibrate the scenario.

In the log output however both modules are initialized as expected, so it seems that the latter addOverridingModule is overriding the previous one in the Script (please see log_terminal_output.txt). However, in the calibration-stats output file both modes are depicted and only the latter is calibrating (please see calibration-stats.txt, here only pt)

Is there an elegant method to run both Cadyts modules at the same time? Maybe I did miss something?

Many thanks in advance!