17 #include "CoinHelperFunctions.hpp"
18 #include "CoinTime.hpp"
22 #if defined HAVE_CSTDINT
24 #elif defined HAVE_STDINT_H
36 #define OBJ_DE ((const ASL_fg *) asl) -> I.obj_de_
37 #define VAR_E ((const ASL_fg *) asl) -> I.var_e_
38 #define CON_DE ((const ASL_fg *) asl) -> I.con_de_
39 #define OBJ_sense ((const ASL_fg *) asl) -> i.objtype_
41 #define THRESHOLD_OUTPUT_READNL 10000
45 using namespace Couenne;
49 {
return ((e==NULL) || ((((
Intcast (e->op)) == OPNUM) &&
58 int CouenneProblem::readnl (
const ASL *asl) {
63 ndefined_ = como + comc + comb + como1 + comc1;
87 for (
int i = n_var - (CoinMax (nlvc,nlvo) +niv+nbv+nwv); i--;)
addVariable(
false, &
domain_);
94 double now = CoinCpuTime ();
105 printf (
"tot var = %d\n",
variables_ . size ());
106 printf (
"c_vars_ = %d\n", ((
const ASL_fg *) asl) -> i.c_vars_ );
107 printf (
"comb_ = %d\n", ((
const ASL_fg *) asl) -> i.comb_ );
108 printf (
"combc_ = %d\n", ((
const ASL_fg *) asl) -> i.combc_ );
109 printf (
"comc1_ = %d\n", ((
const ASL_fg *) asl) -> i.comc1_ );
110 printf (
"comc_ = %d\n", ((
const ASL_fg *) asl) -> i.comc_ );
111 printf (
"como1_ = %d\n", ((
const ASL_fg *) asl) -> i.como1_ );
112 printf (
"como_ = %d\n", ((
const ASL_fg *) asl) -> i.como_ );
118 for (
int i = 0; i < como + comc + comb; i++)
121 for (
int i = 0; i < como1 + comc1; i++)
132 jnlst_ -> Printf (Ipopt::J_ERROR,
J_COUENNE,
"Couenne: warning, no objective function found\nAdded fictitious function f(x)=0\n");
136 for (
int i = 0; i < n_obj; i++) {
143 for (ograd *objgrad = Ograd [i];
145 objgrad = objgrad -> next)
161 int *indexL =
new int [nterms+1];
164 for (ograd *objgrad = Ograd [i]; objgrad; objgrad = objgrad -> next)
167 *indexL++ = objgrad -> varno;
168 *coeff++ = objgrad -> coef;
176 std::vector <std::pair <exprVar *, CouNumber> > lcoeff;
182 nl -> ArgList (NULL);
221 int *nterms =
new int [n_con];
227 for (
int i = n_con; i--;)
234 if (A_colstarts && A_vals)
235 for (
register int j = A_colstarts [n_var];
j--;) {
237 real coeff = A_vals [
j];
240 nterms [A_rownos [
j]] ++;
243 for (
register int i = 0; i < n_con; i++)
244 for (congrad = Cgrad [i];
246 congrad = congrad -> next)
254 int **indexL =
new int * [n_con];
256 for (
register int i = n_con; i--;)
264 if (A_colstarts && A_vals)
265 for (
int j = 0;
j < n_var;
j++)
266 for (
register int i = A_colstarts [
j],
k = A_colstarts [j+1] - i;
k--; i++) {
268 int rowno = A_rownos [i],
269 nt = nterms [rowno] --;
272 int **iline = indexL + rowno;
276 *iline =
new int [nt+1];
280 (*cline) [--
nt] = A_vals [i];
285 for (
int i=0; i < n_con; i++) {
290 int **iline = indexL + i;
293 *iline =
new int [nt+1];
296 for (congrad = Cgrad [i]; congrad; congrad = congrad -> next)
298 (*cline) [--
nt] = congrad -> coef;
299 (*iline) [
nt] = congrad -> varno;
306 for (
int i = 0; i < n_con; i++) {
321 if (lb > negInfinity)
344 if (indexL [i] && (*(indexL [i]) >= 0)) {
346 int code = (*nll) -> code ();
348 std::vector <std::pair <exprVar *, CouNumber> > lcoeff;
360 (*nll) -> ArgList (NULL);
380 if ((lb < negInfinity) &&
383 printf (
"Free constraint %d ignored\n", i);
395 default: printf (
"Could not recognize constraint\n");
return -1;
398 delete [] indexL [i];
419 free (x); free (lb); free (ub);
425 real *Uvx_copy = Uvx;
428 for (
register int i=0; i<n_var; i++) {
430 register int j = 2*i;
436 for (
register int i=n_var; i--;) {
438 Ub (i) = Uvx_copy [i];
442 for (
register int i=n_var; i--;) {
449 for (
register int i=n_var; i--;)
451 if (X0 && havex0 [i])
X (i) = X0 [i];
461 else x = 0.5 * (l+u);
466 for (
register int i=n_var; i<
ndefined_; i++) {
476 jnlst_ -> Printf (Ipopt::J_ERROR,
J_COUENNE,
"%.1f seconds\n", CoinCpuTime () - now);
490 struct cexp *common = ((
const ASL_fg *) asl) -> I.cexps_ + i;
491 struct cexp1 *common1 = ((
const ASL_fg *) asl) -> I.cexps1_ + i;
494 *nle =
Simplified (p -> nl2e (which ? common1 ->
e : common ->
e, asl));
504 printf (
"cexp1 %d [%d]: ", i, p ->
Variables () . size ()); nle -> print (); printf (
" ||| ");
507 int nlin = which ? common1 -> nlin : common -> nlin;
511 linpart *
L = which ? common1 -> L : common ->
L;
513 std::vector <std::pair <exprVar *, CouNumber> > lcoeff;
515 for (
int j = 0; j < nlin; j++) {
518 int indVar = ((uintptr_t) (L [j].v.rp) - (uintptr_t)
VAR_E) /
sizeof (expr_v);
521 lcoeff.push_back (std::pair <exprVar *, CouNumber> (p -> Var (indVar), coeff));
524 Printf(
" %+g x_%d (%-3d)", L [j]. fac, indVar,
525 (expr_v *) (L [j].v.rp) - VAR_E
536 if (lcoeff.size () == 1 &&
537 nle -> Type () ==
CONST &&
538 nle -> Value () == 0.) {
542 if (coeff == 1.) eg =
new exprClone (lcoeff [0].first);
547 int indVar = p -> nVars () - p -> nDefVars () + p -> commonExprs () . size ();
549 if (eg -> Index () != indVar) {
552 p -> addEQConstraint (body,
new exprConst (0.));
555 p -> commonExprs () . push_back (
new exprClone (eg));
559 int indVar = p -> nVars () - p -> nDefVars () + p -> commonExprs () . size ();
561 if (nle -> Index () != indVar) {
564 p -> addEQConstraint (body,
new exprConst (0.));
567 p -> commonExprs () . push_back (
new exprClone (nle));
void addLEConstraint(expression *, expression *=NULL)
Add constraint, .
int nVars() const
Total number of variables.
#define THRESHOLD_OUTPUT_READNL
void addObjective(expression *, const std::string &="min")
Add (non linear) objective function.
std::string problemName_
problem name
bool is_expr_zero(expr *e)
static expression * genExprGroup(CouNumber, lincoeff &, expression **=NULL, int=0)
Generalized (static) constructor: check parameters and return a constant, a single variable...
void fint fint fint real fint real real real real real real real real real * e
Bonmin::BqpdSolver::real real
int ndefined_
Number of "defined variables" (aka "common expressions")
void addEQConstraint(expression *, expression *=NULL)
Add equality constraint .
expression * addVariable(bool isint=false, Domain *d=NULL)
Add original variable.
Class for MINLP problems with symbolic information.
expression clone (points to another expression)
std::vector< exprVar * > variables_
Variables (original, auxiliary, and defined)
void createCommonExpr(CouenneProblem *p, const ASL *asl, int i, int which)
Domain domain_
current point and bounds;
CouNumber * Ub() const
Return vector of upper bounds.
void addGEConstraint(expression *, expression *=NULL)
Add constraint, .
double CouNumber
main number type in Couenne
expression * Simplified(expression *complicated)
Macro to return already simplified expression without having to do the if part every time simplify ()...
void addRNGConstraint(expression *, expression *=NULL, expression *=NULL)
Add range constraint, .
CouNumber * X() const
Return vector of variables.
con_sign
sign of constraint
void push(int dim, CouNumber *x, CouNumber *lb, CouNumber *ub, bool copy=true)
save current point and start using another
JnlstPtr jnlst_
SmartPointer to the Journalist.
void indcoe2vector(int *indexL, CouNumber *coeff, std::vector< std::pair< exprVar *, CouNumber > > &lcoeff)
translates pair (indices, coefficients) into vector with pointers to variables
The in-memory representation of the variables element.
const Ipopt::EJournalCategory J_COUENNE(Ipopt::J_USER8)
void fint fint fint real fint real * x
class for multiplications,
CouNumber * Lb() const
Return vector of lower bounds.