<jupyter_start><jupyter_text>Linear optimization<jupyter_code># Import Gurobi package
import gurobipy as gb<jupyter_output><empty_output><jupyter_text>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}<jupyter_code># 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()
# Get values of decision variables
print('x1 =', x1.X)
print('x2 =', x2.X)
print('Objective function value =', m.ObjVal)<jupyter_output>x1 = 27.77777777777778
x2 = 111.11111111111111
Objective function value = 13833.333333333334
{'fraction_non_alphanumeric': 0.14354066985645933, 'fraction_numerical': 0.13516746411483255, 'mean_word_length': 4.894366197183099, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 3, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '649361', 'license': 'MIT', 'n_tokens_mistral': 426, 'n_tokens_neox': 356, 'n_words': 78, 'path': 'Basics of gurobi optimization/01 Linear optimization.ipynb', 'repo_name': 'j-stalder/portfolio-optimization', 'size': '836'}