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

update interface

parent e3b8c8f7
......@@ -49,7 +49,14 @@ cdef class LPOptimizer:
cdef extern from "mvoptimizer.hpp" namespace "pfopt":
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()
double feval()
int status()
......@@ -64,12 +71,18 @@ cdef class QPOptimizer:
cnp.ndarray[double, ndim=2] cov_matrix,
cnp.ndarray[double] lbound,
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,
cov_matrix.flatten(order='C'),
lbound,
ubound,
cons_matrix.flatten(order='C'),
clbound,
cubound,
risk_aversion)
def __del__(self):
......
......@@ -22,6 +22,7 @@ namespace pfopt {
double riskAversion=1.);
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,
Index &nnz_h_lag, IndexStyleEnum &index_style);
......@@ -44,11 +45,6 @@ namespace pfopt {
Index m, Index nele_jac, Index *iRow, Index *jCol,
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,
Index n, const Number *x, const Number *z_L, const Number *z_U,
Index m, const Number *g, const Number *lambda,
......@@ -66,11 +62,19 @@ namespace pfopt {
VectorXd xReal_;
double riskAversion_;
VectorXd lb_;
VectorXd ub_;
std::vector<double> lb_;
std::vector<double> ub_;
VectorXd grad_f_;
double feval_;
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
......@@ -11,7 +11,10 @@ namespace pfopt {
const std::vector<double> &varMatrix,
const std::vector<double> &lbound,
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(); }
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