Last active
September 12, 2019 12:05
-
-
Save priyanksonis/eeee879cceef61c4a849d4c46ad48824 to your computer and use it in GitHub Desktop.
two clients and one simulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import optparse | |
import time | |
import threading | |
if 'SUMO_HOME' in os.environ: | |
tools = os.path.join(os.environ['SUMO_HOME'], 'tools') | |
sys.path.append(tools) | |
else: | |
sys.exit("please declare environment variable 'SUMO_HOME'") | |
from sumolib import checkBinary # Checks for the binary in environ vars | |
import traci | |
import sumolib | |
from sumolib.miscutils import getFreeSocketPort | |
port = sumolib.miscutils.getFreeSocketPort() | |
class ATCS: | |
def __init__(self): | |
pass | |
def get_options(self): | |
optParser = optparse.OptionParser() | |
optParser.add_option("--nogui", action="store_true", | |
default=True, help="run the commandline version of sumo") | |
options, args = optParser.parse_args() | |
return options | |
if __name__ == "__main__": | |
env = ATCS() | |
options = env.get_options() | |
# check binary | |
if options.nogui: | |
sumoBinary = checkBinary('sumo') | |
else: | |
sumoBinary = checkBinary('sumo-gui') | |
#PORT = port | |
PORT = 41533 | |
#PORT = int(sys.argv[1]) | |
i = 0 | |
step = 0 | |
while 1: | |
traci.start([sumoBinary, "-c", "atcs2.sumocfg", '--start', "--num-clients", "2"], port=PORT) | |
#traci.start([sumoBinary, "-c", "atcs2.sumocfg", '--start', "--num-clients", "2"], port = PORT) | |
traci.setOrder(1) # number can be anything | |
step += 1 | |
while traci.simulation.getMinExpectedNumber() > 0: | |
traci.simulationStep() | |
print("In client_1" ,step, i) | |
i = i+ 1 | |
# more traci commands | |
traci.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
import optparse | |
import time | |
import threading | |
if 'SUMO_HOME' in os.environ: | |
tools = os.path.join(os.environ['SUMO_HOME'], 'tools') | |
sys.path.append(tools) | |
else: | |
sys.exit("please declare environment variable 'SUMO_HOME'") | |
from sumolib import checkBinary # Checks for the binary in environ vars | |
import traci | |
import sumolib | |
from sumolib.miscutils import getFreeSocketPort | |
port = sumolib.miscutils.getFreeSocketPort() | |
class ATCS: | |
def __init__(self): | |
pass | |
def get_options(self): | |
optParser = optparse.OptionParser() | |
optParser.add_option("--nogui", action="store_true", | |
default=False, help="run the commandline version of sumo") | |
options, args = optParser.parse_args() | |
return options | |
if __name__ == "__main__": | |
env = ATCS() | |
options = env.get_options() | |
# check binary | |
if options.nogui: | |
sumoBinary = checkBinary('sumo') | |
else: | |
sumoBinary = checkBinary('sumo-gui') | |
PORT = 41533 | |
#PORT = int(sys.argv[1]) | |
# traci.start(["sumo", "-c", "atcs2.sumocfg", "--num-clients", "2"], port=PORT) | |
step = 0 | |
j = 0 | |
while 1: | |
print('step = ',step) | |
step = step +1 | |
traci.init(PORT) | |
traci.setOrder(2) # number can be anything as long as each client gets its own number | |
while traci.simulation.getMinExpectedNumber() > 0: | |
traci.simulationStep() | |
print("In client_2", step , j) | |
j = j + 1 | |
# more traci commands | |
traci.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment