From e2bfd64933b6917672eea20d14322c373c39714b Mon Sep 17 00:00:00 2001 From: Jonas Charfreitag Date: Mon, 11 Jan 2021 16:52:25 +0100 Subject: [PATCH 01/10] First fixes. --- geco/mips/scheduling.py | 122 +++++++++++++++++++---------- geco/mips/tests/test_scheduling.py | 74 ++++++++++------- 2 files changed, 125 insertions(+), 71 deletions(-) diff --git a/geco/mips/scheduling.py b/geco/mips/scheduling.py index 6bdf382..859c55b 100644 --- a/geco/mips/scheduling.py +++ b/geco/mips/scheduling.py @@ -9,14 +9,14 @@ def hooker_late_tasks_formulation( - number_of_facilities, - number_of_tasks, - time_steps, - processing_times, - capacities, - assignment_costs, - release_dates, - deadlines, + number_of_facilities, + number_of_tasks, + time_steps, + processing_times, + capacities, + assignment_costs, + release_dates, + deadlines, ): """Generates late tasks mip formulation described in section 4 in Hooker, John. (2005). Planning and Scheduling to Minimize Tardiness. 314-327. 10.1007/11564751_25. @@ -42,7 +42,7 @@ def hooker_late_tasks_formulation( # assignment vars x = {} for j, i, t in itertools.product( - range(number_of_tasks), range(number_of_facilities), time_steps + range(number_of_tasks), range(number_of_facilities), time_steps ): var = model.addVar(lb=0, ub=1, obj=0, name=f"x_{j}_{i}_{t}", vtype="B") x[j, i, t] = var @@ -81,7 +81,7 @@ def hooker_late_tasks_formulation( # constraint (d) for i, j, t in itertools.product( - range(number_of_facilities), range(number_of_tasks), time_steps + range(number_of_facilities), range(number_of_tasks), time_steps ): if t < release_dates[j] or t > len(time_steps) - processing_times[j, i]: model.addCons(x[j, i, t] == 0) @@ -98,19 +98,16 @@ def generate_hookers_instances(): for n, t, seed in itertools.product(number_of_tasks, time_steps, seeds): params = 3, n, t, seed yield params, hooker_late_tasks_formulation( - *params[:-1], *generate_params(*params[:-1])[:-1] + *params[:-1], *generate_hooker_params(*params[:-1])[:-1] ) -@py_random_state(2) -def generate_params(number_of_facilities, number_of_tasks, seed=0): +@py_random_state(-1) +def generate_hooker_params(number_of_facilities, number_of_tasks, seed=0): processing_times = {} for j, i in itertools.product(range(number_of_tasks), range(number_of_facilities)): - if number_of_tasks < 22: - processing_times[j, i] = seed.randint(2, 20 + 5 * i) - else: - processing_times[j, i] = seed.randint(5, 20 + 5 * i) + processing_times[j, i] = seed.randint(2, 20 + 5 * i) capacities = [10] * number_of_facilities @@ -122,10 +119,8 @@ def generate_params(number_of_facilities, number_of_tasks, seed=0): release_times = [0] * number_of_tasks - deadlines = {} beta = 20 / 9 - for j in range(number_of_tasks): - deadlines[j] = seed.uniform(beta * number_of_tasks / 4, beta * number_of_tasks) + deadlines = [seed.uniform(beta * number_of_tasks / 4, beta * number_of_tasks) for _ in range(number_of_tasks)] resource_requirements = {} for j, k in itertools.product(range(number_of_tasks), range(number_of_facilities)): @@ -142,14 +137,14 @@ def generate_params(number_of_facilities, number_of_tasks, seed=0): def heinz_formulation( - number_of_facilities, - number_of_tasks, - processing_times, - capacities, - assignment_costs, - release_dates, - deadlines, - resource_requirements, + number_of_facilities, + number_of_tasks, + processing_times, + capacities, + assignment_costs, + release_dates, + deadlines, + resource_requirements, ): """Generates MIP formulation according to Model 4 in Heinz, J. (2013). Recent Improvements Using Constraint Integer Programming for Resource Allocation and Scheduling. @@ -165,7 +160,12 @@ def heinz_formulation( model: SCIP model of the late tasks instance """ model = scip.Model("Heinz Scheduling") - time_steps = range(min(release_dates), int(max(deadlines.values()))) + + earliest_release = min(release_dates) + latest_deadline = max(deadlines) + longest_processing = max(processing_times.values()) + latest_possible_finish = latest_deadline + longest_processing + time_steps = list(range(int(earliest_release), int(latest_possible_finish))) # objective function x = {} @@ -178,7 +178,7 @@ def heinz_formulation( # y vars y = {} for j, k, t in itertools.product( - range(number_of_tasks), range(number_of_facilities), time_steps + range(number_of_tasks), range(number_of_facilities), time_steps ): if release_dates[j] <= t <= deadlines[j] - processing_times[j, k]: var = model.addVar(lb=0, ub=1, obj=0, name=f"y_{j}_{k}_{t}", vtype="B") @@ -190,17 +190,14 @@ def heinz_formulation( model.addCons(scip.quicksum(x[j, k] for k in range(number_of_facilities)) == 1) # constraint (13) + test = 0 for j, k in itertools.product(range(number_of_tasks), range(number_of_facilities)): - model.addCons( - scip.quicksum( - y[j, k, t] - for t in range( - release_dates[j], int(deadlines[j]) - processing_times[j, k] - ) - if t < len(time_steps) - ) - == x[j, k] - ) + ys = list(y[j, k, t] + for t in range( + release_dates[j], max(0, int(deadlines[j]) - processing_times[j, k]) + )) + model.addCons(scip.quicksum(ys) == x[j, k]) + test += 1 # constraint (14) for k, t in itertools.product(range(number_of_facilities), time_steps): @@ -216,7 +213,7 @@ def heinz_formulation( # constraint (15) epsilon = filter( - lambda ts: ts[0] < ts[1], itertools.product(release_dates, deadlines.values()) + lambda ts: ts[0] < ts[1], itertools.product(release_dates, deadlines) ) for k, (t1, t2) in itertools.product(range(number_of_facilities), epsilon): model.addCons( @@ -229,3 +226,46 @@ def heinz_formulation( ) return model + + +@py_random_state(-1) +def generate_heinz_params(number_of_facilities, number_of_tasks, seed=0): + processing_times = {} + + for j, i in itertools.product(range(number_of_tasks), range(number_of_facilities)): + processing_times[j, i] = seed.randint(2, 20 + 5 * (i-2)) + + capacities = [10] * number_of_facilities + + assignment_costs = {} + for i in range(number_of_facilities): + value = seed.randint(1, 10) + for j in range(number_of_tasks): + assignment_costs[j, i] = value + + release_times = [0] * number_of_tasks + + beta = 20 / 9 + deadlines = [seed.uniform(beta * number_of_tasks / 4, beta * number_of_tasks) for _ in range(number_of_tasks)] + + resource_requirements = {} + for j, k in itertools.product(range(number_of_tasks), range(number_of_facilities)): + resource_requirements[j, k] = seed.randint(1, 9) + + return ( + processing_times, + capacities, + assignment_costs, + release_times, + deadlines, + resource_requirements, + ) + + +def generate_small_heinz_instances(): + number_of_facilities = [3] + number_of_tasks = list(range(10, 38 + 1)) + for n, t in itertools.product(number_of_facilities, number_of_tasks): + params = generate_heinz_params(n, t) + print(params) + yield heinz_formulation(n, t, *params) diff --git a/geco/mips/tests/test_scheduling.py b/geco/mips/tests/test_scheduling.py index 1cd6632..88cd51a 100644 --- a/geco/mips/tests/test_scheduling.py +++ b/geco/mips/tests/test_scheduling.py @@ -5,7 +5,7 @@ def test_late_tasks_formulation(): main_params = number_of_facilities, number_of_tasks, time_steps = 3, 10, 100 - params = p, C, c, R, d = generate_params(*main_params[:-1], seed=0)[:-1] + params = p, C, c, R, d = generate_hooker_params(*main_params[:-1], seed=0)[:-1] model = hooker_late_tasks_formulation(*main_params, *params) check_hookers_instance(model, number_of_facilities, number_of_tasks, time_steps) @@ -18,50 +18,64 @@ def test_hooker_generation(): @pytest.mark.parametrize( "number_of_facilities,number_of_tasks,seed", - itertools.product([1, 2, 3], [5, 10, 15], [0, 1, 1337, 53115]), + itertools.product([3], [20], [0, 1, 1337, 53115]), ) def test_heinz_formulation(number_of_facilities, number_of_tasks, seed): main_params = number_of_facilities, number_of_tasks - params = p, C, c, R, d, r = generate_params(*main_params, seed) - time_steps = int(max(d.values()) - min(R)) + params = p, C, c, R, d, r = generate_hooker_params(*main_params, seed) + time_steps = int(max(d) - min(R)) model = heinz_formulation(*main_params, *params) x_vars_count = number_of_facilities * number_of_tasks y_vars_lowerbound = 0 y_vars_upperbound = number_of_facilities * number_of_tasks * time_steps assert ( - x_vars_count + y_vars_lowerbound - <= model.getNVars() - <= x_vars_count + y_vars_upperbound + x_vars_count + y_vars_lowerbound + <= model.getNVars() + <= x_vars_count + y_vars_upperbound ) constraints_lowerbound = ( - number_of_facilities - + number_of_facilities * number_of_tasks - + number_of_tasks - + number_of_tasks - + number_of_facilities * number_of_tasks - + number_of_facilities * number_of_tasks + number_of_facilities + + number_of_facilities * number_of_tasks + + number_of_tasks + + number_of_tasks + + number_of_facilities * number_of_tasks + + number_of_facilities * number_of_tasks ) constraints_upperbound = ( - number_of_facilities - + number_of_facilities * number_of_tasks - + number_of_tasks * time_steps - + number_of_tasks * (time_steps * (time_steps - 1) // 2) - + number_of_facilities * number_of_tasks - + number_of_facilities * number_of_tasks * time_steps + number_of_facilities + + number_of_facilities * number_of_tasks + + number_of_tasks * time_steps + + number_of_tasks * (time_steps * (time_steps - 1) // 2) + + number_of_facilities * number_of_tasks + + number_of_facilities * number_of_tasks * time_steps ) assert constraints_lowerbound <= model.getNConss() <= constraints_upperbound assert model.getObjectiveSense() == "minimize" model.optimize() + model.hideOutput() + model.optimize() + if model.getStatus == "optimal": + print("Success") + else: + print("Inf") + + +def test_heinz_formulation_small(): + for model in generate_small_heinz_instances(): + model.hideOutput() + model.optimize() + assert model.getStatus() == "optimal" + @pytest.mark.parametrize( "n_resources,n_tasks,seed1,seed2", itertools.product([1, 2, 3], [5, 10, 15], [0, 1, 1337, 53115], [0, 1, 1337, 53115]), ) def test_param_generation_seeding(n_resources, n_tasks, seed1, seed2): - params1 = generate_params(n_resources, n_tasks, seed=seed1) - params2 = generate_params(n_resources, n_tasks, seed=seed2) + params1 = generate_hooker_params(n_resources, n_tasks, seed=seed1) + params2 = generate_hooker_params(n_resources, n_tasks, seed=seed2) same_seeds_produce_same_params = seed1 == seed2 and params1 == params2 different_seeds_produce_different_params = seed1 != seed2 and params1 != params2 assert same_seeds_produce_same_params or different_seeds_produce_different_params @@ -130,19 +144,19 @@ def simple_instance_params(): def check_hookers_instance(model, number_of_facilities, number_of_tasks, time_steps): assert ( - model.getNVars() - == number_of_facilities * number_of_tasks * time_steps + number_of_tasks + model.getNVars() + == number_of_facilities * number_of_tasks * time_steps + number_of_tasks ) constraints_lowerbound = ( - number_of_tasks * time_steps - + number_of_tasks - + number_of_facilities * time_steps + number_of_tasks * time_steps + + number_of_tasks + + number_of_facilities * time_steps ) constraints_upperbound = ( - number_of_tasks * time_steps - + number_of_tasks - + number_of_facilities * time_steps - + number_of_facilities * number_of_tasks * time_steps + number_of_tasks * time_steps + + number_of_tasks + + number_of_facilities * time_steps + + number_of_facilities * number_of_tasks * time_steps ) assert constraints_lowerbound <= model.getNConss() <= constraints_upperbound assert model.getObjectiveSense() == "minimize" From 1f6a6d60b23753aa0266d0353698d41e72a72141 Mon Sep 17 00:00:00 2001 From: Jonas Charfreitag Date: Tue, 12 Jan 2021 11:58:44 +0100 Subject: [PATCH 02/10] heinz.py: Add generator for small heinz instances. --- geco/mips/scheduling/heinz.py | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/geco/mips/scheduling/heinz.py b/geco/mips/scheduling/heinz.py index 904f0b4..ad7d816 100644 --- a/geco/mips/scheduling/heinz.py +++ b/geco/mips/scheduling/heinz.py @@ -1,7 +1,5 @@ -import itertools - import pyscipopt as scip -from networkx.utils import py_random_state + from geco.mips.scheduling.generic import * @@ -74,15 +72,15 @@ def heinz_instance(number_of_facilities, number_of_tasks, seed=0): def heinz_formulation( - number_of_facilities, - number_of_tasks, - processing_times, - capacities, - assignment_costs, - release_dates, - deadlines, - resource_requirements, - name="Heinz Scheduling Formulation", + number_of_facilities, + number_of_tasks, + processing_times, + capacities, + assignment_costs, + release_dates, + deadlines, + resource_requirements, + name="Heinz Scheduling Formulation", ): """Generates scheduling MIP formulation according to Model 4 in [1]. @@ -132,7 +130,7 @@ def heinz_formulation( # y vars y = {} for j, k, t in itertools.product( - range(number_of_tasks), range(number_of_facilities), time_steps + range(number_of_tasks), range(number_of_facilities), time_steps ): if release_dates[j] <= t <= deadlines[j] - processing_times[j, k]: var = model.addVar(lb=0, ub=1, obj=0, name=f"y_{j}_{k}_{t}", vtype="B") @@ -183,3 +181,11 @@ def heinz_formulation( ) return model + + +def generate_small_heinz_instances(): + number_of_facilities = [2] + number_of_tasks = list(range(10, 38 + 1)) + for n, t in itertools.product(number_of_facilities, number_of_tasks): + params = heinz_params(n, t) + yield heinz_formulation(n, t, *params) From cf6fad6b86e40a37f476b39d87957663a25f5fdd Mon Sep 17 00:00:00 2001 From: Jonas Charfreitag Date: Tue, 12 Jan 2021 15:24:22 +0100 Subject: [PATCH 03/10] scheduling: Make dealines a list. --- geco/mips/scheduling/generic.py | 4 +--- geco/mips/scheduling/heinz.py | 4 ++-- geco/mips/tests/test_scheduling.py | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/geco/mips/scheduling/generic.py b/geco/mips/scheduling/generic.py index bd72a7b..1aa4733 100644 --- a/geco/mips/scheduling/generic.py +++ b/geco/mips/scheduling/generic.py @@ -58,10 +58,8 @@ def generate_params(number_of_facilities, number_of_tasks, seed=0): release_times = [0] * number_of_tasks - deadlines = {} beta = 20 / 9 - for j in range(number_of_tasks): - deadlines[j] = seed.uniform(beta * number_of_tasks / 4, beta * number_of_tasks) + deadlines = [seed.uniform(beta * number_of_tasks / 4, beta * number_of_tasks) for _ in range(number_of_tasks)] resource_requirements = {} for j, k in itertools.product(range(number_of_tasks), range(number_of_facilities)): diff --git a/geco/mips/scheduling/heinz.py b/geco/mips/scheduling/heinz.py index ad7d816..b9c46b4 100644 --- a/geco/mips/scheduling/heinz.py +++ b/geco/mips/scheduling/heinz.py @@ -117,7 +117,7 @@ def heinz_formulation( """ model = scip.Model(name) - time_steps = range(min(release_dates), int(max(deadlines.values()))) + time_steps = range(min(release_dates), int(max(deadlines))) # objective function x = {} @@ -168,7 +168,7 @@ def heinz_formulation( # constraint (15) epsilon = filter( - lambda ts: ts[0] < ts[1], itertools.product(release_dates, deadlines.values()) + lambda ts: ts[0] < ts[1], itertools.product(release_dates, deadlines) ) for k, (t1, t2) in itertools.product(range(number_of_facilities), epsilon): model.addCons( diff --git a/geco/mips/tests/test_scheduling.py b/geco/mips/tests/test_scheduling.py index 0c6b5f4..e4b111d 100644 --- a/geco/mips/tests/test_scheduling.py +++ b/geco/mips/tests/test_scheduling.py @@ -22,7 +22,7 @@ def test_hooker_generation(): def test_heinz_formulation(number_of_facilities, number_of_tasks, seed): main_params = number_of_facilities, number_of_tasks p, C, c, R, d, r = heinz_params(*main_params, seed) - time_steps = int(max(d.values()) - min(R)) + time_steps = int(max(d) - min(R)) model = heinz_instance(*main_params) x_vars_count = number_of_facilities * number_of_tasks y_vars_lowerbound = 0 From 368bad78881fbfb293b351e3e204c8c3751aad67 Mon Sep 17 00:00:00 2001 From: Jonas Charfreitag Date: Tue, 12 Jan 2021 15:26:04 +0100 Subject: [PATCH 04/10] scheduling: Make dealines a list. --- geco/mips/tests/test_scheduling.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/geco/mips/tests/test_scheduling.py b/geco/mips/tests/test_scheduling.py index e4b111d..be0394e 100644 --- a/geco/mips/tests/test_scheduling.py +++ b/geco/mips/tests/test_scheduling.py @@ -75,7 +75,7 @@ def test_hooker_simple_instance(): def test_heinz_simple_instance(): - ( + params = ( n_resources, n_tasks, time_steps, @@ -86,6 +86,7 @@ def test_heinz_simple_instance(): deadlines, resource_requirements, ) = _simple_instance_params() + print(params) heinz_model = heinz_formulation( n_resources, n_tasks, @@ -112,7 +113,7 @@ def _simple_instance_params(): release_times = [0] # change the deadline to 0 or 1 to make it infeasible for the heinz formulation # and add 1 late task to the hooker formulation - deadlines = {0: 2} + deadlines = [2] resource_requirements = {(0, 0): 1} return ( n_resources, From 17b9cccb7dc7180d038069916a2097307b8670c6 Mon Sep 17 00:00:00 2001 From: Jonas Charfreitag Date: Tue, 12 Jan 2021 15:26:32 +0100 Subject: [PATCH 05/10] scheduling: Make dealines a list. --- geco/mips/tests/test_scheduling.py | 1 - 1 file changed, 1 deletion(-) diff --git a/geco/mips/tests/test_scheduling.py b/geco/mips/tests/test_scheduling.py index be0394e..20a37a9 100644 --- a/geco/mips/tests/test_scheduling.py +++ b/geco/mips/tests/test_scheduling.py @@ -86,7 +86,6 @@ def test_heinz_simple_instance(): deadlines, resource_requirements, ) = _simple_instance_params() - print(params) heinz_model = heinz_formulation( n_resources, n_tasks, From 8aa4f22e0da1dac9b6f7af23bc5fca723f5f0b64 Mon Sep 17 00:00:00 2001 From: Jonas Charfreitag Date: Tue, 12 Jan 2021 15:29:02 +0100 Subject: [PATCH 06/10] black the code --- geco/mips/scheduling/generic.py | 5 ++++- geco/mips/scheduling/heinz.py | 20 ++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/geco/mips/scheduling/generic.py b/geco/mips/scheduling/generic.py index 1aa4733..90203a5 100644 --- a/geco/mips/scheduling/generic.py +++ b/geco/mips/scheduling/generic.py @@ -59,7 +59,10 @@ def generate_params(number_of_facilities, number_of_tasks, seed=0): release_times = [0] * number_of_tasks beta = 20 / 9 - deadlines = [seed.uniform(beta * number_of_tasks / 4, beta * number_of_tasks) for _ in range(number_of_tasks)] + deadlines = [ + seed.uniform(beta * number_of_tasks / 4, beta * number_of_tasks) + for _ in range(number_of_tasks) + ] resource_requirements = {} for j, k in itertools.product(range(number_of_tasks), range(number_of_facilities)): diff --git a/geco/mips/scheduling/heinz.py b/geco/mips/scheduling/heinz.py index b9c46b4..8a70d74 100644 --- a/geco/mips/scheduling/heinz.py +++ b/geco/mips/scheduling/heinz.py @@ -72,15 +72,15 @@ def heinz_instance(number_of_facilities, number_of_tasks, seed=0): def heinz_formulation( - number_of_facilities, - number_of_tasks, - processing_times, - capacities, - assignment_costs, - release_dates, - deadlines, - resource_requirements, - name="Heinz Scheduling Formulation", + number_of_facilities, + number_of_tasks, + processing_times, + capacities, + assignment_costs, + release_dates, + deadlines, + resource_requirements, + name="Heinz Scheduling Formulation", ): """Generates scheduling MIP formulation according to Model 4 in [1]. @@ -130,7 +130,7 @@ def heinz_formulation( # y vars y = {} for j, k, t in itertools.product( - range(number_of_tasks), range(number_of_facilities), time_steps + range(number_of_tasks), range(number_of_facilities), time_steps ): if release_dates[j] <= t <= deadlines[j] - processing_times[j, k]: var = model.addVar(lb=0, ub=1, obj=0, name=f"y_{j}_{k}_{t}", vtype="B") From c55cfaf815d26e554c4cca0b74ffe82fe8459bd4 Mon Sep 17 00:00:00 2001 From: Jonas Charfreitag <33812320+CharJon@users.noreply.github.com> Date: Tue, 12 Jan 2021 15:36:02 +0100 Subject: [PATCH 07/10] Type (big -> bug) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5ab697f..adbedc9 100644 --- a/README.md +++ b/README.md @@ -62,4 +62,4 @@ All the following instances are implemented following some of the generation tec - Graph Coloring # Contributing -If you want to add some new generator, fix a big or enhance the repository in some way, please refer to our [guide](CONTRIBUTING.md). +If you want to add some new generator, fix a bug or enhance the repository in some way, please refer to our [guide](CONTRIBUTING.md). From c487c04c0804be5d7037188e32e577dc0eaaafd3 Mon Sep 17 00:00:00 2001 From: Jonas Charfreitag Date: Mon, 15 Feb 2021 08:59:21 +0100 Subject: [PATCH 08/10] black --- examples/test_scheduling.ipynb | 216 +++++++++++++++++++++++++++++++++ geco/mips/scheduling/heinz.py | 39 ++++-- 2 files changed, 245 insertions(+), 10 deletions(-) create mode 100644 examples/test_scheduling.ipynb diff --git a/examples/test_scheduling.ipynb b/examples/test_scheduling.ipynb new file mode 100644 index 0000000..1aa5f9d --- /dev/null +++ b/examples/test_scheduling.ipynb @@ -0,0 +1,216 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "collapsed": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "optimal\n", + "infeasible\n", + "optimal\n", + "optimal\n", + "optimal\n", + "infeasible\n", + "optimal\n", + "optimal\n", + "optimal\n", + "infeasible\n", + "optimal\n", + "optimal\n", + "infeasible\n", + "optimal\n", + "infeasible\n", + "infeasible\n", + "optimal\n", + "optimal\n", + "optimal\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "optimal\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "optimal\n", + "optimal\n", + "optimal\n", + "infeasible\n", + "optimal\n", + "infeasible\n", + "optimal\n", + "optimal\n", + "optimal\n", + "infeasible\n", + "infeasible\n", + "optimal\n", + "optimal\n", + "optimal\n", + "optimal\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "optimal\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "optimal\n", + "optimal\n", + "optimal\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "optimal\n", + "optimal\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "optimal\n", + "optimal\n", + "optimal\n", + "infeasible\n", + "optimal\n", + "optimal\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "optimal\n", + "optimal\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "optimal\n", + "userinterrupt\n", + "userinterrupt\n", + "infeasible\n", + "infeasible\n", + "infeasible\n", + "infeasible\n" + ] + }, + { + "ename": "KeyboardInterrupt", + "evalue": "", + "output_type": "error", + "traceback": [ + "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", + "\u001B[0;31mKeyboardInterrupt\u001B[0m Traceback (most recent call last)", + "\u001B[0;32m\u001B[0m in \u001B[0;36m\u001B[0;34m\u001B[0m\n\u001B[1;32m 4\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 5\u001B[0m \u001B[0;32mfor\u001B[0m \u001B[0mt\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mrange\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mnum_tries\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m----> 6\u001B[0;31m \u001B[0;32mfor\u001B[0m \u001B[0mm\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mgenerate_heinz_instances\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mt\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 7\u001B[0m \u001B[0mm\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0moptimize\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 8\u001B[0m \u001B[0mprint\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mm\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mgetStatus\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", + "\u001B[0;32m~/Projects/GeCO/geco/mips/scheduling/heinz.py\u001B[0m in \u001B[0;36mgenerate_heinz_instances\u001B[0;34m(seed)\u001B[0m\n\u001B[1;32m 86\u001B[0m \u001B[0;32mfor\u001B[0m \u001B[0mi\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mj\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mitertools\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mproduct\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mnum_resources\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mnum_jobs\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 87\u001B[0m \u001B[0mgenerated\u001B[0m \u001B[0;34m+=\u001B[0m \u001B[0;36m1\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m---> 88\u001B[0;31m \u001B[0;32myield\u001B[0m \u001B[0mheinz_instance\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mi\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mj\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mseed\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 89\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 90\u001B[0m \u001B[0;32massert\u001B[0m \u001B[0mgenerated\u001B[0m \u001B[0;34m==\u001B[0m \u001B[0;36m39\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", + "\u001B[0;32m\u001B[0m in \u001B[0;36mheinz_instance\u001B[0;34m(number_of_facilities, number_of_tasks, seed)\u001B[0m\n", + "\u001B[0;32m~/miniconda3/envs/geco/lib/python3.8/site-packages/networkx/utils/decorators.py\u001B[0m in \u001B[0;36m_random_state\u001B[0;34m(func, *args, **kwargs)\u001B[0m\n\u001B[1;32m 467\u001B[0m \u001B[0mnew_args\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mlist\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0margs\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 468\u001B[0m \u001B[0mnew_args\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0mrandom_state_index\u001B[0m\u001B[0;34m]\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mrandom_state\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 469\u001B[0;31m \u001B[0;32mreturn\u001B[0m \u001B[0mfunc\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m*\u001B[0m\u001B[0mnew_args\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m**\u001B[0m\u001B[0mkwargs\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 470\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 471\u001B[0m \u001B[0;32mreturn\u001B[0m \u001B[0m_random_state\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", + "\u001B[0;32m~/Projects/GeCO/geco/mips/scheduling/heinz.py\u001B[0m in \u001B[0;36mheinz_instance\u001B[0;34m(number_of_facilities, number_of_tasks, seed)\u001B[0m\n\u001B[1;32m 64\u001B[0m \u001B[0;34m(\u001B[0m\u001B[0mpp\u001B[0m\u001B[0;34m.\u001B[0m \u001B[0;36m12\u001B[0m\u001B[0;31m–\u001B[0m\u001B[0;36m27\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m.\u001B[0m \u001B[0mSpringer\u001B[0m \u001B[0mBerlin\u001B[0m \u001B[0mHeidelberg\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 65\u001B[0m \"\"\"\n\u001B[0;32m---> 66\u001B[0;31m return heinz_formulation(\n\u001B[0m\u001B[1;32m 67\u001B[0m \u001B[0mnumber_of_facilities\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 68\u001B[0m \u001B[0mnumber_of_tasks\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", + "\u001B[0;32m~/Projects/GeCO/geco/mips/scheduling/heinz.py\u001B[0m in \u001B[0;36mheinz_formulation\u001B[0;34m(number_of_facilities, number_of_tasks, processing_times, capacities, assignment_costs, release_dates, deadlines, resource_requirements, name)\u001B[0m\n\u001B[1;32m 177\u001B[0m \u001B[0;32mfor\u001B[0m \u001B[0mk\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mt\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mitertools\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mproduct\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mrange\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mnumber_of_facilities\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mtime_steps\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 178\u001B[0m model.addCons(\n\u001B[0;32m--> 179\u001B[0;31m scip.quicksum(\n\u001B[0m\u001B[1;32m 180\u001B[0m \u001B[0mresource_requirements\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0mj\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mk\u001B[0m\u001B[0;34m]\u001B[0m \u001B[0;34m*\u001B[0m \u001B[0my\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0mj\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mk\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mt_prime\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 181\u001B[0m \u001B[0;32mfor\u001B[0m \u001B[0mj\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mrange\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mnumber_of_tasks\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", + "\u001B[0;32msrc/pyscipopt/expr.pxi\u001B[0m in \u001B[0;36mpyscipopt.scip.quicksum\u001B[0;34m()\u001B[0m\n", + "\u001B[0;32m~/Projects/GeCO/geco/mips/scheduling/heinz.py\u001B[0m in \u001B[0;36m\u001B[0;34m(.0)\u001B[0m\n\u001B[1;32m 181\u001B[0m \u001B[0;32mfor\u001B[0m \u001B[0mj\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mrange\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mnumber_of_tasks\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 182\u001B[0m \u001B[0;32mfor\u001B[0m \u001B[0mt_prime\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mrange\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mt\u001B[0m \u001B[0;34m-\u001B[0m \u001B[0mprocessing_times\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0mj\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mk\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mt\u001B[0m \u001B[0;34m+\u001B[0m \u001B[0;36m1\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 183\u001B[0;31m \u001B[0;32mif\u001B[0m \u001B[0;34m(\u001B[0m\u001B[0mj\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mk\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mt_prime\u001B[0m\u001B[0;34m)\u001B[0m \u001B[0;32min\u001B[0m \u001B[0my\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 184\u001B[0m )\n\u001B[1;32m 185\u001B[0m \u001B[0;34m<=\u001B[0m \u001B[0mcapacities\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0mk\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", + "\u001B[0;31mKeyboardInterrupt\u001B[0m: " + ] + } + ], + "source": [ + "from geco.mips.scheduling import *\n", + "\n", + "num_tries = 5\n", + "\n", + "for t in range(num_tries):\n", + " for m in generate_heinz_instances(t):\n", + " m.optimize()\n", + " print(m.getStatus())" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 2 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython2", + "version": "2.7.6" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} \ No newline at end of file diff --git a/geco/mips/scheduling/heinz.py b/geco/mips/scheduling/heinz.py index 8a70d74..8e0d2f2 100644 --- a/geco/mips/scheduling/heinz.py +++ b/geco/mips/scheduling/heinz.py @@ -71,16 +71,35 @@ def heinz_instance(number_of_facilities, number_of_tasks, seed=0): ) +@py_random_state(-1) +def generate_heinz_instances(seed): + generated = 0 + + num_resources = [2] + num_jobs = list(range(10, 38 + 1, 2)) + for i, j in itertools.product(num_resources, num_jobs): + generated += 1 + yield heinz_instance(i, j, seed) + + num_resources = [3, 4] + num_jobs = list(range(10, 32 + 1, 2)) + for i, j in itertools.product(num_resources, num_jobs): + generated += 1 + yield heinz_instance(i, j, seed) + + assert generated == 39 + + def heinz_formulation( - number_of_facilities, - number_of_tasks, - processing_times, - capacities, - assignment_costs, - release_dates, - deadlines, - resource_requirements, - name="Heinz Scheduling Formulation", + number_of_facilities, + number_of_tasks, + processing_times, + capacities, + assignment_costs, + release_dates, + deadlines, + resource_requirements, + name="Heinz Scheduling Formulation", ): """Generates scheduling MIP formulation according to Model 4 in [1]. @@ -130,7 +149,7 @@ def heinz_formulation( # y vars y = {} for j, k, t in itertools.product( - range(number_of_tasks), range(number_of_facilities), time_steps + range(number_of_tasks), range(number_of_facilities), time_steps ): if release_dates[j] <= t <= deadlines[j] - processing_times[j, k]: var = model.addVar(lb=0, ub=1, obj=0, name=f"y_{j}_{k}_{t}", vtype="B") From 33910f5f6e829a43c48f7899b13106891820695d Mon Sep 17 00:00:00 2001 From: Mohammed Ghannam Date: Mon, 22 Feb 2021 09:40:22 +0100 Subject: [PATCH 09/10] Black --- geco/mips/scheduling/heinz.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/geco/mips/scheduling/heinz.py b/geco/mips/scheduling/heinz.py index 8e0d2f2..9bf4ad5 100644 --- a/geco/mips/scheduling/heinz.py +++ b/geco/mips/scheduling/heinz.py @@ -91,15 +91,15 @@ def generate_heinz_instances(seed): def heinz_formulation( - number_of_facilities, - number_of_tasks, - processing_times, - capacities, - assignment_costs, - release_dates, - deadlines, - resource_requirements, - name="Heinz Scheduling Formulation", + number_of_facilities, + number_of_tasks, + processing_times, + capacities, + assignment_costs, + release_dates, + deadlines, + resource_requirements, + name="Heinz Scheduling Formulation", ): """Generates scheduling MIP formulation according to Model 4 in [1]. @@ -149,7 +149,7 @@ def heinz_formulation( # y vars y = {} for j, k, t in itertools.product( - range(number_of_tasks), range(number_of_facilities), time_steps + range(number_of_tasks), range(number_of_facilities), time_steps ): if release_dates[j] <= t <= deadlines[j] - processing_times[j, k]: var = model.addVar(lb=0, ub=1, obj=0, name=f"y_{j}_{k}_{t}", vtype="B") From 268975759e29d000754989d42709dc48624114ef Mon Sep 17 00:00:00 2001 From: Mohammed Ghannam Date: Mon, 22 Feb 2021 10:01:31 +0100 Subject: [PATCH 10/10] Remove unrelated code --- examples/test_scheduling.ipynb | 216 --------------------------------- geco/mips/scheduling/heinz.py | 27 ----- 2 files changed, 243 deletions(-) delete mode 100644 examples/test_scheduling.ipynb diff --git a/examples/test_scheduling.ipynb b/examples/test_scheduling.ipynb deleted file mode 100644 index 1aa5f9d..0000000 --- a/examples/test_scheduling.ipynb +++ /dev/null @@ -1,216 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "collapsed": true - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "optimal\n", - "infeasible\n", - "optimal\n", - "optimal\n", - "optimal\n", - "infeasible\n", - "optimal\n", - "optimal\n", - "optimal\n", - "infeasible\n", - "optimal\n", - "optimal\n", - "infeasible\n", - "optimal\n", - "infeasible\n", - "infeasible\n", - "optimal\n", - "optimal\n", - "optimal\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "optimal\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "optimal\n", - "optimal\n", - "optimal\n", - "infeasible\n", - "optimal\n", - "infeasible\n", - "optimal\n", - "optimal\n", - "optimal\n", - "infeasible\n", - "infeasible\n", - "optimal\n", - "optimal\n", - "optimal\n", - "optimal\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "optimal\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "optimal\n", - "optimal\n", - "optimal\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "optimal\n", - "optimal\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "optimal\n", - "optimal\n", - "optimal\n", - "infeasible\n", - "optimal\n", - "optimal\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "optimal\n", - "optimal\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "optimal\n", - "userinterrupt\n", - "userinterrupt\n", - "infeasible\n", - "infeasible\n", - "infeasible\n", - "infeasible\n" - ] - }, - { - "ename": "KeyboardInterrupt", - "evalue": "", - "output_type": "error", - "traceback": [ - "\u001B[0;31m---------------------------------------------------------------------------\u001B[0m", - "\u001B[0;31mKeyboardInterrupt\u001B[0m Traceback (most recent call last)", - "\u001B[0;32m\u001B[0m in \u001B[0;36m\u001B[0;34m\u001B[0m\n\u001B[1;32m 4\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 5\u001B[0m \u001B[0;32mfor\u001B[0m \u001B[0mt\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mrange\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mnum_tries\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m----> 6\u001B[0;31m \u001B[0;32mfor\u001B[0m \u001B[0mm\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mgenerate_heinz_instances\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mt\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 7\u001B[0m \u001B[0mm\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0moptimize\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 8\u001B[0m \u001B[0mprint\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mm\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mgetStatus\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", - "\u001B[0;32m~/Projects/GeCO/geco/mips/scheduling/heinz.py\u001B[0m in \u001B[0;36mgenerate_heinz_instances\u001B[0;34m(seed)\u001B[0m\n\u001B[1;32m 86\u001B[0m \u001B[0;32mfor\u001B[0m \u001B[0mi\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mj\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mitertools\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mproduct\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mnum_resources\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mnum_jobs\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 87\u001B[0m \u001B[0mgenerated\u001B[0m \u001B[0;34m+=\u001B[0m \u001B[0;36m1\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m---> 88\u001B[0;31m \u001B[0;32myield\u001B[0m \u001B[0mheinz_instance\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mi\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mj\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mseed\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 89\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 90\u001B[0m \u001B[0;32massert\u001B[0m \u001B[0mgenerated\u001B[0m \u001B[0;34m==\u001B[0m \u001B[0;36m39\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", - "\u001B[0;32m\u001B[0m in \u001B[0;36mheinz_instance\u001B[0;34m(number_of_facilities, number_of_tasks, seed)\u001B[0m\n", - "\u001B[0;32m~/miniconda3/envs/geco/lib/python3.8/site-packages/networkx/utils/decorators.py\u001B[0m in \u001B[0;36m_random_state\u001B[0;34m(func, *args, **kwargs)\u001B[0m\n\u001B[1;32m 467\u001B[0m \u001B[0mnew_args\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mlist\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0margs\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 468\u001B[0m \u001B[0mnew_args\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0mrandom_state_index\u001B[0m\u001B[0;34m]\u001B[0m \u001B[0;34m=\u001B[0m \u001B[0mrandom_state\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 469\u001B[0;31m \u001B[0;32mreturn\u001B[0m \u001B[0mfunc\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0;34m*\u001B[0m\u001B[0mnew_args\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0;34m**\u001B[0m\u001B[0mkwargs\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 470\u001B[0m \u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 471\u001B[0m \u001B[0;32mreturn\u001B[0m \u001B[0m_random_state\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", - "\u001B[0;32m~/Projects/GeCO/geco/mips/scheduling/heinz.py\u001B[0m in \u001B[0;36mheinz_instance\u001B[0;34m(number_of_facilities, number_of_tasks, seed)\u001B[0m\n\u001B[1;32m 64\u001B[0m \u001B[0;34m(\u001B[0m\u001B[0mpp\u001B[0m\u001B[0;34m.\u001B[0m \u001B[0;36m12\u001B[0m\u001B[0;31m–\u001B[0m\u001B[0;36m27\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m.\u001B[0m \u001B[0mSpringer\u001B[0m \u001B[0mBerlin\u001B[0m \u001B[0mHeidelberg\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 65\u001B[0m \"\"\"\n\u001B[0;32m---> 66\u001B[0;31m return heinz_formulation(\n\u001B[0m\u001B[1;32m 67\u001B[0m \u001B[0mnumber_of_facilities\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 68\u001B[0m \u001B[0mnumber_of_tasks\u001B[0m\u001B[0;34m,\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", - "\u001B[0;32m~/Projects/GeCO/geco/mips/scheduling/heinz.py\u001B[0m in \u001B[0;36mheinz_formulation\u001B[0;34m(number_of_facilities, number_of_tasks, processing_times, capacities, assignment_costs, release_dates, deadlines, resource_requirements, name)\u001B[0m\n\u001B[1;32m 177\u001B[0m \u001B[0;32mfor\u001B[0m \u001B[0mk\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mt\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mitertools\u001B[0m\u001B[0;34m.\u001B[0m\u001B[0mproduct\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mrange\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mnumber_of_facilities\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mtime_steps\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m:\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 178\u001B[0m model.addCons(\n\u001B[0;32m--> 179\u001B[0;31m scip.quicksum(\n\u001B[0m\u001B[1;32m 180\u001B[0m \u001B[0mresource_requirements\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0mj\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mk\u001B[0m\u001B[0;34m]\u001B[0m \u001B[0;34m*\u001B[0m \u001B[0my\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0mj\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mk\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mt_prime\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 181\u001B[0m \u001B[0;32mfor\u001B[0m \u001B[0mj\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mrange\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mnumber_of_tasks\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", - "\u001B[0;32msrc/pyscipopt/expr.pxi\u001B[0m in \u001B[0;36mpyscipopt.scip.quicksum\u001B[0;34m()\u001B[0m\n", - "\u001B[0;32m~/Projects/GeCO/geco/mips/scheduling/heinz.py\u001B[0m in \u001B[0;36m\u001B[0;34m(.0)\u001B[0m\n\u001B[1;32m 181\u001B[0m \u001B[0;32mfor\u001B[0m \u001B[0mj\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mrange\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mnumber_of_tasks\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[1;32m 182\u001B[0m \u001B[0;32mfor\u001B[0m \u001B[0mt_prime\u001B[0m \u001B[0;32min\u001B[0m \u001B[0mrange\u001B[0m\u001B[0;34m(\u001B[0m\u001B[0mt\u001B[0m \u001B[0;34m-\u001B[0m \u001B[0mprocessing_times\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0mj\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mk\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mt\u001B[0m \u001B[0;34m+\u001B[0m \u001B[0;36m1\u001B[0m\u001B[0;34m)\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0;32m--> 183\u001B[0;31m \u001B[0;32mif\u001B[0m \u001B[0;34m(\u001B[0m\u001B[0mj\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mk\u001B[0m\u001B[0;34m,\u001B[0m \u001B[0mt_prime\u001B[0m\u001B[0;34m)\u001B[0m \u001B[0;32min\u001B[0m \u001B[0my\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n\u001B[0m\u001B[1;32m 184\u001B[0m )\n\u001B[1;32m 185\u001B[0m \u001B[0;34m<=\u001B[0m \u001B[0mcapacities\u001B[0m\u001B[0;34m[\u001B[0m\u001B[0mk\u001B[0m\u001B[0;34m]\u001B[0m\u001B[0;34m\u001B[0m\u001B[0;34m\u001B[0m\u001B[0m\n", - "\u001B[0;31mKeyboardInterrupt\u001B[0m: " - ] - } - ], - "source": [ - "from geco.mips.scheduling import *\n", - "\n", - "num_tries = 5\n", - "\n", - "for t in range(num_tries):\n", - " for m in generate_heinz_instances(t):\n", - " m.optimize()\n", - " print(m.getStatus())" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 2 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython2", - "version": "2.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 0 -} \ No newline at end of file diff --git a/geco/mips/scheduling/heinz.py b/geco/mips/scheduling/heinz.py index 9bf4ad5..8e7a8d0 100644 --- a/geco/mips/scheduling/heinz.py +++ b/geco/mips/scheduling/heinz.py @@ -71,25 +71,6 @@ def heinz_instance(number_of_facilities, number_of_tasks, seed=0): ) -@py_random_state(-1) -def generate_heinz_instances(seed): - generated = 0 - - num_resources = [2] - num_jobs = list(range(10, 38 + 1, 2)) - for i, j in itertools.product(num_resources, num_jobs): - generated += 1 - yield heinz_instance(i, j, seed) - - num_resources = [3, 4] - num_jobs = list(range(10, 32 + 1, 2)) - for i, j in itertools.product(num_resources, num_jobs): - generated += 1 - yield heinz_instance(i, j, seed) - - assert generated == 39 - - def heinz_formulation( number_of_facilities, number_of_tasks, @@ -200,11 +181,3 @@ def heinz_formulation( ) return model - - -def generate_small_heinz_instances(): - number_of_facilities = [2] - number_of_tasks = list(range(10, 38 + 1)) - for n, t in itertools.product(number_of_facilities, number_of_tasks): - params = heinz_params(n, t) - yield heinz_formulation(n, t, *params)