<jupyter_start><jupyter_text>Simple linear programLet us start with defining a linear program in HIPS. First, we need to decide which solver we would like to use. In this example we use the `GurobiSolver`, but any other supported solver also works. Under the hood, HIPS adds variables and constraints directly to the concrete solver to increase efficiency.  Installing the packages<jupyter_code>%%capture
!pip install gurobipy<jupyter_output><empty_output><jupyter_text>Afterwards, we can install hips.<jupyter_code>%%capture
!pip install https://github.com/cxlvinchau/hips/archive/master.zip<jupyter_output><empty_output><jupyter_text>Example 1 **Creating the model**<jupyter_code>from hips import ProblemSense
from hips.solver import GurobiSolver
from hips.models import LPModel

# Create solver
solver = GurobiSolver()
# Create LP model
model = LPModel(solver)
# Create variables
x_1, x_2 = model.add_variable("x_1", lb=0), model.add_variable("x_2", lb=0)
# Set sense
model.set_lp_sense(ProblemSense.MAX)
# Set objective
model.set_objective(2*x_1 + 4*x_2)
# Add constraints
model.add_constraint(x_1 + 2*x_2 <= 20)
model.add_constraint(3*x_1 - x_2 <= 10)<jupyter_output><empty_output><jupyter_text>**Optimizing the model**<jupyter_code>model.optimize()<jupyter_output><empty_output><jupyter_text>**Output the objective value**<jupyter_code>model.get_objective_value()<jupyter_output><empty_output><jupyter_text>**Output values of the variables**<jupyter_code>print(f"x_1: {model.variable_solution(x_1)}")
print(f"x_2: {model.variable_solution(x_2)}")<jupyter_output><empty_output><jupyter_text>Note that the values of variables is a `HIPSArray`.  Example 2 **Creating the model**<jupyter_code>from hips import ProblemSense
from hips.solver import GurobiSolver
from hips.models import LPModel, HIPSArray

# Create solver
solver = GurobiSolver()
# Create LP model
model = LPModel(solver)
# Create 2 dim. variable with lower bound 0
x = model.add_variable("x", lb=0, dim=2)
# Set sense
model.set_lp_sense(ProblemSense.MAX)
# Set objective
model.set_objective(HIPSArray([2, 4]) * x)
# Add constraint
model.add_constraint(HIPSArray([[1, 2], [3, -1]]) * x <= HIPSArray([20, 10]))<jupyter_output><empty_output><jupyter_text>**Optimizing the model**<jupyter_code>model.optimize()<jupyter_output><empty_output><jupyter_text>**Output the objective value**<jupyter_code>model.get_objective_value()<jupyter_output><empty_output><jupyter_text>**Output the value of the variable**<jupyter_code>model.variable_solution(x)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11623325453112687, 'fraction_numerical': 0.015760441292356184, 'mean_word_length': 8.438661710037175, 'pattern_counts': {'":': 0, '<': 44, '<?xml version=': 0, '>': 41, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '26845', 'license': 'MIT', 'n_tokens_mistral': 922, 'n_tokens_neox': 888, 'n_words': 199, 'path': 'notebooks/simple-lp-example.ipynb', 'repo_name': 'cxlvinchau/hips-examples', 'size': '2538'}