pyomo / Ipopt : Error evaluating constraint 1: can‘t evaluate pow‘(0,0.5).
问题描述
当利用pyomo与ipopt求解的非线性凸优化问题形式类似以下形式时:
min∑i=0N−1xis.t.x≥1.0\min \sum_{i=0}^{N-1} x_i \\ s.t. \text{ } \sqrt{x}\geq 1.0mini=0∑N−1xis.t. x≥1.0
from pyomo.environ import *
from pyomo.dae import *
N = 5
m = ConcreteModel()
m.s = Var(RangeSet(0, N-1))
m.s_cons = Constraint(RangeSet(0, N-1), rule=lambda m, i: m.s[i]**(0.5) >= 1.0)
m.obj = Objective(expr=sum(m.s[i] for i in RangeSet(0, N-1)), sense=minimize)
%time SolverFactory('ipopt').solve(m)
会报错Error evaluating constraint 1: can't evaluate pow'(0,0.5).
问题分析
错误提示信息为Error evaluating constraint 1: can't evaluate pow'(0,0.5).
,也即无法评估pow'(0, 0.5)
。此函数中的'
字符表示一阶导数。我们对x\sqrt{x}x求导得12x\frac{1}{2\sqrt{x}}2x1。此时如果x=0x=0x=0时,计算机求得x\sqrt{x}x导数的值。所以才会报错。我们发现xnx^{n}xn中的n<1n<1n<1时,都会出现以上错误。
解决方法
当xnx^{n}xn中的n<1n<1n<1时,将变量绑定到非零值:m.s = Var(RangeSet(0, N-1), bounds=(1e-20,None))
from pyomo.environ import *
from pyomo.dae import *
N = 5
m = ConcreteModel()
m.s = Var(RangeSet(0, N-1), bounds=(1e-20,None))
m.s_cons = Constraint(RangeSet(0, N-1), rule=lambda m, i: m.s[i]**(0.5) >= 1.0)
m.obj = Objective(expr=sum(m.s[i] for i in RangeSet(0, N-1)), sense=minimize)
%time SolverFactory('ipopt').solve(m)
m.display()
print("the opt x is:", [m.s[i]() for i in range(N)])
运行结果如下:
pyomo / Ipopt : Error evaluating constraint 1: can‘t evaluate pow‘(0,0.5).相关推荐
- matlab preloadfcn,simulink中打不开SysytemGenerator?返回错误Error evaluating ...
小女菜鸟一枚,还请大神们帮助,不胜感激~~ 我安装了matlab 2011b和ISE14.3 但是在simulink里打不开system generator模块,双击设置它的属性时弹出错误: 1Err ...
- nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 异常
出现此异常,一般是动态sql的问题,根据后面的提示信息,找到对应的sql,检查动态sql语法. 问题描述 异常信息: nested exception is org.apache.ibatis.bui ...
- Error evaluating expression ‘xxxxx != null and xxxxxx!= ’
Error evaluating expression 'xxxxx != null and xxxxxx!= "'. Cause: org.apache.ibatis.ognl.OgnlE ...
- Vivado System Generator for DSP - “Error evaluating ‘OpenFcn‘ callback of Xilinx Block“错误解决方法
使用Vivado System Generator for DSP时,遇到"Error evaluating 'OpenFcn' callback of Xilinx Block" ...
- nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 的解决办法
问题概述 在基于微服务架构风格的项目开发过程中,为了提高快速开发的目的,提高开发效率,集成了 MyBatisPlus,对于 MyBatisPlus 封装的 CRUD API 接口已经非常强大了,但是有 ...
- org.apache.ibatis.builder.BuilderException: Error evaluating expression ‘p.residentCode‘. Return
问题: Creating a new SqlSession SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@65915 ...
- Caused by: org.apache.ibatis.builder.BuilderException: Error evaluating expression ‘dept.name
Caused by: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'dept.name != nul ...
- MP之自定义分页,多表查询带分页带条件(Error evaluating expression ‘ew.customSqlSegment‘.或 Invalid bound statement)
一.问题 前端所需数据: 但成绩表中只有考生的id及试卷的id,此时就需要进行多表查询,通过考生的id获取姓名字段,通过试卷的id获取试卷名称.分别需要使用到三张表,成绩表,试卷表,考生表.同时需要做 ...
- Error evaluating解决xpression ‘ew.sqlSegment != null and ew.sqlSegment != ‘‘ and ew.nonEmptyOfWhere‘.
(看文章之前要排除,自身的代码bug,本文是在本身代码没问题的基础上,依赖包版本过低导致的) 先上错误和描述,使用的mybatisplus插件,开始用的是3.1.1版本,然后本地运行项目没有问题,之前 ...
- MyBatis-plus报错:Error evaluating expression ‘ew.sqlSegment != null
报错信息 Caused by: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'ew.sqlSegme ...
最新文章
- 拜托,面试别再问我JVM了!!!
- Python使用matplotlib可视化多个时间序列数据、添加双Y轴、以显示具有不同尺度的时间序列数据(secondary y axis)
- 5个找出Linux中“二进制命令”描述和系统中位置的方法
- 易语言怎么判断文件是否一样_怎么判断网站建设公司是否正规
- 在notebook中如何能完整的显示长文本内容
- shell脚本详解(一)——Shell编程规范与变量
- Spring: Bean 注册 - BeanDefinitionRegistry
- 反欺诈的这几个重点内容值得您关注
- W3100SM-S 短信猫代码发送 上
- MyBatis3简介
- DevCpp和VS2019安装armadillo库
- go基础:xml解析
- 魔兽三界血歌鸿蒙武器怎么合成,魔兽RPG剑域N3剧情攻略 特殊副本武器合成指南[多图]...
- 支付宝提现要手续费吗?
- Twitter Inc.(TWTR)2020年第三季度收益电话会议记录
- poi2009 切题记
- 金属与氧气、酸的反应
- paypal是怎么收费的?
- 【python】pygame实现植物大战僵尸小游戏(附源码 有注释)
- Linux密码策略、连接空闲超时时间设置