SUMO - Simulation of Urban MObility
ODAmitranHandler.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // An XML-Handler for Amitran OD matrices
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 
31 #include "ODMatrix.h"
32 #include "ODAmitranHandler.h"
33 
34 
35 // ===========================================================================
36 // method definitions
37 // ===========================================================================
38 ODAmitranHandler::ODAmitranHandler(ODMatrix& matrix, const std::string& file)
39  : SUMOSAXHandler(file), myMatrix(matrix) {}
40 
41 
43 
44 
45 void
47  bool ok = true;
48  switch (element) {
50  myVehicleType = attrs.get<std::string>(SUMO_ATTR_ID, 0, ok);
51  break;
52  case SUMO_TAG_TIMESLICE:
53  myBegin = attrs.get<int>(SUMO_ATTR_STARTTIME, myVehicleType.c_str(), ok);
54  myEnd = myBegin + attrs.get<int>(SUMO_ATTR_DURATION, myVehicleType.c_str(), ok);
55  if (myBegin >= myEnd) {
56  WRITE_ERROR("Invalid duration for timeSlice starting " + toString(myBegin) + ".");
57  }
58  break;
59  case SUMO_TAG_OD_PAIR:
60  myMatrix.add(attrs.get<double>(SUMO_ATTR_AMOUNT, myVehicleType.c_str(), ok),
61  myBegin, myEnd, attrs.get<std::string>(SUMO_ATTR_ORIGIN, myVehicleType.c_str(), ok),
62  attrs.get<std::string>(SUMO_ATTR_DESTINATION, myVehicleType.c_str(), ok), myVehicleType);
63  break;
64  default:
65  break;
66  }
67 }
68 
69 
70 /****************************************************************************/
~ODAmitranHandler()
Destructor.
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called when an opening-tag occurs.
SAX-handler base for SUMO-files.
ODAmitranHandler(ODMatrix &matrix, const std::string &file)
Constructor.
ODMatrix & myMatrix
The matrix to add demand to.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:55
Encapsulated SAX-Attributes.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
An O/D (origin/destination) matrix.
Definition: ODMatrix.h:75
std::string myVehicleType
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
bool add(double vehicleNumber, SUMOTime begin, SUMOTime end, const std::string &origin, const std::string &destination, const std::string &vehicleType)
Builds a single cell from the given values, verifying them.
Definition: ODMatrix.cpp:70