How to use get_steps method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

8Puzzle_BFS_IDDFS.py

Source:8Puzzle_BFS_IDDFS.py Github

copy

Full Screen

...31 32 def get_previous_states(self):33 return self.previous_states34 35 def get_steps(self):36 return self.steps37 38 def get_init_state(self):39 return self.init_state40 41def to_string(data):42 temp=''43 for i in data:44 for j in i:45 temp = temp+j46 return temp47#heler functions that perform the moves48#swaps 0 based on its coordinates49#also leaves a direction for the previous_states list50def move_up(data,zero_i,zero_j):51 direction='U'52 temp_data = copy.deepcopy(data.get_state())53 temp=temp_data[zero_i-1][zero_j]54 temp_data[zero_i-1][zero_j]='0'55 temp_data[zero_i][zero_j]=temp56 del temp57 return temp_data,direction58def move_left(data,zero_i,zero_j):59 direction='L'60 temp_data = copy.deepcopy(data.get_state())61 temp=temp_data[zero_i][zero_j-1]62 temp_data[zero_i][zero_j-1]='0'63 temp_data[zero_i][zero_j]=temp64 del temp65 return temp_data,direction66def move_right(data,zero_i,zero_j):67 direction='R'68 temp_data = copy.deepcopy(data.get_state())69 temp=temp_data[zero_i][zero_j+1]70 temp_data[zero_i][zero_j+1]='0'71 temp_data[zero_i][zero_j]=temp72 del temp73 return temp_data,direction74def move_down(data,zero_i,zero_j):75 direction='D'76 temp_data = copy.deepcopy(data.get_state())77 temp=temp_data[zero_i+1][zero_j]78 temp_data[zero_i+1][zero_j]='0'79 temp_data[zero_i][zero_j]=temp80 del temp81 return temp_data,direction82#the most important function83#determines the legal moves and then makes them84#takes chain objects as data, the dictionary as discovered_states, the queue as q and the dfs flag85#performes different actions that are more appropriate to DFS or BFS86#UPDATE - after changing dfs function DFS mode for actions() only slows it down87#use with false only88#improves performance for both (in terms of time)89#overall this function extremely inefficient due to repeating code, but it is very effective90def actions(data,discovered_states,q,dfs):91 temp=[]92 temp_dir=''93 #find zero, needed to determine legal moves and commit moves themselves94 for i in range(3):95 if '0' in data.get_state()[i]:96 zero_i=i97 for j in range(3):98 if data.get_state()[i][j]=='0':99 zero_j=j100 101 102 if zero_i != 0 and zero_i !=2 and zero_j != 0 and zero_j !=2:103 temp,temp_dir=move_up(data,zero_i,zero_j)104 state=to_string(temp)105 try:106 discovered_states[state]107 if dfs==True:108 if data.get_steps() not in discovered_states[state]:109 discovered_states[state].append(data.get_steps())110 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())111 temp=copy.deepcopy(data.get_previous_states())112 temp.append(temp_dir)113 tempdata.set_previous_states(temp)114 q.put(tempdata)115 116 except:117 if dfs == True:118 discovered_states[state]=[]119 discovered_states[state].append(data.get_steps())120 else:121 discovered_states[state]=0122 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())123 temp=copy.deepcopy(data.get_previous_states())124 temp.append(temp_dir)125 tempdata.set_previous_states(temp)126 q.put(tempdata)127 128 temp,temp_dir=move_right(data,zero_i,zero_j)129 state=to_string(temp)130 try:131 discovered_states[state]132 if dfs==True:133 if data.get_steps() not in discovered_states[state]:134 discovered_states[state].append(data.get_steps())135 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())136 temp=copy.deepcopy(data.get_previous_states())137 temp.append(temp_dir)138 tempdata.set_previous_states(temp)139 q.put(tempdata)140 141 except:142 if dfs == True:143 discovered_states[state]=[]144 discovered_states[state].append(data.get_steps())145 else:146 discovered_states[state]=0147 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())148 temp=copy.deepcopy(data.get_previous_states())149 temp.append(temp_dir)150 tempdata.set_previous_states(temp)151 q.put(tempdata)152 153 temp,temp_dir=move_down(data,zero_i,zero_j)154 state=to_string(temp)155 try:156 discovered_states[state]157 if dfs==True:158 if data.get_steps() not in discovered_states[state]:159 discovered_states[state].append(data.get_steps())160 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())161 temp=copy.deepcopy(data.get_previous_states())162 temp.append(temp_dir)163 tempdata.set_previous_states(temp)164 q.put(tempdata)165 166 except:167 if dfs == True:168 discovered_states[state]=[]169 discovered_states[state].append(data.get_steps())170 else:171 discovered_states[state]=0172 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())173 temp=copy.deepcopy(data.get_previous_states())174 temp.append(temp_dir)175 tempdata.set_previous_states(temp)176 q.put(tempdata)177 178 temp,temp_dir=move_left(data,zero_i,zero_j)179 state=to_string(temp)180 try:181 discovered_states[state]182 if dfs==True:183 if data.get_steps() not in discovered_states[state]:184 discovered_states[state].append(data.get_steps())185 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())186 temp=copy.deepcopy(data.get_previous_states())187 temp.append(temp_dir)188 tempdata.set_previous_states(temp)189 q.put(tempdata)190 191 except:192 if dfs == True:193 discovered_states[state]=[]194 discovered_states[state].append(data.get_steps())195 else:196 discovered_states[state]=0197 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())198 temp=copy.deepcopy(data.get_previous_states())199 temp.append(temp_dir)200 tempdata.set_previous_states(temp)201 q.put(tempdata)202 203 if zero_i == 0:204 if zero_j == 0:205 #down 206 207 temp,temp_dir=move_down(data,zero_i,zero_j)208 state=to_string(temp)209 try:210 discovered_states[state]211 if dfs==True:212 if data.get_steps() not in discovered_states[state]:213 discovered_states[state].append(data.get_steps())214 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())215 temp=copy.deepcopy(data.get_previous_states())216 temp.append(temp_dir)217 tempdata.set_previous_states(temp)218 q.put(tempdata)219 220 except:221 if dfs == True:222 discovered_states[state]=[]223 discovered_states[state].append(data.get_steps())224 else:225 discovered_states[state]=0226 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())227 temp=copy.deepcopy(data.get_previous_states())228 temp.append(temp_dir)229 tempdata.set_previous_states(temp)230 231 q.put(tempdata)232 233 del tempdata234 235 #right236 temp,temp_dir=move_right(data,zero_i,zero_j)237 state=to_string(temp)238 try:239 discovered_states[state]240 if dfs==True:241 if data.get_steps() not in discovered_states[state]:242 discovered_states[state].append(data.get_steps())243 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())244 temp=copy.deepcopy(data.get_previous_states())245 temp.append(temp_dir)246 tempdata.set_previous_states(temp)247 q.put(tempdata)248 249 except:250 if dfs == True:251 discovered_states[state]=[]252 discovered_states[state].append(data.get_steps())253 else:254 discovered_states[state]=0255 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())256 temp=copy.deepcopy(data.get_previous_states())257 temp.append(temp_dir)258 tempdata.set_previous_states(temp)259 q.put(tempdata)260 261 262 elif zero_j == 2:263 #down264 temp,temp_dir=move_down(data,zero_i,zero_j)265 state=to_string(temp)266 try:267 discovered_states[state]268 if dfs==True:269 if data.get_steps() not in discovered_states[state]:270 discovered_states[state].append(data.get_steps())271 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())272 temp=copy.deepcopy(data.get_previous_states())273 temp.append(temp_dir)274 tempdata.set_previous_states(temp)275 q.put(tempdata)276 277 except:278 if dfs == True:279 discovered_states[state]=[]280 discovered_states[state].append(data.get_steps())281 else:282 discovered_states[state]=0283 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())284 temp=copy.deepcopy(data.get_previous_states())285 temp.append(temp_dir)286 tempdata.set_previous_states(temp)287 q.put(tempdata)288 289 #left290 temp,temp_dir=move_left(data,zero_i,zero_j)291 state=to_string(temp)292 try:293 discovered_states[state]294 if dfs==True:295 if data.get_steps() not in discovered_states[state]:296 discovered_states[state].append(data.get_steps())297 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())298 temp=copy.deepcopy(data.get_previous_states())299 temp.append(temp_dir)300 tempdata.set_previous_states(temp)301 q.put(tempdata)302 303 except:304 if dfs == True:305 discovered_states[state]=[]306 discovered_states[state].append(data.get_steps())307 else:308 discovered_states[state]=0309 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())310 temp=copy.deepcopy(data.get_previous_states())311 temp.append(temp_dir)312 tempdata.set_previous_states(temp)313 q.put(tempdata)314 315 else:316 #left317 temp,temp_dir=move_left(data,zero_i,zero_j)318 state=to_string(temp)319 try:320 discovered_states[state]321 if dfs==True:322 if data.get_steps() not in discovered_states[state]:323 discovered_states[state].append(data.get_steps())324 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())325 temp=copy.deepcopy(data.get_previous_states())326 temp.append(temp_dir)327 tempdata.set_previous_states(temp)328 q.put(tempdata)329 330 except:331 if dfs == True:332 discovered_states[state]=[]333 discovered_states[state].append(data.get_steps())334 else:335 discovered_states[state]=0336 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())337 temp=copy.deepcopy(data.get_previous_states())338 temp.append(temp_dir)339 tempdata.set_previous_states(temp)340 q.put(tempdata)341 342 #down343 temp,temp_dir=move_down(data,zero_i,zero_j)344 state=to_string(temp)345 try:346 discovered_states[state]347 if dfs==True:348 if data.get_steps() not in discovered_states[state]:349 discovered_states[state].append(data.get_steps())350 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())351 temp=copy.deepcopy(data.get_previous_states())352 temp.append(temp_dir)353 tempdata.set_previous_states(temp)354 q.put(tempdata)355 356 except:357 if dfs == True:358 discovered_states[state]=[]359 discovered_states[state].append(data.get_steps())360 else:361 discovered_states[state]=0362 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())363 temp=copy.deepcopy(data.get_previous_states())364 temp.append(temp_dir)365 tempdata.set_previous_states(temp)366 q.put(tempdata)367 368 #right369 temp,temp_dir=move_right(data,zero_i,zero_j)370 state=to_string(temp)371 try:372 discovered_states[state]373 if dfs==True:374 if data.get_steps() not in discovered_states[state]:375 discovered_states[state].append(data.get_steps())376 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())377 temp=copy.deepcopy(data.get_previous_states())378 temp.append(temp_dir)379 tempdata.set_previous_states(temp)380 q.put(tempdata)381 382 except:383 if dfs == True:384 discovered_states[state]=[]385 discovered_states[state].append(data.get_steps())386 else:387 discovered_states[state]=0388 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())389 temp=copy.deepcopy(data.get_previous_states())390 temp.append(temp_dir)391 tempdata.set_previous_states(temp)392 q.put(tempdata)393 394 395 elif zero_i == 2:396 if zero_j == 0:397 #up 398 temp,temp_dir=move_up(data,zero_i,zero_j)399 state=to_string(temp)400 try:401 discovered_states[state]402 if dfs==True:403 if data.get_steps() not in discovered_states[state]:404 discovered_states[state].append(data.get_steps())405 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())406 temp=copy.deepcopy(data.get_previous_states())407 temp.append(temp_dir)408 tempdata.set_previous_states(temp)409 q.put(tempdata)410 411 except:412 if dfs == True:413 discovered_states[state]=[]414 discovered_states[state].append(data.get_steps())415 else:416 discovered_states[state]=0417 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())418 temp=copy.deepcopy(data.get_previous_states())419 temp.append(temp_dir)420 tempdata.set_previous_states(temp)421 q.put(tempdata)422 423 #right424 temp,temp_dir=move_right(data,zero_i,zero_j)425 state=to_string(temp)426 try:427 discovered_states[state]428 if dfs==True:429 if data.get_steps() not in discovered_states[state]:430 discovered_states[state].append(data.get_steps())431 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())432 temp=copy.deepcopy(data.get_previous_states())433 temp.append(temp_dir)434 tempdata.set_previous_states(temp)435 q.put(tempdata)436 437 except:438 if dfs == True:439 discovered_states[state]=[]440 discovered_states[state].append(data.get_steps())441 else:442 discovered_states[state]=0443 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())444 temp=copy.deepcopy(data.get_previous_states())445 temp.append(temp_dir)446 tempdata.set_previous_states(temp)447 q.put(tempdata)448 449 elif zero_j == 2:450 #left451 temp,temp_dir=move_left(data,zero_i,zero_j)452 state=to_string(temp)453 try:454 discovered_states[state]455 if dfs==True:456 if data.get_steps() not in discovered_states[state]:457 discovered_states[state].append(data.get_steps())458 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())459 temp=copy.deepcopy(data.get_previous_states())460 temp.append(temp_dir)461 tempdata.set_previous_states(temp)462 q.put(tempdata)463 464 except:465 if dfs == True:466 discovered_states[state]=[]467 discovered_states[state].append(data.get_steps())468 else:469 discovered_states[state]=0470 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())471 temp=copy.deepcopy(data.get_previous_states())472 temp.append(temp_dir)473 tempdata.set_previous_states(temp)474 q.put(tempdata)475 476 #up477 temp,temp_dir=move_up(data,zero_i,zero_j)478 state=to_string(temp)479 try:480 discovered_states[state]481 if dfs==True:482 if data.get_steps() not in discovered_states[state]:483 discovered_states[state].append(data.get_steps())484 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())485 temp=copy.deepcopy(data.get_previous_states())486 temp.append(temp_dir)487 tempdata.set_previous_states(temp)488 q.put(tempdata)489 490 except:491 if dfs == True:492 discovered_states[state]=[]493 discovered_states[state].append(data.get_steps())494 else:495 discovered_states[state]=0496 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())497 temp=copy.deepcopy(data.get_previous_states())498 temp.append(temp_dir)499 tempdata.set_previous_states(temp)500 q.put(tempdata)501 502 else:503 #left504 temp,temp_dir=move_left(data,zero_i,zero_j)505 state=to_string(temp)506 try:507 discovered_states[state]508 if dfs==True:509 if data.get_steps() not in discovered_states[state]:510 discovered_states[state].append(data.get_steps())511 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())512 temp=copy.deepcopy(data.get_previous_states())513 temp.append(temp_dir)514 tempdata.set_previous_states(temp)515 q.put(tempdata)516 517 except:518 if dfs == True:519 discovered_states[state]=[]520 discovered_states[state].append(data.get_steps())521 else:522 discovered_states[state]=0523 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())524 temp=copy.deepcopy(data.get_previous_states())525 temp.append(temp_dir)526 tempdata.set_previous_states(temp)527 q.put(tempdata) 528 529 #right530 temp,temp_dir=move_right(data,zero_i,zero_j)531 state=to_string(temp)532 try:533 discovered_states[state]534 if dfs==True:535 if data.get_steps() not in discovered_states[state]:536 discovered_states[state].append(data.get_steps())537 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())538 temp=copy.deepcopy(data.get_previous_states())539 temp.append(temp_dir)540 tempdata.set_previous_states(temp)541 q.put(tempdata)542 543 except:544 if dfs == True:545 discovered_states[state]=[]546 discovered_states[state].append(data.get_steps())547 else:548 discovered_states[state]=0549 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())550 temp=copy.deepcopy(data.get_previous_states())551 temp.append(temp_dir)552 tempdata.set_previous_states(temp)553 q.put(tempdata)554 555 #up556 temp,temp_dir=move_up(data,zero_i,zero_j)557 state=to_string(temp)558 try:559 discovered_states[state]560 if dfs==True:561 if data.get_steps() not in discovered_states[state]:562 discovered_states[state].append(data.get_steps())563 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())564 temp=copy.deepcopy(data.get_previous_states())565 temp.append(temp_dir)566 tempdata.set_previous_states(temp)567 q.put(tempdata)568 569 except:570 if dfs == True:571 discovered_states[state]=[]572 discovered_states[state].append(data.get_steps())573 else:574 discovered_states[state]=0575 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())576 temp=copy.deepcopy(data.get_previous_states())577 temp.append(temp_dir)578 tempdata.set_previous_states(temp)579 q.put(tempdata)580 581 if zero_j == 0:582 if zero_i == 0:583 #down584 temp,temp_dir=move_down(data,zero_i,zero_j)585 state=to_string(temp)586 try:587 discovered_states[state]588 if dfs==True:589 if data.get_steps() not in discovered_states[state]:590 discovered_states[state].append(data.get_steps())591 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())592 temp=copy.deepcopy(data.get_previous_states())593 temp.append(temp_dir)594 tempdata.set_previous_states(temp)595 q.put(tempdata)596 597 except:598 if dfs == True:599 discovered_states[state]=[]600 discovered_states[state].append(data.get_steps())601 else:602 discovered_states[state]=0603 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())604 temp=copy.deepcopy(data.get_previous_states())605 temp.append(temp_dir)606 tempdata.set_previous_states(temp)607 q.put(tempdata)608 609 #right610 temp,temp_dir=move_right(data,zero_i,zero_j)611 state=to_string(temp)612 try:613 discovered_states[state]614 if dfs==True:615 if data.get_steps() not in discovered_states[state]:616 discovered_states[state].append(data.get_steps())617 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())618 temp=copy.deepcopy(data.get_previous_states())619 temp.append(temp_dir)620 tempdata.set_previous_states(temp)621 q.put(tempdata)622 623 except:624 if dfs == True:625 discovered_states[state]=[]626 discovered_states[state].append(data.get_steps())627 else:628 discovered_states[state]=0629 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())630 temp=copy.deepcopy(data.get_previous_states())631 temp.append(temp_dir)632 tempdata.set_previous_states(temp)633 q.put(tempdata)634 635 elif zero_i == 2:636 #up637 temp,temp_dir=move_up(data,zero_i,zero_j)638 state=to_string(temp)639 try:640 discovered_states[state]641 if dfs==True:642 if data.get_steps() not in discovered_states[state]:643 discovered_states[state].append(data.get_steps())644 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())645 temp=copy.deepcopy(data.get_previous_states())646 temp.append(temp_dir)647 tempdata.set_previous_states(temp)648 q.put(tempdata)649 650 except:651 if dfs == True:652 discovered_states[state]=[]653 discovered_states[state].append(data.get_steps())654 else:655 discovered_states[state]=0656 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())657 temp=copy.deepcopy(data.get_previous_states())658 temp.append(temp_dir)659 tempdata.set_previous_states(temp)660 q.put(tempdata)661 662 #right663 temp,temp_dir=move_right(data,zero_i,zero_j)664 state=to_string(temp)665 try:666 discovered_states[state]667 if dfs==True:668 if data.get_steps() not in discovered_states[state]:669 discovered_states[state].append(data.get_steps())670 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())671 temp=copy.deepcopy(data.get_previous_states())672 temp.append(temp_dir)673 tempdata.set_previous_states(temp)674 q.put(tempdata)675 676 except:677 if dfs == True:678 discovered_states[state]=[]679 discovered_states[state].append(data.get_steps())680 else:681 discovered_states[state]=0682 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())683 temp=copy.deepcopy(data.get_previous_states())684 temp.append(temp_dir)685 tempdata.set_previous_states(temp)686 q.put(tempdata)687 688 else:689 #up690 temp,temp_dir=move_up(data,zero_i,zero_j)691 state=to_string(temp)692 try:693 discovered_states[state]694 if dfs==True:695 if data.get_steps() not in discovered_states[state]:696 discovered_states[state].append(data.get_steps())697 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())698 temp=copy.deepcopy(data.get_previous_states())699 temp.append(temp_dir)700 tempdata.set_previous_states(temp)701 q.put(tempdata)702 703 except:704 if dfs == True:705 discovered_states[state]=[]706 discovered_states[state].append(data.get_steps())707 else:708 discovered_states[state]=0709 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())710 temp=copy.deepcopy(data.get_previous_states())711 temp.append(temp_dir)712 tempdata.set_previous_states(temp)713 q.put(tempdata)714 715 #down716 temp,temp_dir=move_down(data,zero_i,zero_j)717 state=to_string(temp)718 try:719 discovered_states[state]720 if dfs==True:721 if data.get_steps() not in discovered_states[state]:722 discovered_states[state].append(data.get_steps())723 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())724 temp=copy.deepcopy(data.get_previous_states())725 temp.append(temp_dir)726 tempdata.set_previous_states(temp)727 q.put(tempdata)728 729 except:730 if dfs == True:731 discovered_states[state]=[]732 discovered_states[state].append(data.get_steps())733 else:734 discovered_states[state]=0735 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())736 temp=copy.deepcopy(data.get_previous_states())737 temp.append(temp_dir)738 tempdata.set_previous_states(temp)739 q.put(tempdata)740 741 #right742 temp,temp_dir=move_right(data,zero_i,zero_j)743 state=to_string(temp)744 try:745 discovered_states[state]746 if dfs==True:747 if data.get_steps() not in discovered_states[state]:748 discovered_states[state].append(data.get_steps())749 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())750 temp=copy.deepcopy(data.get_previous_states())751 temp.append(temp_dir)752 tempdata.set_previous_states(temp)753 q.put(tempdata)754 755 except:756 if dfs == True:757 discovered_states[state]=[]758 discovered_states[state].append(data.get_steps())759 else:760 discovered_states[state]=0761 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())762 temp=copy.deepcopy(data.get_previous_states())763 temp.append(temp_dir)764 tempdata.set_previous_states(temp)765 q.put(tempdata)766 767 elif zero_j == 2:768 if zero_i == 0:769 #down770 temp,temp_dir=move_down(data,zero_i,zero_j)771 state=to_string(temp)772 try:773 discovered_states[state]774 if dfs==True:775 if data.get_steps() not in discovered_states[state]:776 discovered_states[state].append(data.get_steps())777 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())778 temp=copy.deepcopy(data.get_previous_states())779 temp.append(temp_dir)780 tempdata.set_previous_states(temp)781 q.put(tempdata)782 783 except:784 if dfs == True:785 discovered_states[state]=[]786 discovered_states[state].append(data.get_steps())787 else:788 discovered_states[state]=0789 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())790 temp=copy.deepcopy(data.get_previous_states())791 temp.append(temp_dir)792 tempdata.set_previous_states(temp)793 794 q.put(tempdata)795 796 #left797 temp,temp_dir=move_left(data,zero_i,zero_j)798 state=to_string(temp)799 try:800 discovered_states[state]801 if dfs==True:802 if data.get_steps() not in discovered_states[state]:803 discovered_states[state].append(data.get_steps())804 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())805 temp=copy.deepcopy(data.get_previous_states())806 temp.append(temp_dir)807 tempdata.set_previous_states(temp)808 q.put(tempdata)809 810 except:811 if dfs == True:812 discovered_states[state]=[]813 discovered_states[state].append(data.get_steps())814 else:815 discovered_states[state]=0816 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())817 temp=copy.deepcopy(data.get_previous_states())818 temp.append(temp_dir)819 tempdata.set_previous_states(temp)820 821 q.put(tempdata)822 823 elif zero_i == 2:824 #up825 temp,temp_dir=move_up(data,zero_i,zero_j)826 state=to_string(temp)827 try:828 discovered_states[state]829 if dfs==True:830 if data.get_steps() not in discovered_states[state]:831 discovered_states[state].append(data.get_steps())832 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())833 temp=copy.deepcopy(data.get_previous_states())834 temp.append(temp_dir)835 tempdata.set_previous_states(temp)836 q.put(tempdata)837 838 except:839 if dfs == True:840 discovered_states[state]=[]841 discovered_states[state].append(data.get_steps())842 else:843 discovered_states[state]=0844 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())845 temp=copy.deepcopy(data.get_previous_states())846 temp.append(temp_dir)847 tempdata.set_previous_states(temp)848 q.put(tempdata)849 850 #left851 temp,temp_dir=move_left(data,zero_i,zero_j)852 state=to_string(temp)853 try:854 discovered_states[state]855 if dfs==True:856 if data.get_steps() not in discovered_states[state]:857 discovered_states[state].append(data.get_steps())858 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())859 temp=copy.deepcopy(data.get_previous_states())860 temp.append(temp_dir)861 tempdata.set_previous_states(temp)862 q.put(tempdata)863 864 except:865 if dfs == True:866 discovered_states[state]=[]867 discovered_states[state].append(data.get_steps())868 else:869 discovered_states[state]=0870 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())871 temp=copy.deepcopy(data.get_previous_states())872 temp.append(temp_dir)873 tempdata.set_previous_states(temp)874 q.put(tempdata)875 876 else:877 #up878 temp,temp_dir=move_up(data,zero_i,zero_j)879 state=to_string(temp)880 try:881 discovered_states[state]882 if dfs==True:883 if data.get_steps() not in discovered_states[state]:884 discovered_states[state].append(data.get_steps())885 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())886 temp=copy.deepcopy(data.get_previous_states())887 temp.append(temp_dir)888 tempdata.set_previous_states(temp)889 q.put(tempdata)890 891 except:892 if dfs == True:893 discovered_states[state]=[]894 discovered_states[state].append(data.get_steps())895 else:896 discovered_states[state]=0897 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())898 temp=copy.deepcopy(data.get_previous_states())899 temp.append(temp_dir)900 tempdata.set_previous_states(temp)901 q.put(tempdata)902 903 #down904 temp,temp_dir=move_down(data,zero_i,zero_j)905 state=to_string(temp)906 try:907 discovered_states[state]908 if dfs==True:909 if data.get_steps() not in discovered_states[state]:910 discovered_states[state].append(data.get_steps())911 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())912 temp=copy.deepcopy(data.get_previous_states())913 temp.append(temp_dir)914 tempdata.set_previous_states(temp)915 q.put(tempdata)916 917 except:918 if dfs == True:919 discovered_states[state]=[]920 discovered_states[state].append(data.get_steps())921 else:922 discovered_states[state]=0923 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())924 temp=copy.deepcopy(data.get_previous_states())925 temp.append(temp_dir)926 tempdata.set_previous_states(temp)927 q.put(tempdata)928 929 #left930 temp,temp_dir=move_left(data,zero_i,zero_j)931 state=to_string(temp)932 try:933 discovered_states[state]934 if dfs==True:935 if data.get_steps() not in discovered_states[state]:936 discovered_states[state].append(data.get_steps())937 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())938 temp=copy.deepcopy(data.get_previous_states())939 temp.append(temp_dir)940 tempdata.set_previous_states(temp)941 q.put(tempdata)942 943 except:944 if dfs == True:945 discovered_states[state]=[]946 discovered_states[state].append(data.get_steps())947 else:948 discovered_states[state]=0949 tempdata=chain(temp,data.get_steps()+1,data.get_init_state())950 temp=copy.deepcopy(data.get_previous_states())951 temp.append(temp_dir)952 tempdata.set_previous_states(temp)953 q.put(tempdata)954 955 956 del temp957#Iterative_deepening_DFS() implementation. takes 2 2d lists 3x3 as input958#one is initial state and another is goal state959def Iterative_deepening_DFS(init_state,goal):960 t1=time.time()961 962 current_data=chain(init_state,0,init_state)963 964 #initialize frontier as LIFO queue (stack)965 frontier = LifoQueue()966 967 968 keep = Queue()969 keep.put(current_data)970 #initialize dictionary to save states971 discovered_states={}972 state=to_string(init_state)973 discovered_states[state]=0 974 975 976 #the main loop that defines the 'depth'977 for i in range(0,1000):978 979 while not keep.empty():980 temp=keep.get()981 frontier.put(temp)982 983 984 while not frontier.empty():985 current_data=frontier.get()986 if current_data.get_state()==goal:987 988 t2=time.time()989# print("-----------------------------------------------------")990# print("FOUND!")991# print("Algorithm: IDDFS")992# print(current_data.get_state()[:1])993# print(current_data.get_state()[1:2])994# print(current_data.get_state()[2:3])995# print('----From----')996# print(init_state[:1])997# print(init_state[1:2])998# print(init_state[2:3])999# print("Path:",current_data.get_previous_states())1000# print("Steps taken:",current_data.get_steps())1001# print("Time:",t2-t1)1002# print("-----------------------------------------------------")1003 return current_data1004 1005 if current_data.get_steps() > i:1006 keep.put(current_data)1007 elif current_data.get_steps() <= i:1008 actions(current_data,discovered_states,frontier,False)1009#implementation of function "breadthFirstSearch", takes 2 2d lists 3x3 as input1010#one is initial state and another is goal state1011def breadthFirstSearch(init_state,goal):1012 t1=time.time()1013 1014 #initialize dictionary of discovered_states, add initial state right away1015 discovered_states={}1016 state=to_string(init_state)1017 discovered_states[state]=01018 1019 #initialize current_data as chain() object1020 current_data=chain(init_state,0,init_state)1021 1022 #initialize queue1023 frontier = Queue()1024 frontier.put(current_data)1025 1026 while not frontier.empty():1027 1028 #take item from frontier and start searching with actions() function1029 current_data=frontier.get() 1030 1031 #goal check1032 if current_data.get_state()==goal:1033 t2=time.time()1034# print("-----------------------------------------------------")1035# print("FOUND!")1036# print("Algorithm: BFS")1037# print(current_data.get_state()[:1])1038# print(current_data.get_state()[1:2])1039# print(current_data.get_state()[2:3])1040# print('----From----')1041# print(init_state[:1])1042# print(init_state[1:2])1043# print(init_state[2:3])1044# print("Path:",current_data.get_previous_states())1045# print("Steps taken:",current_data.get_steps())1046# print("Time:",t2-t1)1047# print("-----------------------------------------------------")1048 return current_data1049 actions(current_data,discovered_states,frontier,False) 1050#Helper functions for print_results(result)1051def move_up_list(data,zero_i,zero_j):1052 temp_data = copy.deepcopy(data)1053 temp=temp_data[zero_i-1][zero_j]1054 temp_data[zero_i-1][zero_j]='0'1055 temp_data[zero_i][zero_j]=temp1056 del temp1057 return temp_data1058def move_left_list(data,zero_i,zero_j):1059 temp_data = copy.deepcopy(data)1060 temp=temp_data[zero_i][zero_j-1]1061 temp_data[zero_i][zero_j-1]='0'1062 temp_data[zero_i][zero_j]=temp1063 del temp1064 return temp_data1065def move_right_list(data,zero_i,zero_j):1066 temp_data = copy.deepcopy(data)1067 temp=temp_data[zero_i][zero_j+1]1068 temp_data[zero_i][zero_j+1]='0'1069 temp_data[zero_i][zero_j]=temp1070 del temp1071 return temp_data1072def move_down_list(data,zero_i,zero_j):1073 temp_data = copy.deepcopy(data)1074 temp=temp_data[zero_i+1][zero_j]1075 temp_data[zero_i+1][zero_j]='0'1076 temp_data[zero_i][zero_j]=temp1077 del temp1078 return temp_data1079#implementation of function "print_results(result)"1080#Prints individual result as a sequence of states from initial to goal1081#take chain() class objects as input1082def print_results(result):1083 solution=[]1084 solution = copy.deepcopy(result.get_previous_states())1085 temp_state=result.get_init_state()1086 1087 print(temp_state[0][0],' ',temp_state[0][1],' ',temp_state[0][2])1088 print(temp_state[1][0],' ',temp_state[1][1],' ',temp_state[1][2])1089 print(temp_state[2][0],' ',temp_state[2][1],' ',temp_state[2][2])1090 1091 for k in solution:1092 print('to')1093 1094 for i in range(3):1095 if '0' in temp_state[i]:1096 zero_i=i1097 for j in range(3):1098 if temp_state[i][j]=='0':1099 zero_j=j1100 1101 if k == 'U':1102 temp_state=move_up_list(temp_state,zero_i,zero_j)1103 print(temp_state[0][0],' ',temp_state[0][1],' ',temp_state[0][2])1104 print(temp_state[1][0],' ',temp_state[1][1],' ',temp_state[1][2])1105 print(temp_state[2][0],' ',temp_state[2][1],' ',temp_state[2][2])1106 elif k =="D":1107 temp_state=move_down_list(temp_state,zero_i,zero_j)1108 print(temp_state[0][0],' ',temp_state[0][1],' ',temp_state[0][2])1109 print(temp_state[1][0],' ',temp_state[1][1],' ',temp_state[1][2])1110 print(temp_state[2][0],' ',temp_state[2][1],' ',temp_state[2][2])1111 elif k=='R':1112 temp_state=move_right_list(temp_state,zero_i,zero_j)1113 print(temp_state[0][0],' ',temp_state[0][1],' ',temp_state[0][2])1114 print(temp_state[1][0],' ',temp_state[1][1],' ',temp_state[1][2])1115 print(temp_state[2][0],' ',temp_state[2][1],' ',temp_state[2][2])1116 elif k=='L':1117 temp_state=move_left_list(temp_state,zero_i,zero_j)1118 print(temp_state[0][0],' ',temp_state[0][1],' ',temp_state[0][2])1119 print(temp_state[1][0],' ',temp_state[1][1],' ',temp_state[1][2])1120 print(temp_state[2][0],' ',temp_state[2][1],' ',temp_state[2][2])1121 1122#Final print_result() function1123#Loads the file, takes first example from the file1124#launches BFS and prints its results with help of print_results(result) function defined above1125def print_result():1126 1127 #load file, store its contents in states[] list1128 f= open("Input8PuzzleCases.txt", "r")1129 states=[]1130 for i in range(0,100):1131 temp=[]1132 temp = f.readline().strip('\n')1133 temp=temp.split(', ')1134 states.append(temp)1135 f.close()1136 del temp1137 1138 1139 #load first example from the file into sample[] list1140 sample=[]1141 sample.append(states[0][0:3])1142 sample.append(states[0][3:6])1143 sample.append(states[0][6:9])1144 1145 #construct goal state (0,1,2,3,4,5,6,7,8)1146 goal_state=[]1147 for i in range(0,9,3):1148 goal_state.append([str(i),str(i+1),str(i+2)])1149 1150 print("Solution of the first Scenario:")1151 print('BFS:')1152 print_results(breadthFirstSearch(sample,goal_state))1153 print('IDS:')1154 print_results(Iterative_deepening_DFS(sample,goal_state))1155 print('Recorded averages for 100 cases on my machine:')1156 print(' Average_Steps Average_Time')1157 print('IDS 22.33 7.0 s')1158 print('BFS 22.33 7.4 s')1159 print('Solving 100 cases for your machine...')1160 1161 times_bfs=[]1162 steps_bfs=[]1163 times_iddfs=[]1164 steps_iddfs=[]1165 for i in range(len(states)): 1166 sample=[]1167 sample.append(states[i][0:3])1168 sample.append(states[i][3:6])1169 sample.append(states[i][6:9])1170 1171 t1=time.time()1172 solution=breadthFirstSearch(sample,goal_state)1173 t2=time.time()1174 t2=t2-t11175 times_bfs.append(float(t2))1176 steps_bfs.append(solution.get_steps())1177 print(i+1,"done in",solution.get_steps(),'steps and',format(t2,'.2f'),'s (BFS)')1178 1179 t1=time.time()1180 solution=Iterative_deepening_DFS(sample,goal_state)1181 t3=time.time()1182 t3=t3-t11183 times_iddfs.append(float(t2))1184 steps_iddfs.append(solution.get_steps())1185 print(i+1,"done in",solution.get_steps(),'steps and',format(t3,'.2f'),'s (IDS)\n')1186 1187 avg_time_bfs=sum(times_bfs)/len(times_bfs)1188 avg_steps_bfs=sum(steps_bfs)/len(steps_bfs)1189 avg_time_iddfs=sum(times_iddfs)/len(times_iddfs)1190 avg_steps_iddfs=sum(steps_iddfs)/len(steps_iddfs)1191 print(' Average_Steps Average_Time')1192 print('IDS ',avg_steps_iddfs,' ',format(avg_time_iddfs,'.2f'),'s')1193 print('BFS ',avg_steps_bfs,' ',format(avg_time_bfs,'.2f'),'s')...

Full Screen

Full Screen

test_bilstm.py

Source:test_bilstm.py Github

copy

Full Screen

...68 rnn.b[:] = bilstm.b_f69 rnn.dW[:] = 070 # inputs - random and flipped left-to-right inputs71 lr = np.random.random((input_size, seq_len * batch_size))72 lr_rev = list(reversed(get_steps(lr.copy(), in_shape)))73 rl = con(lr_rev, axis=1)74 inp_lr = bilstm.be.array(lr)75 inp_rl = bilstm.be.array(rl)76 inp_rnn = rnn.be.array(lr)77 # outputs78 out_lr = bilstm.fprop(inp_lr).get().copy()79 bilstm.h_buffer[:] = 080 out_rl = bilstm.fprop(inp_rl).get()81 out_rnn = rnn.fprop(inp_rnn).get().copy()82 # views83 out_lr_f_s = get_steps(out_lr[:nout], out_shape)84 out_lr_b_s = get_steps(out_lr[nout:], out_shape)85 out_rl_f_s = get_steps(out_rl[:nout], out_shape)86 out_rl_b_s = get_steps(out_rl[nout:], out_shape)87 out_rnn_s = get_steps(out_rnn, out_shape)88 # asserts for fprop89 for x_rnn, x_f, x_b, y_f, y_b in zip(out_rnn_s, out_lr_f_s, out_lr_b_s,90 reversed(out_rl_f_s), reversed(out_rl_b_s)):91 assert np.allclose(x_f, y_b, rtol=0.0, atol=1.0e-5)92 assert np.allclose(x_b, y_f, rtol=0.0, atol=1.0e-5)93 assert np.allclose(x_rnn, x_f, rtol=0.0, atol=1.0e-5)94 assert np.allclose(x_rnn, y_b, rtol=0.0, atol=1.0e-5)95def test_biLSTM_fprop(backend_default, fargs):96 # basic sanity check with 0 weights random inputs97 seq_len, input_size, hidden_size, batch_size = fargs98 in_shape = (input_size, seq_len)99 out_shape = (hidden_size, seq_len)100 NervanaObject.be.bsz = batch_size101 # setup the bi-directional rnn102 init_glorot = GlorotUniform()103 bilstm = BiLSTM(hidden_size, gate_activation=Logistic(), init=init_glorot,104 activation=Tanh(), reset_cells=True)105 bilstm.configure(in_shape)106 bilstm.prev_layer = True107 bilstm.allocate()108 # same weight109 nout = hidden_size110 bilstm.W_input_b[:] = bilstm.W_input_f111 bilstm.W_recur_b[:] = bilstm.W_recur_f112 bilstm.b_b[:] = bilstm.b_f113 bilstm.dW[:] = 0114 # inputs - random and flipped left-to-right inputs115 lr = np.random.random((input_size, seq_len * batch_size))116 lr_rev = list(reversed(get_steps(lr.copy(), in_shape)))117 rl = con(lr_rev, axis=1)118 inp_lr = bilstm.be.array(lr)119 inp_rl = bilstm.be.array(rl)120 # outputs121 out_lr = bilstm.fprop(inp_lr).get().copy()122 bilstm.h_buffer[:] = 0123 out_rl = bilstm.fprop(inp_rl).get().copy()124 # views125 out_lr_f_s = get_steps(out_lr[:nout], out_shape)126 out_lr_b_s = get_steps(out_lr[nout:], out_shape)127 out_rl_f_s = get_steps(out_rl[:nout], out_shape)128 out_rl_b_s = get_steps(out_rl[nout:], out_shape)129 # asserts130 for x_f, x_b, y_f, y_b in zip(out_lr_f_s, out_lr_b_s,131 reversed(out_rl_f_s), reversed(out_rl_b_s)):132 assert np.allclose(x_f, y_b, rtol=0.0, atol=1.0e-5)133 assert np.allclose(x_b, y_f, rtol=0.0, atol=1.0e-5)134def test_biLSTM_bprop(backend_default, fargs, deltas_buffer):135 # basic sanity check with 0 weights random inputs136 seq_len, input_size, hidden_size, batch_size = fargs137 in_shape = (input_size, seq_len)138 out_shape = (hidden_size, seq_len)139 NervanaObject.be.bsz = batch_size140 # setup the bi-directional rnn141 init_glorot = GlorotUniform()142 bilstm = BiLSTM(hidden_size, gate_activation=Logistic(),143 activation=Tanh(), init=init_glorot, reset_cells=True)144 bilstm.configure(in_shape)145 bilstm.prev_layer = True146 bilstm.allocate()147 bilstm.allocate_deltas(deltas_buffer)148 deltas_buffer.allocate_buffers()149 bilstm.set_deltas(deltas_buffer)150 # same weight for bi-rnn backward and rnn weights151 nout = hidden_size152 bilstm.W_input_b[:] = bilstm.W_input_f153 bilstm.W_recur_b[:] = bilstm.W_recur_f154 bilstm.b_b[:] = bilstm.b_f155 bilstm.dW[:] = 0156 # inputs and views157 lr = np.random.random((input_size, seq_len * batch_size))158 lr_rev = list(reversed(get_steps(lr.copy(), in_shape)))159 rl = con(lr_rev, axis=1)160 # allocate gpu buffers161 inp_lr = bilstm.be.array(lr)162 inp_rl = bilstm.be.array(rl)163 # outputs164 out_lr_g = bilstm.fprop(inp_lr)165 out_lr = out_lr_g.get().copy()166 del_lr = bilstm.bprop(out_lr_g).get().copy()167 bilstm.h_buffer[:] = 0168 out_rl_g = bilstm.fprop(inp_rl)169 out_rl = out_rl_g.get().copy()170 del_rl = bilstm.bprop(out_rl_g).get().copy()171 # views172 out_lr_f_s = get_steps(out_lr[:nout], out_shape)173 out_lr_b_s = get_steps(out_lr[nout:], out_shape)174 out_rl_f_s = get_steps(out_rl[:nout], out_shape)175 out_rl_b_s = get_steps(out_rl[nout:], out_shape)176 # asserts177 for x_f, x_b, y_f, y_b in zip(out_lr_f_s, out_lr_b_s,178 reversed(out_rl_f_s), reversed(out_rl_b_s)):179 assert np.allclose(x_f, y_b, rtol=0.0, atol=1.0e-5)180 assert np.allclose(x_b, y_f, rtol=0.0, atol=1.0e-5)181 del_lr_s = get_steps(del_lr, in_shape)182 del_rl_s = get_steps(del_rl, in_shape)183 for (x, y) in zip(del_lr_s, reversed(del_rl_s)):...

Full Screen

Full Screen

analysis.py

Source:analysis.py Github

copy

Full Screen

...19# This Library20import topobuilder.core as TBcore21import topobuilder.utils as TButil22__all__ = ['get_steps', 'process_master_geometries']23def get_steps( blist: List[bool] ) -> List[Tuple[int]]:24 """25 """26 def cstp(seq):27 return [seq[i] for i in range(len(seq)) if len(seq[i]) == 1 or (seq[i][0] + 1 == seq[i][1])]28 def f7(seq):29 seen = set()30 seen_add = seen.add31 return [x for x in seq if not (x in seen or seen_add(x))]32 steps = []33 plist = list(range(len(blist)))34 betas = list(np.where(np.asarray(blist))[0])35 if len(betas) == 0:36 steps.append((0, ))37 for i in range(0, len(plist) - 1):38 steps.append(tuple(plist[i: i + 2]))39 else:40 steps.append((betas[0], ))41 for i in range(1, len(betas)):42 if betas[i] > betas[i - 1] + 1:43 steps.append((betas[i], ))44 for i in range(0, len(betas) - 1):45 steps.append(tuple(betas[i: i + 2]))46 for i in range(0, len(plist) - 1):47 steps.append(tuple(plist[i: i + 2]))48 steps = f7(cstp(steps))49 return steps50# assert get_steps([True, False]) == [(0,), (0, 1)]51# assert get_steps([False, True]) == [(1,), (0, 1)]52# assert get_steps([False, False]) == [(0,), (0, 1)]53# assert get_steps([False, False, False]) == [(0,), (0, 1), (1, 2)]54# assert get_steps([False, True, False]) == [(1,), (0, 1), (1, 2)]55# assert get_steps([False, True, True, False]) == [(1,), (1, 2), (0, 1), (2, 3)]56# assert get_steps([False, True, False, True]) == [(1,), (3,), (0, 1), (1, 2), (2, 3)]57# assert get_steps([False, True, True, False, True]) == [(1,), (4,), (1, 2), (0, 1), (2, 3), (3, 4)]58def process_master_geometries( masterdf: pd.DataFrame,59 structures: List[str],60 flip: List[str]61 ) -> pd.DataFrame:62 """Use the PDS matches provided by MASTER to obtain the geometric properties.63 Column modifications:64 =========== ========================================= =======65 column name description status66 =========== ========================================= =======67 pds_path Path to the PDS file containing the match dropped68 pdb_path Path to the PDB file containing the match new!69 sse Identifier of the query secondary new!70 structre.71 layer Layer against which the data SSE is new!...

Full Screen

Full Screen

3-12.py

Source:3-12.py Github

copy

Full Screen

...33 if number in row:34 return row_number35 else:36 row_number += 137 def get_steps(self):38 if self.count == 1:39 return 040 else:41 sy = self._get_row(self.location)42 ey = self._get_row(1)43 sx = self.spiral[sy].index(self.location)44 ex = self.spiral[ey].index(1)45 return abs(ex - sx) + abs(ey - sy)46def test_spiral_memory_1():47 sm = SpiralMemory(1)48 assert sm.get_steps() == 049def test_spiral_memory_2():50 sm = SpiralMemory(12)51 assert sm.get_steps() == 352def test_spiral_memory_3():53 sm = SpiralMemory(23)54 assert sm.get_steps() == 255def test_spiral_memory_4():56 sm = SpiralMemory(1024)57 assert sm.get_steps() == 1758if __name__ == '__main__':59 sm = SpiralMemory(361527)...

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 Lemoncheesecake 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