How to use put_destination method in localstack

Best Python code snippet using localstack_python

Markov_use_bellman.py

Source:Markov_use_bellman.py Github

copy

Full Screen

...25 self.my_map[(index_x, index_y)] = [prim_value,26 prim_action] # 初始化地图27 def put_wall(self, x, y):28 self.my_map[(x, y)] = ['#', '#']29 def put_destination(self, x, y, value):30 self.my_map[(x, y)] = [value, value]31 def change_value(self, new_value):32 for index in new_value.keys():33 self.my_map[index][0] = new_value[index]34 def print_map(self):35 for index_y in range(map.y, 0, -1):36 temp = []37 for index_x in range(1, map.x + 1):38 if self.my_map[(index_x, index_y)][1] == '#':39 temp.append("#")40 elif self.my_map[(index_x, index_y)][1] == 1:41 temp.append(1)42 elif self.my_map[(index_x, index_y)][1] == -1:43 temp.append(-1)44 else:45 temp.append(self.my_map[(index_x, index_y)][1])46 print(temp)47 def print_value(self):48 for index_y in range(map.y, 0, -1):49 temp = []50 for index_x in range(1, map.x + 1):51 if self.my_map[(index_x, index_y)][1] == '#':52 temp.append("#")53 elif self.my_map[(index_x, index_y)][1] == 1:54 temp.append(1)55 elif self.my_map[(index_x, index_y)][1] == -1:56 temp.append(-1)57 else:58 temp.append(self.my_map[(index_x, index_y)][0])59 print(temp)60def up(x, y, map):61 if y + 1 <= map.y and not (map.my_map[(x, y + 1)][0] is symbol[0]):62 y += 163 return x, y64def down(x, y, map):65 if y - 1 > 0 and not (map.my_map[(x, y - 1)][0] is symbol[0]):66 y -= 167 return x, y68def left(x, y, map):69 if x - 1 > 0 and not (map.my_map[(x - 1, y)][0] is symbol[0]):70 x -= 171 return x, y72def right(x, y, map):73 if x + 1 <= map.x and not (map.my_map[(x + 1, y)][0] is symbol[0]):74 x += 175 return x, y76def make_reward(map, value):77 reward = {}78 for index_x in range(1, map.x + 1):79 for index_y in range(1, map.y + 1):80 if not (map.my_map[(index_x, index_y)][0] in symbol):81 reward[(index_x, index_y)] = value82 return reward83def bellman_function(x, y, map, reward, a1, a2, a3, b):84 array = [a1 * map.my_map[up(x, y, map)][0] + \85 a2 * map.my_map[left(x, y, map)][0] + \86 a3 * map.my_map[right(x, y, map)][0],87 # ======================88 a1 * map.my_map[down(x, y, map)][0] + \89 a2 * map.my_map[left(x, y, map)][0] + \90 a3 * map.my_map[right(x, y, map)][0],91 # ======================92 a1 * map.my_map[left(x, y, map)][0] + \93 a2 * map.my_map[up(x, y, map)][0] + \94 a3 * map.my_map[down(x, y, map)][0],95 # ======================96 a1 * map.my_map[right(x, y, map)][0] + \97 a2 * map.my_map[up(x, y, map)][0] + \98 a3 * map.my_map[down(x, y, map)][0]99 # ======================100 ]101 new_value = reward[(x, y)] + b * np.max(array)102 return new_value103def iteration_of_value(map, reward, a1, a2, a3, b):104 new_value = {}105 stop = False106 i = 0107 while not stop:108 for index_x in range(1, map.x + 1):109 for index_y in range(1, map.y + 1):110 if not (map.my_map[(index_x, index_y)][1] in symbol):111 new_value[(index_x, index_y)] = \112 round_point_five(bellman_function(index_x, index_y, map,113 reward,114 a1, a2, a3, b))115 if the_equal(new_value, map):116 stop = True117 i += 1118 # print(i)119 if i == 10000:120 stop = True121 map.change_value(new_value)122 return map123def round_point_five(num):124 return int(num * 100000) / 100000125def the_equal(new_value, map):126 result = True127 for key in new_value.keys():128 if map.my_map[key][0] != new_value[key]:129 result = False130 break131 return result132def choose_best_way(map, a1, a2, a3):133 for x in range(1, map.x + 1):134 for y in range(1, map.y + 1):135 if not (map.my_map[(x, y)][1] in symbol):136 array = [a1 * map.my_map[up(x, y, map)][0] + \137 a2 * map.my_map[left(x, y, map)][0] + \138 a3 * map.my_map[right(x, y, map)][0],139 # ======================140 a1 * map.my_map[down(x, y, map)][0] + \141 a2 * map.my_map[left(x, y, map)][0] + \142 a3 * map.my_map[right(x, y, map)][0],143 # ======================144 a1 * map.my_map[left(x, y, map)][0] + \145 a2 * map.my_map[up(x, y, map)][0] + \146 a3 * map.my_map[down(x, y, map)][0],147 # ======================148 a1 * map.my_map[right(x, y, map)][0] + \149 a2 * map.my_map[up(x, y, map)][0] + \150 a3 * map.my_map[down(x, y, map)][0]151 # ======================152 ]153 max = np.max(array)154 best_way = []155 for index in range(4):156 if array[index] == max:157 best_way.append(num_to_direction(index))158 map.my_map[(x, y)][1] = best_way159def num_to_direction(num):160 direction = ['UP', 'DOWN', 'LEFT', 'RIGHT']161 return direction[num]162if __name__ == "__main__":163 map = map(5, 5) # 生成x * y地图164 # 放置障碍165 map.put_wall(2, 2)166 map.put_wall(4, 3)167 # 放置目标值168 map.put_destination(5, 5, 1)169 map.put_destination(5, 4, -1)170 # 计算回报函数(输入的为回报函数的值)171 reward = make_reward(map, -1)172 # 计算最终的效用值(输入agent的各个方向的概率和折扣因子)173 map = iteration_of_value(map, reward, 0.8, 0.1, 0.1, 0.5)174 # 计算最优路径175 choose_best_way(map, 0.8, 0.1, 0.1)176 # 打印相关数据177 map.print_map()...

Full Screen

Full Screen

copy.py

Source:copy.py Github

copy

Full Screen

...16 files = message['files']17 source = files['source']18 destination = files['destination']19 source_content = self.get_source(source)20 success = self.put_destination(destination, source_content)21 return success22 def get_source(self, source):23 """Get the content of the source file."""24 service, file_path = source.split(":")25 if service == "cloudfiles":26 body = self._get_from_rackspace(file_path)27 if service == "s3":28 body = self._get_from_aws(file_path)29 else:30 raise NotImplementedError31 return body32 def put_destination(self, destination, source_content):33 """Upload content to the destination."""34 service, destination_path = destination.split(":")35 if service == "s3":36 success = self._put_to_aws(destination_path, source_content)37 else:38 raise NotImplementedError39 return success40 def _get_from_rackspace(self, file_path):41 """Get the content from rackspace."""42 obj_name, container_name = self._parse_file_dir_name(file_path)43 response = self.rackspace.object_store.download_object(44 obj_name, container=container_name)45 return response46 def _get_from_aws(self, file_path):...

Full Screen

Full Screen

cli.py

Source:cli.py Github

copy

Full Screen

...41def copy(source, destination):42 """Copy one file."""43 fc = FileCopier()44 source_content = fc.get_source(source)45 success = fc.put_destination(destination, source_content)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful