bool AmplTNLP::eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f) { DBG_START_METH("AmplTNLP::eval_grad_f", dbg_verbosity); ASL_pfgh* asl = asl_; DBG_ASSERT(asl_); if (!apply_new_x(new_x, n, x)) { return false; } if (n_obj==0) { for (Index i=0; i<n; i++) { grad_f[i] = 0.; } } else { objgrd(obj_no, const_cast<Number*>(x), grad_f, (fint*)nerror_); if (!nerror_ok(nerror_)) { return false; } if (obj_sign_==-1) { for (Index i=0; i<n; i++) { grad_f[i] *= -1.; } } } return true; }
static bool eval_grad_f(void * amplInfo, int n, const double * x, bool new_x, double * grad_f) { CbcAmplInfo * info = (CbcAmplInfo *) amplInfo; ASL_pfgh* asl = info->asl_; if (!apply_new_x(info, new_x, n, x)) { return false; } int i; if (n_obj == 0) { for (i = 0; i < n; i++) { grad_f[i] = 0.; } } else { objgrd(0, info->non_const_x_, grad_f, (fint*)&info->nerror_); if (info->nerror_) { return false; } if (info->obj_sign_ == -1) { for (i = 0; i < n; i++) { grad_f[i] = -grad_f[i]; } } } return true; }
static bool eval_f(void * amplInfo, int n, const double * x, bool new_x, double & obj_value) { CbcAmplInfo * info = (CbcAmplInfo *) amplInfo; if (!apply_new_x(info, new_x, n, x)) { return false; } return internal_objval(info, obj_value); }
bool AmplTNLP::eval_f(Index n, const Number* x, bool new_x, Number& obj_value) { DBG_START_METH("AmplTNLP::eval_f", dbg_verbosity); if (!apply_new_x(new_x, n, x)) { return false; } return internal_objval(x, obj_value); }
bool AmplTNLP::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) { DBG_START_METH("AmplTNLP::eval_h", dbg_verbosity); ASL_pfgh* asl = asl_; DBG_ASSERT(asl_); DBG_ASSERT(n == n_var); DBG_ASSERT(m == n_con); if (iRow && jCol && !values) { // setup the structure int k=0; for (int i=0; i<n; i++) { for (int j=sputinfo->hcolstarts[i]; j<sputinfo->hcolstarts[i+1]; j++) { iRow[k] = i + 1; jCol[k] = sputinfo->hrownos[j]+1; k++; } } DBG_ASSERT(k==nele_hess); return true; } else if (!iRow & !jCol && values) { if (!apply_new_x(new_x, n, x)) { return false; } if (!objval_called_with_current_x_) { Number dummy; internal_objval(x, dummy); internal_conval(x, m); } if (!conval_called_with_current_x_) { internal_conval(x, m); } real* OW = new real[Max(1,n_obj)]; if (n_obj>0) { for (Index i=0; i<n_obj; i++) { OW[i] = 0.; } OW[obj_no] = obj_sign_*obj_factor; } sphes(values, -1, OW, const_cast<Number*>(lambda)); delete [] OW; return true; } else { DBG_ASSERT(false && "Invalid combination of iRow, jCol, and values pointers"); } return false; }
bool AmplTNLP::eval_g(Index n, const Number* x, bool new_x, Index m, Number* g) { DBG_START_METH("AmplTNLP::eval_g", dbg_verbosity); DBG_DO(ASL_pfgh* asl = asl_); DBG_ASSERT(n == n_var); DBG_ASSERT(m == n_con); if (!apply_new_x(new_x, n, x)) { return false; } return internal_conval(x, m, g); }
static bool eval_g(void * amplInfo, int n, const double * x, bool new_x, double * g) { CbcAmplInfo * info = (CbcAmplInfo *) amplInfo; #ifndef NDEBUG ASL_pfgh* asl = info->asl_; #endif // warning: n_var is a macro that assumes we have a variable called asl assert(n == n_var); if (!apply_new_x(info, new_x, n, x)) { return false; } return internal_conval(info, g); }
bool AmplTNLP::eval_jac_g(Index n, const Number* x, bool new_x, Index m, Index nele_jac, Index* iRow, Index *jCol, Number* values) { DBG_START_METH("AmplTNLP::eval_jac_g", dbg_verbosity); ASL_pfgh* asl = asl_; DBG_ASSERT(asl_); DBG_ASSERT(n == n_var); DBG_ASSERT(m == n_con); if (iRow && jCol && !values) { // setup the structure Index current_nz = 0; for (Index i=0; i<n_con; i++) { for (cgrad* cg=Cgrad[i]; cg; cg = cg->next) { iRow[cg->goff] = i + 1; jCol[cg->goff] = cg->varno + 1; // iRow[current_nz] = i + 1; // jCol[current_nz] = cg->varno+1; current_nz++; } } DBG_ASSERT(current_nz == nele_jac); return true; } else if (!iRow && !jCol && values) { if (!apply_new_x(new_x, n, x)) { return false; } jacval(const_cast<Number*>(x), values, (fint*)nerror_); if (nerror_ok(nerror_)) { return true; } } else { DBG_ASSERT(false && "Invalid combination of iRow, jCol, and values pointers"); } return false; }
static bool eval_jac_g(void * amplInfo, int n, const double * x, bool new_x, double * values) { CbcAmplInfo * info = (CbcAmplInfo *) amplInfo; ASL_pfgh* asl = info->asl_; assert(n == n_var); assert (values); if (!apply_new_x(info, new_x, n, x)) { return false; } jacval(info->non_const_x_, values, (fint*)&info->nerror_); if (!info->nerror_) { return true; } else { abort(); } return false; }