Using pyomo module in Matlab

4 次查看(过去 30 天)
Hi everyone,
I'm currtly working on a project involving pyomo in matlab. I've managed to use other python modules in matlab (numpy for example), in different ways without any problem. It seems I've also succeed in creating a pyomo ConcreteModel from matlab. However, I can't get RangeSet() to work. I'll explain what I've tired and I hope someone can see what I've done wrong.
Fisrt with line command:
mod = py.importlib.import_module('pyomo');
py.RangeSet() % Option 1
py.pyomo.RangeSet() % Option 2
py.mod.RangeSet() % Option 3
None of this is working, each time I get the same error 'Unable to resolve the name py.RangeSet.'
Second I've try calling a pyhton file (testRangeFile.py):
mod = py.importlib.import_module('pyomo');
test = py.importlib.import_module('testRangeFile');
test.testRange(2)
test.testRangeFile.testRange(2)
My pyhton fuction for testing being:
def testRange(value):
from pyomo.environ import pyomo % also tried importing outside def
return pyomo.RangeSet(value)
In that case the error is 'Unrecognized method, property, or field 'testRange' for class 'py.module'.'
I don't know what else to try, and I can't figure out why this is not working when the other modules/functions are. If someone as an explanation so I uderstand best how this works it would help a lot.
Thanks for reading :)
PS: I'm using 2020b
  1 个评论
hossein jbn
hossein jbn 2022-9-6
Hi my friend
i would like to add pyomo in matlab but i don't know how i can do it. please guide me. to contact me you can send an email to Hossein.jobran77@gmail.com.
thanks a lot

请先登录,再进行评论。

采纳的回答

Ileperff
Ileperff 2022-5-19
I did'nt managed to solve this problem. But in case some faces the same issue, I avoided it by recreating RangeSet() on my own (which is quite easy) and then call it in Matlab:
def MyRangeSet(value):
array = []
for i in range(1, value+1):
array.append(i)
return array

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by