## Step 1: Define the variables and their attributes
We have four variables: 
- $x_0$: military intelligence companies
- $x_1$: water purification units
- $x_2$: armored companies
- $x_3$: light infantry companies

Each variable has attributes defined by the resources $r_0$ and $r_1$:
- $r_0$: defensive capability rating
- $r_1$: logistics footprint

The attributes for each variable are given as:
- $r_0$: $x_0 = 2$, $x_1 = 6$, $x_2 = 6$, $x_3 = 4$
- $r_1$: $x_0 = 4$, $x_1 = 4$, $x_2 = 1$, $x_3 = 7$

And the upper bounds for $r_0$ and $r_1$ are 58 and 39 respectively.

## Step 2: Formulate the objective function
The objective function to maximize is: $7x_0 + 3x_1 + 9x_2 + 3x_3$.

## 3: Define the constraints
1. Defensive capability rating constraints:
- $2x_0 + 6x_1 + 6x_2 \geq 12$
- $2x_0 + 6x_1 + 4x_3 \leq 43$
- $2x_0 + 4x_3 \leq 31$
- $2x_0 + 6x_2 \leq 47$
- $6x_1 + 6x_2 + 4x_3 \leq 39$
- $2x_0 + 6x_1 + 6x_2 + 4x_3 \leq 39$

2. Logistics footprint constraints:
- $4x_0 + 4x_1 \geq 5$
- $4x_0 + 4x_1 + 7x_3 \geq 9$
- $x_2 + 7x_3 \leq 30$
- $4x_0 + 4x_1 \leq 36$
- $4x_1 + 7x_3 \leq 30$
- $4x_1 + x_2 \leq 26$
- $4x_0 + x_2 \leq 18$
- $4x_0 + 4x_1 + x_2 + 7x_3 \leq 18$

## 4: Implement the problem in Gurobi
We will use Gurobi to solve this mixed-integer linear programming problem.

```python
import gurobi

def solve_optimization_problem():
    # Create a new model
    model = gurobi.Model()

    # Define the variables
    x0 = model.addVar(vtype=gurobi.GRB.INTEGER, name="military_intelligence_companies")
    x1 = model.addVar(vtype=gurobi.GRB.INTEGER, name="water_purification_units")
    x2 = model.addVar(vtype=gurobi.GRB.INTEGER, name="armored_companies")
    x3 = model.addVar(vtype=gurobi.GRB.INTEGER, name="light_infantry_companies")

    # Define the objective function
    model.setObjective(7 * x0 + 3 * x1 + 9 * x2 + 3 * x3, gurobi.GRB.MAXIMIZE)

    # Defensive capability rating constraints
    model.addConstr(2 * x0 + 6 * x1 + 6 * x2 >= 12, name="defensive_capability_rating_1")
    model.addConstr(2 * x0 + 6 * x1 + 4 * x3 <= 43, name="defensive_capability_rating_2")
    model.addConstr(2 * x0 + 4 * x3 <= 31, name="defensive_capability_rating_3")
    model.addConstr(2 * x0 + 6 * x2 <= 47, name="defensive_capability_rating_4")
    model.addConstr(6 * x1 + 6 * x2 + 4 * x3 <= 39, name="defensive_capability_rating_5")
    model.addConstr(2 * x0 + 6 * x1 + 6 * x2 + 4 * x3 <= 39, name="defensive_capability_rating_6")

    # Logistics footprint constraints
    model.addConstr(4 * x0 + 4 * x1 >= 5, name="logistics_footprint_1")
    model.addConstr(4 * x0 + 4 * x1 + 7 * x3 >= 9, name="logistics_footprint_2")
    model.addConstr(x2 + 7 * x3 <= 30, name="logistics_footprint_3")
    model.addConstr(4 * x0 + 4 * x1 <= 36, name="logistics_footprint_4")
    model.addConstr(4 * x1 + 7 * x3 <= 30, name="logistics_footprint_5")
    model.addConstr(4 * x1 + x2 <= 26, name="logistics_footprint_6")
    model.addConstr(4 * x0 + x2 <= 18, name="logistics_footprint_7")
    model.addConstr(4 * x0 + 4 * x1 + x2 + 7 * x3 <= 18, name="logistics_footprint_8")

    # Non-negativity constraints
    model.addConstr(x0 >= 0, name="non_negativity_x0")
    model.addConstr(x1 >= 0, name="non_negativity_x1")
    model.addConstr(x2 >= 0, name="non_negativity_x2")
    model.addConstr(x3 >= 0, name="non_negativity_x3")

    # Integrate all the changes
    model.update()

    # Solve the model
    model.optimize()

    # Print the solution
    if model.status == gurobi.GRB.OPTIMAL:
        print("Optimal solution found.")
        print(f"military_intelligence_companies: {x0.varValue}")
        print(f"water_purification_units: {x1.varValue}")
        print(f"armored_companies: {x2.varValue}")
        print(f"light_infantry_companies: {x3.varValue}")
        print(f"Objective: {model.objVal}")
    else:
        print("No optimal solution found.")

solve_optimization_problem()
```