AnswerBun.com

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.

One Answer

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

Add your own answers!

Related Questions

CPLEX MIP warm start seems slow down the program?

1  Asked on August 19, 2021 by mengfan-ma

   

Two M/M/1 queues working independently

0  Asked on August 19, 2021 by cookiemonster

 

Scheduling with setup cost

0  Asked on August 19, 2021 by dirk-nachbar

 

MINLP Solution same as Global Optimum?

2  Asked on August 19, 2021 by clement

   

Meta papers on operations research

2  Asked on August 19, 2021 by luke599999

 

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

 

Is there any OR way to solve this problem?

3  Asked on August 19, 2021 by samiczy

 

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP