问题描述

当利用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−1​xi​s.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}}2x​1​。此时如果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).相关推荐

  1. matlab preloadfcn,simulink中打不开SysytemGenerator?返回错误Error evaluating ...

    小女菜鸟一枚,还请大神们帮助,不胜感激~~ 我安装了matlab 2011b和ISE14.3 但是在simulink里打不开system generator模块,双击设置它的属性时弹出错误: 1Err ...

  2. nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 异常

    出现此异常,一般是动态sql的问题,根据后面的提示信息,找到对应的sql,检查动态sql语法. 问题描述 异常信息: nested exception is org.apache.ibatis.bui ...

  3. Error evaluating expression ‘xxxxx != null and xxxxxx!= ’

    Error evaluating expression 'xxxxx != null and xxxxxx!= "'. Cause: org.apache.ibatis.ognl.OgnlE ...

  4. Vivado System Generator for DSP - “Error evaluating ‘OpenFcn‘ callback of Xilinx Block“错误解决方法

    使用Vivado System Generator for DSP时,遇到"Error evaluating 'OpenFcn' callback of Xilinx Block" ...

  5. nested exception is org.apache.ibatis.builder.BuilderException: Error evaluating expression 的解决办法

    问题概述 在基于微服务架构风格的项目开发过程中,为了提高快速开发的目的,提高开发效率,集成了 MyBatisPlus,对于 MyBatisPlus 封装的 CRUD API 接口已经非常强大了,但是有 ...

  6. org.apache.ibatis.builder.BuilderException: Error evaluating expression ‘p.residentCode‘. Return

    问题: Creating a new SqlSession SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@65915 ...

  7. 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 ...

  8. MP之自定义分页,多表查询带分页带条件(Error evaluating expression ‘ew.customSqlSegment‘.或 Invalid bound statement)

    一.问题 前端所需数据: 但成绩表中只有考生的id及试卷的id,此时就需要进行多表查询,通过考生的id获取姓名字段,通过试卷的id获取试卷名称.分别需要使用到三张表,成绩表,试卷表,考生表.同时需要做 ...

  9. Error evaluating解决xpression ‘ew.sqlSegment != null and ew.sqlSegment != ‘‘ and ew.nonEmptyOfWhere‘.

    (看文章之前要排除,自身的代码bug,本文是在本身代码没问题的基础上,依赖包版本过低导致的) 先上错误和描述,使用的mybatisplus插件,开始用的是3.1.1版本,然后本地运行项目没有问题,之前 ...

  10. MyBatis-plus报错:Error evaluating expression ‘ew.sqlSegment != null

    报错信息 Caused by: org.apache.ibatis.builder.BuilderException: Error evaluating expression 'ew.sqlSegme ...

最新文章

  1. 拜托,面试别再问我JVM了!!!
  2. Python使用matplotlib可视化多个时间序列数据、添加双Y轴、以显示具有不同尺度的时间序列数据(secondary y axis)
  3. 5个找出Linux中“二进制命令”描述和系统中位置的方法
  4. 易语言怎么判断文件是否一样_怎么判断网站建设公司是否正规
  5. 在notebook中如何能完整的显示长文本内容
  6. shell脚本详解(一)——Shell编程规范与变量
  7. Spring: Bean 注册 - BeanDefinitionRegistry
  8. 反欺诈的这几个重点内容值得您关注
  9. W3100SM-S 短信猫代码发送 上
  10. MyBatis3简介
  11. DevCpp和VS2019安装armadillo库
  12. go基础:xml解析
  13. 魔兽三界血歌鸿蒙武器怎么合成,魔兽RPG剑域N3剧情攻略 特殊副本武器合成指南[多图]...
  14. 支付宝提现要手续费吗?
  15. Twitter Inc.(TWTR)2020年第三季度收益电话会议记录
  16. poi2009 切题记
  17. 金属与氧气、酸的反应
  18. paypal是怎么收费的?
  19. 【python】pygame实现植物大战僵尸小游戏(附源码 有注释)
  20. Linux密码策略、连接空闲超时时间设置

热门文章

  1. arcgis 触屏实现键盘模拟
  2. 基于networkx的《人民的名义》人物关系图
  3. 斐讯N1盒子刷Armbian安装jdk做Java服务器
  4. 斐讯n1刷armbian建lnmp环境+WordPress
  5. CoreText(四):行 CTLineRef
  6. 箭头函数写法_JavaScript|箭头函数的用法
  7. 终端安全管理之殇:安全管控能力与用户体验
  8. NAFSM中值滤波器讲解与实现
  9. 小码哥php教程,小码哥Java从0到高级工程师
  10. 一首有趣的回环诗~秦观