Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

q1. q2 q3 Here we will check the proposed journey path is possible given the provided pony capacity, poryy assignment to route segments, and village

q1. image text in transcribed
image text in transcribed
image text in transcribed
q2
image text in transcribed
image text in transcribed
image text in transcribed
q3
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Here we will check the proposed journey path is possible given the provided pony capacity, poryy assignment to route segments, and village elevation. The joumey path is provided, it should always start at the start village (0,0) and finish at the final village (M,N). The final point (M,N) is at the comer- that is. M and N are the: maximum indicies that x and y can take. Write a function chick, path (elevations, path, copactities, assignnents) Arguments: elevations - a list of rows, where each row is a list of cells, each cell (village) is provided with its absolute elevation level path - a list of tuples, each tuple provides (x,y) coordinates tor each path segment to take the trolley on. Should start with (0,0) anid finish at (MM) capacities - a list of available pony types assignents - a list of assignments (tuples) for each pair of ponies to a path segment. The function returns wone if the assigned ponies are capable of getting from the initial (,0) point to the destination using the provided path. Otherwise, it should return a tuple with a cell coordinate and associated error message string. If thete are multiple possible ertor messages, return the first one in the error message list. the possible error messages are provided below. Note that the (M,N) mossoge requires replacing (MNN) with the appropriate values. Cell coordinate is out of Pounds Path should start at (0,0) A cell listed in path is out of map boundaries according to cell_elevations coordinate Path should end at (N coordinate illegal move Insufficient capacity The first element in the path isn't (0,0) assigniment The pattis last element isnt the final village (replace M,N in the crrot message with values for the current data, where M and N are the. Exceedine pony limit maximam indicies that x and y can take). The path contains any move other than plus one x coordinate or plus one y cocrdinate.(") Assigned pony capacity isnt enough to overcome an elevation taise on the way to the next cell in path. (") (") Whenever an erar is assoelated to a move (source cell-> deatination cell), return the move's source cell as the error.coli.. If multipte errors occue, report one listed first in the description table of errors of the same kind, return one occurting earlier in a path. If there are multiple possible error messages. return the first one in the error messace list. In the previous question we provided ponies for each segment. That is often not the case in real-wotld scenarios. In this question, we will write a function to assign ponies for each segment on the path provided. The function should find the best allocation according to the following criterla: - (the man optirnization criterion) 1. Assignment is superior if it has lower totar unused pony capacity - (an extra heuristic to resolve a tie at criterion 1) 2. Smaller differences befween the capacify of two assigned ponies are preferred - Used in Q3 onlyl (an extra heuristic to resolve a tie at criterion 2) 3. If moves are different, prefer the one with greater elevation raise. - [Used in Q3 anlyl (an extra heuristic to resolve a tie at criterion 3) 4. Prefer moves into lower value (xy) coordinates Here "lower" meant (x1,y1)(c2,b2,c2) will return True if at >a2 regardless of b1, q1,b2,c2 valces. O1harwise if. reall wil be False. 1 H data examples def assign_pony_to_path(elevations, path, pony_capacities): \# TODO: Implement this function (delete this comment when you begin) In this cuestion we are neither provided with a path nor an assignment of ponies: Our task is to get the trolley from the initial point (0,0) to the final point ( M,N). Fecall that the final point (MN,N) is at the comer, that is, M and N are the maximum values that x and y can take. Try choosing the path step direction and pory assignment at each time step, one at a time, starting from the initial point (0,0). Specifically, you will need to use a greedy algorithm. Greedy algorithms make the best available choice at each step, fegardiess of whether that choice leads to the overall optirnal solution. You can see more info here. As an example, you want to buy a 12 -dollar meal using the smallest number of coins, and the avallable coins are 5 dollar, 4 . dollar and 1-dollar coins. What would you do? The ogtimal solution would be to use three 4 -doillar coins. But if you're using a greedy algorishm, you will select coins cone at a time and always select the coin with the largest value - you will select a 5 -dollar coiny another 5 -dollar coin, a 1 -dollar coin, and then another 1 -dollar coin, resulting in using 4 . coins total instead of just 3. The greedy algorithm that we will use for this question works in a similar way to the coin problem: At each location (x, y), we consider eather moving to the next location ( x+1, y) or (x,y+1). We choose the move by comparing the four criteria (described below) for the two possible next locations. Then we repeat the same procedure until the finat destination cell is reached. For example, at (0,0), we first choose to go to (0,1) because it is better than (1,0) based on the four criteria. Then from (0,1), we choose to go to (0,2), then we go to (1,2) from (0,2) _ until we reach (M,N). Similaf to the previous question, the following criteria should be used (make sure you follow the order): 1. Assignment is superior if it has lower total unused pony capacity 2 Prefor smalier differences between the capacity of two assigned ponies 3. If moves are different, ptefer the one with greater elovation faise 4. Prefer moves into lower( (x,y) coordinates Apsy the first rule and, if some move assignments are preferrable based on the first rule, adopt this docision. If some move assignments tie in the first nile, we proceed to the next ruke, and so on. Check the details in 02 . Wrise the furction find_bath zreedy (elevations, capacicles) Argumenis: H/ evatiens ; a lint of rows, where each row is a list of cells, each cell (village) is provided with its absolute elevation level capac it tes - a list of elevations by which every pory can puil the trolioy The function should teturn a tupie with path and ass igwents. The structure of variables should te conaistent with that in previous cuestions. it is pessible that no aliocation The function should return a tupie with path and assignnents. The structure of variables should be consiatent with that in previous questions. It is possible that no allocation exists for some point on the path. In the example inage: No allocation existe for the noxt move at the location ( 5.5). In this case, we return the partiaf assignments and partial path (ie. the path is [(6, e), (6,1), (e, 2). ( 6 , 1),(1,3),(2,3),(2,4),(3,4),(3,5),(4,5),(5,5)] in this example ) until the location where we get stuck. bory-copacitiog =[17,37,73] Joutary, steth =[(0,0),(0,1),(0,2),(0,3),(1,3),(1,4),(1,5)] vitlace_et ovaticas =[{100,200,300,400,100,600],[0,100,200,300,400,500]} wath {(0,0)=(0,1),(0,2),(0,3),(1,3),(1,4),(1,5)] 32) arsispant [01,73),(31,73),(37,73),(17,17),(37,73),(57,73)] def find_path_greedy(elevations, capacities): \# TODO: Implement this function (delete this comment when you begin)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

Students also viewed these Databases questions

Question

a. Which political changes have occurred within the past 5 years?

Answered: 1 week ago