Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[sumo-user] Sumo Multi-Clients

Hello,

I am currently using sumo to do research with A3C. However, when I was trying to use multi-clients with the method from sumo documentation, it always shows 'waiting for clients'. Could you please help me with this?

Below is my code.

try:
        sys.path.append(os.path.join(os.path.dirname(
                __file__), '..', '..', '..', '..', "tools"))  # tutorial in tests
        sys.path.append(os.path.join(os.environ.get("SUMO_HOME", os.path.join(
                os.path.dirname(__file__), "..", "..", "..")), "tools"))  # tutorial in docs
        from sumolib import checkBinary  # noqa
        from sumolib.miscutils import getFreeSocketPort
except ImportError:
        sys.exit(
                "please declare environment variable 'SUMO_HOME' as the root directory of your sumo installation (it should contain folders 'bin', 'tools' and 'docs')")
       

PORT = 8813
sumoBinary = checkBinary('sumo-gui')
       
#client1
# PORT = int(sys.argv[1]) # example
traci.start([sumoBinary, "-c", "fixed_avg.sumocfg", "--num-clients", "2"], port=PORT)
traci.setOrder(1) # number can be anything
while traci.simulation.getMinExpectedNumber() > 0:
   traci.simulationStep()
   # more traci commands
traci.close()

# client2
# PORT = int(sys.argv[1]) # example
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()
   # more traci commands
traci.close()

Thank you very much!

Best,
Lewis

Back to the top