Package it.polito.appeal.traci
Class SumoTraciConnection
- java.lang.Object
-
- it.polito.appeal.traci.SumoTraciConnection
-
public class SumoTraciConnection extends Object
Models a TCP/IP connection to a local or remote SUMO server via the TraCI protocol.- Author:
- Enrico Gueli <enrico.gueli@gmail.com>, Mario Krumnow
-
-
Constructor Summary
Constructors Constructor Description SumoTraciConnection(int remotePort)Instantiates a new sumo traci connection.SumoTraciConnection(String sumo_bin)Instantiates a new sumo traci connection.SumoTraciConnection(String configFile, int randomSeed, boolean useGeoOffset)Instantiates a new sumo traci connection.SumoTraciConnection(String sumo_bin, String configFile)Instantiates a new sumo traci connection.SumoTraciConnection(String sumo_bin, String net_file, String route_file)Instantiates a new sumo traci connection.SumoTraciConnection(String sumo_bin, String net_file, String route_file, String additional_file)Instantiates a new sumo traci connection.SumoTraciConnection(String sumo_bin, String net_file, String route_file, String additional_file, String gui_settings)Instantiates a new sumo traci connection.SumoTraciConnection(SocketAddress sockAddr)Instantiates a new sumo traci connection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddObserver(Observer o)Adds the observer.voidaddOption(String option, String value)Adds a custom option to the SUMO command line before executing it.voidclose()Closes the connection, quits the simulator, frees any stale resource and makes all Vehicle instances inactive.Objectdo_job_get(SumoCommand cmd)Do job get.voiddo_job_set(SumoCommand cmd)Do job set.voiddo_subscription(Subscription cs)Do subscription.voiddo_timestep()Do timestep.voiddo_timestep(double targetTime)Do timestep.booleanisClosed()Returnstrueif the connection was closed by the user, or if anIOExceptionwas thrown after the connection was made.voidprintSumoError(boolean b)Prints the sumo error.voidprintSumoOutput(boolean b)Prints the sumo output.voidrunServer()Runs a SUMO instance and tries to connect at it.voidrunServer(int _remotePort)Runs a SUMO instance and tries to connect at it.voidsetOrder(int index)Sets the order.
-
-
-
Constructor Detail
-
SumoTraciConnection
public SumoTraciConnection(String sumo_bin)
Instantiates a new sumo traci connection.- Parameters:
sumo_bin- the sumo bin
-
SumoTraciConnection
public SumoTraciConnection(String sumo_bin, String net_file, String route_file)
Instantiates a new sumo traci connection.- Parameters:
sumo_bin- the sumo binnet_file- the net fileroute_file- the route file
-
SumoTraciConnection
public SumoTraciConnection(String sumo_bin, String net_file, String route_file, String additional_file)
Instantiates a new sumo traci connection.- Parameters:
sumo_bin- the sumo binnet_file- the net fileroute_file- the route fileadditional_file- the additional file
-
SumoTraciConnection
public SumoTraciConnection(String sumo_bin, String net_file, String route_file, String additional_file, String gui_settings)
Instantiates a new sumo traci connection.- Parameters:
sumo_bin- the sumo binnet_file- the net fileroute_file- the route fileadditional_file- the additional filegui_settings- the gui settings
-
SumoTraciConnection
public SumoTraciConnection(String sumo_bin, String configFile)
Instantiates a new sumo traci connection.- Parameters:
sumo_bin- the sumo binconfigFile- the config file
-
SumoTraciConnection
public SumoTraciConnection(String configFile, int randomSeed, boolean useGeoOffset)
Instantiates a new sumo traci connection.- Parameters:
configFile- the config filerandomSeed- the random seeduseGeoOffset- the use geo offset
-
SumoTraciConnection
public SumoTraciConnection(int remotePort) throws IOException, InterruptedExceptionInstantiates a new sumo traci connection.- Parameters:
remotePort- the remote port- Throws:
IOException- Signals that an I/O exception has occurred.InterruptedException- the interrupted exception
-
SumoTraciConnection
public SumoTraciConnection(SocketAddress sockAddr) throws IOException, InterruptedException
Instantiates a new sumo traci connection.- Parameters:
sockAddr- the sock addr- Throws:
IOException- Signals that an I/O exception has occurred.InterruptedException- the interrupted exception
-
-
Method Detail
-
addOption
public void addOption(String option, String value)
Adds a custom option to the SUMO command line before executing it.- Parameters:
option- the option name, in long form (e.g. "no-warnings" instead of "W") and without initial dashesvalue- the option value, ornullif the option has no value
-
runServer
public void runServer() throws IOExceptionRuns a SUMO instance and tries to connect at it.- Throws:
IOException- if something wrong occurs while starting SUMO or connecting at it.
-
runServer
public void runServer(int _remotePort) throws IOExceptionRuns a SUMO instance and tries to connect at it.- Parameters:
_remotePort- the remote port- Throws:
IOException- if something wrong occurs while starting SUMO or connecting at it.
-
close
public void close()
Closes the connection, quits the simulator, frees any stale resource and makes all Vehicle instances inactive.
-
isClosed
public boolean isClosed()
Returnstrueif the connection was closed by the user, or if anIOExceptionwas thrown after the connection was made.- Returns:
- boolean
- See Also:
close()
-
do_job_set
public void do_job_set(SumoCommand cmd) throws Exception
Do job set.- Parameters:
cmd- the cmd- Throws:
Exception- the exception
-
do_job_get
public Object do_job_get(SumoCommand cmd) throws Exception
Do job get.- Parameters:
cmd- the cmd- Returns:
- the object
- Throws:
Exception- the exception
-
setOrder
public void setOrder(int index) throws ExceptionSets the order.- Parameters:
index- the new order- Throws:
Exception- the exception
-
do_timestep
public void do_timestep() throws ExceptionDo timestep.- Throws:
Exception- the exception
-
do_timestep
public void do_timestep(double targetTime) throws ExceptionDo timestep.- Parameters:
targetTime- the target time- Throws:
Exception- the exception
-
addObserver
public void addObserver(Observer o)
Adds the observer.- Parameters:
o- the o
-
do_subscription
public void do_subscription(Subscription cs) throws Exception
Do subscription.- Parameters:
cs- the cs- Throws:
Exception- the exception
-
printSumoOutput
public void printSumoOutput(boolean b)
Prints the sumo output.- Parameters:
b- the b
-
printSumoError
public void printSumoError(boolean b)
Prints the sumo error.- Parameters:
b- the b
-
-