<commit_before>import logging

from rllab.envs.base import Env
from rllab.envs.base import Step

import numpy as np

import subprocess, sys

import random

import copy
import traci


"""
This file provides the interface for controlling a SUMO simulation. Using the environment class, you can
start sumo, provide a scenario to specify a configuration and controllers, perform simulation steps, and
reset the simulation to an initial configuration.

This class cannot be used as is: you must extend it to implement an action applicator method, and
properties to define the MDP if you choose to use it with RLLab.

"""

COLORS = [(255,0,0,0),(0, 255,0,0),(0, 0, 255,0), (255, 255,0,0),(0, 255,255,0),(255, 0,255,0), (255, 255,255,0)]


class SumoEnvironment(Env):

    def __init__(self,env_params, sumo_binary, sumo_params, scenario):
        """[summary]
        
        [description]
        
        Arguments:
            env_params {dictionary} -- [description]
            sumo_binary {string} -- Either "sumo" or "sumo-gui"
            sumo_params {dictionary} -- {"port": {integer} connection to SUMO,
                            "timestep": {float} default=0.01s, SUMO default=1.0s}
            scenario {Scenario} -- @see Scenario; abstraction of the SUMO XML files
                                    which specify the vehicles placed on the net
        
        Raises:
            ValueError -- Raised if a SUMO port not provided
        """
        self.env_params = env_params
        self.sumo_binary = sumo_binary
        self.scenario = scenario
        
        # Vehicles: Key = Vehicle ID, Value = Dictionary describing the vehicle
        self.vehicles = {}

        # Represents number of steps taken
        self.timer = 0
        # 0.01 = default time step for our research
        self.time_step = sumo_params["time_step"] if "time_step" in sumo_params else 0.01

        if "port" not in sumo_params:
            raise ValueError("SUMO port not defined")

        logging.info(" Starting SUMO on port " + str(sumo_params["port"]))
        logging.debug(" Cfg file " + str(self.scenario.cfg))

        # Opening the I/O thread to SUMO
        cfg_file = self.scenario.cfg
        if "mode" in env_params and env_params["mode"] == "ec2":
            cfg_file = "/root/code/rllab/" + cfg_file
        subprocess.Popen([self.sumo_binary, "-c", self.scenario.cfg, "--remote-port",
                                        str(sumo_params["port"]), "--step-length", str(self.time_step)], stdout=sys.stdout, stderr=sys.stderr)

        logging.debug(" Initializing TraCI on port " + str(sumo_params["port"]) + "!")
        traci.init(sumo_params["port"])
<commit_msg>sorry quick fix<commit_after>import logging

from rllab.envs.base import Env
from rllab.envs.base import Step

import numpy as np

import subprocess, sys

import random

import copy
import traci


"""
This file provides the interface for controlling a SUMO simulation. Using the environment class, you can
start sumo, provide a scenario to specify a configuration and controllers, perform simulation steps, and
reset the simulation to an initial configuration.

This class cannot be used as is: you must extend it to implement an action applicator method, and
properties to define the MDP if you choose to use it with RLLab.

"""

COLORS = [(255,0,0,0),(0, 255,0,0),(0, 0, 255,0), (255, 255,0,0),(0, 255,255,0),(255, 0,255,0), (255, 255,255,0)]


class SumoEnvironment(Env):

    def __init__(self,env_params, sumo_binary, sumo_params, scenario):
        """[summary]
        
        [description]
        
        Arguments:
            env_params {dictionary} -- [description]
            sumo_binary {string} -- Either "sumo" or "sumo-gui"
            sumo_params {dictionary} -- {"port": {integer} connection to SUMO,
                            "timestep": {float} default=0.01s, SUMO default=1.0s}
            scenario {Scenario} -- @see Scenario; abstraction of the SUMO XML files
                                    which specify the vehicles placed on the net
        
        Raises:
            ValueError -- Raised if a SUMO port not provided
        """
        self.env_params = env_params
        self.sumo_binary = sumo_binary
        self.scenario = scenario
        
        # Vehicles: Key = Vehicle ID, Value = Dictionary describing the vehicle
        self.vehicles = {}

        # Represents number of steps taken
        self.timer = 0
        # 0.01 = default time step for our research
        self.time_step = sumo_params["time_step"] if "time_step" in sumo_params else 0.01

        if "port" not in sumo_params:
            raise ValueError("SUMO port not defined")

        logging.info(" Starting SUMO on port " + str(sumo_params["port"]))
        logging.debug(" Cfg file " + str(self.scenario.cfg))

        # Opening the I/O thread to SUMO
        cfg_file = self.scenario.cfg
        if "mode" in env_params and env_params["mode"] == "ec2":
            cfg_file = "/root/code/rllab/" + cfg_file
        subprocess.Popen([self.sumo_binary, "-c", cfg_file, "--remote-port",
                                        str(sumo_params["port"]), "--step-length", str(self.time_step)], stdout=sys.stdout, stderr=sys.stderr)

        logging.debug(" Initializing TraCI on port " + str(sumo_params["port"]) + "!")
        traci.init(sumo_params["port"])

{'fraction_non_alphanumeric': 0.10479209397725153, 'fraction_numerical': 0.02424016408726459, 'mean_word_length': 2.4673561732385263, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '650059', 'n_tokens_mistral': 1665, 'n_tokens_neox': 1544, 'n_words': 510}