Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

How to pass json object to pyomo solvers?

I have a json object that contains data that I want to pass to the glpk solver in pyomo. I have tried passing this data directly using the code below :

jsonObj = {"i" : i , "j" : j , "data" : [....]}
instance = model.create_instance(jsonObj)

The above code does not create the instance, so I tried converting my json object into json file and then execute the below code :

with open('data.json', 'w') as outfile:
    json.dump(jsonObj, outfile)

data = DataPortal()
data.load(filename='data.json')

instance = model.create_instance(data)

But this throws a TypeError : array is not json serializable.

How do I pass my data in json object to pyomo solvers and successfully create a model?

Comments