def request(self): '''The method that determines the actual ping that will be made by the pinger object.''' randy = uniform(0, 1) ping_cdf = h.cdf(self.E) ping = h.get_index(randy, ping_cdf) return ping
def next_action(self): randy = uniform(0, 1) # Throwback to Archer. index = 0 # Worst case select the first action. # print("The p is: " + str(self.p)) probs = self.p / sum(self.p) cdf = h.cdf(probs) # print("The cdf is: " + str(cdf)) index = h.get_index(randy, cdf) return index
def next_action(self): '''Pick the next action of the learning automata based on the probability vector, self.p, of the LRI automata. At the first time instant all action probabilities are equally likely.''' # Pick a uniformly distributed random number to be tested against # the CDF of self.p. Used to determine the action of the # automaton. randy = uniform(0, 1) # Throwback to Archer. # On catastrophic failure pick the first action. index = 0 # Worst case select the first action. # print("The p is: " + str(self.p)) # Debug the change in self.p. cdf = h.cdf(self.p) # print("The cdf is: " + str(cdf)) # Debug the selected action. # index is the index of the CDF corresponding to the random # action. This value is the next action the automaton will choose. index = h.get_index(randy, cdf) return index
print('Введите желаемый адрес либо "0", если хотите изменить настройки: \n') inp = input() if inp == '0': language = change_settings(language) else: address = f'{{"query": "{inp}", "language": "{language}"}}'.encode('utf-8') res = requests.post(url, data=address, headers=headers).json().get('suggestions') if res: if len(res) > 1: print('Выберите нужный вам вариант либо введите "0", если хотите закрыть программу: \n') for ad in res: index = res.index(ad) + 1 print(f"{index}: {ad['value']}") wanted_address_index = get_index(res) if wanted_address_index == 0: sys.exit(0) else: wanted_address_index -= 1 wanted_address = res[wanted_address_index] print(f'\n{wanted_address.get("value")}, ' f"Широта: {wanted_address.get('data').get('geo_lat')}," f" Долгота: {wanted_address.get('data').get('geo_lon')} ") else: print(f'\nПо вашему запросу найден один вариант: {res[0].get("value")}, ' f'Широта: {res[0].get("data").get("geo_lat")}, ' f'Долгота: {res[0].get("data").get("geo_lon")}') else: print('По вашему запросу не найдено адресов') print('\nПродолжить использование программы? Введите ответ в формате Y/N')