What is distributed task allocation in drone programming?
Distributed task allocation is a method where multiple drones share and assign tasks among themselves without a central controller, improving efficiency and fault tolerance.
Click to reveal answer
beginner
Name one advantage of distributed task allocation over centralized task allocation.
Distributed task allocation reduces the risk of a single point of failure and allows drones to adapt dynamically to changes in the environment or drone availability.
Click to reveal answer
intermediate
In distributed task allocation, what is a common way drones communicate to share tasks?
Drones often communicate using wireless networks to broadcast their status and task availability, enabling peer-to-peer negotiation for task assignments.
Click to reveal answer
intermediate
Explain the role of a bidding mechanism in distributed task allocation.
A bidding mechanism allows drones to propose how suitable they are for a task based on criteria like distance or battery life, helping the group decide who should perform the task.
Click to reveal answer
beginner
What challenge does distributed task allocation help solve in drone fleets?
It helps solve the challenge of coordinating many drones efficiently without relying on a single controller, which can be slow or fail under heavy load.
Click to reveal answer
What is a key benefit of distributed task allocation in drones?
ANo single point of failure
BRequires a central controller
CSlower task completion
DLess communication needed
✗ Incorrect
Distributed task allocation avoids a single point of failure by letting drones share tasks among themselves.
Which method do drones use to decide who performs a task in distributed allocation?
ARandom selection
BBidding based on suitability
CCentral server assignment
DFirst come, first served
✗ Incorrect
Drones often use bidding mechanisms to decide task assignments based on suitability.
{'droneA': ['scan', 'map'], 'droneB': ['deliver', 'charge']} -> Option A
Quick Check:
Modulo cycles tasks evenly [OK]
Hint: Match task index modulo drone count to assign tasks [OK]
Common Mistakes:
Mixing task order in assignments
Ignoring modulo cycling
Appending tasks to wrong drone
4. Identify the error in this drone task allocation code:
drones = ['D1', 'D2', 'D3']
tasks = ['photo', 'survey', 'deliver']
assignments = {}
for i in range(len(tasks)):
drone = drones[i // len(drones)]
assignments.setdefault(drone, []).append(tasks[i])
print(assignments)
medium
A. assignments.setdefault is used incorrectly
B. Using range(len(tasks)) is incorrect for looping
C. Using integer division (//) instead of modulo (%) assigns all tasks to the first drone
D. The drones list should be empty
Solution
Step 1: Check drone index calculation
Using i // len(drones) results in index 0 for i=0,1,2 (len(drones)=3), assigning all tasks to 'D1' instead of cycling round-robin.
Step 2: Identify correct operator
Modulo (%) should be used to cycle through drone indices safely.
Final Answer:
Using integer division (//) instead of modulo (%) assigns all tasks to the first drone -> Option C
Quick Check:
Use modulo (%) to cycle indices [OK]
Hint: Use % not // to cycle through drone indices [OK]
Common Mistakes:
Confusing // with %
Thinking range(len(tasks)) is wrong
Misusing setdefault method
5. You have 3 drones and 7 tasks. You want to assign tasks so each drone gets tasks in a round-robin way but skip any task named 'wait'. Which code snippet correctly implements this?
hard
A. assignments = {}
for i, task in enumerate(tasks):
if task == 'wait':
continue
drone = drones[len(drones) % i]
assignments.setdefault(drone, []).append(task)
B. assignments = {}
for i, task in enumerate(tasks):
drone = drones[i % len(drones)]
if task != 'wait':
assignments.setdefault(drone, []).append(task)
C. assignments = {}
for task in tasks:
if task == 'wait':
continue
drone = drones[tasks.index(task) % len(drones)]
assignments.setdefault(drone, []).append(task)
D. assignments = {}
for i in range(len(tasks)):
if tasks[i] == 'wait':
continue
drone = drones[i // len(drones)]
assignments.setdefault(drone, []).append(tasks[i])
Solution
Step 1: Filter out 'wait' tasks correctly
Check task != 'wait' before assigning to drones.
Step 2: Assign tasks using modulo for round-robin
Use i % len(drones) to cycle drones correctly.
Step 3: Avoid using index() inside loop to prevent errors with duplicates
Using tasks.index(task) can cause wrong drone assignment if tasks repeat.
Final Answer:
assignments = {}
for i, task in enumerate(tasks):
drone = drones[i % len(drones)]
if task != 'wait':
assignments.setdefault(drone, []).append(task) -> Option B
Quick Check:
Filter first, then assign with modulo [OK]
Hint: Check task before assign; use modulo for drone cycling [OK]
Common Mistakes:
Using integer division instead of modulo
Using tasks.index() causing wrong assignments
Not skipping 'wait' tasks properly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.