[C Programming] Implement code to construct an adjacency list representation of a graph

***Attached is base code to help you get started. You must use this base project/code and any functions outlined in this document***Introduction:You are a member of a team developing a mars rover. Your job is to develop the path-finding system and it is crucially important that you minimise energy consumption. Given a digital elevation map of the terrain, you must identify the path between two points of least energy cost. Specification: You will be given a digital elevation map (DEM) and an equation for calculating energy use in moving from one elevation to another adjacent elevation. To simplify the task you consider only the discrete positions and elevations represented by the DEM and will consider only moves in the four cardinal directions (NSEW). You will be provided with code that contains some code to get you started. int** make_dem(int size, int roughness); This code generates a 2D array of ints representing the heights of a square area of the terrain. The size should be one more than a power of 2 (e.g. 9, 17, 33, 65) and roughness values around 4xsize work well. You will also notice that the code sets a random seed – this can be set to a fixed value for testing purposes (to ensure that you always get the same map). int cost_funcA(int diff); int cost_funcB(int diff); These are two different cost functions for calculating the energy use from moving between two adjacent points in the DEM with the given height difference. The first will be used for part A and will always produce a positive number. The second is used for part B and includes a term for regenerative breaking – hence it can generate a negative value when going downhill. There are also two functions for printing DEMs and markers: void print_2D(int** array2D, int size); void print_2D_ascii(int** array2D, int size); These functions take a DEM where heights are expected to be in the range 0-99. Any negative value will be printed as a marker. You should use these functions to visualise your solution (setting the height of positions that are on your path to -1). You can use either print function. The first function gives more detail, but the second is a bit easier to interpret. (NOTE: these function print with the y axis going across the page and the x axis going down). Your first task is to use these functions to generate an adjacency list graph representation of the terrain. Start by generating a DEM, then use the cost functions to build the weighted graph. The vertex number of a given x,y position in the map should be calculated as x*size+y. So, for example, the following DEM: 49 51 51 56 57 46 47 50 52 54 45 47 48 50 49 46 46 47 47 47 45 45 45 45 47 Would result in an edge from vertex 0 to vertex 5 (in bold) with weight calculate using cost_funcA(46-49). You must use the following data structures to represent the graph as an adjacency list: typedef struct edge{ int to_vertex; int weight; } Edge; typedef struct edgeNode{ Edge edge; struct edgeNode *next; } *EdgeNodePtr; typedef struct edgeList{ EdgeNodePtr head; } EdgeList; typedef struct graph{ int V; EdgeList *edges; } Graph; ***To help you get started, follow these steps outlined below to help you progress in your assignment*** Part A: For part A you will use cost_funcA which always produces positive edge weights to generate the adjacency list. You should then implement Dijkstra’s algorithm based on the pseudocode on Wikipedia (https://en.wikipedia.org/wiki/Dijkstra%27s_algorit…). While a priority-queue implementation would be best for our scenario, you should instead use a simple search to find the nearest vertex. Your submission must contain a main function that: generates a DEM converts it to an adjacency list using const_funcA calculates the shortest paths from vertex 0 (top left in the DEM) reconstructs the path to the last vertex (bottom right in the DEM) creates a copy of the DEM with the heights changed to -1 for any vertex on the path prints the DEM to show the path Part B: For part B you will use cost_funcB, which may produce negative edge weights (but no negatively weighted cycles, to build a new adjacency list. You should then implement the Floyd-Warshall algorithm based on the pseudocode on Wikipedia (https://en.wikipedia.org/wiki/Floyd%E2%80%93Warsha…). Your solution must follow this pseudocode as closely as possible (note however, that in our graph specification the vertex labels start at 0). Your submission must contain a main function that: includes all of the code from part A calculates a new adjacency list using const_funcB calculates all shortest paths using Floyd-Warshall reconstructs the path from the first to last vertex (top-left to bottom-right) creates a copy of the DEM with the heights changed to -1 for any vertex on the path prints the DEM to show the path Part B does NOT have to be in a separate project. I have not specified file names and code structure. You should endeavour to make your code as general, and hence reusable, as possible. Code should be organised into functions and files that make reuse easy. Functions and data structures should be properly commented so that another programmer will know how to use them. The assessment steps for this task are: 1. Implement code to construct an adjacency list representation of a graph 2. Implement Dijkstra’s algorithm to find shortest paths 3. Implement Floyd-Warshall algorithm to find shortest paths
kit205assig2base.zip

Unformatted Attachment Preview

Don't use plagiarized sources. Get Your Custom Essay on
[C Programming] Implement code to construct an adjacency list representation of a graph
Just from $13/Page
Order Essay


Purchase answer to see full
attachment

Order a unique copy of this paper
(550 words)

Approximate price: $22

Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
Paper format
  • 275 words per page
  • 12 pt Arial/Times New Roman
  • Double line spacing
  • Any citation style (APA, MLA, Chicago/Turabian, Harvard)

Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

Read more

Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

Read more

Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Read more

Privacy policy

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

Read more

Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

Read more

Calculate the price of your order

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
$26
The price is based on these factors:
Academic level
Number of pages
Urgency

Order your essay today and save 15% with the discount code DISCOUNT15