Skip to main content

Defense Unit Task Allocation

Generalized Assignment Problem (GAP)

Assign heterogeneous defense units to shield generator locations across the city. Each unit has different effectiveness and resource consumption at each location, and each location has limited capacity. Maximize total defensive effectiveness — a classical GAP, NP-hard in general.

Shield Generator Defense

The city has 3 shield generator stations (North Shield, Central Hub, South Gate), each with limited power capacity. 6 heterogeneous defense units (mechs, tanks, drones, infantry, snipers) must be assigned to these stations. Each unit has different combat effectiveness and energy consumption at each location. The goal: maximize total defensive effectiveness without exceeding any station's power capacity. This is the Generalized Assignment Problem (GAP) — NP-hard in general (Ross & Soland, 1975).
Defense DomainOR ElementSymbolExample
Defense unitItem (agent)i ∈ {1,...,6}Mech-A
Shield locationBin (task)j ∈ {1,...,3}North Shield
Combat effectivenessValuevᵢˇ8
Energy/space usedWeightwᵢˇ4
Station power limitCapacity10
Deploy decisionBinary variablexᵢˇ ∈ {0,1}1 = assigned
MAXIMIZE Σᵢ Σˇ vᵢˇ · xᵢˇ subject to: Σˇ xᵢˇ ≤ 1 ∀ i ∈ Units // each unit assigned at most once Σᵢ wᵢˇ · xᵢˇ ≤ Cˇ ∀ j ∈ Locations // location capacity xᵢˇ ∈ {0,1} ∀ i,j // NP-hard in general (Ross & Soland 1975) // LP relaxation provides upper bound; gap indicates hardness

Why is this hard?

The GAP generalizes the knapsack problem: each location is a knapsack with its own capacity, and items have location-dependent values and weights. Even with a single location (one knapsack), the problem is NP-hard. With multiple locations, the assignment constraint (each unit to at most one location) adds combinatorial structure that makes it harder still. The LP relaxation is typically tight enough to guide heuristics but may have a non-zero integrality gap.

Assignment Optimizer

★★☆ Heuristic
6 Units × 3 Locations

Value matrix (effectiveness) and weight matrix (energy consumption):

VALUES vᵢˇ
NorthCentralSouth
Mech-A856
Mech-B794
Tank-C678
Drone-D539
Infantry-E483
Sniper-F947
WEIGHTS wᵢˇ · Capacities: N=10, C=8, S=12
NorthCentralSouth
Mech-A435
Mech-B543
Tank-C654
Drone-D326
Infantry-E242
Sniper-F534

The Algorithms

1. Greedy by Value-to-Weight Ratio

O(n·m·log(n·m))

For each (unit, location) pair, compute the ratio vᵢˇ/wᵢˇ. Sort all pairs by ratio descending. Assign greedily: accept the assignment if the unit is unassigned and the location has remaining capacity.

  1. Compute vᵢˇ/wᵢˇ for all 18 pairs
  2. Sort by ratio descending
  3. For each pair: if unit i unassigned AND wᵢˇ ≤ remaining capacity of j, assign
  4. Stop when all units assigned or no feasible pair remains

2. LP Relaxation + Rounding

O(n·m) LP variables — provides upper bound

Relax xᵢˇ ∈ {0,1} to xᵢˇ ∈ [0,1]. Solve the continuous LP (here via a simplified greedy LP approximation). Round fractional solutions. The LP value is an upper bound on the true integer optimum; the gap shows how much the rounding costs.

  1. Allow fractional assignments xᵢˇ ∈ [0,1]
  2. Fill each location with highest-ratio fractional amounts up to capacity
  3. LP value = upper bound on integer optimal
  4. Round: assign each unit to the location where it has the largest fractional assignment
  5. Repair any capacity violations by removing lowest-value assignments
References
Published Ross, G.T. & Soland, R.M. (1975). “A Branch and Bound Algorithm for the Generalized Assignment Problem.” Mathematical Programming, 8, 91–103. — Original B&B formulation; NP-hardness established.
Published Martello, S. & Toth, P. (1990). Knapsack Problems: Algorithms and Computer Implementations. Wiley. — Comprehensive treatment including GAP heuristics and exact methods.

Preparing for First Contact

If the aliens arrive, we suspect you will not be visiting a GitHub Pages site. We do recommend the Hungarian algorithm. It works on any planet.

👽🛸⚠️

Educational Fiction Disclaimer

This is a fictional educational scenario.

  • All “alien invasion” content exists purely to teach OR concepts
  • All data and parameters are entirely fictional
  • No actual military applications are intended or endorsed
  • The author advocates for peace and opposes militarization