Pyomo variable creation dilemma

Operations Research Asked by Ethan Deakins on October 31, 2020

I am working on a pyomo model, and need to create a few different sets of variables that are dependent on a solution from a master model. I need the variables to be indexed variables however the conventional method of using "Var(indexSet1, indexSet2, indexSet3, etc.)" is not applicable because "indexSet2, indexSet3, etc." are dependent upon the current index of "indexSet1". So as an example if I have an index set called crews = [0,1,2], then I will have a two dimensional array of jobs where the first index of the array is the crew and the second index of the set is job one of the jobs assigned to that crew. So jobs would look like [[0,3,7], [1,2,6],[4,5]]. Then I would like to create a variable "x_ij" using the first index set and the second two dimensional array. I tried x_ij= Var(crews, jobs[crews]) but this obviously didn’t work. I also tried the add_component method which does add the correct variables to the model, but I tried to store them in a python dict with the keys being their index tuple (i,j), however, add_component does not have a return value so my dict has the form dict = {(i,j): none}. Any help on how to do this would be greatly appreciated.

I am preparing a list of tuple of index based on the conditions, after then giving to index parameter to "Var". For your problem, if I understand it correctly, this will be enough:

index_list = [(0,1),(0,3), (0,7), (1,1), (1,2), (1,6), (2,4), (2,5)]
x_ij = Var(index_list)


You can prepare this list any way, such as:

index_list = []
for crew in crews:
for job in jobs[crew]:
index_list.append((crew,job))


Answered by kur ag on October 31, 2020

Related Questions

What is a general procedure to prove that the LP relaxation of an IP delivers the optimal IP solution?

2  Asked on August 19, 2021 by k88074

CPLEX MIP warm start seems slow down the program?

1  Asked on August 19, 2021 by mengfan-ma

(Iterative?) Solutions to a certain quadratic program with non-convex constraints

2  Asked on August 19, 2021 by cfp

Problem with implementing squared terms in the objective function

1  Asked on August 19, 2021 by poofybridge

Scheduling with setup cost

0  Asked on August 19, 2021 by dirk-nachbar

Is a convex or MILP (without big-M) formulation possible for this problem

1  Asked on August 19, 2021 by batwing

MINLP Solution same as Global Optimum?

2  Asked on August 19, 2021 by clement

Linear objective function with non-linear constraints

2  Asked on August 19, 2021 by fightmilk

Meta papers on operations research

2  Asked on August 19, 2021 by luke599999

Verifying the correctness of KKT conditions

0  Asked on August 19, 2021 by s_scouse

How can I use warm start in C#

1  Asked on August 19, 2021 by fhm-ider

Feasible sets represented as point clouds

1  Asked on August 19, 2021 by harry-cohen

Is this the same as Agent Based DES or something different?

0  Asked on August 19, 2021 by brendan-hill

Column generation when intractable variables appear in the objective function

1  Asked on August 19, 2021 by mostafa

Is there any OR way to solve this problem?

3  Asked on August 19, 2021 by samiczy

Find a particular optimal solution

1  Asked on August 19, 2021 by ljg

How to find all vertices of a polyhedron

3  Asked on August 19, 2021

Can every convex problem use Lagrangian dual method?

0  Asked on August 19, 2021

Does strong duality hold when I dualize only a subset of the constraints?

1  Asked on August 19, 2021 by george-chang

Get help from others!