Skip to main content

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

Hi Lewis,

do you run one python script per client?

Greetings Harald


Am 08.07.21 um 08:38 schrieb Philippe Käufer:

Hi Lewis,

i have an setup with one Java and one Python client. I had the same problem some moth ago. I can not remember what i done exactly. I hope that my code helps you out in some way where i got via traci.getConnection("2") the connection instance:

1. Client (Java):

    conn = new SumoTraciConnection(sumoExec, sumoConfig);
    conn.addOption("num-clients", "2");
    conn.runServer(sumoPort);
    conn.setOrder(1);

2. Client (Python):
        traci.init(9100, 5, "127.0.0.1", label="2")
        conn = traci.getConnection("2")
        conn.setOrder(2)


regards,

    Philippe

Am 08.07.2021 um 01:46 schrieb Yue Zhu:
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

_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user

_______________________________________________
sumo-user mailing list
sumo-user@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/sumo-user

Back to the top