## Problem Description and Formulation

The businessman has $20,000 to invest in two factories: a shoe factory and a hat factory. The goal is to maximize earnings given the following constraints:

1. The total investment is $20,000.
2. The investment in the shoe factory must be at least 4 times the investment in the hat factory.
3. The investment in the shoe factory cannot exceed $15,000.
4. The shoe factory earns 7% on investment, and the hat factory earns 6% on investment.

## Symbolic Representation

Let \(S\) be the investment in the shoe factory and \(H\) be the investment in the hat factory. The problem can be formulated as:

### Objective Function
Maximize earnings: \(0.07S + 0.06H\)

### Constraints
1. \(S + H \leq 20000\)
2. \(S \geq 4H\)
3. \(S \leq 15000\)
4. \(S, H \geq 0\) (Non-negativity constraint, as investments cannot be negative)

## Gurobi Code

```python
import gurobi

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

    # Define variables
    S = model.addVar(name="Shoe_Factory_Investment", lb=0)
    H = model.addVar(name="Hat_Factory_Investment", lb=0)

    # Objective function: Maximize earnings
    model.setObjective(0.07 * S + 0.06 * H, gurobi.GRB.MAXIMIZE)

    # Constraints
    model.addConstr(S + H <= 20000, name="Total_Investment")
    model.addConstr(S >= 4 * H, name="Shoe_to_Hat_Min_Ratio")
    model.addConstr(S <= 15000, name="Shoe_Factory_Max_Investment")

    # Solve the model
    model.optimize()

    # Print the solution
    if model.status == gurobi.GRB.OPTIMAL:
        print(f"Optimal investment in shoe factory: ${S.varValue:.2f}")
        print(f"Optimal investment in hat factory: ${H.varValue:.2f}")
        print(f"Maximized earnings: ${0.07 * S.varValue + 0.06 * H.varValue:.2f}")
    else:
        print("The model is infeasible.")

solve_investment_problem()
```