Initialization
1. Base Coordinates: The base is initialized at (0, 0) using the Base constructor.
2. Number of UAVs: You enter 3 UAVs.
o UAV 1: (id=1, capacity=34, speed=56, max_distance=89)
o UAV 2: (id=2, capacity=45, speed=12, max_distance=89)
o UAV 3: (id=3, capacity=67, speed=89, max_distance=45)
3. Number of Outposts: You enter 3 outposts.
o Outpost 1: (id=1, deadline=47, weight_needed=90, coordinates=(5, 4))
o Outpost 2: (id=2, deadline=2, weight_needed=56, coordinates=(1, 1))
o Outpost 3: (id=3, deadline=6, weight_needed=67, coordinates=(2, 2))
2. Processing the Outposts
The allocateResources function in the Base class is called, which prioritizes and allocates
UAVs to outposts based on feasibility.
1. Sorting Outposts by Priority:
o The sortOutpostsByPriority method sorts outposts by their priority score, calculated
as 1 / deadline. The lower the deadline, the higher the priority.
o Priority order: Outpost 2 (1/2), Outpost 3 (1/6), Outpost 1 (1/47).
2. Iterating Through Outposts:
o The algorithm tries to find a suitable UAV for each outpost in the sorted order.
3. Allocation Details
Outpost 2:
Weight Needed: 56
Coordinates: (1, 1)
Deadline: 2
For each UAV:
UAV 1:
o Can carry only 34 (less than 56). Not feasible.
UAV 2:
o Can carry 45 (less than 56). Not feasible.
UAV 3:
o Can carry 67 and travel the distance to (1, 1) within 2 seconds.
o Distance: sqrt((1-0)^2 + (1-0)^2) = sqrt(2) ≈ 1.41
o Travel time: 1.41 / 89 ≈ 0.016 seconds.
o This UAV is selected for Outpost 2.
Delivery: UAV 3 delivers to Outpost 2 and resets to the base. It is marked as delivered.
Outpost 3:
Weight Needed: 67
Coordinates: (2, 2)
Deadline: 6
For each UAV:
UAV 1:
o Can carry only 34. Not feasible.
UAV 2:
o Can carry 45. Not feasible.
UAV 3:
o Now at base, it can still carry 67, meet the weight requirement, and travel to (2, 2) in
time.
o Distance: sqrt((2-0)^2 + (2-0)^2) = sqrt(8) ≈ 2.83
o Travel time: 2.83 / 89 ≈ 0.0318 seconds.
o This UAV is selected for Outpost 3.
Delivery: UAV 3 delivers to Outpost 3 and resets to the base. It is marked as delivered.
Outpost 1:
Weight Needed: 90
Coordinates: (5, 4)
Deadline: 47
For each UAV:
UAV 1:
o Can carry only 34. Not feasible.
UAV 2:
o Can carry 45. Not feasible.
UAV 3:
o Can carry 67 (less than 90). Not feasible.
No Delivery: No UAV meets the requirements for Outpost 1.
4. Final Output
Based on the above processing:
1. Outpost 2: UAV 3 successfully delivers.
2. Outpost 3: UAV 3 successfully delivers.
3. Outpost 1: No UAV can fulfill the requirements.
Output
UAV 3 delivered to Outpost 2.
UAV 3 delivered to Outpost 3.
No UAV can fulfill Outpost 1 on time.