# Linear optimization


```python
# Import Gurobi package
import gurobipy as gb
```

## Exercise

\begin{align}
Min. 98x_1 + 100x_2\\
6x_1 + 3x_2 \geq 500\\
7x_2 \geq 500\\
2x_1 +4x_2 \geq 500\\
x_1,x_2 \geq 0
\end{align}


```python
# Create model
m = gb.Model()

# Add variables
x1 = m.addVar()
x2 = m.addVar()

# Define objective function
m.setObjective(98 * x1 + 100 * x2, sense=gb.GRB.MINIMIZE)

# Add constraints
m.addConstr(6 * x1 + 3 * x2 >= 500)
m.addConstr(7 * x2 >= 500)
m.addConstr(2 * x1 + 4 * x2 >= 500)

# Run optimization
m.optimize()
```

    Gurobi Optimizer version 9.0.1 build v9.0.1rc0 (win64)
    Optimize a model with 3 rows, 2 columns and 5 nonzeros
    Model fingerprint: 0x276de63b
    Coefficient statistics:
      Matrix range     [2e+00, 7e+00]
      Objective range  [1e+02, 1e+02]
      Bounds range     [0e+00, 0e+00]
      RHS range        [5e+02, 5e+02]
    Presolve removed 1 rows and 0 columns
    Presolve time: 0.00s
    Presolved: 2 rows, 2 columns, 4 nonzeros
    
    Iteration    Objective       Primal Inf.    Dual Inf.      Time
           0    1.1809524e+04   7.440476e+00   0.000000e+00      0s
           1    1.3833333e+04   0.000000e+00   0.000000e+00      0s
    
    Solved in 1 iterations and 0.00 seconds
    Optimal objective  1.383333333e+04



```python
# Get values of decision variables
print('x1 =', x1.X)
print('x2 =', x2.X)
print('Objective function value =', m.ObjVal)
```

    x1 = 27.77777777777778
    x2 = 111.11111111111111
    Objective function value = 13833.333333333334



```python

```

a4ee41af311231bdac7cc49cbe2cabc04246f7ab
ipynb
Jupyter Notebook
Basics of gurobi optimization/01 Linear optimization.ipynb
j-stalder/portfolio-optimization
f2f8c2d80a3ff43405aa7ac7e2e9e96a44c476df
MIT
Basics of gurobi optimization/01 Linear optimization.ipynb
j-stalder/portfolio-optimization
f2f8c2d80a3ff43405aa7ac7e2e9e96a44c476df
MIT
Basics of gurobi optimization/01 Linear optimization.ipynb
j-stalder/portfolio-optimization
f2f8c2d80a3ff43405aa7ac7e2e9e96a44c476df
MIT
Qwen/Qwen-72B
1. YES
2. YES