## Problem Description and Formulation

The company wants to maximize viewership by purchasing ads on planes, blimps, and hot air balloons. The goal is to determine the optimal number of ads to buy on each platform given the constraints.

### Parameters

- Cost and viewership for each ad type:
  - Plane: $5000, 100000 viewers
  - Blimp: $2000, 50000 viewers
  - Hot Air Balloon: $1000, 20000 viewers
- Budget: $50000
- Maximum ads from the same company: 5
- At most half of the total ads can be on hot air balloons
- At least 20% of the total ads must be on blimps

### Decision Variables

- \(P\): Number of ads on planes
- \(B\): Number of ads on blimps
- \(H\): Number of ads on hot air balloons

### Objective Function

Maximize total viewership: \(100000P + 50000B + 20000H\)

### Constraints

1. Budget constraint: \(5000P + 2000B + 1000H \leq 50000\)
2. Maximum ads per type: \(P \leq 5\), \(B \leq 5\), \(H \leq 5\)
3. Non-negativity: \(P \geq 0\), \(B \geq 0\), \(H \geq 0\)
4. Hot air balloon limit: \(H \leq 0.5(P + B + H)\) or \(0.5P + 0.5B \geq 0.5H\)
5. Blimp minimum: \(B \geq 0.2(P + B + H)\)

## Gurobi Code

```python
import gurobipy as gp

# Create a new model
m = gp.Model("Advertising")

# Decision variables
P = m.addVar(lb=0, ub=5, name="Plane_ads")
B = m.addVar(lb=0, ub=5, name="Blimp_ads")
H = m.addVar(lb=0, ub=5, name="Hot_Air_Balloon_ads")

# Objective: Maximize viewership
m.setObjective(100000*P + 50000*B + 20000*H, gp.GRB.MAXIMIZE)

# Budget constraint
m.addConstr(5000*P + 2000*B + 1000*H <= 50000, name="Budget")

# Maximum ads per type is inherently handled by variable bounds

# Hot air balloon limit: at most half of total ads
m.addConstr(0.5*P + 0.5*B - 0.5*H >= 0, name="Hot_Air_Balloon_Limit")

# Blimp minimum: at least 20% of total ads
m.addConstr(B - 0.2*P - 0.2*B - 0.2*H >= 0, name="Blimp_Minimum")

# Solve the model
m.optimize()

# Print the results
if m.status == gp.GRB.OPTIMAL:
    print("Optimal Solution:")
    print(f"Plane ads: {P.varValue}")
    print(f"Blimp ads: {B.varValue}")
    print(f"Hot Air Balloon ads: {H.varValue}")
    print(f"Max Viewership: {m.objVal}")
else:
    print("No optimal solution found")
```