Sunteți pe pagina 1din 8

Delivery

ProblemstatementforOnlineQualificationRound,HashCode2016

Introduction
The Internet has profoundly changed the way we buy things, but the online shopping of today is likely not
the end of that change after each purchase we still need to wait multiple days for physical goods to be
carriedtoourdoorstep.

This is where drones come in autonomous, electricvehiclesdeliveringonlinepurchases.Flying,sonever


stuck in traffic. As drone technology improveseveryyear,thereremainsamajorissue:howdowemanage
andcoordinateallthosedrones?

Task
Given a fleet of drones, a list of customer orders and availability of the individual products inwarehouses,
schedulethedroneoperationssothattheordersarecompletedassoonaspossible.

Problemdescription
Map
The simulation takes place on a twodimensional grid. The gridisnotcyclicandadronecannotflyoutside
ofthegrid.Thedronescanflyoverallcellswithinthegrid.

Eachcellisidentifiedbyapairofintegercoordinates[r,
c]
( 0 r < rowcount, 0 c < columncount ).

Products
There are a number of product types available for order.Eachproducttypehasoneormoreproductitems
available inwarehouses.Eachproducttypehasafixedproductweight,identicalforallproductitems.Every
productweightisguaranteedtobesmallerorequaltothemaximumpayloadthatadronecancarry.

Warehouses
Product items are stored in several warehouses. Each warehouse is located in one particular cell of the
grid, different for each warehouse. Each warehouse initially stocks a known number of product items of
each product type. No new product items beyond the initial availability will be stocked in the warehouses
during the simulation,butthedronescantransportproductitemsbetweenthewarehouses.Anywarehouse
doesnotnecessarilyneedtohaveeveryproducttypeavailable.

Orders
Each order specifies theproductitemspurchasedbythecustomer.Theproductitemsinanordercanbeof
oneormultipleproducttypesandcancontainmultipleproductitemsofthesameproducttype.

Each order specifies the cell in the grid wheretheproductitemshavetobedelivered.Itispossibletohave


multipleorderswiththesamedeliverycell.Noorderhasthedeliverycellthatisalocationofawarehouse.

The order is considered fulfilled when all of the ordered product items are delivered. Individual product
items can be delivered in multiple steps, in any order.Itisvalidtodelivertheindividualproductitemsofan
orderusingmultipledrones,includingusingdifferentdronesattheverysametime.

It is guaranteed that for each product type, the total number of product items in all orders is
not greater
thanthetotalavailabilityofproductitemsofthisproducttypeinallwarehouses.

Itisnot
requiredtodeliverallorders(seetheScoringsectionattheend).

Google2016,Allrightsreserved.

1
Drones
Dronestransportproductitemsfromwarehousestocustomersandbetweenthewarehouses.

The drones always use the shortest path to fly from one cell in the grid to another. The distance from cell
[ra , ca ] to cell [rb , cb ] is calculated as
|r
a rb |2 + |ca cb |2 (
twodimensional Euclidean distance)
. We
define a drone flight as a single movement of thedronethathappensbetweentwosubsequentcommands
forthegivendrone(asdescribedbelow).Eachdroneflighttakes oneturnperoneunitofdistancebetween
thestartandthedestinationcell, roundeduptothenextinteger.

Multiple drones can be in the same cell at any moment they never collide, as they can fly at different
altitudes.

For
example, if the distance to be flown is 2.9 distance units, the duration of the flight is 3 turns. If the
distancetobeflownisexactly4distanceunits,thedurationoftheflightis4turns.

Atthebeginningofthesimulation,alldronesareatthefirstwarehouse(warehousewithid0).

Commands
Eachdronecanbegiventhefollowingbasiccommands:

Load : Moves the specified number of items of the specified product type from a warehouse to the
drones inventory. If the drone isnt at the warehouse it will fly there using the shortest path before
loading the product items. The requested number of items of the specified product type must be
available in the warehouse. The total weight of the items in the drones inventory after the load
cannotbebiggerthanthedronesmaximumload.
Deliver : Delivers the specified number of items of the specified product type to a customer. If the
drone isnt at the destination it will fly there using the shortest path before delivering the product
items. The drone must have the requested number of items of the specified product type in its
inventory.

Each drone can also be given the following advanced commands. These commandsare notnecessaryto
solvetheproblem,butyoucanusethemtofurtherimproveyoursolution.

Unload :Movesthespecifiednumberofitemsofthespecifiedproducttypefromdronesinventoryto
a warehouse. If the drone isnt at the warehouse it will fly there using the shortest path before
unloading the product items. The drone must have the requested number of items of the specified
producttypeinitsinventory.
Wait :Waitsthespecifiednumberofturnsinthedrone'scurrentlocation.

Google2016,Allrightsreserved.

2
Simulation
The simulation proceeds in T turns, from 0 to T 1 . A drone executes the commands issued to it in the
orderinwhichtheyarespecified,onebyone.Thefirstcommandissuedtothedronestartsinturn0.

Thedurationofacommanddependsonitstype:

Each Load /D
eliver/U
nload command takes d + 1 turns, where d is the distance travelled by the
drone to perform the requested action ( d can be 0 if the drone is already in the requiredlocation).
Whenthecommandstarts,thedronefliestotherequiredlocationin d turns.Then,the actualaction
(loading,deliveryorunloading)takesplaceandtakes1turn.
Each Wait commandtakes w turns,where w isthespecifiednumberofturns.

For
example ,letsassumethatatthebeginningofthesimulation(atthebeginningofturn0)adroneisin
warehouse 0 at the cell [1,1], warehouse 1 is in cell [1, 3], customer order0hastobedeliveredto[1,4],
andpandqaresomeproducttypes,theitemsofwhicharepartoforder0.

Letsconsiderthefollowingcommands:

Load one item of product type p at warehouse 0. This will take 1 turn: 0 turns to get to the
warehouseand1turntoloadtheitem.
Load five items of product typeqatwarehouse1.Thiswilltake3turns:2turnstogetfrom[1,
1]tothewarehouseat[1,3]and1turntoloadtheitems.
Deliver one item of product type p for customer order 0 . This will take 2 turns: 1 turn to get
from[1,3]tothedeliverycellat[1,4]and1turntodelivertheitem.
Deliver five items of product type q for customer order 0 . This will take 1 turn:0turnstoget
tothedeliverycelland1turntodelivertheitems.

If there are multiple


actual actions (see above) taking place in the same turn in the same warehouse, all
unloadingcommandsareprocessed beforeallloadingcommands.

For
example, lets assume that in one turn, three different drones are all located at warehouse 0 and
orderedtoperformthefollowingactions:
Loadoneitemofproducttypepatwarehouse0.(firstdrone)
Loadoneitemofproducttypepatwarehouse0.(seconddrone)
Unloadtwoitemsoftypepatwarehouse0.(thirddrone)

Because unloading takes precedence over loading, all commands will succeed even if there were no
itemsofproducttypepatthewarehousebeforethisturn.

Inputdataset
The input data is provided as a data set file a plain text file containing exclusively ASCII characters with
linesterminatedwithasingle\ncharacterattheendofeachline(UNIX stylelineendings).

Product types, warehouses and orders arereferencedbyintegerIDs.Thereare Pproducttypesnumbered


from 0 to P 1 ,
W
warehousesnumberedfrom 0 to W 1 and C
ordersnumberedfrom 0 to C 1 .

Google2016,Allrightsreserved.

3
Fileformat

The first section of the file describes the parametersofthesimulation .Thissectioncontainsasingleline


containingthefollowingnaturalnumbersseparatedbysinglespaces:
numberofrowsintheareaofthesimulation (1 numberof rows 10000)
numberofcolumnsintheareaofthesimulation (1 numberof columns 10000)
D numberofdronesavailable (1 D 1000)
deadlineofthesimulation (1 deadlineof thesimulation 1000000)
maximumloadofadrone (1 maximumloadof adrone 10000)

The next section of the file describes the weights of the products available for orders . This section
contains:
alinecontainingthefollowingnaturalnumber:
P thenumberofdifferentproducttypesavailableinwarehouses (1 P 10000)
a line containing P natural numbers separated by single spaces denoting weights of subsequent
products types, from product type 0 to product type P 1. For each weight,
1 weight maximumloadof adrone .

The next section of the file describes the warehouses and availability of individual product types at
eachwarehouse.Thissectioncontains:
alinecontainingthefollowingnaturalnumber:
W thenumberofwarehouses (1 W 10000)
two lines for each warehouse, each two lines describing the subsequent warehouses from
warehouse0towarehouse W 1 :
a line containing two natural numbers separated by a single space: therowandthecolumn
inwhichthewarehouseislocated
(0 row < numberof rows; 0 column < numberof columns)
a line containing P natural numbers separated by single spaces: number of items of the
subsequent product types available at the warehouse, from product type 0 to product type
P 1 .Foreachproducttype, 0 numberof items 10000 holds.

Thenextsectionofthefiledescribesthe customer o
rders .Thissectioncontains:
alinecontainingthefollowingnaturalnumber:
C thenumberofcustomerorders (1 C 10000)
threelinesforeachorder,eachthreelinesdescribingthesubsequentordersfromorder0to C
1:
a line containing two natural numbers separated by a single space: the row of the delivery
cellandthecolumnofthedeliverycell
(0 row < numberof rows; 0 column < numberof columns)
a line containing one natural number L i the number of the ordered product items
(1 Li < 10000)
a line containing Li
integers separated by single spaces: the product types of the individual
productitems.Foreachoftheproducttypes, 0 producttype < P holds.

Google2016,Allrightsreserved.

4
Example
Inthecomments,uisanabbreviationforunitsofweight.

100100350500 100rows,1
00columns,3drones,50turns,maxpayloadis500u
3 Thereare3differentproducttypes.
1005450 Theproducttypesweigh:100u,5u,450u.
2 Thereare2warehouses.
00 Firstwarehouseislocatedat[0,0].
510 Itstores5itemsofproduct0and1ofproduct1.
55 Secondwarehouseislocatedat[5,5].
0102 Itstores10itemsofproduct1and2itemsofproduct2.
3 Thereare3orders.
11 Firstordertobedeliveredto[1,1].
2 Firstordercontains2items.
20 Itemsofproducttypes:2,0.
33 Secondordertobedeliveredto[3,3].
3 Secondordercontains3items.
000 Itemsofproducttypes:0,0,0.
56 Thirdordertobedeliveredto[5,6]
1 Thirdordercontains1item.
2 Itemsofproducttypes:2.
Exampleinputfile.

Submissions
Fileformat
The first line of the outputfilecontainsasingleinteger
Q,thenumberofdronecommands( 0 Q D T ) ,
where D isthenumberofdronesand T
isthedurationofthesimulation.

The rest of the output file should describe the individual commands to the drones, each command in a
separate line. Commands for different drones can be intertwined but commands for any given drone must
comeinchronologicalorder.

Drones are referenced by integer IDs, from 0 to D 1 , where


Disthenumberofdronesgivenintheinput
file.

Each Load or Unload command is described by a line with the following elements separated by single
spaces:
theIDofthedronethatthecommandisfor
thecommandtagasinglecharacter,eitherL(forload)orU(forunload),
theIDofthewarehousefromwhichweloaditems/towhichweunloaditems
theIDoftheproducttype
thenumberofitemsoftheproducttypetobeloadedorunloadeda positive
integer

Example command:0L123(Command to drone0,loadatwarehouse1productsofproducttype


2,threeofthem.

Google2016,Allrightsreserved.

5

Each
Deliver
commandisdescribedbyalinewiththefollowingelementsseparatedbysinglespaces:
theIDofthedronethatthecommandisfor
thecommandtagsinglecharacterD
theIDofthecustomerorderwearedeliveringitemsfor
theIDoftheproducttype
thenumberofitemsoftheproducttypetobedelivereda
positive
integer

Example command: 0D123 (Command to drone 0, deliver for order 1 items of product type 2,
threeofthem.

Each
Wait
commandisdescribedbyalinewiththefollowingelementsseparatedbysinglespaces:
theIDofthedronethatthecommandisfor
thecommandtagsinglecharacterW
thenumberofturnsforwhichthedroneneedstowaita
positive
integer

Examplecommand:
0W3
(Commandtodrone0,waitforthreeturns)

Example

9 9commandsintotal.
0L001 Drone0:l
oad
oneproduct0atwarehouse0.
0L011 Drone0:l
oad
oneproduct1atwarehouse0.
0D001 Drone0:flytocustomer0andd
eliver
oneproduct0.
0L121 Drone0:flytowarehouse1andl
oad
oneproduct2.
0D021 Drone0:flytocustomer0andd
eliver
oneproduct2.
1L121 Drone1:flytowarehouse1andl
oad
oneproduct2.
1D221 Drone1:flytocustomer2andd
eliver
oneproduct2.
1L001 Drone1:flytowarehouse0andl
oad
oneproduct0.
1D101 Drone1:flytocustomer1andd
eliver
oneproduct0.
Examplesubmissionfile.

Validation
Theoutputfileisconsideredvalidifitmeetsthefollowingcriteria:

Theformatoftheoutputfilematchesthedescriptionabove
AllcommandsarevalidwithregardtotherequirementsintheCommandssection
No order receives more product items ofanytypethanthenumberofproductitemsofthistypethat
isspecifiedintheorder.
All commands for any given drone take at most T turns in total, where
T is the number of turns of
thesimulation.

Google2016,Allrightsreserved.

6
Scoring
Each completed order will earn between 1 and 100 points, depending on the turn in whichitiscompleted.
Theorderiscompletedinthefirstturnattheendofwhichallitemsintheorderaredelivered.

For an order completedinturntandasimulationtaking Tturnsintotal,thescorefortheorderiscalculated


as (T t)/T 100 ,roundeduptothenextinteger.

For example , if the simulation takes 160 turns (


T = 160),andanorderconsistsofthreeitems,delivered
at turns 5, 15 and 15, then the order is considered completed at t = 15, and the score is calculated as
(160 15)/160 = 0.90625 ,multipliedby100androundedupto 91points .

For an order completed in the last turn of the simulation ( t = 159,
T = 160), the score would be
(160 159)/160 = 0.00625 ,multipliedby100androundedupto 1point
.

Thescoreforasingledatasetwillbethesumofthescoresofallcompletedorders.

Note that there aremultipledatasetsrepresentingseparateinstancesoftheproblem.Thefinalscoreforyour


teamwillbethesumofyourbestscoresontheindividualdatasets.

Scoringexample

Scorefortheexamplesolutiongivenaboveiscalculatedasfollows.

Drone0:
loads item0fromwarehouse0 inturn0
loads item1fromwarehouse0 inturn1
flies toorder0inturns2and3
delivers item0toorder0
inturn4
flies towarehouse1 inturns5to10
loads item2fromwarehouse1 inturn11
flies toorder0inturns12to17
delivers
item2toorder0
inturn18
.Order0isnowfulfilled, (5050
scoring 18)
100 = 64 points


Drone1
:
flies
towarehouse1 inturns0to7
loads item2fromwarehouse1 inturn8
flies
toorder2inturn9
(5010)
delivers
item2toorder2
inturn10
.Order2isnowfulfilled,
scoring 50 100 = 80 points

flies
towarehouse0 inturns11to18
loads item0fromwarehouse0 inturn19
flies
toorder1inturns20to24
delivers
item0toorder1
inturn25
.Order1isnowfulfilled, (5050
scoring 25)
100 = 50 points


Drone2isntusedatallandtherearenootherorders.

Thescoreoftheexamplesubmissionis 64 + 50 + 80 = 194 points.

Google2016,Allrightsreserved.

S-ar putea să vă placă și