Commit 0ee8b1cb authored by Dr.李's avatar Dr.李

update interface

parent e3b8c8f7
...@@ -49,7 +49,14 @@ cdef class LPOptimizer: ...@@ -49,7 +49,14 @@ cdef class LPOptimizer:
cdef extern from "mvoptimizer.hpp" namespace "pfopt": cdef extern from "mvoptimizer.hpp" namespace "pfopt":
cdef cppclass MVOptimizer: cdef cppclass MVOptimizer:
MVOptimizer(vector[double], vector[double], vector[double], vector[double], double) except + MVOptimizer(vector[double],
vector[double],
vector[double],
vector[double],
vector[double],
vector[double],
vector[double],
double) except +
vector[double] xValue() vector[double] xValue()
double feval() double feval()
int status() int status()
...@@ -64,12 +71,18 @@ cdef class QPOptimizer: ...@@ -64,12 +71,18 @@ cdef class QPOptimizer:
cnp.ndarray[double, ndim=2] cov_matrix, cnp.ndarray[double, ndim=2] cov_matrix,
cnp.ndarray[double] lbound, cnp.ndarray[double] lbound,
cnp.ndarray[double] ubound, cnp.ndarray[double] ubound,
double risk_aversion): cnp.ndarray[double, ndim=2] cons_matrix,
cnp.ndarray[double] clbound,
cnp.ndarray[double] cubound,
double risk_aversion=1.0):
self.cobj = new MVOptimizer(expected_return, self.cobj = new MVOptimizer(expected_return,
cov_matrix.flatten(order='C'), cov_matrix.flatten(order='C'),
lbound, lbound,
ubound, ubound,
cons_matrix.flatten(order='C'),
clbound,
cubound,
risk_aversion) risk_aversion)
def __del__(self): def __del__(self):
......
...@@ -22,6 +22,7 @@ namespace pfopt { ...@@ -22,6 +22,7 @@ namespace pfopt {
double riskAversion=1.); double riskAversion=1.);
bool setBoundedConstraint(const std::vector<double>& lb, const std::vector<double>& ub); bool setBoundedConstraint(const std::vector<double>& lb, const std::vector<double>& ub);
bool setLinearConstrains(const std::vector<double>& consMatrix, const std::vector<double>& clb, const std::vector<double>& cub);
virtual bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g, virtual bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g,
Index &nnz_h_lag, IndexStyleEnum &index_style); Index &nnz_h_lag, IndexStyleEnum &index_style);
...@@ -44,11 +45,6 @@ namespace pfopt { ...@@ -44,11 +45,6 @@ namespace pfopt {
Index m, Index nele_jac, Index *iRow, Index *jCol, Index m, Index nele_jac, Index *iRow, Index *jCol,
Number *values); Number *values);
virtual bool eval_h(Index n, const Number* x, bool new_x,
Number obj_factor, Index m, const Number* lambda,
bool new_lambda, Index nele_hess, Index* iRow,
Index* jCol, Number* values);
virtual void finalize_solution(SolverReturn status, virtual void finalize_solution(SolverReturn status,
Index n, const Number *x, const Number *z_L, const Number *z_U, Index n, const Number *x, const Number *z_L, const Number *z_U,
Index m, const Number *g, const Number *lambda, Index m, const Number *g, const Number *lambda,
...@@ -66,11 +62,19 @@ namespace pfopt { ...@@ -66,11 +62,19 @@ namespace pfopt {
VectorXd xReal_; VectorXd xReal_;
double riskAversion_; double riskAversion_;
VectorXd lb_; std::vector<double> lb_;
VectorXd ub_; std::vector<double> ub_;
VectorXd grad_f_; VectorXd grad_f_;
double feval_; double feval_;
std::vector<double> x_; std::vector<double> x_;
std::vector<Index> iRow_;
std::vector<Index> jCol_;
std::vector<double> g_grad_values_;
std::vector<double> consMatrix_;
std::vector<double> clb_;
std::vector<double> cub_;
Index m_;
}; };
} }
#endif #endif
...@@ -11,7 +11,10 @@ namespace pfopt { ...@@ -11,7 +11,10 @@ namespace pfopt {
const std::vector<double> &varMatrix, const std::vector<double> &varMatrix,
const std::vector<double> &lbound, const std::vector<double> &lbound,
const std::vector<double> &ubound, const std::vector<double> &ubound,
double riskAversion); const std::vector<double> &consMatrix = std::vector<double>(),
const std::vector<double> &clb = std::vector<double>(),
const std::vector<double> &cub = std::vector<double>(),
double riskAversion = 1.);
std::vector<double> xValue() const { return mvImpl_->xValue(); } std::vector<double> xValue() const { return mvImpl_->xValue(); }
double feval() const { return mvImpl_->feval(); } double feval() const { return mvImpl_->feval(); }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment