Question

In: Computer Science

You are required to solve the problem on Terrain Navigation. Terrain navigation is a key component...

You are required to solve the problem on Terrain Navigation.

Terrain navigation is a key component in the design of unmanned aerial vehicles (UAVs). Vehichles such as a robot or a car, can travel on land; and vehiches such as a drone or a plane can fly above the land. A UAV system contains an on board computer that has stored the terrain information for the area in which it is to be operated, Because it knows where it is at all times (often using a global positioning system (GPS) receiver), the vehicle can then select the best path to get to a designed spot. If the destination changes, the vehicle can refer to its internal maps and recompute the new path. The computer software that guides these vechicles must be tested over a variety of land formations and topologies. Elevvation information for large grids of land is available in computer databases. One way of measuring the "difficulty" of a lanad grid with respect to terrain navigation is to determine the number of peaks in the grid, where a peak is a point that has lower elevations all around it. For this problem, we want to determine whether the value in grid position [m] [n] is peak. Assume that the values in the four positions shown are adjacent to grid position [m] [n]:

grid [m-1] [n]
grid [m][n-1] grid [m][n]    grid [m][n+1]
grid [m+1] [n]

Write a program that reads elevation data from a data file named grid1. txt. (this file you have to create and name it as grid 1.txt.) data as shown below which represent elevation for a grid that has 6 points along the side and seven points along the top ( the peaks have been highlighted and underlined):

5039 5127 5238 5259 5248 5310 5299

5150 5392 5410 5401 5352 5820 5321

5290   5560    5490 5421 5530 5831    5210

5110 5429 5430 5411 5459 5630 5319

4920 5129 4921   5821 4722 4921 5129

5023 5129 4822 4872 4794 4862 4245

Then prints the number of peaks and their locations. Assume that the first line of the data file contains the number of rows and the number of columns for the grid of information. These values are then followed by the elevation values, in row order. The maximum size of the grid is 25 rows by 25 columns.

Hints:

  1. Define and print the number of peaks and their locations in an elevation grid.
  2. input is a file containing the elevation data and the output is a listing of the location of the peaks.
  3. to specify the location of the peaks, you need to assign an addressing scheme to the data because you are going to implement this solution in c. Therefore, choose its 2D array subscripting notation.
  4. assume the top left corner is position [0][0], the row numbers increase by 1 as move down the page and the column numbers increase by 1 as move to the right.
  5. These peaks then occur at position[2][1], [2][5], and [4][3].
  6. To determine the peaks, compare a potential peak with its four neighbouring points.
  7. if all four neighboring points are less that the potential peak, then the potential peak is a real peak.
  8. the points on the edges of the array or grid cannot be potential peaks because do not have elevation information on all four sides of the points.

Solutions

Expert Solution

Answer is written with minor modifications so that you can grasp the concept well, All three programs are completely same with one two line change only

#Program for taking input from user directly (not through file) and without count

#include <stdio.h>

int main(void) {
int m,n; // Two variables to hold (m - for no. of rows, n - for no. of columns)
   scanf("%d %d", &m,&n);
   int arr[m][n]; // (An array of size m*n to store elevation data)
   for(int i=0;i<m;i++) // Taking the input of elevation data in next 5 lines
   for(int j=0;j<n;j++)
   {
       scanf("%d",&arr[i][j]);
   }
// See explanation below for i =1 and i<m-1 and same for j
       for(int i=1;i<m-1;i++) // Checking with neighbors to get the peak
   for(int j=1;j<n-1;j++)
   {
       if(arr[i][j]>arr[i-1][j] && arr[i][j]>arr[i][j-1] && arr[i][j]>arr[i+1][j] && arr[i][j]>arr[i][j+1]) // main logic
       {
           printf("%d %d", i, j);
           printf("\n");
  
       }
   }
  
   return 0;
  
}

Explanation for i =1 and i<m-1 and same for j: Since we don't have to check at corners thus we will start i =1 and not 0. Similarly other corners occurs when i = m-1 ( not n as counting begins with 0), j=0 and j=n-1.

#Program for taking input through file and with count

#include <stdio.h>

int main(void) {

freopen("grid1.txt","r",stdin); // For opening a file to read.
int m,n;
   scanf("%d %d", &m,&n);
   int arr[m][n];
   for(int i=0;i<m;i++)
   for(int j=0;j<n;j++)
   {
       scanf("%d",&arr[i][j]);
   }
       int count =0;
       for(int i=1;i<m-1;i++)
   for(int j=1;j<n-1;j++)
   {
       if(arr[i][j]>arr[i-1][j] && arr[i][j]>arr[i][j-1] && arr[i][j]>arr[i+1][j] && arr[i][j]>arr[i][j+1])
       {
           printf("%d %d", i, j);
           printf("\n");
           count++; // added count variable in the loop to get total no. of peaks
       }
   }
   printf("No.of Peaks is:%d", count);
  
   return 0;
  
}

# if you want to print "count", before the indexes of peaks then we need to store indexes in an array and print two at a time (First one is row no. of peak and second one is column no. of peak)

#include <stdio.h>

int main(void) {
   freopen("grid1.txt","r",stdin);
int m,n;
   scanf("%d %d", &m,&n);
   int arr[m][n];
   for(int i=0;i<m;i++)
   for(int j=0;j<n;j++)
   {
       scanf("%d",&arr[i][j]);
   }
       int count =0, PeakLoc[100]; // PeakLoc array to store indexes of peak
       for(int i=1;i<m-1;i++)
   for(int j=1;j<n-1;j++)
   {
       if(arr[i][j]>arr[i-1][j] && arr[i][j]>arr[i][j-1] && arr[i][j]>arr[i+1][j] && arr[i][j]>arr[i][j+1])
       {
           PeakLoc[count++]=i; // storing value of row at first index
           PeakLoc[count++]=j; // storing value of column at second index
          
       }
   }
   printf("No.of Peaks is:%d\n", count/2);
   for(int i=0;i<count;i=i+2) // Fetching two values at a time for row and column thus increment by two
   {
       printf("%d %d", PeakLoc[i], PeakLoc[i+1]);
       printf("\n");
   }
  
   return 0;
  
}



Related Solutions

You are required to solve the problem on Terrain Navigatio. Terrain navigation is a key component...
You are required to solve the problem on Terrain Navigatio. Terrain navigation is a key component in the design of unmanned aerial vehicles (UAVs). Vehichles such as a robot or a car, can travel on land; and vehiches such as a drone or a plane can fly above the land. A UAV system contains an on board computer that has stored the terrain information for the area in which it is to be operated, Because it knows where it is...
You are required to solve the problem on Terrain Navigatio. Terrain navigation is a key component...
You are required to solve the problem on Terrain Navigatio. Terrain navigation is a key component in the design of unmanned aerial vehicles (UAVs). Vehichles such as a robot or a car, can travel on land; and vehiches such as a drone or a plane can fly above the land. A UAV system contains an on board computer that has stored the terrain information for the area in which it is to be operated, Because it knows where it is...
Terrain navigation is a key component in the design of unmanned aerial vehicles (UAVs). Vehichles such...
Terrain navigation is a key component in the design of unmanned aerial vehicles (UAVs). Vehichles such as a robot or a car, can travel on land; and vehiches such as a drone or a plane can fly above the land. A UAV system contains an on board computer that has stored the terrain information for the area in which it is to be operated, Because it knows where it is at all times (often using a global positioning system (GPS)...
Terrain navigation is a key component in the design of unmanned aerial vehicles (UAVs). Vehichles such...
Terrain navigation is a key component in the design of unmanned aerial vehicles (UAVs). Vehichles such as a robot or a car, can travel on land; and vehiches such as a drone or a plane can fly above the land. A UAV system contains an on board computer that has stored the terrain information for the area in which it is to be operated, Because it knows where it is at all times (often using a global positioning system (GPS)...
Instructions to solve the problem: You are required to use a financial calculator or spreadsheet (Excel)...
Instructions to solve the problem: You are required to use a financial calculator or spreadsheet (Excel) to solve the problem related to the cost of capital. You are required to show the following 3 steps for the problem. (i) Describe and interpret the assumptions related to the problem. (ii) Apply the appropriate mathematical model to solve the problem. (iii) Calculate the correct solution to the problem. Submit all answers as percentages and round to two decimal places. Problem: Cosa Nostra...
Landmark Systems Inc. designs and manufactures global positioning navigation systems for all-terrain vehicles and watercraft. It...
Landmark Systems Inc. designs and manufactures global positioning navigation systems for all-terrain vehicles and watercraft. It has two support departments: Design and Engineering; and, two production departments, Vehicle Systems and Water Craft Systems. The budgeted level of service relationships at the start of the year was: Used by: Design Engineering Vehicles Water Craft Supplied by:   Design 0.10 0.40 0.50   Engineering 0.05 0.35 0.60 Landmark Systems Inc. collects fixed costs and variable costs of each support department in separate pools. The...
Required: Formulate and solve the LP Relaxation of the problem. Solve it graphically, and round down...
Required: Formulate and solve the LP Relaxation of the problem. Solve it graphically, and round down to find a feasible solution. Explain/show what excel parameters and cells should be entered into the excel to come up with the answer. Consider the following all-integer linear program: ??? 10?1 + 3?2 ?.?. 6?1 + 7?2 ≤ 40 3?1 + 1?2 ≤ 11 ?1,?2 ≥ 0 and integer
Waterloo, Ltd. manufactures a component used in aircraft navigation systems. Demand has been strong and the...
Waterloo, Ltd. manufactures a component used in aircraft navigation systems. Demand has been strong and the executive staff at Waterloo is planning for next year. Yesterday, you were called into a budgeting meeting where production plans are being reviewed. You learn that the inventory policy at Waterloo is to hold one and one-half months’ worth of sales (to avoid issues with transportation disruptions). The sales budget for next year is 660,000 units, spread evenly over the year. Because of an...
***Excel is required to solve this problem. Please use excel and show all formulas used in...
***Excel is required to solve this problem. Please use excel and show all formulas used in each cell I would really appreciate the work*** Three-Stage FCFE Model: Biomet Inc., designs, manufactures and markets reconstructive and trauma devices, and reported earnings per share of $0.56 in 1993, on which it paid no dividends. (It had revenues per share in 1993 of $2.91). It had capital expenditures of $0.13 per share in 1993 and depreciation in the same year of $0.08 per...
What is meant by problem-solving in terms of psychology? Describe the steps required to successfully solve...
What is meant by problem-solving in terms of psychology? Describe the steps required to successfully solve a problem. Identify at least two factors that inhibit problem-solving and, for each factor, suggest two strategies for reducing their effects.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT