In an abstract model from the pyomo library I have three different Sets, each one depending on the previous one and with different dimension size.
model.V = pyo.Set()
model.P = pyo.Set(model.V)
model.m = pyo.Set(model.V, model.P)
When I try to load the Set values from a JSON file, the following Exception is raised:
TypeError: Cannot index a component with an indexed set
Here is the code from the JSON file:
{
"V" : [1, 2, 3],
"P" : {"1": [1, 2],
"2": [1, 2, 3],
"3": [1]},
"m" : {"1": [{"1": [1, 2],
"2": [1, 2, 3, 4]}],
"2": [{"1": [1],
"2": [1, 2],
"3": [1, 2, 3]}],
"3": [{"1": [1, 2, 3, 4, 5, 6]}]}
}
I suppose the problem is due to the definition of m in the JSON file because the Traceback takes me to the model.m = pyo.Set(model.V, model.P)
line.
I have checked the documentation of Pyomo Data Portals, but I got no information of 3D JSON data.
Does any one know which is the error in the definition of the 3 dimensional m set?
I solved the error of my problem. I found that you have to prove all the possible indices of the sets.
This are the set definitions
model.V = pyo.Set()
model.P = pyo.Set(dimen=2)
model.m = pyo.Set(dimen=3)
And this is the JSON file:
{
"V" : [1, 2],
"P" : [[1, 1], [1, 2],
[2, 1], [2, 2]],
"m" : [[1, 1, 1], [1, 1, 2],
[1, 2, 1],
[2, 1, 1], [2, 1, 2],
[2, 2, 1]]
}