<jupyter_start><jupyter_text>Feasibility Pump example  Installing the packages In the following we use the `GurobiSolver` and thus need to install gurobi.<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 First add the required imports:<jupyter_code>from hips import load_problem
from hips.heuristics._feasibility_pump import FeasibilityPump<jupyter_output><empty_output><jupyter_text>Now let us load a problem. In this example we load the `10teams` example from MIPLIB 2017. The example can be found [here](https://miplib.zib.de/instance_details_10teams.html).<jupyter_code>mip_model = load_problem("10teams")<jupyter_output><empty_output><jupyter_text>Now let us create Feasibility Pump and specify the iteration maximum `max_iter` to 1000 and the perturbation factor `t` to 15:<jupyter_code>heur = FeasibilityPump(mip_model, t=15)
heur.compute(max_iter=1000)<jupyter_output><empty_output><jupyter_text>Now let us inspect the solution found:<jupyter_code>print("Status: {}".format(heur.get_status()))
print("Found solution: {}".format(heur.get_objective_value()))
heur.tracker.plot("feasibility objective")<jupyter_output><empty_output><jupyter_text>Playing with the parameter  The Feasibility Pump can achieve quite different solutions, depending on the parameter `t`. This parameter represent how many variables we perturb, in case a cycle is detected. Let us therefore play with its values.To avoid different outcomes in the following experiments, we will furthermore set a seed for the Feasibility Pump.<jupyter_code>import time
import numpy as np<jupyter_output><empty_output><jupyter_text>We will start of with a high value for `t`:<jupyter_code>print("#-------- Start experiment 1 --------#")"

feasible = []
times = []
test_number = 5
for i in range(test_number):
    mip_model = hips.load_problem_gurobi("10teams")

    mip_model.set_mip_sense(ProblemSense.MIN)
    start = time.time()

    fs = FeasibilityPump(mip_model, t=20, seed=i)
    fs.compute(1000)

    end = time.time()

    sol = {var: fs.variable_solution(var) for var in mip_model.lp_model.vars}
    feasible.append(mip_model.is_feasible(sol))

    times.append(end-start)
    print("Model {} solved.".format(i))

print("#----------------------------------#")
print("Feasible solutions found in {} tests: {}".format(test_number, sum(feasible)))

print(times)
print("Average time consumed: {}s".format(sum(times)/len(times)))

times = np.array(times)
feasible_times = times[np.array(feasible)]
print("Average time consumed for feasible solutions: {}s".format(sum(feasible_times)/len(feasible_times)))<jupyter_output><empty_output><jupyter_text>We should observe, that every run of the Feasibility Pump has found a solution. The runtime of each specific computation,does not differ much from the average.Now we will do the same computations with a lower value for `t`:<jupyter_code>print("#-------- Start experiment 2 --------#")"

feasible = []
times = []
test_number = 5
for i in range(test_number):
    mip_model = hips.load_problem_gurobi("10teams")

    mip_model.set_mip_sense(ProblemSense.MIN)
    start = time.time()

    fs = FeasibilityPump(mip_model, t=4, seed=i)
    fs.compute(1000)

    end = time.time()

    sol = {var: fs.variable_solution(var) for var in mip_model.lp_model.vars}
    feasible.append(mip_model.is_feasible(sol))

    times.append(end-start)
    print("Model {} solved.".format(i))

print("#----------------------------------#")
print("Feasible solutions found in {} tests: {}".format(test_number, sum(feasible)))

print(times)
print("Average time consumed: {}s".format(sum(times)/len(times)))

times = np.array(times)
feasible_times = times[np.array(feasible)]
print("Average time consumed for feasible solutions: {}s".format(sum(feasible_times)/len(feasible_times)))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1389442231075697, 'fraction_numerical': 0.010209163346613545, 'mean_word_length': 5.376190476190477, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 2, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '569198', 'license': 'MIT', 'n_tokens_mistral': 1377, 'n_tokens_neox': 1287, 'n_words': 320, 'path': 'notebooks/.ipynb_checkpoints/feasibility_pump_example-checkpoint.ipynb', 'repo_name': 'cxlvinchau/hips-examples', 'size': '4016'}