logo

Crowdly

Browser

Додати до Chrome

Consider a scenario where a city is hosting an international music festival even...

✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.

Consider a scenario where a city is hosting an international music festival event expected to have several hundreds of thousands of people attending.

The city commissioned a public infrastructure authority to set up the basic infrastructure for lighting (i.e. electricity cables for lamp posts) and the points-of-sale (i.e., both electricity and Internet/data cables for vending machines and cash registers at bars). 

The area where the event is being held is divided as a grid of 10 x 10 sub-areas called sectors, and named from A0 to J9. 

Each sector is a 1000m x 1000m square. Each sector has one electricity access point and one data access point at its geometric center, i.e., 500m x 500m point inside the sector.  Each location has global positive x and y coordinates, with the top-left corner of sector A0 being (0, 0) and the bottom-right corner of J9 being (9999,9999).

The infrastructure is going to be laid out in parallel across the 100 sectors. Each sector has a dense grid of pathways (for bicycles, pedestrians, etc.), along with trenches where cables can be placed/installed/laid out.  

Therefore, the infrastructure authority wants to calculate the extension of electricity cables and data cables that are needed, in each sector, to properly connect all the lamp posts and points-of-sale directly to the relevant access points in that sector (e.g., sector A1 needs 4000m of electricity cable and 400m of data cable).

In general, the authority needs to iterate over the multiple locations proposed to place lamp posts and points-of-sale, and determine based on their global coordinates:

- what cables to connect, where to connect them to, and therefore calculate the extent of electricity and/or data cable needed, so that totals for each specific sector can be obtained.

 

The input consists of one text file.

In the file locations.txt, each line stores one intended location for a lamp (post-type=LAMP) or a point-of-sale (post-type=SALE):     

<postID>, <post-type>, <x-coord>, <y-coord> 

Assume the standard signature for the mapper: List<k2,v2> map(int, string) and reducer:  List<k3, v3> reduce(k2, List<v2>) functions, where map has the default MapReduce input (cursor/line number and text line content) and k2, v2, k3 and v3 can all be replaced with types of your choice.  

Write the pseudocode for a MapReduce application, with a single map and a single reduce method.

 

The final output of the reduce function should produce, if required:

- a single record for each sector, identifying it, and with two data fields, stating in meters the total extent of electricity cables and of data cables required to properly connect all the locations in that sector.

 

(if you need, you can briefly state any assumptions at the end of the answer after the pseudocode.)

(No penalty for wrong answer.)

Note: MapReduce is not natural language. Pseudocode needs not be Java but it must include clear operating steps well identified, it should not be a paragraph or set of paragraphs rephrasing the question. But do express your reasoning, nonetheless.

Більше питань подібних до цього

Хочете миттєвий доступ до всіх перевірених відповідей на moodle.dei.tecnico.ulisboa.pt?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!

Browser

Додати до Chrome