MATSIM
Static Public Member Functions | Static Private Attributes | List of all members
tutorial.converter.networkFromEmme.RunNetworkEmme2MatsimExample Class Reference

Static Public Member Functions

static void readNetwork (Scenario sc)
 
static void main (String[] args)
 

Static Private Attributes

static final Logger log = Logger.getLogger(RunNetworkEmme2MatsimExample.class)
 
static final int PSRC = 0
 
static final int EUGENE = 1
 
static final int NW_NAME = PSRC
 

Detailed Description

Translates emme networks into matsim networks.

Uses the "emme network export" result as input, NOT the GIS export.

A serious problem is that there is not enough info in the headers of the emme files: (column counting starts at 0!!!)

Keyword(s): emme/2

I moved this here because in this way it can be html-referenced out of matsim.org. Additional code that does similar things can be found by searching the playground for "emme/2". kai, mar'11

Author
nagel

Definition at line 59 of file RunNetworkEmme2MatsimExample.java.

Member Function Documentation

static void tutorial.converter.networkFromEmme.RunNetworkEmme2MatsimExample.readNetwork ( Scenario  sc)
static

Definition at line 67 of file RunNetworkEmme2MatsimExample.java.

References org.matsim.api.core.v01.network.Network.addLink(), org.matsim.api.core.v01.network.Network.addNode(), org.matsim.api.core.v01.network.NetworkFactory.createLink(), org.matsim.api.core.v01.network.NetworkFactory.createNode(), org.matsim.core.utils.io.IOUtils.getBufferedReader(), org.matsim.api.core.v01.network.Network.getFactory(), org.matsim.api.core.v01.Scenario.getNetwork(), org.matsim.api.core.v01.network.Network.getNodes(), org.matsim.api.core.v01.network.Link.setCapacity(), org.matsim.api.core.v01.network.Network.setCapacityPeriod(), org.matsim.api.core.v01.network.Link.setFreespeed(), org.matsim.api.core.v01.network.Link.setLength(), and org.matsim.api.core.v01.network.Link.setNumberOfLanes().

Referenced by tutorial.converter.networkFromEmme.RunNetworkEmme2MatsimExample.main().

67  {
68  Network network = sc.getNetwork() ;
69  ((Network) network).setCapacityPeriod(3600.) ;
70  ((Network) network).setEffectiveLaneWidth(3.75) ;
71 // network.setEffectiveCellSize(7.5) ;
72 
73  // read emme3 network
74  try {
75 // BufferedReader reader = IOUtils.getBufferedReader("/home/nagel/tmp/tab/net1.out" ) ;
76  BufferedReader reader = IOUtils.getBufferedReader("/Users/nagel/eclipse/shared-svn/studies/countries/us/psrc/network/emme-export/net1.out" ) ;
77 
78  boolean weAreReadingNodes = true ;
79  long linkCnt = 0 ;
80 
81  String line ;
82  while ( (line = reader.readLine()) != null ) {
83  String[] parts = line.split("[ \t\n]+");
84 
85  if ( parts[0].equals("c") ) {
86  // is a comment; ignore
87  } else if ( parts[0].equals("t") ) {
88  if ( parts[1].equals("links") ) {
89  weAreReadingNodes = false ;
90  }
91  } else if ( parts[0].equals("a") ) { // || parts[0].equals("a*") ) { // a* seem to be centroid connectors
92  if ( weAreReadingNodes ) {
93  String idStr = parts[1] ;
94  String xxStr = parts[2] ;
95  String yyStr = parts[3] ;
96  Node node = network.getFactory().createNode(Id.create(idStr, Node.class),
97  new Coord(Double.parseDouble(xxStr), Double.parseDouble(yyStr)));
98  network.addNode( node ) ;
99  } else {
100  Node fromNode = network.getNodes().get(Id.create(parts[1], Node.class));
101  Node toNode = network.getNodes().get(Id.create(parts[2], Node.class));
102  if ( fromNode==null || toNode==null ) {
103 // log.info("fromNode or toNode ==null; probably connector link; skipping it ...") ;
104  continue ;
105  }
106  if ( parts[4].equals("r") || parts[4].equals("b") ) {
107  log.info("rail only or bus only link; skipping it ...") ;
108  continue;
109  }
110  double length = 1600 * Double.parseDouble( parts[3] ) ; // probably miles
111 // String type = parts[5] ;
112 
113  double permlanes = Double.parseDouble( parts[6] ) ;
114  if ( permlanes <= 0 ) { permlanes = 0.5 ; }
115 
116  double capacity, freespeed ;
117  if ( NW_NAME==PSRC ) {
118  capacity = permlanes * Double.parseDouble( parts[8] ) ;
119  if ( capacity <= 500 ) { capacity = 500. ; }
120 
121  freespeed = Double.parseDouble( parts[9] ) ; // mph
122  if ( freespeed < 10. ) { freespeed = 10. ; }
123  freespeed *= 1600./3600. ;
124  } else if ( NW_NAME==EUGENE ) {
125  log.warn("For EUGENE, I have not clarified if capacity really needs to be multiplied by number of lanes.");
126  capacity = permlanes * Double.parseDouble( parts[10] ) ;
127  if ( capacity <= 500 ) { capacity = 500. ; }
128 
129  freespeed = Double.parseDouble( parts[9] ) ; // mph
130  if ( freespeed < 10. ) { freespeed = 10. ; }
131  freespeed *= 1600./3600. ;
132  } else {
133  log.error( "NW_NAME not known; aborting" ) ;
134  System.exit(-1);
135  }
136 
137  Id<Link> id = Id.create(linkCnt, Link.class);
138  linkCnt++;
139 
140  Link link = network.getFactory().createLink(id, fromNode, toNode ) ;
141  link.setLength(length) ;
142  link.setFreespeed(freespeed) ;
143  link.setCapacity(capacity) ;
144  link.setNumberOfLanes(permlanes) ;
145 
146  network.addLink(link);
147  }
148  } else {
149  // something else; do nothing
150  }
151  }
152  } catch (FileNotFoundException e) {
153  e.printStackTrace();
154  } catch (IOException e) {
155  e.printStackTrace();
156  }
157  }

Here is the call graph for this function:

static void tutorial.converter.networkFromEmme.RunNetworkEmme2MatsimExample.main ( String[]  args)
static
Parameters
args

Definition at line 164 of file RunNetworkEmme2MatsimExample.java.

References org.matsim.core.config.ConfigUtils.createConfig(), org.matsim.core.scenario.ScenarioUtils.createScenario(), org.matsim.api.core.v01.Scenario.getNetwork(), tutorial.converter.networkFromEmme.RunNetworkEmme2MatsimExample.readNetwork(), org.matsim.core.network.algorithms.NetworkCleaner.run(), and org.matsim.api.core.v01.network.NetworkWriter.write().

164  {
165  Config config = ConfigUtils.createConfig() ;
166  // (no api-only way to get a scenario without config)
167 
168  Scenario sc = ScenarioUtils.createScenario(config) ;
169  // (no api-only way to get a network, Id, Coord without scenario)
170 
171  Network network = sc.getNetwork();
172 
173  log.info("reading network ...");
174  readNetwork(sc) ;
175  log.info("... finished reading network.\n");
176 
177  log.info("cleaning network ...");
178  NetworkCleaner nwCleaner = new NetworkCleaner() ;
179  nwCleaner.run( network ) ;
180  log.info("... finished cleaning network.\n") ;
181 
182  log.info("writing network ...") ;
183  new NetworkWriter(network).write("/home/nagel/tmp/net.xml.gz");
184  log.info("... finished writing network.\n") ;
185  }

Here is the call graph for this function:

Member Data Documentation

final Logger tutorial.converter.networkFromEmme.RunNetworkEmme2MatsimExample.log = Logger.getLogger(RunNetworkEmme2MatsimExample.class)
staticprivate

Definition at line 60 of file RunNetworkEmme2MatsimExample.java.

final int tutorial.converter.networkFromEmme.RunNetworkEmme2MatsimExample.PSRC = 0
staticprivate

Definition at line 62 of file RunNetworkEmme2MatsimExample.java.

final int tutorial.converter.networkFromEmme.RunNetworkEmme2MatsimExample.EUGENE = 1
staticprivate

Definition at line 63 of file RunNetworkEmme2MatsimExample.java.

final int tutorial.converter.networkFromEmme.RunNetworkEmme2MatsimExample.NW_NAME = PSRC
staticprivate

Definition at line 65 of file RunNetworkEmme2MatsimExample.java.


The documentation for this class was generated from the following file: