0
0
Drone Programmingprogramming~30 mins

Distributed task allocation in Drone Programming - Mini Project: Build & Apply

Choose your learning style9 modes available
Distributed Task Allocation for Drones
📖 Scenario: You are programming a group of delivery drones. Each drone can carry out tasks like delivering packages to different locations. To work efficiently, drones need to decide which tasks to take based on their current battery level and task distance.
🎯 Goal: Build a simple program that assigns tasks to drones based on their battery level and the distance of each task. The program will create a list of tasks each drone can handle without running out of battery.
📋 What You'll Learn
Create a dictionary of drones with their battery levels
Create a dictionary of tasks with their distances
Set a battery usage rate per distance unit
Assign tasks to drones if the drone has enough battery for the task
Print the assigned tasks for each drone
💡 Why This Matters
🌍 Real World
Delivery companies use distributed task allocation to assign packages to drones efficiently, saving battery and time.
💼 Career
Understanding task allocation algorithms is important for roles in robotics programming, logistics automation, and drone fleet management.
Progress0 / 4 steps
1
Create drones and tasks data
Create a dictionary called drones with these exact entries: 'DroneA': 100, 'DroneB': 80, 'DroneC': 50 representing battery levels. Also create a dictionary called tasks with these exact entries: 'Task1': 30, 'Task2': 60, 'Task3': 40 representing task distances.
Drone Programming
Need a hint?

Use curly braces to create dictionaries. Put the drone names as keys and battery levels as values. Do the same for tasks with distances.

2
Set battery usage rate per distance
Create a variable called battery_usage_per_km and set it to 1 to represent battery used per distance unit.
Drone Programming
Need a hint?

This variable will help calculate if a drone has enough battery for a task.

3
Assign tasks to drones based on battery
Create an empty dictionary called assigned_tasks. Use a for loop with variables drone and battery to iterate over drones.items(). Inside it, create an empty list for each drone in assigned_tasks. Then use another for loop with variables task and distance to iterate over tasks.items(). If battery is greater than or equal to distance * battery_usage_per_km, append task to the drone's list in assigned_tasks.
Drone Programming
Need a hint?

Use nested loops to check each task for each drone. Use the battery check to decide if the drone can do the task.

4
Print the assigned tasks for each drone
Use a for loop with variables drone and tasks_list to iterate over assigned_tasks.items(). Inside the loop, print the string f"{drone} can do tasks: {tasks_list}".
Drone Programming
Need a hint?

Use a loop to print each drone's name and the list of tasks it can do.