Skip to content

faq 83722244

Billy Charlton edited this page Sep 5, 2018 · 2 revisions

How to use TripsAnalyzer (analysis contrib)

by Rolando Armas on 2016-09-09 10:16:53


Hey, Guys.

I need to compute the travel time according to leg modes. 

The functionality that allows that is inside org.matsim.contrib.analysis.christoph.TripsAnalyzer.java. But I do not how to use it. I have tried the following:


public static void main(String[] args) {
                
                 Set<String> sortedModes = new TreeSet<String>(); 
                 // please adjust your paths to your output directory
                 EventsManager eventsManager = EventsUtils.createEventsManager();
                 Scenario scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig());
                
                 String tripsFilename="output/pt/tripFile.txt";
                 String durationsFileName="output/pt/durationFile.txt";
                
                 // modes which are analyzed by default
                 sortedModes.add(TransportMode.bike);
                 sortedModes.add(TransportMode.car);
                 sortedModes.add(TransportMode.pt);
                 sortedModes.add(TransportMode.ride);
                 sortedModes.add(TransportMode.walk);
                
                 TripsAnalyzer tripAnalyzer = new TripsAnalyzer(tripsFilename,durationsFileName,sortedModes,false);
                
                 eventsManager.addHandler(tripAnalyzer);
                
                
                 new MatsimEventsReader(eventsManager).readFile("output/pt/ITERS/it.10/10.events.xml.gz");
                

     }

But it does not work.

Please, could you show me the proper way to do that?


Thanks.


Comments: 1


Re: How to use TripsAnalyzer (analysis contrib)

by Kai Nagel on 2016-09-14 08:38:49

Dear Rolando,

It is not my code ... but that code is not designed to be run standalone.   From looking at the code, it needs something like

tripAnalyszer.notifyStartup(...);
 ...EventsReader...readFile(...) ;
 tripAnalyzer.notifyIterationEnds(...);
 tripAnalyzer.notifyShutdown(...);

(or inserted into a Controler).

Rather than faking startup/shutdown events, it might be easier to extract the code that writes to file from those methods and include them into your code.  Or insert it into your Controler right away.

---

The "analysis" contrib is there for different reasons than most other contribs:

(1) It contains code that is used by other contribs and thus has to be in a contrib because of the hierarchical maven dependencies.  Similar to "common".

(2) We started it separately from "common", but then decided to leave it separately because it contains code that may give people ideas.  But other than most other contribs, it is more meant for looking at it than for "using" it.

Hope that helps, best wishes

Kai

Clone this wiki locally