# PuLP : getting started

PuLP installation:

```
pip install pulp
```

## Simple PuLP Model (bonds_simple-PuLP.py)

$$
\begin{align}
    \max_{x_1,x_2} & \quad 4 x_1 + 3 x_2 \\
    \text{s.t.}    & \quad   x_1 +   x_2 \leq 100 \\
                   & \quad 2 x_1 +   x_2 \leq 150 \\
                   & \quad 3 x_1 + 4 x_2 \leq 360 \\
                   & \quad x_1, x_2 \geq 0
\end{align}
$$

Example taken from: https://www.ima.umn.edu/materials/2017-2018.2/W8.21-25.17/26306/PythonModeling.pdf


```python
from pulp import LpProblem, LpVariable, lpSum, LpMaximize, value
```


```python
prob = LpProblem("Dedication Model", LpMaximize)
```


```python
X1 = LpVariable("X1", 0, None)
X2 = LpVariable("X2", 0, None)
```


```python
# Objective function
prob += 4*X1 + 3*X2              # Objectives are nothing more than expressions without a right hand side

# Constraints
prob +=   X1 +   X2 <= 100
prob += 2*X1 +   X2 <= 150
prob += 3*X1 + 4*X2 <= 360
```


```python
prob.solve()
```


```python
print("Optimal total cost is: ", value(prob.objective))
```


```python
print("X1 :", X1.varValue)
print("X2 :", X2.varValue)
```

89a32863632e37d06c2fef804a7315c01d064c87
ipynb
Jupyter Notebook
nb_dev_python/python_pulp_getting_started.ipynb
jdhp-docs/python-notebooks
91a97ea5cf374337efa7409e4992ea3f26b99179
MIT
2017-05-03T12:23:36.000Z
2020-10-26T17:30:56.000Z
nb_dev_python/python_pulp_getting_started.ipynb
jdhp-docs/python-notebooks
91a97ea5cf374337efa7409e4992ea3f26b99179
MIT
nb_dev_python/python_pulp_getting_started.ipynb
jdhp-docs/python-notebooks
91a97ea5cf374337efa7409e4992ea3f26b99179
MIT
2020-10-26T17:30:57.000Z
2020-10-26T17:30:57.000Z
Qwen/Qwen-72B
1. YES
2. YES