Loading 3D索引参数从CSV文件到Python Pyomo优化模型并调试约束。

huangapple go评论78阅读模式
英文:

loading 3d index parameters from CSV files into python pyomo optimization model and debugging constraints

问题

I'm having trouble debugging my Abstract Model (it can't be Concrete) and I really don't understand why. I would really appreciate some help. I attach my GitHub repo with the Jupyter Notebook and the sets and parameters as CSV files. https://github.com/juanraposo2000/PYOMO

I tried debugging it several times, changing constraints, and uploading CSV files of parameters, but it doesn't work.

英文:

I'm having trouble debbuging my Abstract Model (it can't be Concrete) and i really don't understand why. I would really appreciate some help. I attach my github repo with the Jupyter Notebook and the sets and parameters as CSV files. https://github.com/juanraposo2000/PYOMO

I tried debbuging it several times, changing constraints and uploading csv files of parameters but it doesnt work.

答案1

得分: 0

In the future, if you post the code into the question as a minimally reproducible example, you will receive better and quicker responses, rather than providing a link to an external site.

Your issue is related to the syntax used in your constraints. You originally have this:

# Upper thermal limit
def Upper_Thermal_rule(model, t, n, s, p):
    return m.qt[t, n, s, p] <= m.u[t, n, s, p] * m.k[t] * m.qmax[t]

You should make this fix (in all of them):

# Upper thermal limit
def Upper_Thermal_rule(m, t, n, s, p):
    return m.qt[t, n, s, p] <= m.u[t, n, s, p] * m.k[t] * m.qmax[t]

Note that the first argument in the function is m instead of model. You can use any consistent name, but it must be consistent throughout your code. In your function, model refers to your model, so when it encounters m.qt[], it produces an error because m is not defined.

Make sure to find and replace in all of your constraints to ensure consistency. Additionally, check that you are passing in all the required parameters in several of the constraints, such as Upper_Hydro. Carefully read the error messages for guidance.

英文:

In the future, you'll get better/quicker responses if you post the code into the question in a minimally reproducible example instead of a link to some external site.

That said, you are closer than you think. Your issue is in the syntax you used in your constraints. You have this:

    #Upper thermal limit 
def Upper_Thermal_rule(model,t,n,s,p):
    return m.qt[t,n,s,p] <= m.u[t,n,s,p] * m.k[t] * m.qmax[t]

You should have this fix (in all of them):

    #Upper thermal limit 
def Upper_Thermal_rule(m,t,n,s,p):
    return m.qt[t,n,s,p] <= m.u[t,n,s,p] * m.k[t] * m.qmax[t]

Note that the first argument in the function is m instead of model. You can actually use any/either/or something else, but it must be consistent. Inside your function, model refers to your model, so when it gets to m.qt[] it barfs because m is not defined.

Do a find/replace in all of your constraints and make them consistent, and then you'll note that in several of the constraints you are not passing in the parameters (like Upper_Hydro). Just read the errors closely and you'll get there.

huangapple
  • 本文由 发表于 2023年5月15日 08:35:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76250230.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定