TransWikia.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!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP