1. Homepage
  2. Programming
  3. EECS281 Data Structures and Algorithms - Project 1: Back to the Ship!

EECS281 Data Structures and Algorithms - Project 1: Back to the Ship!

Engage in a Conversation
USUMichUniversity of MichiganEECS281Data Structures and AlgorithmsBack to the ShipC++

Back to the Ship! CourseNana.COM

Due Thursday, January 26, 2023 at 11:59 PM CourseNana.COM

Overview CourseNana.COM

You have just broken out of the detention level of a large and strangely moon-like space station. You need to find your way back to your old spacecraft of questionable space-worthiness to escape. Your adorable robot friend has hacked into the elevator system of the space station to assist you in your escape. CourseNana.COM

Learning Objectives CourseNana.COM

These are the skills and concepts encountered in this project: CourseNana.COM

  • 3D Maze: read, store, access, and write
  • Breadth first search (BFS w/ queue)
  • Depth first search (DFS w/ stack)
  • Map and coordinate list mode input
  • Map and coordinate list mode output
  • Use getopt_long() to handle command line arguments

Command Line Options CourseNana.COM

ship should take the following (optional) command line options: CourseNana.COM

  • --stack-s

The search container will be used like a stack and the routing scheme will perform a depth first search (DFS). The stack option may be invoked by calling the program with either --stack or -s, it accepts no arguments. CourseNana.COM

  • --queue-q

The search container will be used like a queue and the routing scheme will perform a breadth first search (BFS). The queue option may be invoked by calling the program with either --queue or -q, it accepts no arguments. CourseNana.COM

  • --output (M|L)-o (M|L)

format). If this option is not provided when running the program, the default output format is map format. If specified, this option requires that an argument be provided, and the autograder will only use valid arguments. CourseNana.COM

  • --help-h

This causes the program to print a helpful message about how to use the program and then immediately exit(0). CourseNana.COM

Legal command lines must include exactly one of --stack or --queue (or their respective short forms -s or -q). If none are specified or more than one is specified, the program should print an informative message to standard error (cerr) and exit(1). CourseNana.COM

Using getopt_long() will make this much easier. See Project 0 and the man page for getopt, for more information. CourseNana.COM

Legal Command Lines CourseNana.COM

$ ./ship --stack < infile > outfile
This will run the program using a stack and map output mode.
$ ./ship --queue --output M < infile > outfile
This will run the program using a queue and map output mode.
$ ./ship --stack --output L < infile > outfile
This will run the program using a stack and coordinate list output mode.
CourseNana.COM

These examples use the shell redirection operators < and > to redirect standard input (cin) and standard output (cout). This is a convenient way to read input from a file and write output to a file, without having to write any code to open and close files. The operating system “connects” cin to read the input file, and print statements to cout to the output file. CourseNana.COM

Illegal Command Lines CourseNana.COM

$ ./ship --queue -s < infile > outfile
Contradictory choice of routing, both stack and queue are specified.
$ ./ship < infile > outfile
You must specify one of stack or queue options.
$ ./ship -o < infile > outfile
Output option requires an argument describing the output mode.
CourseNana.COM

Space Station Layout CourseNana.COM

A space station is composed of up to 10 square levels with elevators to travel between levels. The description of a space station will be provided by an input file using a 3-D coordinate system and special characters. CourseNana.COM

The special characters and what they represent: CourseNana.COM

  • ’.’ floor space
  • ’#’ walls (the only character that cannot be walked on/through)
  • ‘S’ your starting location at the detention level
  • ‘H’ the hangar of the spacecraft location (the goal)
  • ‘E’ corresponds to elevators that transport you from that location to the same row and column of the levels that have an elevator on the same location

You may discover new locations north, east, south or west from any floor space (.) as well as the starting location (S); no discoveries may be made diagonally. CourseNana.COM

Input File Formats CourseNana.COM

The program gets its description of the space station from a file that will be read from standard input (cin). This input file is a simple text file specifying the layout of the space station. We require that you make your program compatible with two input modes: Map Mode (M) and coordinate list mode (L). CourseNana.COM

The reason for having two input modes is that a large percentage of the runtime of your program will be spent on reading input or writing output. Coordinate list mode exists so that we can express very large graphs with relatively few lines of a file, map input mode exists to express dense graphs CourseNana.COM

command line option. CourseNana.COM

  • The second line will be a single, positive integer 1≤l≤10, indicating the number of levels in the space station.
  • The third line will be a single, positive integer n≥2, indicating the size of every level of the space station. Each level is n×n in size.

Comments may also be included in any input file. Comment lines begin with // and they are allowed anywhere in any file, after the file header. CourseNana.COM

Map Input Mode CourseNana.COM

For this input mode, the file header will start with an ‘M’ and contain a 2D map of characters defining each level, starting with level 0 and ending with level l−1. CourseNana.COM

A map input mode example file for a space station that has two 4x4 levels: CourseNana.COM

p1-back-to-the-ship/spec-m.txt CourseNana.COM

M CourseNana.COM

2 CourseNana.COM

4 CourseNana.COM

//sample M mode input file with two 4x4 levels CourseNana.COM

//level 0 CourseNana.COM

.H.. CourseNana.COM

.... CourseNana.COM

E..S CourseNana.COM

#..# CourseNana.COM

//level 1 CourseNana.COM

.... CourseNana.COM

#... CourseNana.COM

E#.. CourseNana.COM

#... CourseNana.COM

Coordinate List Input Mode CourseNana.COM

For this input mode, the file header will start with an ‘L’ and contain a list of coordinates for at least all non-floor space characters in the space station. A coordinate is specified in precisely the following form: (level,row,column,character). The level values will be in the range [0,l), and the row and column values will be in the range [0,n). Only one coordinate will appear on each line, and there is no guarantee that the coordinates will be grouped by floor or ordered in any way. By default, all unspecified coordinates within the space station are of type ‘.’ (floor space); however, it is not invalid to redundantly specify them to be so. CourseNana.COM

Valid coordinates (for a space station with three 4x4 levels): CourseNana.COM

(0,0,1,#) CourseNana.COM

(2,2,2,H) CourseNana.COM

(1,1,3,.)    -- Unnecessary, but valid CourseNana.COM

Invalid coordinates (for a space station with three 4x4 levels): CourseNana.COM

(9,1,2,#)    -- level 9 does not exist CourseNana.COM

(3,4,2,.)    -- row 4 does not exist CourseNana.COM

(2,1,5,#)    -- column 5 does not exist CourseNana.COM

(0,0,1,F)    -- 'F' is an invalid map character CourseNana.COM

A coordinate list input mode example file with two 4x4 levels, equivalent to the example above: CourseNana.COM

p1-back-to-the-ship/spec-l.txt CourseNana.COM

Routing schemes CourseNana.COM

You are to develop two routing schemes to get from the starting location to the hangar location tile: CourseNana.COM

  • A routing scheme that uses a queue as the search container
  • A routing scheme that uses a stack as the search container

Both of these routing schemes will always lead you to the hangar (if a path exists). Whether you’re supposed to be using stack or queue based, the algorithm is basically the same. Read the “Project 1 the STL and You” file, it will tell you (among many other useful things) CourseNana.COM

Search container (the deque) is where you add things to help you find the hangar. Think of this as the places that might help you get to the hangar, but haven’t had a chance to investigate yet. CourseNana.COM

  • Discovered means that this square has been added to the search container. You can never discover the same location twice (this prevents infinite loops and other problems). You must keep track of what has been discovered and what has not.

Create a search container. Before you start looping, add the starting location to the search container, and mark it as discovered. As long as the search container is not empty, do the following: CourseNana.COM

  1. Take the “next location” from the search container; we will refer to this as the current location. Remove it from the search container.
  2. Investigate the current location, which means discover all of the locations that are reachable from the current location. For each one, if it is off the edge, a wall, or already discovered before, ignore it. Otherwise, add it to the search container and mark it as
  3. As soon as you find the hangar tile H, you should stop searching. If you don’t stop, loop back to step 1.

Output file format CourseNana.COM

The program will write its output to standard output (cout). Similar to input, we require that you implement two possible output formats. Unlike input, however, the output format will be specified through a command-line option –output, or -o, which will be followed by an argument of M or L (M for map output and L for coordinate list output). See the section on command line arguments below for more details. CourseNana.COM

For both output formats, you will show the path you took from start to finish. CourseNana.COM

Map output mode (M): CourseNana.COM

For this output mode, you should print the map of the levels, replacing existing characters as needed to show the path you took. Beginning at the starting location, overwrite the characters in your path with ‘n’, ‘e’, ‘s’, ‘w’, or ‘0-9’ (where you got off the elevator) to indicate which tile you moved to next. Elevator tiles that you use in your final path should be overwritten with the number of the level where you exited the elevator. Do not overwrite the ‘H’ at the end of the path, but do overwrite the ‘S’ at the beginning. For all spaces that are not a part of the path, simply reprint the original space station space. CourseNana.COM

Using the same input file but with the stack-based routing scheme, you should produce the following output: CourseNana.COM

Start in level 0, row 2, column 3 CourseNana.COM

//level 0 CourseNana.COM

eH.. CourseNana.COM

n... CourseNana.COM

nwww CourseNana.COM

#..# CourseNana.COM

//level 1 CourseNana.COM

.... CourseNana.COM

#... CourseNana.COM

E#.. CourseNana.COM

#... CourseNana.COM

Coordinate list output mode (L): CourseNana.COM

For this output mode, you should print only the coordinates that make up the path you traveled. Print [each step of] your path from the start to the hangar and omit the hangar itself. The coordinates should be printed in the same format as they are specified in coordinate list input mode (the (level,row,column,character) format). The character of the coordinate should be ‘n’, ‘e’, ‘s’, ‘w’, or ‘0-9’ (where you got off the elevator) to indicate spatially which tile is moved to next. You should discard all comments from the input file, but you should add one comment on line 1, just before you list the coordinates of the path that says “//path taken”. CourseNana.COM

For the queue solution: CourseNana.COM

//path taken CourseNana.COM

(0,2,3,n) CourseNana.COM

(0,1,3,n) CourseNana.COM

(0,0,3,w) CourseNana.COM

(0,0,2,w) CourseNana.COM

For the stack solution: CourseNana.COM

//path taken CourseNana.COM

(0,2,3,w) CourseNana.COM

(0,2,2,w) CourseNana.COM

(0,2,1,w) CourseNana.COM

(0,2,0,n) CourseNana.COM

(0,1,0,n) CourseNana.COM

(0,0,0,e) CourseNana.COM

There is only one acceptable solution per routing scheme for each map of the space station. If no valid route exists, the program should simply reprint the space station with no route shown for Map output mode, and should have no coordinates listed after the “//path taken” comment in List output mode. CourseNana.COM

The mode of input and output can differ. That is, the input mode may be List mode, but the output may be requested in Map mode and vise-versa. They may also be the same (but are not guaranteed to be). CourseNana.COM

Test files CourseNana.COM

It is extremely frustrating to turn in code that you are ‘certain’ is functional and then receive half credit. We will be grading for correctness primarily by running your program on a number of test files. If you have a single silly bug that causes most of the test cases on the autograder to fail, you will get a very low score on that part of the project even though you completed 95% of the work. Most of your grade will come from correctness testing. Therefore, it is imperative that you test your code thoroughly. To help you do this we will require that you write and submit a suite of test files that thoroughly test your project. CourseNana.COM

  CourseNana.COM

./ship -s --output L < test-1-sl.txt > test-1-output.txt CourseNana.COM

Test files may have no more than 10 levels, and the size of a level may not exceed 8x8. You may submit up to 15 test files (though it is possible to get full credit with fewer test files). The tests the autograder runs on your solution are NOT limited to 10x8x8; your solution should not impose any size limits smaller than 65,535 (as long as sufficient system memory is available). CourseNana.COM

Get in Touch with Our Experts

WeChat WeChat
Whatsapp WhatsApp
US代写,UMich代写,University of Michigan代写,EECS281代写,Data Structures and Algorithms代写,Back to the Ship代写,C++代写,US代编,UMich代编,University of Michigan代编,EECS281代编,Data Structures and Algorithms代编,Back to the Ship代编,C++代编,US代考,UMich代考,University of Michigan代考,EECS281代考,Data Structures and Algorithms代考,Back to the Ship代考,C++代考,UShelp,UMichhelp,University of Michiganhelp,EECS281help,Data Structures and Algorithmshelp,Back to the Shiphelp,C++help,US作业代写,UMich作业代写,University of Michigan作业代写,EECS281作业代写,Data Structures and Algorithms作业代写,Back to the Ship作业代写,C++作业代写,US编程代写,UMich编程代写,University of Michigan编程代写,EECS281编程代写,Data Structures and Algorithms编程代写,Back to the Ship编程代写,C++编程代写,USprogramming help,UMichprogramming help,University of Michiganprogramming help,EECS281programming help,Data Structures and Algorithmsprogramming help,Back to the Shipprogramming help,C++programming help,USassignment help,UMichassignment help,University of Michiganassignment help,EECS281assignment help,Data Structures and Algorithmsassignment help,Back to the Shipassignment help,C++assignment help,USsolution,UMichsolution,University of Michigansolution,EECS281solution,Data Structures and Algorithmssolution,Back to the Shipsolution,C++solution,