I am trying to figure out a post-processing code to extract data from the output of an indexing-variable in PYOMO. The output of the variable is given below.
x : Size=24, Index=x_index
Key : Lower : Value : Upper : Fixed : Stale : Domain
('alum', 'Face 1') : 0 : 0.0 : 1 : False : False : Binary
('alum', 'Face 2') : 0 : 0.0 : 1 : False : False : Binary
('alum', 'Face 3') : 0 : 0.0 : 1 : False : False : Binary
('alum', 'Face 4') : 0 : 0.0 : 1 : False : False : Binary
('alum', 'Face 5') : 0 : 0.0 : 1 : False : False : Binary
('alum', 'Face 6') : 0 : 0.0 : 1 : False : False : Binary
('copper', 'Face 1') : 0 : 1.0 : 1 : False : False : Binary
('copper', 'Face 2') : 0 : 1.1025499604398013e-08 : 1 : False : False : Binary
('copper', 'Face 3') : 0 : 0.7535049595290465 : 1 : False : False : Binary
('copper', 'Face 4') : 0 : 1.0003766762453678e-08 : 1 : False : False : Binary
('copper', 'Face 5') : 0 : 1.0265826814190929e-08 : 1 : False : False : Binary
('copper', 'Face 6') : 0 : 1.0 : 1 : False : False : Binary
('steel', 'Face 1') : 0 : 0.0 : 1 : False : False : Binary
('steel', 'Face 2') : 0 : 0.0 : 1 : False : False : Binary
('steel', 'Face 3') : 0 : 0.0 : 1 : False : False : Binary
('steel', 'Face 4') : 0 : 0.0 : 1 : False : False : Binary
('steel', 'Face 5') : 0 : 0.0 : 1 : False : False : Binary
('steel', 'Face 6') : 0 : 0.0 : 1 : False : False : Binary
('zinc', 'Face 1') : 0 : 1.0461836921235404e-08 : 1 : False : False : Binary
('zinc', 'Face 2') : 0 : 1.0 : 1 : False : False : Binary
('zinc', 'Face 3') : 0 : 0.24649506011873923 : 1 : False : False : Binary
('zinc', 'Face 4') : 0 : 1.0 : 1 : False : False : Binary
('zinc', 'Face 5') : 0 : 1.0 : 1 : False : False : Binary
('zinc', 'Face 6') : 0 : 9.618909950291308e-09 : 1 : False : False : Binary
The expected output is a dictionary as shown below
selected_materials = {'Face 1':'copper',
'Face 2':'zinc',
'Face 3':'copper',
'Face 4':'zinc',
'Face 5':'zinc',
'Face 6':'copper' }
The idea is to choose a material for each face. The selection criteria is the maximum value obtained in the output variable 'x', for each key (combinations of material, face). Eg. For Face 1, the value is compared among 4 materials and the one with highest value is chosen.
My attempt:
I created a code to find the highest value among materials for an individual face as shown below.
max([pyo.value(mdl.x[m, 'Face 1']) for m in materials])
where m is a list as given below (defined in the initial step of the algorithm)
materials = ['steel', 'alum', 'copper', 'zinc']
But finding the material corresponding to the highest value seems challenging. If someone has an idea, kindly help me.
I would appreciate it if you could suggest me some better idea if any.