Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
ODAmitranHandler.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// An XML-Handler for Amitran OD matrices
19/****************************************************************************/
20#include <config.h>
21
23#include "ODMatrix.h"
24#include "ODAmitranHandler.h"
25
26
27// ===========================================================================
28// method definitions
29// ===========================================================================
30ODAmitranHandler::ODAmitranHandler(ODMatrix& matrix, const std::string& file)
31 : SUMOSAXHandler(file), myMatrix(matrix) {}
32
33
35
36
37void
39 bool ok = true;
40 switch (element) {
42 myVehicleType = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
43 break;
45 myBegin = attrs.get<int>(SUMO_ATTR_STARTTIME, myVehicleType.c_str(), ok);
46 myEnd = myBegin + attrs.get<int>(SUMO_ATTR_DURATION, myVehicleType.c_str(), ok);
47 if (myBegin >= myEnd) {
48 WRITE_ERRORF(TL("Invalid duration for timeSlice starting %."), toString(myBegin));
49 }
50 break;
52 myMatrix.add(attrs.get<double>(SUMO_ATTR_AMOUNT, myVehicleType.c_str(), ok),
53 std::make_pair(myBegin, myEnd), attrs.get<std::string>(SUMO_ATTR_ORIGIN, myVehicleType.c_str(), ok),
54 attrs.get<std::string>(SUMO_ATTR_DESTINATION, myVehicleType.c_str(), ok), myVehicleType);
55 break;
56 default:
57 break;
58 }
59}
60
61
62/****************************************************************************/
#define WRITE_ERRORF(...)
Definition MsgHandler.h:305
#define TL(string)
Definition MsgHandler.h:315
@ SUMO_TAG_OD_PAIR
@ SUMO_TAG_TIMESLICE
@ SUMO_TAG_ACTORCONFIG
@ SUMO_ATTR_ORIGIN
@ SUMO_ATTR_DESTINATION
@ SUMO_ATTR_STARTTIME
@ SUMO_ATTR_ID
@ SUMO_ATTR_DURATION
@ SUMO_ATTR_AMOUNT
MSMeanData_Amitran.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
~ODAmitranHandler()
Destructor.
ODMatrix & myMatrix
The matrix to add demand to.
std::string myVehicleType
void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called when an opening-tag occurs.
ODAmitranHandler(ODMatrix &matrix, const std::string &file)
Constructor.
An O/D (origin/destination) matrix.
Definition ODMatrix.h:68
bool add(double vehicleNumber, const std::pair< SUMOTime, SUMOTime > &beginEnd, const std::string &origin, const std::string &destination, const std::string &vehicleType, const bool originIsEdge=false, const bool destinationIsEdge=false, bool noScaling=false)
Builds a single cell from the given values, verifying them.
Definition ODMatrix.cpp:75
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.
SAX-handler base for SUMO-files.