Difference between revisions of "CISC220 F2023 Lab9"

From class_wiki
Jump to: navigation, search
(Created page with "==Lab #9== ===1. Word graphs === Two classes are provided in starter code [https://drive.google.com/file/d/13Ik1VIwu0HB8n7hV4iwAxc29OpzvlsLk/view?usp=sharing here]: <tt>Ma...")
 
Line 20: Line 20:
 
Sample output '''from solution code''' for various methods creating a 3 x 4 maze with the same random seed are shown below:
 
Sample output '''from solution code''' for various methods creating a 3 x 4 maze with the same random seed are shown below:
  
====3_4_A_F_F_F_3====
 
  
#########
+
===2. Programming tasks===
#S      #
 
# + + + #
 
#      #
 
# + + + #
 
#      F#
 
#########
 
 
0:3, 1:0, 2:5, 3:-1, 4:0, 5:0, 6:2, 7:0, 8:0, 9:8, 10:8, 11:7
 
  
====3_4_S_F_F_F_3====
+
These are core functions that are required but not directly tests.  Every print function should either call one of these or use data structures it has modified.
  
#########
+
* <tt>calculate_neighbor_words()</tt>
#S    | #
+
* <tt>DFS_traversal(string &)</tt>
# + + +-#
+
* <tt>BFS_traversal(string &)</tt>
# |  | #
 
# + +-+ #
 
#      F#
 
#########
 
 
0:-1, 1:0, 2:5, 3:-1, 4:0, 5:0, 6:2, 7:0, 8:0, 9:8, 10:8, 11:7
 
  
====3_4_SNL_F_F_F_3====
+
These functions will be directly tested:
  
#########
+
* '''[0.5 points]''' <tt>print_num_neighbors()</tt>
#S  | | #
+
* '''[0.5 points]''' <tt>print_neighbors()</tt>
# + + +-#
+
* '''[1 point]''' <tt>DFS_print_connected(string &, string &)</tt>
# |  | #
+
* '''[1 point]''' <tt>DFS_print_num_connected(string &)</tt>
# +-+-+ #
+
* '''[1 point]''' <tt>BFS_print_path()</tt>
#      F#
+
* '''[0.5 points]''' <tt>BFS_print_path_length()</tt>
#########
+
* '''[0.5 points]''' <tt>BFS_print_longest_path()</tt>
 
0:-1, 1:0, 2:5, 3:-1, 4:0, 5:0, 6:2, 7:0, 8:0, 9:8, 10:8, 11:7
 
 
 
====3_4_SNLAC_F_F_F_3====
 
 
 
#########
 
#S  | | #
 
# + + + #
 
# |  | #
 
# +-+-+ #
 
#      F#
 
#########
 
 
0:3, 1:0, 2:5, 3:-1, 4:0, 5:0, 6:2, 7:0, 8:0, 9:8, 10:8, 11:7
 
 
 
===2. Programming tasks===
 
  
* '''[1 point]''' There's a starter function called <tt>knock_down_all_walls()</tt> already provided in <tt>main.cpp</tt>.  This simply deletes random walls, one at a time and unconditionally, until they're all gone (DEBUG = T causes M and U as well as the last wall picked to be printed after each step).  M changes, but U is NOT updated in the code provided.  Fill in appropriate calls to U's methods <tt>find()</tt> and <tt>union_sets()</tt> in <tt>knock_down_all_walls()</tt> so that U IS updated after each wall is removed (this function is called when method "A" is chosen in the MSS).
+
* '''[0.5 points]''' <tt>print_aloofs()</tt>
** Take a look at the helper functions in <tt>maze.hh</tt> called <tt>UF_index_to_rowcol()</tt> and <tt>rowcol_to_UF_index()</tt> for going back and forth between referring to a grid cell by its row and column vs. by its index in the union/find array.
 
* '''[1 point]''' Fill in <tt>knock_down_til_solvable()</tt> in <tt>main.cpp</tt> (called when method "S" is selected). 
 
* '''[1 point]''' Fill in <tt>knock_down_til_solvable_no_loops()</tt> in <tt>main.cpp</tt> (called for method "SNL")
 
* '''[1 point]''' Fill in <tt>knock_down_til_solvable_no_loops_all_connected()</tt> in <tt>main.cpp</tt> (called for method "SNLAC")
 
* '''[0.5 points]''' Modify the <tt>union_sets()</tt> function in <tt>unionfind.hh</tt> to use "union by size" when U's member variable <tt>do_smart_union</tt> is True 
 
* '''[0.5 points]''' Modify the <tt>find()</tt> function in <tt>unionfind.hh</tt> to use "path compression" when U's member variable <tt>do_path_compression</tt> is True
 
  
 
'''You may work with a (human) partner on this lab'''
 
'''You may work with a (human) partner on this lab'''

Revision as of 16:02, 9 November 2023

Lab #9

1. Word graphs

Two classes are provided in starter code here: Maze and UnionFind. UnionFind is an implementation of the union/find data structure which uses an array to represent the equivalence class "uptrees", and Maze is a data structure to represent and draw N x M grids with walls (see the comments in maze.hh for details).

The wordgraph executable is called as follows: wordgraph <dictionary> <command> <0, 1, or 2 command parameters. Commands and their parameters are explained below:

  • ROWS and COLS should be positive integers
  • METHOD = A : Knock down walls randomly until ALL gone
  • METHOD = S : Knock down walls until SOLUTION is found (start and finish are connected). The start and finish cells are always in the upper-left and lower-right corners of the maze, respectively
  • METHOD = SNL : Same as S, but make sure cells on each side of wall to be removed are not already connected, ensuring NO LOOPS
  • METHOD = SNLAC : Same as SNL, but keep going until cells are ALL CONNECTED to each other
  • SMART, PATH, and DEBUG are T or F, where SMART enables smart union, PATH enables path compression, and you can use DEBUG to turn on extra printing (or not -- your call)
  • Random number SEED is an integer which makes pseudo-random number sequences repeatable. If you want variability during testing, write "C" here instead to use the clock to automatically set a different seed for each run

The output of the program (when DEBUG is F) should be just a representation of the final maze M and the final union-find uptree U. This happens automatically with the calls to M->print() and U->print_horizontal() right before main() returns. Sample output from solution code for various methods creating a 3 x 4 maze with the same random seed are shown below:


2. Programming tasks

These are core functions that are required but not directly tests. Every print function should either call one of these or use data structures it has modified.

  • calculate_neighbor_words()
  • DFS_traversal(string &)
  • BFS_traversal(string &)

These functions will be directly tested:

  • [0.5 points] print_num_neighbors()
  • [0.5 points] print_neighbors()
  • [1 point] DFS_print_connected(string &, string &)
  • [1 point] DFS_print_num_connected(string &)
  • [1 point] BFS_print_path()
  • [0.5 points] BFS_print_path_length()
  • [0.5 points] BFS_print_longest_path()
  • [0.5 points] print_aloofs()

You may work with a (human) partner on this lab

3. Submission

Submit 3 files to Gradescope: (1) your README, (2) your modified unionfind.hh, and (3) your modified main.cpp. The README should contain your name and your partner's name, notes on any limitations or issues with your code, and your interpretation of any ambiguities in the assignment instructions. Both code files should also contain your name(s)