1 /****************************************************************************/ 2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2017-2018 German Aerospace Center (DLR) and others. 4 // TraaS module 5 // Copyright (C) 2016-2017 Dresden University of Technology 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 // SPDX-License-Identifier: EPL-2.0 11 /****************************************************************************/ 12 /// @file Simulation.java 13 /// @author Mario Krumnow 14 /// @author Evamarie Wiessner 15 /// @date 2016 16 /// @version $Id$ 17 /// 18 // 19 /****************************************************************************/ 20 package de.tudresden.sumo.cmd; 21 import de.tudresden.sumo.config.Constants; 22 import de.tudresden.sumo.util.SumoCommand; 23 import de.tudresden.ws.container.SumoPosition2D; 24 25 /** 26 * 27 * @author Mario Krumnow 28 * @author Evamarie Wiessner 29 * 30 */ 31 32 public class Simulation { 33 34 //getter methods 35 36 /** 37 * convert2D 38 * @param edgeID edge id 39 * @param pos pos 40 * @param laneIndex index 41 * @param toGeo geo 42 * @return SumoCommand 43 */ convert2D(String edgeID, double pos, byte laneIndex, String toGeo)44 public static SumoCommand convert2D(String edgeID, double pos, byte laneIndex, String toGeo){ 45 Object[] array = new Object[]{pos, laneIndex, toGeo}; 46 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.POSITION_CONVERSION, edgeID, array, Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_STRINGLIST); 47 } 48 49 /** 50 * convert3D 51 * @return SumoCommand 52 * @param edgeID edge id 53 * @param pos pos 54 * @param laneIndex index 55 * @param toGeo geo 56 */ convert3D(String edgeID, double pos, byte laneIndex, String toGeo)57 public static SumoCommand convert3D(String edgeID, double pos, byte laneIndex, String toGeo){ 58 Object[] array = new Object[]{pos, laneIndex, toGeo}; 59 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.POSITION_CONVERSION, edgeID, array, Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_STRINGLIST); 60 } 61 62 63 /** 64 * convertGeo 65 * @return SumoCommand 66 * @param x x 67 * @param y y 68 * @param fromGeo geo 69 */ convertGeo(double x, double y, boolean fromGeo)70 public static SumoCommand convertGeo(double x, double y, boolean fromGeo){ 71 72 byte fromType = Constants.POSITION_2D; 73 byte toType = Constants.POSITION_LON_LAT; 74 75 if(fromGeo){ 76 fromType = Constants.POSITION_LON_LAT; 77 toType = Constants.POSITION_2D; 78 } 79 80 Object[] array = new Object[]{fromType, x, y, toType}; 81 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.POSITION_CONVERSION, "", array, Constants.RESPONSE_GET_SIM_VARIABLE, fromGeo ? Constants.POSITION_2D : Constants.POSITION_LON_LAT); 82 } 83 84 /** 85 * convertRoad 86 * @return SumoCommand 87 * @param x x 88 * @param y y 89 * @param isGeo geo 90 */ convertRoad(double x, double y, String isGeo)91 public static SumoCommand convertRoad(double x, double y, String isGeo){ 92 Object[] array = new Object[]{y, isGeo}; 93 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_POSITION, x, array, Constants.RESPONSE_GET_SIM_VARIABLE, Constants.POSITION_2D); 94 } 95 96 /** 97 * Returns a list of IDs of vehicles which arrived in this time step. 98 * @return list of vehicles 99 */ 100 getArrivedIDList()101 public static SumoCommand getArrivedIDList(){ 102 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_ARRIVED_VEHICLES_IDS, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_STRINGLIST); 103 } 104 105 /** 106 * Returns the number of vehicles which arrived in this time step. 107 * @return number of vehicles 108 */ 109 getArrivedNumber()110 public static SumoCommand getArrivedNumber(){ 111 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_ARRIVED_VEHICLES_NUMBER, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_INTEGER); 112 } 113 114 /** 115 * Returns the current waiting time on bus stops(in ms). 116 * @return waiting time 117 */ 118 getBusStopWaiting()119 public static SumoCommand getBusStopWaiting(){ 120 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_BUS_STOP_WAITING, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_INTEGER); 121 } 122 123 /** 124 * getParkingEndingVehiclesIDList() 125 * @return number of vehicles 126 */ 127 getParkingEndingVehiclesIDList()128 public static SumoCommand getParkingEndingVehiclesIDList(){ 129 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_PARKING_ENDING_VEHICLES_IDS, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_STRINGLIST); 130 } 131 132 133 /** 134 * getParkingEndingVehiclesNumber() 135 * @return number of vehicles 136 */ 137 getParkingEndingVehiclesNumber()138 public static SumoCommand getParkingEndingVehiclesNumber(){ 139 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_PARKING_ENDING_VEHICLES_NUMBER, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_INTEGER); 140 } 141 142 /** 143 * getParkingStartingVehiclesIDList() 144 * @return number of vehicles 145 */ 146 getParkingStartingVehiclesIDList()147 public static SumoCommand getParkingStartingVehiclesIDList(){ 148 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_PARKING_STARTING_VEHICLES_IDS, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_STRINGLIST); 149 } 150 151 152 /** 153 * getParkingStartingVehiclesNumber() 154 * @return number of vehicles 155 */ 156 getParkingStartingVehiclesNumber()157 public static SumoCommand getParkingStartingVehiclesNumber(){ 158 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_PARKING_STARTING_VEHICLES_NUMBER, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_INTEGER); 159 } 160 161 162 /** 163 * getStopEndingVehiclesIDList() 164 * @return number of vehicles 165 */ 166 getStopEndingVehiclesIDList()167 public static SumoCommand getStopEndingVehiclesIDList(){ 168 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_STOP_ENDING_VEHICLES_IDS, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_STRINGLIST); 169 } 170 171 172 /** 173 * getCollidingVehiclesNumber() 174 * @return Return number of vehicles involved in a collision (typically 2 per collision). 175 */ 176 getCollidingVehiclesNumber()177 public static SumoCommand getCollidingVehiclesNumber(){ 178 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_COLLIDING_VEHICLES_NUMBER, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_INTEGER); 179 } 180 181 /** 182 * getCollidingVehiclesNumber() 183 * @return Return Ids of vehicles involved in a collision (typically 2 per collision) 184 */ 185 getCollidingVehiclesIDList()186 public static SumoCommand getCollidingVehiclesIDList(){ 187 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_COLLIDING_VEHICLES_IDS, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_STRINGLIST); 188 } 189 190 /** 191 * getEmergencyStoppingVehiclesNumber() 192 * @return Return number of vehicles that performed an emergency stop in the last step 193 */ 194 getEmergencyStoppingVehiclesNumber()195 public static SumoCommand getEmergencyStoppingVehiclesNumber(){ 196 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_EMERGENCYSTOPPING_VEHICLES_NUMBER, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_INTEGER); 197 } 198 199 /** 200 * getEmergencyStoppingVehiclesIDList() 201 * @return Return Ids of vehicles that peformed an emergency stop in the last step 202 */ 203 getEmergencyStoppingVehiclesIDList()204 public static SumoCommand getEmergencyStoppingVehiclesIDList(){ 205 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_EMERGENCYSTOPPING_VEHICLES_IDS, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_STRINGLIST); 206 } 207 208 209 /** 210 * getStopEndingVehiclesNumber() 211 * @return number of vehicles 212 */ 213 getStopEndingVehiclesNumber()214 public static SumoCommand getStopEndingVehiclesNumber(){ 215 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_STOP_ENDING_VEHICLES_NUMBER, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_INTEGER); 216 } 217 218 219 220 /** 221 * getStopStartingVehiclesIDList() 222 * @return list of vehicles 223 */ 224 getStopStartingVehiclesIDList()225 public static SumoCommand getStopStartingVehiclesIDList(){ 226 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_STOP_STARTING_VEHICLES_IDS, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_STRINGLIST); 227 } 228 229 230 /** 231 * getStopStartingVehiclesIDList() 232 * @return list of vehicles 233 */ 234 getStopStartingVehiclesNumber()235 public static SumoCommand getStopStartingVehiclesNumber(){ 236 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_STOP_STARTING_VEHICLES_NUMBER, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_INTEGER); 237 } 238 239 240 /** 241 * getCurrentTime 242 * @return current time in ms (integer). Note: this method only supports a simulation time up to 24 days and is only kept for legacy reasons 243 */ 244 getCurrentTime()245 public static SumoCommand getCurrentTime(){ 246 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_TIME_STEP, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_INTEGER); 247 } 248 249 /** 250 * getTime 251 * @return current time in s (double) 252 */ 253 getTime()254 public static SumoCommand getTime(){ 255 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_TIME, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_DOUBLE); 256 } 257 258 /** 259 * getDeltaT 260 * @return delat time 261 */ 262 getDeltaT()263 public static SumoCommand getDeltaT(){ 264 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_DELTA_T, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_INTEGER); 265 } 266 267 /** 268 * Returns a list of IDs of vehicles which departed in this time step. 269 * @return list of IDs of vehicles which departed in this time step. 270 */ 271 getDepartedIDList()272 public static SumoCommand getDepartedIDList(){ 273 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_DEPARTED_VEHICLES_IDS, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_STRINGLIST); 274 } 275 276 /** 277 * Returns the number of vehicles which departed in this time step. 278 * @return the number of vehicles which departed in this time step. 279 */ 280 getDepartedNumber()281 public static SumoCommand getDepartedNumber(){ 282 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_DEPARTED_VEHICLES_NUMBER, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_INTEGER); 283 } 284 285 /** 286 * Reads two coordinate pairs and an indicator whether the air or the driving distance shall be computed. Returns the according distance. 287 */ 288 289 /** 290 * @param x1 x1 291 * @param y1 y1 292 * @param x2 x2 293 * @param y2 y2 294 * @param isGeo is geo 295 * @param isDriving is driving 296 * @return distance 297 */ getDistance2D(double x1, double y1, double x2, double y2, boolean isGeo, boolean isDriving)298 public static SumoCommand getDistance2D(double x1, double y1, double x2, double y2, boolean isGeo, boolean isDriving){ 299 Object[] array = new Object[]{new SumoPosition2D(x1, y1), new SumoPosition2D(x2, y2), isGeo, isDriving}; 300 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.DISTANCE_REQUEST, array, Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_DOUBLE); 301 } 302 303 /** 304 * getDistanceRoad 305 */ 306 307 /** 308 * @param edgeID1 first edge 309 * @param pos1 first position 310 * @param edgeID2 second edge 311 * @param pos2 second position 312 * @param isDriving is drinving 313 * @return the distance in [m] 314 */ getDistanceRoad(String edgeID1, double pos1, String edgeID2, double pos2, boolean isDriving)315 public static SumoCommand getDistanceRoad(String edgeID1, double pos1, String edgeID2, double pos2, boolean isDriving){ 316 Object[] array = new Object[]{edgeID1, pos1, edgeID2, pos2, isDriving}; 317 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.DISTANCE_REQUEST, array, Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_DOUBLE); 318 } 319 320 /** 321 * Returns a list of IDs of vehicles which ended to be teleported in this time step. 322 * @return SumoCommand 323 */ 324 getEndingTeleportIDList()325 public static SumoCommand getEndingTeleportIDList(){ 326 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_TELEPORT_ENDING_VEHICLES_IDS, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_STRINGLIST); 327 } 328 329 /** 330 * Returns the number of vehicles which ended to be teleported in this time step. 331 * @return SumoCommand 332 */ 333 getEndingTeleportNumber()334 public static SumoCommand getEndingTeleportNumber(){ 335 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_TELEPORT_ENDING_VEHICLES_NUMBER, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_INTEGER); 336 } 337 338 /** 339 * Returns a list of IDs of vehicles which were loaded in this time step. 340 * @return SumoCommand 341 */ 342 getLoadedIDList()343 public static SumoCommand getLoadedIDList(){ 344 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_LOADED_VEHICLES_IDS, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_STRINGLIST); 345 } 346 347 /** 348 * Return the number of vehicles which were loaded in this time step. * @return SumoCommand 349 * @return SumoCommand 350 */ 351 getLoadedNumber()352 public static SumoCommand getLoadedNumber(){ 353 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_LOADED_VEHICLES_NUMBER, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_INTEGER); 354 } 355 356 /** 357 * Returns the number of vehicles which are in the net plus the ones still waiting to start. 358 * @return SumoCommand 359 */ 360 getMinExpectedNumber()361 public static SumoCommand getMinExpectedNumber(){ 362 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_MIN_EXPECTED_VEHICLES, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_INTEGER); 363 } 364 365 /** 366 * Returns the boundary box of the simulation network. 367 * @return SumoCommand 368 */ getNetBoundary()369 public static SumoCommand getNetBoundary(){ 370 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_NET_BOUNDING_BOX, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_POLYGON); 371 } 372 373 /** 374 * Returns a list of IDs of vehicles which started to teleport in this time step. 375 * @return SumoCommand 376 */ 377 getStartingTeleportIDList()378 public static SumoCommand getStartingTeleportIDList(){ 379 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_TELEPORT_STARTING_VEHICLES_IDS, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_STRINGLIST); 380 } 381 382 /** 383 * Returns the number of vehicles which started to teleport in this time step. 384 * @return SumoCommand 385 */ 386 getStartingTeleportNumber()387 public static SumoCommand getStartingTeleportNumber(){ 388 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.VAR_TELEPORT_STARTING_VEHICLES_NUMBER, "", Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_INTEGER); 389 } 390 391 //setter methods 392 393 /** 394 * Clear pending 395 * @param routeID route id 396 * @return SumoCommand 397 */ 398 clearPending(String routeID)399 public static SumoCommand clearPending(String routeID){ 400 return new SumoCommand(Constants.CMD_SET_SIM_VARIABLE, Constants.CMD_CLEAR_PENDING_VEHICLES, "", routeID); 401 } 402 403 /** 404 * save state 405 * @param filename 406 * @return SumoCommand 407 */ 408 saveState(String filename)409 public static SumoCommand saveState(String filename){ 410 return new SumoCommand(Constants.CMD_SET_SIM_VARIABLE, Constants.CMD_SAVE_SIMSTATE, "", filename); 411 } 412 413 /** 414 * findRoute 415 * @param fromEdge first edge 416 * @param toEdge second edge 417 * @param vType vehicle type 418 * @param depart depart 419 * @param routingMode routing mode 420 * @return the route 421 */ findRoute(String fromEdge, String toEdge, String vType, double depart, int routingMode)422 public static SumoCommand findRoute(String fromEdge, String toEdge, String vType, double depart, int routingMode){ 423 Object[] array = new Object[]{fromEdge, toEdge, vType, depart, routingMode}; 424 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.FIND_ROUTE, "", array, Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_COMPOUND); 425 } 426 427 /** 428 * findIntermodalRoute 429 * @param fromEdge first edge 430 * @param toEdge second edge 431 * @param modes modes 432 * @param depart depart 433 * @param routingMode routing mode 434 * @param speed speed 435 * @param walkingFactor walkingFactor 436 * @param departPos departPos 437 * @param arrivalPos arrivalPos 438 * @param departPosLat departPosLat 439 * @param pType pType 440 * @param vType vType 441 * @param destStop destStop 442 * @return the route 443 */ findIntermodalRoute(String fromEdge, String toEdge, String modes, double depart, int routingMode, double speed, double walkingFactor, double departPos, double arrivalPos, double departPosLat, String pType, String vType, String destStop)444 public static SumoCommand findIntermodalRoute(String fromEdge, String toEdge, String modes, double depart, int routingMode, 445 double speed, double walkingFactor, double departPos, double arrivalPos, double departPosLat, String pType, String vType, String destStop){ 446 Object[] array = new Object[]{fromEdge, toEdge, modes, depart, routingMode, speed, walkingFactor, departPos, arrivalPos, departPosLat, pType, vType, destStop}; 447 return new SumoCommand(Constants.CMD_GET_SIM_VARIABLE, Constants.FIND_INTERMODAL_ROUTE, "", array, Constants.RESPONSE_GET_SIM_VARIABLE, Constants.TYPE_COMPOUND); 448 } 449 450 } 451