<jupyter_start><jupyter_text>Pyomo - Getting started Pyomo installation: see http://www.pyomo.org/installation```pip install pyomo``` See also these excellent tutorials that details how to install Pyomo and several solvers (GLPK, COIN-OR CBC, COIN-OR Ipopt, ...):- https://nbviewer.jupyter.org/github/jckantor/ND-Pyomo-Cookbook/blob/master/notebooks/01.01-Installing-Pyomo.ipynb- https://nbviewer.jupyter.org/github/jckantor/ND-Pyomo-Cookbook/blob/master/notebooks/01.02-Running-Pyomo-on-Google-Colab.ipynb- https://nbviewer.jupyter.org/github/jckantor/ND-Pyomo-Cookbook/blob/master/notebooks/01.04-Cross-Platform-Installation-of-Pyomo-and-Solvers.ipynb<jupyter_code>from pyomo.environ import *<jupyter_output><empty_output><jupyter_text>Example 1<jupyter_code>model = ConcreteModel(name="Getting started")

model.x = Var(bounds=(-10, 10))

model.obj = Objective(expr=model.x)

model.const_1 = Constraint(expr=model.x >= 5)

# @tail:
opt = SolverFactory('glpk')  # "glpk" or "cbc"

res = opt.solve(model)    # solves and updates instance

model.display()

print()
print("Optimal solution: ", value(model.x))
print("Cost of the optimal solution: ", value(model.obj))
# @:tail<jupyter_output><empty_output><jupyter_text>Example 2 $$\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}$$ ```Optimal total cost is:  350.0x_1 = 50.x_2 = 50.```<jupyter_code>model = ConcreteModel(name="Getting started")

model.x1 = Var(within=NonNegativeReals)
model.x2 = Var(within=NonNegativeReals)

model.obj = Objective(expr=4. * model.x1 + 3. * model.x2, sense=maximize)

model.ineq_const_1 = Constraint(expr=model.x1 + model.x2 <= 100)
model.ineq_const_2 = Constraint(expr=2. * model.x1 + model.x2 <= 150)
model.ineq_const_3 = Constraint(expr=3. * model.x1 + 4. * model.x2 <= 360)

# @tail:
opt = SolverFactory('glpk')  # "glpk" or "cbc"

results = opt.solve(model)    # solves and updates instance

model.display()

print()
print("Optimal solution: ({}, {})".format(value(model.x1), value(model.x2)))
print("Gain of the optimal solution: ", value(model.obj))
# @:tail<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16209150326797386, 'fraction_numerical': 0.03747276688453159, 'mean_word_length': 4.171171171171171, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 14, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '537565', 'license': 'MIT', 'n_tokens_mistral': 947, 'n_tokens_neox': 881, 'n_words': 160, 'path': 'nb_dev_python/python_pyomo_getting_started_1.ipynb', 'repo_name': 'jdhp-docs/python-notebooks', 'size': '2295'}