当前位置: 首页>>代码示例>>Python>>正文


Python NLP.constraints方法代码示例

本文整理汇总了Python中openopt.NLP.constraints方法的典型用法代码示例。如果您正苦于以下问题:Python NLP.constraints方法的具体用法?Python NLP.constraints怎么用?Python NLP.constraints使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在openopt.NLP的用法示例。


在下文中一共展示了NLP.constraints方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: oovars

# 需要导入模块: from openopt import NLP [as 别名]
# 或者: from openopt.NLP import constraints [as 别名]
from FuncDesigner import *
from openopt import NLP
a, b, c = oovars('a', 'b', 'c')
f = sum(a*[1, 2])**2+b**2+c**2
startPoint = {a:[100, 12], b:2, c:40}
p = NLP(f, startPoint)
p.constraints = [(2*c+a-10)**2<1.5, (a-10)**2<1.5, a[0]>8.9, a+b>[ 7.97999836,  7.8552538 ], \
                 a<9, (c-2)**2<1, b<-1.02, c>1.01, log2(c-15*a/b)+a>4, ((b+2*c-1)**2).eq(0)]
r = p.solve('ralg', iprint =1)
print r.xf
# {a: array([ 8.99999769,  8.87525255]), b: array([-1.0199994]), c: array([ 1.01000874])}
开发者ID:PythonCharmers,项目名称:OOSuite,代码行数:13,代码来源:t_opt.py

示例2: oovars

# 需要导入模块: from openopt import NLP [as 别名]
# 或者: from openopt.NLP import constraints [as 别名]
from FuncDesigner import *
from openopt import NLP

a, b, c = oovars('a', 'b', 'c')
f = sum(a*[1, 2])**2+b**2+c**2
startPoint = {a:[100, 12], b:2, c:40} # however, you'd better use numpy arrays instead of Python lists
p = NLP(f, startPoint)
p.constraints = [(2*c+a-10)**2 < 1.5 + 0.1*b, (a-10)**2<1.5, a[0]>8.9, (a+b > [ 7.97999836, 7.8552538 ])('sum_a_b', tol=1.00000e-12), \
a < 9, ((c-2)**2 < 1), (b < -1.02), c > 1.01, ((b + c * log10(a).sum() - 1) ** 2==0)(tol=1e-6)]
r = p.minimize('ralg', plot=0, xtol=1e-7)
#r = p.solve('ralg') # for NLPs old-style (openopt 0.25 and below) p.solve() is same to p.minimize()
#r = p.maximize('ralg')
print(r.xf)
print(a(r.xf))
a_opt,  b_opt, c_opt = r(a, b, c)
# or any of the following: 
# a_opt,  b_opt, c_opt = r(a), r(b), r(c)
# r('a'), r('b'), r('c') (provided you have assigned the names to oovars as above)
# r('a', 'b', 'c')
# a(r), b(r), c(r)

"""
Expected output:
...
objFunValue: 717.75631 (feasible, max constraint =  7.44605e-07)
{a: array([ 8.99999792,  8.87525277]), b: array([-1.01999971]), c: array([ 1.0613562])}
"""
开发者ID:PythonCharmers,项目名称:OOSuite,代码行数:29,代码来源:nlp1.py

示例3: oovar

# 需要导入模块: from openopt import NLP [as 别名]
# 或者: from openopt.NLP import constraints [as 别名]
from FuncDesigner import *
from openopt import NLP, oosolver
from numpy import arange
N = 10
a = oovar('a', size=N)
b = oovar('b', size=N)
f = (sum(abs(a*arange(1,N+1))**2.5)+sum(abs(b*arange(1,N+1))**1.5)) / 10000

startPoint = {a:cos(arange(N)), b:sin(arange(N))} # however, you'd better use numpy arrays instead of Python lists
p = NLP(f, startPoint)
#p.constraints = [(a>1)(tol=1e-5), a**2+b**2 < 0.1+a+b]# + [(a[i]**2+b[i]**2 < 3+abs(a[i])+abs(b[i])) for i in range(N)]

p.constraints = [a>1, 10*a>10]          # + [(a[i]**2+b[i]**2 < 3+abs(a[i])+abs(b[i])) for i in range(N)]
#p.constraints = []
#C = sum(a**2+b**2 - (0.1+a+b)
C = [ifThenElse(a[i]**2+b[i]**2 - (0.1+a[i]+b[i])<0,  0,  a[i]**2+b[i]**2 - (0.1+a[i]+b[i])) for i in range(N)]
p.constraints.append(sum(C)<0)
solver = 'ipopt'
solver = oosolver('ralg')
#solver = oosolver('ralg', approach='nqp')
r = p.minimize(solver, maxIter = 15000)
开发者ID:PythonCharmers,项目名称:OOSuite,代码行数:23,代码来源:nlp_mixed.py


注:本文中的openopt.NLP.constraints方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。