leaderboard/leaderboard/scenarios/train_scenario.py
def _scenario_sampling(self, potential_scenarios_definitions, random_seed=0):
        """
        The function used to sample the scenarios that are going to happen for this route.
        """

        # fix the random seed for reproducibility
        # rgn = random.RandomState(random_seed)

        def position_sampled(scenario_choice, sampled_scenarios):
            """
            Check if a position was already sampled, i.e. used for another scenario
            """
            for existent_scenario in sampled_scenarios:
                # If the scenarios have equal positions then it is true.
                if compare_scenarios(scenario_choice, existent_scenario):
                    return True

            return False

        def select_scenario(list_scenarios):
            # priority to the scenarios with higher number: 10 has priority over 9, etc.
            higher_id = -1
            selected_scenario = None
            for scenario in list_scenarios:
                try:
                    scenario_number = int(scenario['name'].split('Scenario')[1])
                except:
                    scenario_number = -1

                if scenario_number >= higher_id:
                    higher_id = scenario_number
                    selected_scenario = scenario

            return selected_scenario

        # The idea is to randomly sample a scenario per trigger position.
        sampled_scenarios = []
        for trigger in potential_scenarios_definitions.keys():
            possible_scenarios = potential_scenarios_definitions[trigger]

            # scenario_choice = select_scenario(possible_scenarios)
            scenario_choice = random.choice(possible_scenarios)
            del possible_scenarios[possible_scenarios.index(scenario_choice)]
            # We keep sampling and testing if this position is present on any of the scenarios.
            while position_sampled(scenario_choice, sampled_scenarios):
                if possible_scenarios is None or not possible_scenarios:
                    scenario_choice = None
                    break
                scenario_choice = random.choice(possible_scenarios)
                del possible_scenarios[possible_scenarios.index(scenario_choice)]

            if scenario_choice is not None:
                sampled_scenarios.append(scenario_choice)

        return sampled_scenarios

        The function used to sample the scenarios that are going to happen for this route.
        
The function used to sample the scenarios that are going to happen for this route.
The function used to sample the scenarios that are going to happen for this route .
def _scenario_sampling(self, potential_scenarios_definitions, random_seed=0):
        def position_sampled(scenario_choice, sampled_scenarios):
            for existent_scenario in sampled_scenarios:
                if compare_scenarios(scenario_choice, existent_scenario):
                    return True
            return False
        def select_scenario(list_scenarios):
            higher_id = -1
            selected_scenario = None
            for scenario in list_scenarios:
                try:
                    scenario_number = int(scenario['name'].split('Scenario')[1])
                except:
                    scenario_number = -1
                if scenario_number >= higher_id:
                    higher_id = scenario_number
                    selected_scenario = scenario
            return selected_scenario
        sampled_scenarios = []
        for trigger in potential_scenarios_definitions.keys():
            possible_scenarios = potential_scenarios_definitions[trigger]
            scenario_choice = random.choice(possible_scenarios)
            del possible_scenarios[possible_scenarios.index(scenario_choice)]
            while position_sampled(scenario_choice, sampled_scenarios):
                if possible_scenarios is None or not possible_scenarios:
                    scenario_choice = None
                    break
                scenario_choice = random.choice(possible_scenarios)
                del possible_scenarios[possible_scenarios.index(scenario_choice)]
            if scenario_choice is not None:
                sampled_scenarios.append(scenario_choice)
        return sampled_scenarios
def _scenario_sampling ( self , potential_scenarios_definitions , random_seed = 0 ) : def position_sampled ( scenario_choice , sampled_scenarios ) : """
            Check if a position was already sampled, i.e. used for another scenario
            """ for existent_scenario in sampled_scenarios : if compare_scenarios ( scenario_choice , existent_scenario ) : return True return False def select_scenario ( list_scenarios ) : higher_id = - 1 selected_scenario = None for scenario in list_scenarios : try : scenario_number = int ( scenario [ 'name' ] . split ( 'Scenario' ) [ 1 ] ) except : scenario_number = - 1 if scenario_number >= higher_id : higher_id = scenario_number selected_scenario = scenario return selected_scenario sampled_scenarios = [ ] for trigger in potential_scenarios_definitions . keys ( ) : possible_scenarios = potential_scenarios_definitions [ trigger ] scenario_choice = random . choice ( possible_scenarios ) del possible_scenarios [ possible_scenarios . index ( scenario_choice ) ] while position_sampled ( scenario_choice , sampled_scenarios ) : if possible_scenarios is None or not possible_scenarios : scenario_choice = None break scenario_choice = random . choice ( possible_scenarios ) del possible_scenarios [ possible_scenarios . index ( scenario_choice ) ] if scenario_choice is not None : sampled_scenarios . append ( scenario_choice ) return sampled_scenarios
The function used to sample the scenarios that are going to happen for this route.
The function used to sample the scenarios that are going to happen for this route .
"""
        The function used to sample the scenarios that are going to happen for this route.
        """ # fix the random seed for reproducibility # rgn = random.RandomState(random_seed) """
            Check if a position was already sampled, i.e. used for another scenario
            """ # If the scenarios have equal positions then it is true. # priority to the scenarios with higher number: 10 has priority over 9, etc. # The idea is to randomly sample a scenario per trigger position. # scenario_choice = select_scenario(possible_scenarios) # We keep sampling and testing if this position is present on any of the scenarios.
self
potential_scenarios_definitions
random_seed