Best Python code snippet using Airtest
tac2x64.py
Source:tac2x64.py
...49 self.condition = ['je', 'jz', 'jne', 'jnz', 'jl',50 'jnge', 'jle', 'jng', 'jg', 'jnle', 'jge', 'jnl']51 for i in range(min(len(self.args), 6)):52 self.strs += [53 f'\tmovq {self.tmp_var_regester[i + 1]}, {self.get_pos(args[i])}']54 def get_pos(self, var, f = 1, offset = 1):55 if (isinstance(var, str) and var[:2] == '%%'):56 return var[1:]57 if (isinstance(var, int)):58 if (f):59 return f'${var}'60 else:61 return f'{var}'62 if (var in self.global_var):63 return f"{var[1:]}(%rip)"64 if (var in self.args):65 if (self.args.index(var) >= 6):66 return f"{(16 + 8 * (len(self.args) - self.args.index(var) - 1))}(%rbp)"67 if (var in self.stack.keys()):68 return f"{(-8 * self.stack[var])}(%rbp)"69 else:70 self.stack_pos += offset71 self.stack[var] = self.stack_pos - offset + 172 return f"{(-8 * self.stack_pos)}(%rbp)"73 def to_str(self, tac_expr):74 op = tac_expr.opcode75 dest = tac_expr.dest76 arg1 = tac_expr.arg177 arg2 = tac_expr.arg278 if (op == 'const'):79 self.strs += [f"\tmovabsq ${arg1}, %r10",80 f"\tmovq %r10, {self.get_pos(dest)}"]81 elif (op == 'copy'):82 if (arg1 in self.global_arr):83 self.strs += [f"\tleaq {self.get_pos(arg1)}, %r10",84 f"\tmovq %r10, {self.get_pos(dest)}"]85 else:86 self.strs += [f"\tmovq {self.get_pos(arg1)}, %r10",87 f"\tmovq %r10, {self.get_pos(dest)}"]88 elif op == 'label':89 self.strs += [arg1[1:] + ":"]90 elif op == 'jmp':91 self.strs += [f"\tjmp {arg1[1:]}"]92 elif op in self.binop.keys():93 op_name = self.binop[op]94 self.strs += [f"\tmovq {self.get_pos(arg1)}, %r10",95 f"\t{op_name} {self.get_pos(arg2)}, %r10",96 f"\tmovq %r10, {self.get_pos(dest)}"]97 elif op in self.unop.keys():98 op_name = self.unop[op]99 self.strs += [f"\tmovq {self.get_pos(arg1)}, %r10",100 f"\t{op_name} %r10",101 f"\tmovq %r10, {self.get_pos(dest)}"]102 elif op in self.shiftop.keys():103 op_name = self.shiftop[op]104 self.strs += [f"\tmovq {self.get_pos(arg1)}, %r10",105 f"\tmovq {self.get_pos(arg2)}, %rcx",106 f"\t{op_name} %cl, %r10",107 f"\tmovq %r10, {self.get_pos(dest)}"]108 elif op in self.div.keys():109 op_name = 'idivq'110 self.strs += [f"\tmovq {self.get_pos(arg1)}, %rax",111 f"\tcqto",112 f"\t{op_name} {self.get_pos(arg2)}",113 f"\tmovq {self.div[op]}, {self.get_pos(dest)}"]114 elif op in self.condition:115 self.strs += [f"\tmovq {self.get_pos(arg1)},%r10",116 f"\tcmpq $0, %r10",117 f"\t{op} {arg2[1:]}"]118 elif op == 'param':119 if arg1 <= 6:120 self.strs += [121 f"\tmovq {self.get_pos(arg2)} , {self.tmp_var_regester[arg1]}"]122 else:123 self.strs += [f"\tpushq {self.get_pos(arg2)}"]124 elif op == 'call':125 self.strs += [f'\tcallq {arg1[1:]}']126 if dest != None:127 self.strs += [f'\tmovq %rax, {self.get_pos(dest)}']128 elif op == 'ret':129 if arg1 == None:130 self.strs += ['\txorq %rax, %rax',131 f'\tjmp .Lend_{self.name[1:]}']132 else:133 self.strs += [f'\tmovq {self.get_pos(arg1)}, %rax',134 f'\tjmp .Lend_{self.name[1:]}']135 elif op == 'load':136 if (arg1[0] in self.global_var):137 self.strs += [f'\tleaq {self.get_pos(arg1[0])}, %r12']138 else:139 self.strs += [f'\tmovq {self.get_pos(arg1[0])}, %r12']140 self.strs += [f'\tmovq {self.get_pos(arg1[1])}, %r13',141 f'\tmovq {self.get_pos(arg1[3])}, %r14',142 f'\taddq %r14, %r13',143 f'\tleaq 0(%r12, %r13, {self.get_pos(arg1[2], 0)}), %r10',144 f'\tmovq (%r10), %r11',145 f'\tmovq %r11, {self.get_pos(dest)}']146 elif op == 'getaddress_var':147 self.strs += [f'\tleaq {self.get_pos(arg1[0])}, %r12',148 f'\tmovq {self.get_pos(arg1[1])}, %r13',149 f'\tmovq {self.get_pos(arg1[3])}, %r14',150 f'\taddq %r14, %r13',151 f'\tleaq 0(%r12, %r13, {self.get_pos(arg1[2], 0)}), %r10',152 f'\tmovq %r10, {self.get_pos(dest)}']153 elif op == 'getaddress_array':154 if (arg1[0] in self.global_var):155 self.strs += [f'\tleaq {self.get_pos(arg1[0])}, %r12']156 else:157 self.strs += [f'\tmovq {self.get_pos(arg1[0])}, %r12']158 self.strs += [f'\tmovq {self.get_pos(arg1[1])}, %r13',159 f'\tmovq {self.get_pos(arg1[3])}, %r14',160 f'\taddq %r14, %r13',161 f'\tleaq 0(%r12, %r13, {self.get_pos(arg1[2], 0)}), %r10',162 f'\tmovq %r10, {self.get_pos(dest)}']163 elif op == 'store':164 if (dest[0] in self.global_var):165 self.strs += [f'\tleaq {self.get_pos(dest[0])}, %r12']166 else:167 self.strs += [f'\tmovq {self.get_pos(dest[0])}, %r12']168 self.strs += [f'\tmovq {self.get_pos(dest[1])}, %r13',169 f'\tmovq {self.get_pos(dest[3])}, %r14',170 f'\taddq %r14, %r13',171 f'\tleaq 0(%r12, %r13, {self.get_pos(dest[2], 0)}), %r10',172 f'\tmovq {self.get_pos(arg1)}, %r11',173 f'\tmovq %r11, (%r10)']174 elif op == 'alloc':175 self.strs += [f'\tmovq {self.get_pos(arg1)}, %rdi',176 f'\tmovq {self.get_pos(arg2)}, %rsi',177 f'\tcallq calloc',178 f'\tmovq %rax, {self.get_pos(dest)}']179 else:180 ValueError("Unknown Opcode")181 def main(self, tac_file):182 for line in tac_file:183 self.to_str(line)184 head = [f'\t.globl {self.name[1:]}', '\t.text', f'{self.name[1:]}:', '\tpushq %rbp',185 '\tmovq %rsp, %rbp', f'\tsubq ${8 * len(self.stack)}, %rsp']186 if (self.name[1:] == 'main'):187 tail = [f'.Lend_{self.name[1:]}:', '\tmovq %rbp, %rsp ', '\tpopq %rbp ',188 '\txorq %rax, %rax', '\tretq', '']189 else:190 tail = [f'.Lend_{self.name[1:]}:', '\tmovq %rbp, %rsp ', '\tpopq %rbp ',191 '\tretq', '']192 return head + self.strs + tail...
share_bicycle0.py
Source:share_bicycle0.py
...57 58 def get_num_bikes(self):59 return self.num_b60 61 def get_pos(self):62 return (self.x, self.y)63 def get_id(self):64 return self.id65 def __eq__(self,other):66 if self.x==other.x and self.y==other.y:67 return True68 else:69 return False70class Truck:71 full_load = FULL_LOAD72 def __init__(self,load,depot_x,depot_y):73 self.num_bikes = load74 self.x=depot_x75 self.y=depot_y76 77 def get_num_bikes(self):78 return self.num_bikes79 80 def change_bikes(self,val,station):81 self.num_bikes += val82 station.change(-val)83 def get_pos(self):84 return(self.x,self.y)85 86 def move_to(self,pos):87 self.x = pos[0]88 self.y= pos[1]89def getDistance(pos1,pos2):90 d = pow((pos1[0]-pos2[0]),2)+pow((pos1[1]-pos2[1]),2)91 return math.sqrt(d)92 93def get_tsp(stations,start):94 '''95 if len(stations) == 0:96 return tsp97 else: 98 next_station = None99 dist = INFINIT100 for station in stations:101 if getDistance(station.get_pos(),start.get_pos())<dist:102 dist = getDistance(station.get_pos(),start.get_pos())103 next_station = station104 tsp.append(next_station)105 stations.remove(next_station)106 return generate_tsp(stations,next_station,tsp)107 '''108 stations.insert(0,start)109 coord_list = []110 for station in stations:111 each_coord = []112 each_coord.append(station.get_pos()[0])113 each_coord.append(station.get_pos()[1])114 coord_list.append(each_coord)115 tour_length,tour_path=generate_tsp.tsp(coord_list)116 #print(tour_path)117 tour_path.pop(-1)118 119 final_tour = []120 if tour_path[0] == 0:121 final_tour = tour_path.copy()122 else:123 tour_path.pop(-1)124 lenth = len(tour_path)125 index = tour_path.index(0)126 for i in range(0,lenth):127 next_i = (i+index)%lenth128 129 final_tour.append(tour_path[next_i])130 final_tour.append(0)131 132 #print(len(final_tour),final_tour)133 return final_tour134def set_vplus(edge_index,tsp):135 for i in range(edge_index,len(tsp)):136 if tsp[i].lessthan_target()==False:137 return tsp[i]138 return tsp[-1]139def set_vminus(edge_index,tsp):140 for i in range(0,len(tsp)):141 if tsp[i].lessthan_target()==True: 142 return tsp[i]143 return tsp[-1]144def move_to_first_can_be_colletted(v_plus,tsp,truck,carbon,sum_distance):145 if Truck.full_load-truck.get_num_bikes()>=(v_plus.get_num_bikes()) or pos_to_id(v_plus.get_pos(),tsp) == 0:146 carbon+=getDistance(truck.get_pos(),v_plus.get_pos())*(TRUCK_WEIGHT+truck.get_num_bikes())147 sum_distance+=getDistance(truck.get_pos(),v_plus.get_pos())148 #print("truck's position: ",pos_to_id(truck.get_pos(),tsp), " ", truck.get_num_bikes(), "sum distance so far: ",sum_distance, "sum carbonP: ", carbon)149 if v_plus.id >= 90:150 pass151 #print("v_plus: ",v_plus.id,"truck_position: ", pos_to_id(truck.get_pos(),tsp))152 truck.move_to(v_plus.get_pos())153 truck.change_bikes(v_plus.get_num_bikes(), v_plus)154 155 return truck,carbon,sum_distance156 else:157 edge_index = get_index(tsp,v_plus)158 v_plus = set_vplus(edge_index+1,tsp)159 160 #print("v_plus: ",v_plus.id,"truck_position: ", pos_to_id(truck.get_pos(),tsp))161 return move_to_first_can_be_colletted(v_plus,tsp,truck,carbon,sum_distance)162def generate_data(path):163# Driver code164 165 csvF = open(path,"r")166 reader = csv.reader(csvF)167 stations = []168 rows = []169 k=1170 asum = 0171 for row in reader:172 #print(row)173 asum += int(row[2])174 station = Station(k,int(row[2]),float(row[0]),float(row[1]))175 k+=1176 stations.append(station)177 rows.append(row)178 #print(rows)179 return stations180def get_index(tsp,station):181 k = 0182 for i in tsp:183 184 if i.id==station.id:185 return k186 k+=1187 188def read_csv():189 csv_path = []190 for i in range(1,27):191 path = "stations"+str(i)+".csv"192 csv_path.append(path)193 return csv_path194def generate_carbon(stations):195 sum_x = 0196 sum_y = 0197 for station in stations:198 sum_x += station.x199 sum_y += station.y200 201 depot = Station(0,0,depot_x,depot_y)202 carbon = 0203 edge_index = 0204 v_plus = None205 v_minus = None206 tsp_path = get_tsp(stations,depot)207 208 tsp = []209 for i in tsp_path:210 for station in stations:211 if station.id == i:212 tsp.append(station)213 sum_bikes = 0214 sum_dis_tsp = 0215 for i in range(len(tsp)):216 sum_bikes+= tsp[i].get_num_bikes()217 #print(tsp[i].id, tsp[i].get_num_bikes())218 if i != len(tsp)-1:219 sum_dis_tsp+=getDistance(tsp[i].get_pos(),tsp[i+1].get_pos())220 print("tsp_dist: ", sum_dis_tsp)221 tsp[-1].num_b = 0222 if sum_bikes >= 0:223 truck = Truck(0+START_BIKES,depot_x,depot_y)224 else:225 truck = Truck(abs(sum_bikes)+START_BIKES,depot_x,depot_y)226 p = 0227 sum_distance = 0228 truck_pos = 9999229 230 while edge_index<=len(tsp)-1 and p<=120 and truck_pos != 0:231 p+=1232 v_plus = set_vplus(0,tsp)233 v_minus = set_vminus(edge_index,tsp)234 #print("v_minus id: ",v_minus.id)235 236 #print(sum_distance)237 if truck.get_num_bikes()>=abs(v_minus.get_num_bikes()) and truck.get_num_bikes() != 0 and v_minus.id != 0:238 carbon+=getDistance(truck.get_pos(),v_minus.get_pos())*(TRUCK_WEIGHT+truck.get_num_bikes())239 sum_distance+=getDistance(truck.get_pos(),v_minus.get_pos())240 #print("truck's position: ",pos_to_id(truck.get_pos(),tsp), " ", truck.get_num_bikes(), "sum distance so far: ",sum_distance, "sum carbonP: ", carbon)241 truck.move_to(v_minus.get_pos())242 truck.change_bikes(v_minus.get_num_bikes(),v_minus)243 244 edge_index = get_index(tsp,v_minus)245 #edge_index +=1246 elif get_index(tsp,v_minus)<get_index(tsp,v_plus) and truck.get_num_bikes()+v_plus.get_num_bikes()>abs(v_minus.get_num_bikes()) and v_minus.id != 0:247 carbon+=getDistance(truck.get_pos(),v_plus.get_pos())*(TRUCK_WEIGHT+truck.get_num_bikes())248 sum_distance+=getDistance(truck.get_pos(),v_plus.get_pos())249 #print("truck's position: ",pos_to_id(truck.get_pos(),tsp), " ", truck.get_num_bikes(), "sum distance so far: ",sum_distance, "sum carbonP: ", carbon)250 truck.move_to(v_plus.get_pos())251 truck.change_bikes(v_plus.get_num_bikes(), v_plus)252 253 carbon+=getDistance(truck.get_pos(),v_minus.get_pos())*(TRUCK_WEIGHT+truck.get_num_bikes())254 sum_distance+=getDistance(truck.get_pos(),v_minus.get_pos())255 #print("truck's position: ",pos_to_id(truck.get_pos(),tsp), " ", truck.get_num_bikes(), "sum distance so far: ",sum_distance, "sum carbonP: ", carbon)256 truck.move_to(v_minus .get_pos())257 truck.change_bikes(v_minus.get_num_bikes(),v_minus)258 259 edge_index = get_index(tsp,v_plus)260 #edge_index +=2261 elif Truck.full_load-truck.get_num_bikes()>=v_plus.get_num_bikes():262 carbon+=getDistance(truck.get_pos(),v_plus.get_pos())*(TRUCK_WEIGHT+truck.get_num_bikes())263 sum_distance+=getDistance(truck.get_pos(),v_plus.get_pos())264 #print("truck's position: ",pos_to_id(truck.get_pos(),tsp), " ", truck.get_num_bikes(), "sum distance so far: ",sum_distance, "sum carbonP: ", carbon)265 266 #print("3_step_v_plus: ",v_plus.id,"edge_index: ",edge_index)267 truck.move_to(v_plus.get_pos())268 truck.change_bikes(v_plus.get_num_bikes(), v_plus) 269 edge_index = get_index(tsp,v_plus)270 #edge_index +=1271 elif Truck.full_load-truck.get_num_bikes()<v_plus.get_num_bikes():272 truck,carbon,sum_distance=move_to_first_can_be_colletted(v_plus,tsp,truck,carbon,sum_distance)273 edge_index = get_index(tsp,v_plus)274 truck_pos = pos_to_id(truck.get_pos(),tsp)275 #print(truck_pos,"truck bikes:", truck.get_num_bikes())276 #print("v_minus id: ",v_minus.id,"v_plus id: ", v_plus.id)277 '''278 for i in range(len(tsp)):279 sum_bikes+= tsp[i].get_num_bikes()280 print(tsp[i].id, tsp[i].get_num_bikes())281 '''282 return carbon,sum_distance283def pos_to_id(pos, tsp):284 for station in tsp:285 if station.get_pos() == pos:286 return station.id287def main():288 csv_list = read_csv()289 sum_car = 0290 i = 0291 result = []292 for csv_f in csv_list:293 #print(csv_f)294 i+=1295 if i ==12:296 #print(csv_f)297 298 stations = generate_data(csv_f)299 carbon,sum_distance = generate_carbon(stations)...
share_bicycle10.py
Source:share_bicycle10.py
...57 58 def get_num_bikes(self):59 return self.num_b60 61 def get_pos(self):62 return (self.x, self.y)63 def get_id(self):64 return self.id65 def __eq__(self,other):66 if self.x==other.x and self.y==other.y:67 return True68 else:69 return False70class Truck:71 full_load = FULL_LOAD72 def __init__(self,load,depot_x,depot_y):73 self.num_bikes = load74 self.x=depot_x75 self.y=depot_y76 77 def get_num_bikes(self):78 return self.num_bikes79 80 def change_bikes(self,val,station):81 self.num_bikes += val82 station.change(-val)83 def get_pos(self):84 return(self.x,self.y)85 86 def move_to(self,pos):87 self.x = pos[0]88 self.y= pos[1]89def getDistance(pos1,pos2):90 d = pow((pos1[0]-pos2[0]),2)+pow((pos1[1]-pos2[1]),2)91 return math.sqrt(d)92 93def get_tsp(stations,start):94 '''95 if len(stations) == 0:96 return tsp97 else: 98 next_station = None99 dist = INFINIT100 for station in stations:101 if getDistance(station.get_pos(),start.get_pos())<dist:102 dist = getDistance(station.get_pos(),start.get_pos())103 next_station = station104 tsp.append(next_station)105 stations.remove(next_station)106 return generate_tsp(stations,next_station,tsp)107 '''108 stations.insert(0,start)109 coord_list = []110 for station in stations:111 each_coord = []112 each_coord.append(station.get_pos()[0])113 each_coord.append(station.get_pos()[1])114 coord_list.append(each_coord)115 tour_length,tour_path=generate_tsp.tsp(coord_list)116 #print(tour_path)117 tour_path.pop(-1)118 119 final_tour = []120 if tour_path[0] == 0:121 final_tour = tour_path.copy()122 else:123 tour_path.pop(-1)124 lenth = len(tour_path)125 index = tour_path.index(0)126 for i in range(0,lenth):127 next_i = (i+index)%lenth128 129 final_tour.append(tour_path[next_i])130 final_tour.append(0)131 132 #print(len(final_tour),final_tour)133 return final_tour134def set_vplus(edge_index,tsp):135 for i in range(edge_index,len(tsp)):136 if tsp[i].lessthan_target()==False:137 return tsp[i]138 return tsp[-1]139def set_vminus(edge_index,tsp):140 for i in range(0,len(tsp)):141 if tsp[i].lessthan_target()==True: 142 return tsp[i]143 return tsp[-1]144def move_to_first_can_be_colletted(v_plus,tsp,truck,carbon,sum_distance):145 if Truck.full_load-truck.get_num_bikes()>=(v_plus.get_num_bikes()) or pos_to_id(v_plus.get_pos(),tsp) == 0:146 carbon+=getDistance(truck.get_pos(),v_plus.get_pos())*(TRUCK_WEIGHT+truck.get_num_bikes())147 sum_distance+=getDistance(truck.get_pos(),v_plus.get_pos())148 #print("truck's position: ",pos_to_id(truck.get_pos(),tsp), " ", truck.get_num_bikes(), "sum distance so far: ",sum_distance, "sum carbonP: ", carbon)149 if v_plus.id >= 90:150 pass151 #print("v_plus: ",v_plus.id,"truck_position: ", pos_to_id(truck.get_pos(),tsp))152 truck.move_to(v_plus.get_pos())153 truck.change_bikes(v_plus.get_num_bikes(), v_plus)154 155 return truck,carbon,sum_distance156 else:157 edge_index = get_index(tsp,v_plus)158 v_plus = set_vplus(edge_index+1,tsp)159 160 #print("v_plus: ",v_plus.id,"truck_position: ", pos_to_id(truck.get_pos(),tsp))161 return move_to_first_can_be_colletted(v_plus,tsp,truck,carbon,sum_distance)162def generate_data(path):163# Driver code164 165 csvF = open(path,"r")166 reader = csv.reader(csvF)167 stations = []168 rows = []169 k=1170 asum = 0171 for row in reader:172 #print(row)173 asum += int(row[2])174 station = Station(k,int(row[2]),float(row[0]),float(row[1]))175 k+=1176 stations.append(station)177 rows.append(row)178 #print(rows)179 return stations180def get_index(tsp,station):181 k = 0182 for i in tsp:183 184 if i.id==station.id:185 return k186 k+=1187 188def read_csv():189 csv_path = []190 for i in range(1,27):191 path = "stations"+str(i)+".csv"192 csv_path.append(path)193 return csv_path194def generate_carbon(stations):195 sum_x = 0196 sum_y = 0197 for station in stations:198 sum_x += station.x199 sum_y += station.y200 201 depot = Station(0,0,depot_x,depot_y)202 carbon = 0203 edge_index = 0204 v_plus = None205 v_minus = None206 tsp_path = get_tsp(stations,depot)207 208 tsp = []209 for i in tsp_path:210 for station in stations:211 if station.id == i:212 tsp.append(station)213 sum_bikes = 0214 sum_dis_tsp = 0215 for i in range(len(tsp)):216 sum_bikes+= tsp[i].get_num_bikes()217 #print(tsp[i].id, tsp[i].get_num_bikes())218 if i != len(tsp)-1:219 sum_dis_tsp+=getDistance(tsp[i].get_pos(),tsp[i+1].get_pos())220 #print("tsp_dist: ", sum_dis_tsp)221 tsp[-1].num_b = 0222 if sum_bikes >= 0:223 truck = Truck(0+START_BIKES,depot_x,depot_y)224 else:225 truck = Truck(abs(sum_bikes)+START_BIKES,depot_x,depot_y)226 p = 0227 sum_distance = 0228 truck_pos = 9999229 230 while edge_index<=len(tsp)-1 and p<=120 and truck_pos != 0:231 p+=1232 v_plus = set_vplus(0,tsp)233 v_minus = set_vminus(edge_index,tsp)234 #print("v_minus id: ",v_minus.id)235 236 #print(sum_distance)237 if truck.get_num_bikes()>=abs(v_minus.get_num_bikes()) and truck.get_num_bikes() != 0 and v_minus.id != 0:238 carbon+=getDistance(truck.get_pos(),v_minus.get_pos())*(TRUCK_WEIGHT+truck.get_num_bikes())239 sum_distance+=getDistance(truck.get_pos(),v_minus.get_pos())240 #print("truck's position: ",pos_to_id(truck.get_pos(),tsp), " ", truck.get_num_bikes(), "sum distance so far: ",sum_distance, "sum carbonP: ", carbon)241 truck.move_to(v_minus.get_pos())242 truck.change_bikes(v_minus.get_num_bikes(),v_minus)243 244 edge_index = get_index(tsp,v_minus)245 #edge_index +=1246 elif get_index(tsp,v_minus)<get_index(tsp,v_plus) and truck.get_num_bikes()+v_plus.get_num_bikes()>abs(v_minus.get_num_bikes()) and v_minus.id != 0:247 carbon+=getDistance(truck.get_pos(),v_plus.get_pos())*(TRUCK_WEIGHT+truck.get_num_bikes())248 sum_distance+=getDistance(truck.get_pos(),v_plus.get_pos())249 #print("truck's position: ",pos_to_id(truck.get_pos(),tsp), " ", truck.get_num_bikes(), "sum distance so far: ",sum_distance, "sum carbonP: ", carbon)250 truck.move_to(v_plus.get_pos())251 truck.change_bikes(v_plus.get_num_bikes(), v_plus)252 253 carbon+=getDistance(truck.get_pos(),v_minus.get_pos())*(TRUCK_WEIGHT+truck.get_num_bikes())254 sum_distance+=getDistance(truck.get_pos(),v_minus.get_pos())255 #print("truck's position: ",pos_to_id(truck.get_pos(),tsp), " ", truck.get_num_bikes(), "sum distance so far: ",sum_distance, "sum carbonP: ", carbon)256 truck.move_to(v_minus .get_pos())257 truck.change_bikes(v_minus.get_num_bikes(),v_minus)258 259 edge_index = get_index(tsp,v_plus)260 #edge_index +=2261 elif Truck.full_load-truck.get_num_bikes()>=v_plus.get_num_bikes():262 carbon+=getDistance(truck.get_pos(),v_plus.get_pos())*(TRUCK_WEIGHT+truck.get_num_bikes())263 sum_distance+=getDistance(truck.get_pos(),v_plus.get_pos())264 #print("truck's position: ",pos_to_id(truck.get_pos(),tsp), " ", truck.get_num_bikes(), "sum distance so far: ",sum_distance, "sum carbonP: ", carbon)265 266 #print("3_step_v_plus: ",v_plus.id,"edge_index: ",edge_index)267 truck.move_to(v_plus.get_pos())268 truck.change_bikes(v_plus.get_num_bikes(), v_plus) 269 edge_index = get_index(tsp,v_plus)270 #edge_index +=1271 elif Truck.full_load-truck.get_num_bikes()<v_plus.get_num_bikes():272 truck,carbon,sum_distance=move_to_first_can_be_colletted(v_plus,tsp,truck,carbon,sum_distance)273 edge_index = get_index(tsp,v_plus)274 truck_pos = pos_to_id(truck.get_pos(),tsp)275 #print(truck_pos,"truck bikes:", truck.get_num_bikes())276 #print("v_minus id: ",v_minus.id,"v_plus id: ", v_plus.id)277 '''278 for i in range(len(tsp)):279 sum_bikes+= tsp[i].get_num_bikes()280 print(tsp[i].id, tsp[i].get_num_bikes())281 '''282 return carbon,sum_distance283def pos_to_id(pos, tsp):284 for station in tsp:285 if station.get_pos() == pos:286 return station.id287def main():288 csv_list = read_csv()289 sum_car = 0290 i = 0291 result = []292 for csv_f in csv_list:293 #print(csv_f)294 i+=1295 if i ==12:296 #print(csv_f)297 298 stations = generate_data(csv_f)299 carbon,sum_distance = generate_carbon(stations)...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!