20 #include "CoinHelperFunctions.hpp"
21 #include "CoinTime.hpp"
25 #if defined HAVE_CSTDINT
27 #elif defined HAVE_STDINT_H
39 #define OBJ_DE ((const ASL_fg *) asl) -> I.obj_de_
40 #define VAR_E ((const ASL_fg *) asl) -> I.var_e_
41 #define CON_DE ((const ASL_fg *) asl) -> I.con_de_
42 #define OBJ_sense ((const ASL_fg *) asl) -> i.objtype_
44 #define THRESHOLD_OUTPUT_READNL 10000
48 using namespace Couenne;
52 {
return ((e==NULL) || ((((
Intcast (e->op)) == OPNUM) &&
61 int CouenneProblem::readnl (
const ASL *asl) {
66 ndefined_ = como + comc + comb + como1 + comc1;
90 for (
int i = n_var - (CoinMax (nlvc,nlvo) +niv+nbv+nwv); i--;)
addVariable(
false, &
domain_);
97 double now = CoinCpuTime ();
108 printf (
"tot var = %d\n",
variables_ . size ());
109 printf (
"c_vars_ = %d\n", ((
const ASL_fg *) asl) -> i.c_vars_ );
110 printf (
"comb_ = %d\n", ((
const ASL_fg *) asl) -> i.comb_ );
111 printf (
"combc_ = %d\n", ((
const ASL_fg *) asl) -> i.combc_ );
112 printf (
"comc1_ = %d\n", ((
const ASL_fg *) asl) -> i.comc1_ );
113 printf (
"comc_ = %d\n", ((
const ASL_fg *) asl) -> i.comc_ );
114 printf (
"como1_ = %d\n", ((
const ASL_fg *) asl) -> i.como1_ );
115 printf (
"como_ = %d\n", ((
const ASL_fg *) asl) -> i.como_ );
121 for (
int i = 0; i < como + comc + comb; i++)
124 for (
int i = 0; i < como1 + comc1; i++)
135 jnlst_ -> Printf (Ipopt::J_ERROR,
J_COUENNE,
"Couenne: warning, no objective function found\nAdded fictitious function f(x)=0\n");
139 for (
int i = 0; i < n_obj; i++) {
146 for (ograd *objgrad = Ograd [i];
148 objgrad = objgrad -> next)
164 int *indexL =
new int [nterms+1];
167 for (ograd *objgrad = Ograd [i]; objgrad; objgrad = objgrad -> next)
170 *indexL++ = objgrad -> varno;
171 *coeff++ = objgrad -> coef;
179 std::vector <std::pair <exprVar *, CouNumber> > lcoeff;
185 nl -> ArgList (NULL);
224 int *nterms =
new int [n_con];
230 for (
int i = n_con; i--;)
237 if (A_colstarts && A_vals)
238 for (
register int j = A_colstarts [n_var];
j--;) {
240 real coeff = A_vals [
j];
243 nterms [A_rownos [
j]] ++;
246 for (
register int i = 0; i < n_con; i++)
247 for (congrad = Cgrad [i];
249 congrad = congrad -> next)
257 int **indexL =
new int * [n_con];
259 for (
register int i = n_con; i--;)
267 if (A_colstarts && A_vals)
268 for (
int j = 0;
j < n_var;
j++)
269 for (
register int i = A_colstarts [
j],
k = A_colstarts [j+1] - i;
k--; i++) {
271 int rowno = A_rownos [i],
272 nt = nterms [rowno] --;
275 int **iline = indexL + rowno;
279 *iline =
new int [nt+1];
283 (*cline) [--
nt] = A_vals [i];
288 for (
int i=0; i < n_con; i++) {
293 int **iline = indexL + i;
296 *iline =
new int [nt+1];
299 for (congrad = Cgrad [i]; congrad; congrad = congrad -> next)
301 (*cline) [--
nt] = congrad -> coef;
302 (*iline) [
nt] = congrad -> varno;
309 for (
int i = 0; i < n_con; i++) {
324 if (lb > negInfinity)
347 if (indexL [i] && (*(indexL [i]) >= 0)) {
349 int code = (*nll) -> code ();
351 std::vector <std::pair <exprVar *, CouNumber> > lcoeff;
363 (*nll) -> ArgList (NULL);
383 if ((lb < negInfinity) &&
386 printf (
"Free constraint %d ignored\n", i);
398 default: printf (
"Could not recognize constraint\n");
return -1;
401 delete [] indexL [i];
422 free (x); free (lb); free (ub);
428 real *Uvx_copy = Uvx;
431 for (
register int i=0; i<n_var; i++) {
433 register int j = 2*i;
439 for (
register int i=n_var; i--;) {
441 Ub (i) = Uvx_copy [i];
445 for (
register int i=n_var; i--;) {
452 for (
register int i=n_var; i--;)
454 if (X0 && havex0 [i])
X (i) = X0 [i];
464 else x = 0.5 * (l+u);
469 for (
register int i=n_var; i<
ndefined_; i++) {
479 jnlst_ -> Printf (Ipopt::J_ERROR,
J_COUENNE,
"%.1f seconds\n", CoinCpuTime () - now);
493 struct cexp *common = ((
const ASL_fg *) asl) -> I.cexps_ + i;
494 struct cexp1 *common1 = ((
const ASL_fg *) asl) -> I.cexps1_ + i;
497 *nle =
Simplified (p -> nl2e (which ? common1 ->
e : common ->
e, asl));
507 printf (
"cexp1 %d [%d]: ", i, p ->
Variables () . size ()); nle -> print (); printf (
" ||| ");
510 int nlin = which ? common1 -> nlin : common -> nlin;
514 linpart *
L = which ? common1 -> L : common ->
L;
516 std::vector <std::pair <exprVar *, CouNumber> > lcoeff;
518 for (
int j = 0; j < nlin; j++) {
521 int indVar = ((uintptr_t) (L [j].v.rp) - (uintptr_t)
VAR_E) /
sizeof (expr_v);
524 lcoeff.push_back (std::pair <exprVar *, CouNumber> (p -> Var (indVar), coeff));
527 Printf(
" %+g x_%d (%-3d)", L [j]. fac, indVar,
528 (expr_v *) (L [j].v.rp) - VAR_E
539 if (lcoeff.size () == 1 &&
540 nle -> Type () ==
CONST &&
541 nle -> Value () == 0.) {
545 if (coeff == 1.) eg =
new exprClone (lcoeff [0].first);
550 int indVar = p -> nVars () - p -> nDefVars () + p -> commonExprs () . size ();
552 if (eg -> Index () != indVar) {
555 p -> addEQConstraint (body,
new exprConst (0.));
558 p -> commonExprs () . push_back (
new exprClone (eg));
562 int indVar = p -> nVars () - p -> nDefVars () + p -> commonExprs () . size ();
564 if (nle -> Index () != indVar) {
567 p -> addEQConstraint (body,
new exprConst (0.));
570 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.