95 #include <mesosim/MELoop.h>
103 #ifdef CHECK_MEMORY_LEAKS
105 #endif // CHECK_MEMORY_LEAKS
154 throw ProcessError(
"A network was not yet constructed.");
162 myRouterTTInitialized(false),
163 myRouterTTDijkstra(0),
167 throw ProcessError(
"A network was already constructed.");
204 std::vector<SUMOTime> stateDumpTimes,
205 std::vector<std::string> stateDumpFiles) {
248 delete MSGlobals::gMesoNet;
311 std::ostringstream msg;
312 msg <<
"Performance: " <<
"\n" <<
" Duration: " << duration <<
" ms" <<
"\n";
315 msg.setf(std::ios::fixed , std::ios::floatfield);
316 msg.setf(std::ios::showpoint);
322 const std::string collisionNotice = (
325 const std::string teleportNotice = (
329 msg <<
"Vehicles: " <<
"\n"
374 MSGlobals::gMesoNet->simulate(
myStep);
458 if (stopTime >= 0 &&
myStep >= stopTime) {
471 return "The final simulation step has been reached.";
473 return "All vehicles have left the simulation.";
475 return "TraCI requested termination.";
477 return "An error occured (see log).";
479 return "Too many vehicles.";
481 return "Unknown reason.";
540 timestep = timestep.substr(0, timestep.length() - 3);
542 std::string filename = output +
"_" + timestep +
".vtp";
562 <<
"meanWaitingTime=\"";
564 od <<
"\" meanTravelTime=\"";
581 for (std::vector<MSEdge*>::const_iterator i = edges.begin(); i != edges.end(); ++i) {
582 const std::vector<MSLane*>& lanes = (*i)->getLanes();
583 for (std::vector<MSLane*>::const_iterator j = lanes.begin(); j != lanes.end(); ++j) {
584 const std::vector<MSLink*>& links = (*j)->getLinkCont();
585 for (std::vector<MSLink*>::const_iterator k = links.begin(); k != links.end(); ++k) {
586 (*k)->writeApproaching(od, (*j)->getID());
628 std::ostringstream oss;
629 oss.setf(std::ios::fixed , std::ios::floatfield);
630 oss.setf(std::ios::showpoint);
637 oss <<
" (0ms ?*RT. ?";
639 oss <<
"UPS, vehicles"
644 std::cout << oss.str().substr(0, 78 - prev.length());
670 (*i)->vehicleStateChanged(vehicle, to);
692 for (std::map<std::string, MSBusStop*>::const_iterator it = vals.begin(); it != vals.end(); ++it) {
695 return stop->
getID();
707 if (routingAlgorithm ==
"dijkstra") {
711 if (routingAlgorithm !=
"astar") {
712 WRITE_WARNING(
"TraCI and Triggers cannot use routing algorithm '" + routingAlgorithm +
"'. using 'astar' instead.");
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
int getPendingFlowCount() const
Returns the number of flows that are still active.
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.
void loadNext(SUMOTime step)
loads the next routes
void removeVehicleStateListener(VehicleStateListener *listener)
Removes a vehicle states listener.
unsigned int getRunningVehicleNo() const
Returns the number of build and inserted, but not yet deleted vehicles.
MSEventControl * myEndOfTimestepEvents
Controls events executed at the end of a time step;.
static SUMOReal getEffort(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the effort to pass an edge.
unsigned int getDepartedVehicleNo() const
Returns the number of inserted vehicles.
static size_t numericalDictSize()
Returns the number of edges with a numerical id.
The simulation contains too many vehicles (.
virtual bool add(const std::string &id, T item)
Adds an item.
void patchActiveLanes()
Resets information whether a lane is active for all lanes.
MSVehicleControl * myVehicleControl
Controls vehicle building and deletion;.
bool retrieveExistingTravelTime(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t, SUMOReal &value) const
Returns a travel time for an edge and time if stored.
void updateDetectors(const SUMOTime step)
Computes detector values.
std::vector< SUMOTime > myStateDumpTimes
Times at which a state shall be written.
virtual void execute(SUMOTime time)
Executes time-dependant commands.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
int simulate(SUMOTime start, SUMOTime stop)
Simulates from timestep start to stop.
void changeLanes(SUMOTime t)
Moves (precomputes) critical vehicles.
std::string time2string(SUMOTime t)
int getActiveVehicleCount() const
Returns the number of build vehicles that have not been removed or need to wait for a passenger...
MSPersonControl * myPersonControl
Controls person building and deletion;.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSEdgeControl * myEdges
Controls edges, performs vehicle movement;.
The final simulation step has been performed.
void writeOutput(SUMOTime step, bool closing)
Writes the output to be generated within the given time step.
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.
static void write(OutputDevice &of, SUMOTime timestep)
Dumping a hugh List of Parameters available in the Simulation.
SUMOReal getEndLanePosition() const
Returns the end position of this bus stop.
bool retrieveExistingEffort(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t, SUMOReal &value) const
Returns an effort for an edge and time if stored.
Detectors container; responsible for string and output generation.
A storage for edge travel times and efforts.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step (in s)
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterEffort(const std::vector< MSEdge * > &prohibited=std::vector< MSEdge * >()) const
void printMeanTravelTime(OutputDevice &od) const
Returns the mean travel time of vehicles The mean travel time of ended vehicles (-1 if no vehicle has...
std::string getBusStopID(const MSLane *lane, const SUMOReal pos) const
Returns the bus stop close to the given position.
void addVehicleStateListener(VehicleStateListener *listener)
Adds a vehicle states listener.
void printMeanWaitingTime(OutputDevice &od) const
Prints the mean waiting time of vehicles. The mean time vehicles had to wait for being inserted (-1 i...
SimulationState
Possible states of a simulation - running or stopped with different reasons.
#define WRITE_WARNING(msg)
The simulated network and simulation perfomer.
static OptionsCont & getOptions()
Retrieves the options.
SUMOLong myVehiclesMoved
The overall number of vehicle movements.
ShapeContainer * myShapeContainer
A container for geometrical shapes;.
const MSLane & getLane() const
Returns the lane this bus stop is located at.
Container for junctions; performs operations on all stored junctions.
bool addBusStop(MSBusStop *busStop)
Adds a bus stop.
static bool gCheck4Accidents
static void write(OutputDevice &of, SUMOTime timestep)
Export the queueing length in front of a junction (very experimental!)
T get(const std::string &id) const
Retrieves an item.
static void write(OutputDevice &of, SUMOTime timestep)
Writes the complete network state of the given edges into the given device.
unsigned int getCollisionCount() const
return the number of collisions
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)
TraCI server used to control sumo by a remote TraCI client.
const std::string & getID() const
Returns the id.
A road/street connecting two junctions.
void prohibit(const std::vector< E * > &toProhibit)
long mySimStepBegin
The last simulation step begin, end and duration.
The simulation does not contain further vehicles.
void detectCollisions(SUMOTime timestep, int stage)
Detect collisions.
unsigned int getLoadedVehicleNo() const
Returns the number of build vehicles.
An error occured during the simulation step.
static void clear()
Clears the dictionary (delete all known routes, too)
static bool wasClosed()
check whether close was requested
void writeOutput()
Write netstate, summary and detector output.
unsigned int getTeleportCount() const
return the number of teleports (including collisions)
unsigned int getWaitingVehicleNo() const
Returns the number of waiting vehicles.
void abortWaiting()
aborts the plan for any person that is still waiting for a ride
MSInsertionControl * myInserter
Controls vehicle insertion;.
Representation of a vehicle.
void checkInsertions(SUMOTime time)
Checks "movement" of stored vehicles.
static void write(OutputDevice &of, SUMOTime timestep)
Writes the posion and the angle of each vehcile into the given device.
SUMORouteLoaderControl * myRouteLoaders
Route loader for dynamic loading of routes.
void closeSimulation(SUMOTime start)
Closes the simulation (all files, connections, etc.)
bool myLogStepNumber
Information whether the number of the simulation step shall be logged.
A lane area vehicles can halt at.
An output device that encapsulates an ofstream.
static void clear()
Clears the dictionary.
MSVehicleControl & getVehicleControl()
Returns the vehicle control.
static SUMOReal getTravelTime(const MSEdge *const e, const SUMOVehicle *const v, SUMOReal t)
Returns the travel time to pass an edge.
MSDetectorControl * myDetectorControl
Controls detectors;.
void checkWaitingPersons(MSNet *net, const SUMOTime time)
checks whether any persons waiting or walking time is over
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.
DijkstraRouterTT_ByProxi< MSEdge, SUMOVehicle, prohibited_withRestrictions< MSEdge, SUMOVehicle > > * myRouterTTDijkstra
The simulation is running.
SUMOTime string2time(const std::string &r)
void check2Switch(SUMOTime step)
Checks whether any WAUT is trying to switch a tls into another program.
void preSimStepOutput() const
Prints the current step number.
static void close()
request termination of connection
MSBusStop * getBusStop(const std::string &id) const
Returns the named bus stop.
static void cleanup()
properly deletes all trigger instances
AStarRouterTT_ByProxi< MSEdge, SUMOVehicle, prohibited_withRestrictions< MSEdge, SUMOVehicle > > * myRouterTTAStar
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
static void generateOutputForUnfinished()
generate vehroute output for vehicles which are still in the network
Inserts vehicles into the network when their departure time is reached.
void postloadInitContainer()
Closes building of junctions.
static TraCIServer * getInstance()
void abortWaiting()
removes any vehicles that are still waiting
VehicleState
Definition of a vehicle state.
bool hasNonWaiting() const
checks whether any person is still engaged in walking / stopping
static MSVehicleTransfer * getInstance()
Returns the instance of this object.
const IDMap & getMyMap() const
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.
bool myRouterTTInitialized
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.
void close(SUMOTime step)
Closes the detector outputs.
SimulationState simulationState(SUMOTime stopTime) const
Called after a simulation step, this method returns the current simulation state. ...
MSJunctionControl * myJunctions
Controls junctions, realizes right-of-way rules;.
virtual MSPersonControl & getPersonControl()
Returns the person control.
static void processCommandsUntilSimStep(SUMOTime step)
process all commands until a simulation step is wanted
static OutputDevice & getDeviceByOption(const std::string &name)
Returns the device described by the option.
MSEventControl * myBeginOfTimestepEvents
Controls events executed at the begin of a time step;.
A storage for options typed value containers)
MSEdgeWeightsStorage * myEdgeWeights
The net's knowledge about edge efforts/travel times;.
MSNet(MSVehicleControl *vc, MSEventControl *beginOfTimestepEvents, MSEventControl *endOfTimestepEvents, MSEventControl *insertionEvents, ShapeContainer *shapeCont=0)
Constructor.
unsigned int emitVehicles(SUMOTime time)
Emits vehicles that want to depart at the given time.
SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouterTT(const std::vector< MSEdge * > &prohibited=std::vector< MSEdge * >()) const
unsigned int getEndedVehicleNo() const
Returns the number of removed vehicles.
void informVehicleStateListener(const SUMOVehicle *const vehicle, VehicleState to)
Informs all added listeners about a vehicle's state change.
static void cleanup()
cleanup remaining data structures
long mySimBeginMillis
The overall simulation duration.
virtual ~MSNet()
Destructor.
const std::vector< MSEdge * > & getEdges() const
Returns loaded edges.
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 const bool gUseMesoSim
static std::string getStateMessage(SimulationState state)
Returns the message to show if a certain state occurs.
SUMOReal getMinimumTravelTime(const SUMOVehicle *const veh) const
returns the minimum travel time for the given vehicle
bool logSimulationDuration() const
Returns whether duration shall be logged.
SUMOTime myStep
Current time step.
The class responsible for building and deletion of vehicles.
void closeBuilding(MSEdgeControl *edges, MSJunctionControl *junctions, SUMORouteLoaderControl *routeLoaders, MSTLLogicControl *tlc, std::vector< SUMOTime > stateDumpTimes, std::vector< std::string > stateDumpFiles)
Closes the network's building process.
NamedObjectCont< MSBusStop * > myBusStopDict
Dictionary of bus stops.
void simulationStep()
Performs a single simulation step.
static long getCurrentMillis()
Returns the current time in milliseconds.
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)
MSEventControl * myInsertionEvents
Controls insertion events;.
int myTooManyVehicles
Storage for maximum vehicle number.
Representation of a lane in the micro simulation.
const MSEdgeWeightsStorage & getWeightsStorage() const
Returns the vehicle's internal edge travel times/efforts container.
Stores time-dependant events and executes them at the proper time.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
static void write(OutputDevice &of, const MSEdgeControl &ec, SUMOTime timestep)
Writes the complete network state of the given edges into the given device.
static void saveState(const std::string &file, SUMOTime step)
Saves the current state.
MSEdgeWeightsStorage & getWeightsStorage()
Returns the net's internal edge travel times/efforts container.
DijkstraRouterEffort_ByProxi< MSEdge, SUMOVehicle, prohibited_withRestrictions< MSEdge, SUMOVehicle > > * myRouterEffort