提交 812fb556 编写于 作者: J Julien Schueller

SWIG: Fix get_initial_step wrapping

Closes #319
上级 a10f7bc2
......@@ -340,7 +340,7 @@ Just as in the C API, you can [get and set the initial step sizes](NLopt_Referen
```
opt.set_initial_step(dx)
opt.get_initial_step(x)
dx = opt.get_initial_step(x)
```
......
......@@ -17,6 +17,10 @@ namespace std {
%template(nlopt_doublevector) vector<double>;
};
// dont use the in-place version of get_initial_step
%ignore nlopt::opt::get_initial_step;
%rename(get_initial_step) nlopt::opt::get_initial_step_;
// prepend "nlopt_" in Guile to substitute for namespace
#if defined(SWIGGUILE)
%rename(nlopt_opt) nlopt::opt;
......
......@@ -25,7 +25,8 @@
(myconstraint x grad -1 1))
1e-8)
(nlopt-opt-set-xtol-rel opt 1e-4)
(define x (nlopt-opt-optimize opt (vector 1.234 5.678)))
(define x0 (vector 1.234 5.678))
(define x (nlopt-opt-optimize opt x0))
(define minf (nlopt-opt-last-optimum-value opt))
(define result (nlopt-opt-last-optimize-result opt))
(display "x=")
......@@ -34,3 +35,6 @@
(display "minf=")
(display minf)
(newline)
(define ini_step (nlopt-opt-get-initial-step opt x0))
(display "initial step")
(display ini_step)
......@@ -23,9 +23,11 @@ opt.set_min_objective(myfunc)
opt.add_inequality_constraint(lambda x, grad: myconstraint(x,grad, 2, 0), 1e-8)
opt.add_inequality_constraint(lambda x, grad: myconstraint(x,grad, -1, 1), 1e-8)
opt.set_xtol_rel(1e-4)
x = opt.optimize([1.234, 5.678])
x0 = [1.234, 5.678]
x = opt.optimize(x0)
minf = opt.last_optimum_value()
print('optimum at ', x[0], x[1])
print('optimum at ', x)
print('minimum value = ', minf)
print('result code = ', opt.last_optimize_result())
print('nevals = ', opt.get_numevals())
print('initial step =', opt.get_initial_step(x0))
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册