Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[sumo-user] Getting issues with 3 clients

Hello All,

I am running a simulation with 3 clients. But my second client gives htis error:

 raise FatalTraCIError("connection closed by SUMO")
traci.exceptions.FatalTraCIError: connection closed by SUMO

It runs fine with two clients.
What can be the cause of this? 

Attaching 3 client files.

Regards,
Priyank Soni
M. 8882242322

import keras
from keras import Model
from keras.layers import Input, Conv2D, Flatten, Dense
from keras.optimizers import Adam
import tensorflow as tf
from keras.callbacks import TensorBoard
from collections import deque
import numpy as np
import random

import os
from os import  path
import sys
import optparse
import time

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__":


    random.seed(1)
    np.random.seed(1)
    tf.set_random_seed(1)

    env = ATCS()
    options = env.get_options()


    # check binary
    if options.nogui:
        sumoBinary = checkBinary('sumo')
    else:
        sumoBinary = checkBinary('sumo-gui')

    # Iterate the game

    print('port = ', port)

    PORT = 46025

    while 1:
        traci.start([sumoBinary, "-c", "atcs.sumocfg", '--start', "--num-clients", "3"], port=PORT)

        traci.setOrder(1)  # number can be anything

        step = 0

        while  step< 1000 and traci.simulation.getMinExpectedNumber() > 0:

            traci.simulationStep()
            print("client_1, step = ",step)
            step+=1

        traci.close()

import keras
from keras import Model
from keras.layers import Input, Conv2D, Flatten, Dense
from keras.optimizers import Adam
import tensorflow as tf
from keras.callbacks import TensorBoard
from collections import deque
import numpy as np
import random

import os
import sys
import optparse
import time
from os import  path

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

MODEL_NAME = 'ATCS_MODEL'
AGGREGATE_STATS_EVERY = 50
epsilon = 1


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__":


    random.seed(1)
    np.random.seed(1)
    tf.set_random_seed(1)
    # initialize gym environment and the agent
    env = ATCS()
    options = env.get_options()

    '''
    try:
       #agent.load('Models/reinf_traf_control.h5')
        agent.load('Models2/reinf_traf_control_1450.h5')
        print('Model found')
    except:
       print('No models found')
    '''

    # check binary
    if options.nogui:
        sumoBinary = checkBinary('sumo')
    else:
        sumoBinary = checkBinary('sumo-gui')

    while 1:

        traci.init(46025)
        traci.setOrder(3)

        while traci.simulation.getMinExpectedNumber() > 0:

            traci.simulationStep()
            print("client 3")

        time.sleep(2)
        traci.close()
        time.sleep(2)

import keras
from keras import Model
from keras.layers import Input, Conv2D, Flatten, Dense
from keras.optimizers import Adam
import tensorflow as tf
from keras.callbacks import TensorBoard
from collections import deque
import numpy as np
import random

import os
import sys
import optparse
import time
from os import  path

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

MODEL_NAME = 'ATCS_MODEL'
AGGREGATE_STATS_EVERY = 50
epsilon = 1


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__":


    random.seed(1)
    np.random.seed(1)
    tf.set_random_seed(1)
    # initialize gym environment and the agent
    env = ATCS()
    options = env.get_options()

    '''
    try:
       #agent.load('Models/reinf_traf_control.h5')
        agent.load('Models2/reinf_traf_control_1450.h5')
        print('Model found')
    except:
       print('No models found')
    '''

    # check binary
    if options.nogui:
        sumoBinary = checkBinary('sumo')
    else:
        sumoBinary = checkBinary('sumo-gui')


    while 1:
        traci.init(46025)
        traci.setOrder(2)

        step = 0

        while traci.simulation.getMinExpectedNumber() > 0:

            traci.simulationStep()
            print("client 2, step = ",step)
            step+=1
        time.sleep(.5)
        traci.close()
        time.sleep(.5)


Back to the top