173 throw ProcessError(
"A network was not yet constructed.");
188 throw ProcessError(
"A network was already constructed.");
223 std::vector<SUMOTime> stateDumpTimes,
224 std::vector<std::string> stateDumpFiles,
301 const std::map<SUMOVehicleClass, double>*
303 std::map<std::string, std::map<SUMOVehicleClass, double> >::const_iterator i =
myRestrictions.find(
id);
341 std::cout <<
SIMTIME <<
" MSNet::simulate(" << start <<
", " << stop <<
")" 385 std::ostringstream msg;
387 msg <<
"Performance: " <<
"\n" <<
" Duration: " << duration <<
"ms" <<
"\n";
389 msg <<
" Real time factor: " << (
STEPS2TIME(
myStep - start) * 1000. / (double)duration) <<
"\n";
390 msg.setf(std::ios::fixed , std::ios::floatfield);
391 msg.setf(std::ios::showpoint);
392 msg <<
" UPS: " << ((double)
myVehiclesMoved / ((
double)duration / 1000)) <<
"\n";
397 msg <<
"Vehicles: " <<
"\n" 404 std::vector<std::string> reasons;
423 msg <<
"Persons: " <<
"\n" 441 std::cout <<
SIMTIME <<
": MSNet::simulationStep() called" 442 <<
", myStep = " <<
myStep 480 MSDevice_Routing::waitForAll();
525 MSDevice_Routing::waitForAll();
570 if (stopTime < 0 || myStep > stopTime) {
587 if (stopTime >= 0 &&
myStep >= stopTime) {
603 return "The final simulation step has been reached.";
605 return "All vehicles have left the simulation.";
607 return "TraCI requested termination.";
609 return "An error occured (see log).";
611 return "Too many teleports.";
613 return "TraCI issued load command.";
615 return "Unknown reason.";
650 if (oc.
isSet(
"netstate-dump")) {
652 oc.
getInt(
"netstate-dump.precision"));
663 oc.
getInt(
"emission-output.precision"));
669 oc.
getInt(
"battery-output.precision"));
692 timestep = timestep.substr(0, timestep.length() - 3);
694 std::string filename = output +
"_" + timestep +
".vtp";
719 od.
writeAttr(
"meanWaitingTime", meanWaitingTime);
720 od.
writeAttr(
"meanTravelTime", meanTravelTime);
723 od.
writeAttr(
"meanSpeed", meanSpeed.first);
724 od.
writeAttr(
"meanSpeedRelative", meanSpeed.second);
740 for (MSEdgeVector::const_iterator i = edges.begin(); i != edges.end(); ++i) {
741 const std::vector<MSLane*>& lanes = (*i)->getLanes();
742 for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
743 const std::vector<MSLink*>& links = (*j)->getLinkCont();
744 for (std::vector<MSLink*>::const_iterator k = links.begin(); k != links.end(); ++k) {
745 (*k)->writeApproaching(od, (*j)->getID());
801 std::ostringstream oss;
802 oss.setf(std::ios::fixed , std::ios::floatfield);
803 oss.setf(std::ios::showpoint);
808 << (
TS / durationSec) <<
"*RT, ~" 811 oss <<
" (0ms ?*RT. ?";
824 std::cout << oss.str().substr(0, 78 - prev.length());
850 (*i)->vehicleStateChanged(vehicle, to);
872 for (std::map<std::string, MSStoppingPlace*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
875 return stop->
getID();
895 for (std::map<std::string, MSStoppingPlace*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
898 return stop->
getID();
918 for (std::map<std::string, MSParkingArea*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
921 return stop->
getID();
942 for (std::map<std::string, MSChargingStation*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
945 return chargingStation->
getID();
956 it->second->writeChargingStationOutput(output);
965 if (routingAlgorithm ==
"dijkstra") {
969 if (routingAlgorithm !=
"astar") {
970 WRITE_WARNING(
"TraCI and Triggers cannot use routing algorithm '" + routingAlgorithm +
"'. using 'astar' instead.");
1015 for (MSEdgeVector::const_iterator e = edges.begin(); e != edges.end(); ++e) {
1016 for (std::vector<MSLane*>::const_iterator i = (*e)->getLanes().begin(); i != (*e)->getLanes().end(); ++i) {
1017 if ((*i)->getShape().hasElevation()) {
1038 std::pair<double, double>
1040 double speedSum = 0;
1041 double relSpeedSum = 0;
1052 return std::make_pair(speedSum / count, relSpeedSum / count);
1054 return std::make_pair(-1, -1);
std::string myStateDumpSuffix
double getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
static void write(OutputDevice &of, const MSEdgeControl &ec, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
A lane area vehicles can halt at.
std::string getBusStopID(const MSLane *lane, const double pos) const
Returns the bus stop close to the given position.
int getTeleportCount() const
return the number of teleports (including collisions)
static std::vector< std::string > & getLoadArgs()
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Computes the shortest path through a network using the Dijkstra algorithm.
bool lefthand() const
return whether the network was built for lefthand traffic
int getPendingFlowCount() const
Returns the number of flows that are still active.
int getRunningNumber() const
Returns the number of build and inserted, but not yet deleted transportables.
static const std::set< MSDevice * > & getInstances()
returns all currently existing SSM devices
int getDepartedVehicleNo() const
Returns the number of inserted vehicles.
virtual bool isOnRoad() const =0
Returns the information whether the vehicle is on a road (is simulated)
void postSimStepOutput() const
Prints the statistics of the step at its end.
Representation of a vehicle in the micro simulation.
Interface for objects listening to vehicle state changes.
bool retrieveExistingTravelTime(const MSEdge *const e, const double t, double &value) const
Returns a travel time for an edge and time if stored.
void loadNext(SUMOTime step)
loads the next routes up to and including the given time step
virtual bool isRemoteControlled() const =0
Returns the information whether the vehicle is fully controlled via TraCI.
void removeVehicleStateListener(VehicleStateListener *listener)
Removes a vehicle states listener.
MSEventControl * myEndOfTimestepEvents
Controls events executed at the end of a time step;.
NamedObjectCont< MSParkingArea * > myParkingAreaDict
Dictionary of parking areas.
MSParkingArea * getParkingArea(const std::string &id) const
Returns the named parking area.
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types...
static void cleanup()
Clean up remaining devices instances.
A lane area vehicles can halt at.
std::string getParkingAreaID(const MSLane *lane, const double pos) const
Returns the parking area close to the given position.
virtual bool add(const std::string &id, T item)
Adds an item.
constVehIt loadedVehBegin() const
Returns the begin of the internal vehicle map.
void patchActiveLanes()
Resets information whether a lane is active for all lanes.
static void fill(RTREE &into)
Fills the given RTree with lane instances.
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
int gPrecision
the precision for floating point outputs
void updateDetectors(const SUMOTime step)
Computes detector values.
A device which collects info on the vehicle trip (mainly on departure and arrival) ...
std::vector< SUMOTime > myStateDumpTimes
Times at which a state shall be written.
virtual void execute(SUMOTime time)
Executes time-dependant commands.
bool hasInternalLinks() const
return whether the network contains internal links
double getSpeedLimit() const
Returns the speed limit of the edge The speed limit of the first lane is retured; should probably be...
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
SimulationState simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
SUMOAbstractRouter< MSEdge, SUMOVehicle > * myRouterEffort
double getTotalDepartureDelay() const
Returns the total departure delay.
void changeLanes(SUMOTime t)
Moves (precomputes) critical vehicles.
std::string time2string(SUMOTime t)
A RT-tree for efficient storing of SUMO's Named objects.
Computes the shortest path through a network using the A* algorithm.
MSPedestrianRouterDijkstra & getPedestrianRouter(const MSEdgeVector &prohibited=MSEdgeVector()) const
virtual const MSEdge * getEdge() const =0
Returns the edge the vehicle is currently at.
std::pair< double, double > getVehicleMeanSpeeds() const
get current absolute and relative mean vehicle speed in the network
int getActiveVehicleCount() const
Returns the number of build vehicles that have not been removed or need to wait for a passenger or a ...
MSChargingStation * getChargingStation(const std::string &id) const
Returns the named charging station.
bool addBusStop(MSStoppingPlace *busStop)
Adds a bus stop.
int getTeleportsJam() const
return the number of teleports due to jamming
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
int getCollisionCount() const
return the number of collisions
bool myHavePermissions
Whether the network contains edges which not all vehicles may pass.
MSEdgeControl * myEdges
Controls edges, performs vehicle movement;.
double getEndLanePosition() const
Returns the end position of this stop.
The final simulation step has been performed.
int getEndedVehicleNo() const
Returns the number of removed vehicles.
void writeOutput(SUMOTime step, bool closing)
Writes the output to be generated within the given time step.
double myVersion
the network version
std::vector< std::string > myStateDumpFiles
The names for the state files.
bool myLogExecutionTime
Information whether the simulation duration shall be logged.
Storage for geometrical objects.
bool addParkingArea(MSParkingArea *parkingArea)
Adds a parking area.
static const std::string STAGE_LANECHANGE
void cleanup()
clean up subscriptions
static void write(OutputDevice &of, SUMOTime timestep)
Dumping a hugh List of Parameters available in the Simulation.
NamedObjectCont< MSStoppingPlace * > myContainerStopDict
Dictionary of container stops.
Detectors container; responsible for string and output generation.
bool myLefthand
Whether the network was built for left-hand traffic.
A storage for edge travel times and efforts.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
void detectCollisions(SUMOTime timestep, const std::string &stage)
Detect collisions.
bool retrieveExistingEffort(const MSEdge *const e, const double t, double &value) const
Returns an effort for an edge and time if stored.
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
int getWaitingVehicleNo() const
Returns the number of waiting vehicles.
SimulationState
Possible states of a simulation - running or stopped with different reasons.
MSPedestrianRouterDijkstra * myPedestrianRouter
#define WRITE_WARNING(msg)
The simulated network and simulation perfomer.
Computes the shortest path through a network using the Dijkstra algorithm.
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
static OptionsCont & getOptions()
Retrieves the options.
ShapeContainer * myShapeContainer
A container for geometrical shapes;.
std::pair< bool, NamedRTree > myLanesRTree
An RTree structure holding lane IDs.
void abortWaitingForVehicle()
aborts the plan for any transportable that is still waiting for a ride
Container for junctions; performs operations on all stored junctions.
const std::map< SUMOVehicleClass, double > * getRestrictions(const std::string &id) const
Returns the restrictions for an edge type If no restrictions are present, 0 is returned.
static bool gCheck4Accidents
static void write(OutputDevice &of, SUMOTime timestep)
Export the queueing length in front of a junction (very experimental!)
virtual MSTransportableControl & getContainerControl()
Returns the container control.
static void write(OutputDevice &of, SUMOTime timestep, bool elevation)
Writes the position and the angle of each vehicle into the given device.
T get(const std::string &id) const
Retrieves an item.
A class that stores and controls tls and switching of their programs.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
const std::string & getID() const
Returns the id.
A road/street connecting two junctions.
long long int myVehiclesMoved
The overall number of vehicle movements.
The simulation does not contain further vehicles.
bool hasNonWaiting() const
checks whether any transportable is still engaged in walking / stopping
int getLoadedNumber() const
Returns the number of build transportables.
static void generateOutputForUnfinished()
generate output for vehicles which are still in the network
virtual double getSpeed() const =0
Returns the vehicle's current speed.
An error occured during the simulation step.
const MSLane & getLane() const
Returns the lane this stop is located at.
static void clear()
Clears the dictionary (delete all known routes, too)
The main mesocopic simulation loop.
void writeOutput()
Write netstate, summary and detector output.
MSStoppingPlace * getBusStop(const std::string &id) const
Returns the named bus stop.
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static std::string printStatistics()
get statistics for printing to stdout
MSInsertionControl * myInserter
Controls vehicle insertion;.
Representation of a vehicle.
bool myHasNeighs
Whether the network contains explicit neighbor lanes.
void checkInsertions(SUMOTime time)
Checks "movement" of stored vehicles.
int emitVehicles(SUMOTime time)
Emits vehicles that want to depart at the given time.
SUMORouteLoaderControl * myRouteLoaders
Route loader for dynamic loading of routes.
virtual MSTransportableControl & getPersonControl()
Returns the person control.
static double getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the travel time to pass an edge.
void closeSimulation(SUMOTime start)
Closes the simulation (all files, connections, etc.)
std::map< std::string, std::map< SUMOVehicleClass, double > > myRestrictions
The vehicle class specific speed restrictions.
bool myLogStepNumber
Information whether the number of the simulation step shall be logged.
An output device that encapsulates an ofstream.
double version() const
return the network version
static void clear()
Clears the dictionary.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
MSDetectorControl * myDetectorControl
Controls detectors;.
Stores edges and lanes, performs moving of vehicle.
MSTLLogicControl * myLogics
Controls tls logics, realizes waiting on tls rules;.
static void write(OutputDevice &of, SUMOTime timestep)
Produce a VTK output to use with Tools like ParaView.
The connection to a client was closed by the client.
The simulation is running.
bool hasNeighs() const
return whether the network contains explicit neighbor lanes
std::string getChargingStationID(const MSLane *lane, const double pos) const
Returns the charging station close to the given position.
SUMOTime string2time(const std::string &r)
std::string getContainerStopID(const MSLane *lane, const double pos) const
Returns the container stop close to the given position.
void check2Switch(SUMOTime step)
Checks whether any WAUT is trying to switch a tls into another program.
void addRestriction(const std::string &id, const SUMOVehicleClass svc, const double speed)
Adds a restriction for an edge type.
int getRunningVehicleNo() const
Returns the number of build and inserted, but not yet deleted vehicles.
int getHaltingVehicleNumber() const
count number of standing vehicles in the network
void preSimStepOutput() const
Prints the current step number.
void updateAndWriteOutput()
This is called once per time step in MSNet::writeOutput() and collects the surrounding vehicles...
virtual bool isStopped() const =0
Returns whether the vehicle is at a stop.
static void cleanup()
properly deletes all trigger instances
PedestrianRouterDijkstra< MSEdge, MSLane, MSJunction, MSVehicle > MSPedestrianRouterDijkstra
SUMOTime getTargetTime() const
TraCI server used to control sumo by a remote TraCI client.
double getTotalTravelTime() const
Returns the total travel time.
static void generateOutputForUnfinished()
generate vehroute output for vehicles which are still in the network
SUMOTime myStateDumpPeriod
The period for writing state.
Inserts vehicles into the network when their departure time is reached.
long myTraCIStepDuration
The last simulation step duration.
void postloadInitContainer()
Closes building of junctions.
int myMaxTeleports
Maximum number of teleports.
void abortWaiting()
informes about all waiting vehicles (deletion in destructor)
VehicleState
Definition of a vehicle state.
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const MSEdgeVector &prohibited=MSEdgeVector()) const
void closeBuilding(const OptionsCont &oc, MSEdgeControl *edges, MSJunctionControl *junctions, SUMORouteLoaderControl *routeLoaders, MSTLLogicControl *tlc, std::vector< SUMOTime > stateDumpTimes, std::vector< std::string > stateDumpFiles, bool hasInternalLinks, bool hasNeighs, bool lefthand, double version)
Closes the network's building process.
static MSVehicleTransfer * getInstance()
Returns the instance of this object.
static const std::string STAGE_MOVEMENTS
const IDMap & getMyMap() const
Returns a reference to the internal map.
void processCommandsUntilSimStep(SUMOTime step)
process all commands until the next SUMO simulation step. It is guaranteed that t->getTargetTime() >=...
std::vector< VehicleStateListener * > myVehicleStateListeners
Container for vehicle state listener.
static MSNet * myInstance
Unique instance of MSNet.
bool isEmpty()
Returns whether events are in the que.
static void clearAll()
Clears all dictionaries.
The simulation is loading.
bool hasTransportables() const
checks whether any transportable waits to finish her plan
void planMovements(SUMOTime t)
Compute safe velocities for all vehicles based on positions and speeds from the last time step...
void executeMovements(SUMOTime t)
Executes planned vehicle movements with regards to right-of-way.
bool addContainerStop(MSStoppingPlace *containerStop)
Adds a container stop.
bool addChargingStation(MSChargingStation *chargingStation)
Adds a chargingg station.
void close(SUMOTime step)
Closes the detector outputs.
int getTeleportsYield() const
return the number of teleports due to vehicles stuck on a minor road
SimulationState simulationState(SUMOTime stopTime) const
Called after a simulation step, this method returns the current simulation state. ...
MSTransportableControl * myContainerControl
Controls container building and deletion;.
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
static void clear()
Clears the dictionary.
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
MSTransportableControl * myPersonControl
Controls person building and deletion;.
static const MSEdgeVector & getAllEdges()
Returns all edges with a numerical id.
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
bool checkElevation()
check all lanes for elevation data
static void cleanup()
remove state at simulation end
static TraCIServer * getInstance()
int getLoadedVehicleNo() const
Returns the number of build vehicles.
MSEventControl * myBeginOfTimestepEvents
Controls events executed at the begin of a time step;.
A storage for options typed value containers)
static void cleanup()
removes remaining vehicleInformation in sVehicles
MSEdgeWeightsStorage * myEdgeWeights
The net's knowledge about edge efforts/travel times;.
MSStoppingPlace * getContainerStop(const std::string &id) const
Returns the named container stop.
The simulation had too many teleports.
MSNet(MSVehicleControl *vc, MSEventControl *beginOfTimestepEvents, MSEventControl *endOfTimestepEvents, MSEventControl *insertionEvents, ShapeContainer *shapeCont=0)
Constructor.
void checkWaiting(MSNet *net, const SUMOTime time)
checks whether any transportables waiting time is over
static void write(OutputDevice &of, const SUMOTime timestep)
Writes the complete network state into the given device.
static MELoop * gMesoNet
mesoscopic simulation infrastructure
std::map< std::string, SUMOVehicle * >::const_iterator constVehIt
Definition of the internal vehicles map iterator.
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to)
Informs all added listeners about a vehicle's state change.
const NamedRTree & getLanesRTree() const
Returns an RTree that contains lane IDs.
static void cleanup()
cleanup remaining data structures
double getBeginLanePosition() const
Returns the begin position of this stop.
const double SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
int getJammedNumber() const
Returns the number of times a transportables was jammed.
long mySimBeginMillis
The overall simulation duration.
virtual ~MSNet()
Destructor.
bool myHasElevation
Whether the network contains elevation data.
static void write(OutputDevice &of, SUMOTime timestep, int precision)
Writes the complete network state of the given edges into the given device.
std::string myStateDumpPrefix
name components for periodic state
Static storage of an output device and its base (abstract) implementation.
static void cleanup()
deletes the router instance
bool closeTag()
Closes the most recently opened tag.
static std::string getStateMessage(SimulationState state)
Returns the message to show if a certain state occurs.
NamedObjectCont< MSChargingStation * > myChargingStationDict
Dictionary of charging Stations.
int getTeleportsWrongLane() const
return the number of teleports due to vehicles stuck on the wrong lane
constVehIt loadedVehEnd() const
Returns the end of the internal vehicle map.
bool logSimulationDuration() const
Returns whether duration shall be logged.
void writeChargingStationOutput() const
write charging station output
SUMOTime myStep
Current time step.
The class responsible for building and deletion of vehicles.
std::vector< MSEdge * > MSEdgeVector
void simulationStep()
Performs a single simulation step.
static long getCurrentMillis()
Returns the current time in milliseconds.
void simulate(SUMOTime tMax)
Perform simulation up to the given time.
int getInt(const std::string &name) const
Returns the int-value of the named option (only for Option_Integer)
void loadRoutes()
loads routes for the next few steps
#define WRITE_MESSAGE(msg)
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterEffort(const MSEdgeVector &prohibited=MSEdgeVector()) const
static const std::string STAGE_INSERTIONS
MSEventControl * myInsertionEvents
Controls insertion events;.
Representation of a lane in the micro simulation.
const MSEdgeWeightsStorage & getWeightsStorage() const
Returns the vehicle's internal edge travel times/efforts container.
NamedObjectCont< MSStoppingPlace * > myBusStopDict
Dictionary of bus stops.
static bool wasClosed()
check whether close was requested
Stores time-dependant events and executes them at the proper time.
bool myHasInternalLinks
Whether the network contains internal links/lanes/edges.
std::string joinToString(const std::vector< T > &v, const T_BETWEEN &between, std::streamsize accuracy=gPrecision)
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
SUMOAbstractRouter< MSEdge, SUMOVehicle > * myRouterTT
static void cleanup()
remove state at simulation end
void determineCandidates(SUMOTime time)
Checks for all vehicles whether they can be emitted.
void prohibit(const std::vector< E * > &toProhibit)
static void saveState(const std::string &file, SUMOTime step)
Saves the current state.
int getEmergencyStops() const
return the number of emergency stops
const MSEdgeVector & getEdges() const
Returns loaded edges.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
static double getEffort(const MSEdge *const e, const SUMOVehicle *const v, double t)
Returns the effort to pass an edge.
MSEdgeWeightsStorage & getWeightsStorage()
Returns the net's internal edge travel times/efforts container.
static const std::string STAGE_EVENTS
string constants for simstep stages