I want to select specific value from a list result from pyomo abstract model. I have 240 values and I want to divide it into 10 groups and extract the values from each group.I try to make it as a array and slice the specific part of values.But it does't work.
Anyone can help me with it? Thanks!
Code:
...
for j in instance.J:
for t in instance.T:
print(value(instance.P[j,t]))
Result:
...
80.0
80.0
80.0
80.0
80.0
80.0
119.61130640682207
124.38162436892358
148.5439185323972
151.69344888703213
150.13095948759553
153.9634325088356
151.4005914397506
146.00465298729122
...
The data object in question is not a numpy array, so the comments above (unfortunately) won't work. The object is a pyomo model object.
Vivi- You are close. You need to index the object with the index variables as you are doing. Just inspect the .value
attribute (see my edit below). You can push all of these things into a list and lose track of their index (which would be an odd choice, I think) or put them into a python data structure or just print them.
You will also need to chop up the double index you have in some smart way if you want to subdivide. Or just chop up the thing that you put them in afterwards...
all_results = []
for j in instance.J:
for t in instance.T:
all_results.append(instance.P[j,t].value)) # <- note use of "value"
first_half = all_results[:len(all_results)//2]