In this project, you will develop algorithms that find road routes through the bridges to travel between islands. The input is a text file containing data about the given map. Each file begins with the number of rows and columns in the map considered as maximum latitudes and maximum longitudes respectively on the map. The character "X" in the file represents the water that means if a cell contains "X" then the traveler is not allowed to occupy that cell as this car is not drivable on water. The character "O" in the file represents the road connected island. That means if a cell contains "O" then the traveler is allowed to occupy that cell as this car can drive on roads. The traveler starts at the island located at latitude = 0 and longitude = 0 (i.e., (0,0)) in the upper left comer, and the goal is to drive to the island located at (MaxLattitude-1, MaxLongitudes-1) in the lower right corner. A legal move from an island is to move left, right, up, or down to an immediately adjacent cell that has road connectivity which means a cell that contains "O". Moving off any edge of the map is not allowed. Input: The map files Output: Print paths as explicitly specified for all the functions in Part A You should have single main function that calls all the required functions for Part A for all the 3 given input map files one by one. Please use the graph.h file provided in this module for this project rather than the standard library file downloaded online as it is specially modified to ease you work in this project. You do not have to use this file mandatory, but if you are struggling to even start the project then this should definitely make your life much easier.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
1. Using the above class map, write function void map::mapToGraph(graph &g){...} to create a graph g that represents the
legal moves in the map m. Each vertex should represent a cell, and each edge should represent a legal move between
adjacent cells.
2. Write a recursive function findPathRecursive(graph &g, stack<int> &moves) that looks for a path from the start island
to the destination island. If a path from the start to the destination exists, your function should call the map::printPath()
function that should print a sequence of correct moves (Go left, Go right, Go down, Go up, etc.). If no path from the
start to the destination exists, the program should print, "No path exists". If a solution exists the solver should also
simulate the solution to each map by calling the map::print() function. The map::print() function prints out a map
visualization, with the goal and current position of the car in the map at each move, marked to show the progress. Hint:
consider recursive-DFS.
3. Write a function find PathNonRecursive1(graph &g, stack<int> &moves) that does the same thing as in 2, but by using
stack and without using recursion. If a path from the start to the destination exists, your function should call the
map::printPath() function that should print a sequence of correct moves (Go left, Go right, Go down, Go up, etc.). If no
path from the start to the destination exists, the program should print, "No path exists". If a solution exists the solver
should also simulate the solution to each map by calling the map::print() function. The map::print() function prints out a
map visualization, with the goal and current position of the car in the map at each move, marked to show the progress.
Hint: consider stack-based DFS.
4. Write a function find PathNonRecursive2(graph &g, queue<int> &moves) that does the same thing as in 2, but by
using queue and without using recursion. If a path from the start to the destination exists, your function should call the
map::printPath() function that should print a sequence of correct moves (Go left, Go right, Go down, Go up, etc.). If no
path from the start to the destination exists, the program should print, "No path exists". If a solution exists the solver
should also simulate the solution to each map by calling the map::print() function. The map::print() function prints out a
map visualization, with the goal and current position of the car in the map at each move, marked to show the progress.
Hint: consider queue-based BFS.
The code you submit should apply all three findPath functions to each map, one after the other.
The map input files named map1.txt, map2.txt, and map3.txt can be downloaded from the canvas. Example of a map
input file:
7
10
Start-OXXXXXXXX
00000000XX
OXOXOXOXXX
OXOXOX0000
XXOXXXOXXX
X0000000XX
XXXXXXX000Z - Destination
Transcribed Image Text:1. Using the above class map, write function void map::mapToGraph(graph &g){...} to create a graph g that represents the legal moves in the map m. Each vertex should represent a cell, and each edge should represent a legal move between adjacent cells. 2. Write a recursive function findPathRecursive(graph &g, stack<int> &moves) that looks for a path from the start island to the destination island. If a path from the start to the destination exists, your function should call the map::printPath() function that should print a sequence of correct moves (Go left, Go right, Go down, Go up, etc.). If no path from the start to the destination exists, the program should print, "No path exists". If a solution exists the solver should also simulate the solution to each map by calling the map::print() function. The map::print() function prints out a map visualization, with the goal and current position of the car in the map at each move, marked to show the progress. Hint: consider recursive-DFS. 3. Write a function find PathNonRecursive1(graph &g, stack<int> &moves) that does the same thing as in 2, but by using stack and without using recursion. If a path from the start to the destination exists, your function should call the map::printPath() function that should print a sequence of correct moves (Go left, Go right, Go down, Go up, etc.). If no path from the start to the destination exists, the program should print, "No path exists". If a solution exists the solver should also simulate the solution to each map by calling the map::print() function. The map::print() function prints out a map visualization, with the goal and current position of the car in the map at each move, marked to show the progress. Hint: consider stack-based DFS. 4. Write a function find PathNonRecursive2(graph &g, queue<int> &moves) that does the same thing as in 2, but by using queue and without using recursion. If a path from the start to the destination exists, your function should call the map::printPath() function that should print a sequence of correct moves (Go left, Go right, Go down, Go up, etc.). If no path from the start to the destination exists, the program should print, "No path exists". If a solution exists the solver should also simulate the solution to each map by calling the map::print() function. The map::print() function prints out a map visualization, with the goal and current position of the car in the map at each move, marked to show the progress. Hint: consider queue-based BFS. The code you submit should apply all three findPath functions to each map, one after the other. The map input files named map1.txt, map2.txt, and map3.txt can be downloaded from the canvas. Example of a map input file: 7 10 Start-OXXXXXXXX 00000000XX OXOXOXOXXX OXOXOX0000 XXOXXXOXXX X0000000XX XXXXXXX000Z - Destination
In this project, you will develop algorithms that find road routes through the bridges to travel between islands.
The input is a text file containing data about the given map. Each file begins with the number of rows and columns in
the map considered as maximum latitudes and maximum longitudes respectively on the map. The character "X" in the
file represents the water that means if a cell contains "X" then the traveler is not allowed to occupy that cell as this car is
not drivable on water. The character "0" in the file represents the road connected island. That means if a cell contains
"0" then the traveler is allowed to occupy that cell as this car can drive on roads.
The traveler starts at the island located at latitude = 0 and longitude = 0 (i.e., (0,0)) in the upper left comer, and the goal
is to drive to the island located at (MaxLattitude-1, MaxLongitudes-1) in the lower right corner. A legal move from an
island is to move left, right, up, or down to an immediately adjacent cell that has road connectivity which means a cell
that contains "0". Moving off any edge of the map is not allowed.
Input: The map files
Output: Print paths as explicitly specified for all the functions in Part A
You should have single main function that calls all the required functions for Part A for all the 3 given input map files
one by one.
Please use the graph.h file provided in this module for this project rather than the standard library file downloaded
online as it is specially modified to ease you work in this project. You do not have to use this file mandatory, but if you
are struggling to even start the project then this should definitely make your life much easier.
Part A
Consider the following class map,
class map
{
public:
map(ifstream &fin):
void print(int,int,int,int);
bool isLegal(int i, int j);
void setMaplint i, int j, int n);
int getMap(int i, int j) const;
int getReverseMapl(int n) const;
int getReverseMapJ(int n) const;
void mapToGraph(graph &g);
bool findPathRecursive(graph &g, stack<int> &moves);
bool findPathNonRecursive1(graph &g, stack<int>&moves);
bool findPathNonRecursive2(graph &g, queue<int> &moves);
bool findShortestPath1(graph &g, stack<int> &bestMoves);
bool findShortestPath2(graph &, vector<int> &bestMoves);
void map::printPath(stack<int> &s);
int numRows(){return rows;};
int numCols(){return cols;};
private:
int rows; // number of latitudes/rows in the map
int cols; // number of longitudes/columns in the map
matrix<bool> value;
matrix<int> mapping: // Mapping from latitude and longitude co-ordinates (ij) values to node index values
vector<int> reverseMapl; // Mapping from node index values to map latitude i value
vector<int> reverseMapJ; // Mapping from node index values to map longitude j value
};
Transcribed Image Text:In this project, you will develop algorithms that find road routes through the bridges to travel between islands. The input is a text file containing data about the given map. Each file begins with the number of rows and columns in the map considered as maximum latitudes and maximum longitudes respectively on the map. The character "X" in the file represents the water that means if a cell contains "X" then the traveler is not allowed to occupy that cell as this car is not drivable on water. The character "0" in the file represents the road connected island. That means if a cell contains "0" then the traveler is allowed to occupy that cell as this car can drive on roads. The traveler starts at the island located at latitude = 0 and longitude = 0 (i.e., (0,0)) in the upper left comer, and the goal is to drive to the island located at (MaxLattitude-1, MaxLongitudes-1) in the lower right corner. A legal move from an island is to move left, right, up, or down to an immediately adjacent cell that has road connectivity which means a cell that contains "0". Moving off any edge of the map is not allowed. Input: The map files Output: Print paths as explicitly specified for all the functions in Part A You should have single main function that calls all the required functions for Part A for all the 3 given input map files one by one. Please use the graph.h file provided in this module for this project rather than the standard library file downloaded online as it is specially modified to ease you work in this project. You do not have to use this file mandatory, but if you are struggling to even start the project then this should definitely make your life much easier. Part A Consider the following class map, class map { public: map(ifstream &fin): void print(int,int,int,int); bool isLegal(int i, int j); void setMaplint i, int j, int n); int getMap(int i, int j) const; int getReverseMapl(int n) const; int getReverseMapJ(int n) const; void mapToGraph(graph &g); bool findPathRecursive(graph &g, stack<int> &moves); bool findPathNonRecursive1(graph &g, stack<int>&moves); bool findPathNonRecursive2(graph &g, queue<int> &moves); bool findShortestPath1(graph &g, stack<int> &bestMoves); bool findShortestPath2(graph &, vector<int> &bestMoves); void map::printPath(stack<int> &s); int numRows(){return rows;}; int numCols(){return cols;}; private: int rows; // number of latitudes/rows in the map int cols; // number of longitudes/columns in the map matrix<bool> value; matrix<int> mapping: // Mapping from latitude and longitude co-ordinates (ij) values to node index values vector<int> reverseMapl; // Mapping from node index values to map latitude i value vector<int> reverseMapJ; // Mapping from node index values to map longitude j value };
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY