我已经编写了一个使用pyOpt执行NSGA2优化的过程,但是该解决方案打印出优化变量以及相应的约束。我想使用优化变量进行进一步分析。如何输出最终设计变量列表?
例如,优化的输出如下:
NSGA-II Solution to Reservoir Operations Optimization
Objective Function: benefit
Solution:
--------------------------------------------------------------------------------
Total Time: 358.4790
Total Function Evaluations:
Objectives:
Name Value Optimum
f -19539.3 0
Variables (c - continuous, i - integer, d - discrete):
Name Type Value Lower Bound Upper Bound
x_0 c 1523.796492 1.50e+03 9.00e+03
x_1 c 5064.324074 1.50e+03 9.00e+03
x_2 c 2162.772045 1.50e+03 9.00e+03
x_3 c 3177.890807 1.50e+03 9.00e+03
x_4 c 2318.221792 1.50e+03 9.00e+03
x_5 c 1801.992503 1.50e+03 9.00e+03
x_6 c 4205.181367 1.50e+03 9.00e+03
x_7 c 1500.013593 1.50e+03 9.00e+03
x_8 c 1500.026373 1.50e+03 9.00e+03
x_9 c 1500.002134 1.50e+03 9.00e+03
x_10 c 1500.000983 1.50e+03 9.00e+03
x_11 c 1500.007746 1.50e+03 9.00e+03
x_12 c 1500.001387 1.50e+03 9.00e+03
x_13 c 1500.023302 1.50e+03 9.00e+03
x_14 c 1500.019080 1.50e+03 9.00e+03
x_15 c 1500.001947 1.50e+03 9.00e+03
Constraints (i - inequality, e - equality):
Name Type Bounds
g_0 i -1.00e+21 <= -265630.357944 <= 0.00e+00
g_1 i -1.00e+21 <= -274500.633582 <= 0.00e+00
g_2 i -1.00e+21 <= -277659.633602 <= 0.00e+00
但是,我只想将x_0,x_1 ......的值作为列表。
答案 0 :(得分:1)
要解决此问题,您必须将优化问题产生的结果保存到变量中
因此,您必须执行类似的操作
from pyOpt import Optimization, ALHSO
# Make the objective function
def of(x):
return x**2, [], 0
# Setup the optimisation problem
opt_prob = Optimization('min_sq', of)
opt_prob.addVar('x', 'c', value=10, lower=-10, upper=10)
opt_eng = ALHSO()
opt_eng.setOption('fileout', 0)
sol = opt_eng(opt_prob)
从这一点开始,结果变量(sol)将是具有以下内容的列表:
词典附加信息
>>sol
(array([ 1.15734425e-08]),
array([ 0.00010758]),
{'fevals': 398,
'opt_g': array([], dtype=float64),
'time': 0.007999897003173828})
我希望这可以解决问题
答案 1 :(得分:0)
您也可以从解决方案结构中获取变量的值:
docker run -t -p 7000:3000 react-app:latest