Using pyomo module in Matlab

4 ビュー (過去 30 日間)
Ileperff
Ileperff 2022 年 5 月 16 日
コメント済み: hossein jbn 2022 年 9 月 6 日
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 Center および File ExchangeGet 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