15 #include "CoinPragma.hpp"
19 #if defined HAVE_CSTDINT
21 #elif defined HAVE_STDINT_H
56 #define OBJ_DE ((const ASL_fg *) asl) -> I.obj_de_
57 #define VAR_E ((const ASL_fg *) asl) -> I.var_e_
58 #define CON_DE ((const ASL_fg *) asl) -> I.con_de_
59 #define OBJ_sense ((const ASL_fg *) asl) -> i.objtype_
67 KW(const_cast<char*>(
"timing"), L_val, &
timing, const_cast<char*>(
"display timings for the run")),
71 Option_Info
Oinfo = {
const_cast<char*
>(
"testampl"), const_cast<char*>(
"ANALYSIS TEST"),
72 const_cast<char*
>(
"concert_options"),
keywds, nkeywds, 0, const_cast<char*>(
"ANALYSIS TEST") };
77 using namespace Couenne;
80 roptions->AddStringOption1(
"nlfile",
"name of an ampl .nl file to get the problem from",
"",
"*",
"name of .nl file");
119 jnlst->Printf(Ipopt::J_ERROR, Ipopt::J_INITIALIZATION,
"Error: Need registered options to create AmplTMINLP object!\n");
124 options->GetStringValue(
"nlfile", nlfile,
"");
125 char** argv =
new char*[3];
126 argv[0] =
const_cast<char*
>(
"dummy");
127 argv[1] = strdup(nlfile.c_str());
142 message =
"Couenne found a solution.\n";
144 message =
"Couenne could not found a solution.\n";
147 write_sol(const_cast<char*>(message), const_cast<double*>(bab.
bestSolution()), NULL, NULL);
156 options->GetStringValue(
"nlfile", nlfile,
"");
161 char** argv =
new char*[3];
162 argv[0] =
const_cast<char*
>(
"dummy");
163 argv[1] = strdup(nlfile.c_str());
167 asl = (ASL*) ASL_alloc (ASL_read_fg);
169 char* stub = getstub (&argv, &
Oinfo);
174 FILE* nl = jac0dim (stub, - (
fint) strlen (stub));
181 X0 =
new real [n_var];
182 havex0 =
new char [n_var];
183 pi0 =
new real [n_con];
184 havepi0 =
new char [n_con];
187 fg_read (nl, ASL_return_read_err | ASL_findgroups);
210 options->GetStringValue(
"nlfile", nlfile,
"");
211 problem -> setProblemName (nlfile);
214 problem -> setNDefVars(como + comc + comb + como1 + comc1);
220 for (
int i = 0; i < nlvb - nlvbi; i++)
problem -> addVariable (
false,
problem -> domain ());
221 for (
int i = 0; i < nlvbi; i++)
problem -> addVariable (
true,
problem -> domain ());
226 for (
int i = 0; i < nlvc - (nlvb + nlvci); i++)
problem -> addVariable (
false,
problem -> domain ());
227 for (
int i = 0; i < nlvci; i++)
problem -> addVariable (
true,
problem -> domain ());
228 for (
int i = 0; i < nlvo - (nlvc + nlvoi); i++)
problem -> addVariable (
false,
problem -> domain ());
229 for (
int i = 0; i < nlvoi; i++)
problem -> addVariable (
true,
problem -> domain ());
231 for (
int i = 0; i < nlvo - (nlvb + nlvoi); i++)
problem -> addVariable (
false,
problem -> domain ());
232 for (
int i = 0; i < nlvoi; i++)
problem -> addVariable (
true,
problem -> domain ());
233 for (
int i = 0; i < nlvc - (nlvo + nlvci); i++)
problem -> addVariable (
false,
problem -> domain ());
234 for (
int i = 0; i < nlvci; i++)
problem -> addVariable (
true,
problem -> domain ());
237 for (
int i = 0; i < nwv; i++)
problem -> addVariable(
false,
problem -> domain ());
238 for (
int i = n_var - (CoinMax (nlvc,nlvo) +niv+nbv+nwv); i--;)
problem -> addVariable(
false,
problem -> domain ());
239 for (
int i = 0; i < nbv; i++)
problem -> addVariable(
true,
problem -> domain ());
240 for (
int i = 0; i < niv; i++)
problem -> addVariable(
true,
problem -> domain ());
248 printf (
"tot var = %d\n", variables_ . size ());
249 printf (
"c_vars_ = %d\n", ((
const ASL_fg *)
asl) -> i.c_vars_ );
250 printf (
"comb_ = %d\n", ((
const ASL_fg *)
asl) -> i.comb_ );
251 printf (
"combc_ = %d\n", ((
const ASL_fg *)
asl) -> i.combc_ );
252 printf (
"comc1_ = %d\n", ((
const ASL_fg *)
asl) -> i.comc1_ );
253 printf (
"comc_ = %d\n", ((
const ASL_fg *)
asl) -> i.comc_ );
254 printf (
"como1_ = %d\n", ((
const ASL_fg *)
asl) -> i.como1_ );
255 printf (
"como_ = %d\n", ((
const ASL_fg *)
asl) -> i.como_ );
262 for (
int i = 0; i < como + comc + comb; i++) {
264 struct cexp *common = ((
const ASL_fg *)
asl) -> I.cexps_ + i;
268 printf (
"cexp %d [%d]: ", i,
problem -> nVars()); nle -> print (); printf (
" ||| ");
271 int nlin = common -> nlin;
275 int *indexL =
new int [nlin+1];
278 linpart *
L = common ->
L;
280 for (
int j = 0;
j < nlin;
j++) {
283 coeff [
j] = L [
j]. fac;
284 indexL [
j] = ((uintptr_t) (L [
j].v.rp) - (uintptr_t)
VAR_E) /
sizeof (expr_v);
286 Printf(
" %+g x_%-3d", L [j]. fac,
287 (expr_v *) (L [j].v.rp) - VAR_E
298 std::vector <std::pair <exprVar *, CouNumber> > lcoeff;
299 problem -> indcoe2vector (indexL, coeff, lcoeff);
302 problem -> commonExprs (). push_back (eg);
304 else problem -> commonExprs () . push_back (nle);
310 for (
int i = 0; i < como1 + comc1; i++) {
312 struct cexp1 *common = ((
const ASL_fg *)
asl) -> I.cexps1_ + i;
316 printf (
"cexp1 %d [%d]: ", i, variables_ . size ()); nle -> print (); printf (
" ||| ");
319 int nlin = common -> nlin;
323 int *indexL =
new int [nlin+1];
326 linpart *
L = common ->
L;
328 for (
int j = 0;
j < nlin;
j++) {
330 coeff [
j] = L [
j]. fac;
331 indexL [
j] = ((uintptr_t) (L [
j].v.rp) - (uintptr_t)
VAR_E) /
sizeof (expr_v);
333 Printf(
" %+g x_%-3d", L [j]. fac,
334 (expr_v *) (L [j].v.rp) - VAR_E
345 std::vector <std::pair <exprVar *, CouNumber> > lcoeff;
346 problem -> indcoe2vector (indexL, coeff, lcoeff);
349 problem -> commonExprs () . push_back (eg);
351 else problem -> commonExprs () . push_back (nle);
360 for (
int i = 0; i < n_obj; i++) {
367 for (ograd *objgrad = Ograd [i];
369 objgrad = objgrad -> next)
379 int *indexL =
new int [nterms+1];
382 for (ograd *objgrad = Ograd [i]; objgrad; objgrad = objgrad -> next)
385 *indexL++ = objgrad -> varno;
386 *coeff++ = objgrad -> coef;
394 std::vector <std::pair <exprVar *, CouNumber> > lcoeff;
395 problem -> indcoe2vector (indexL, coeff, lcoeff);
400 nl -> ArgList (NULL);
439 int *nterms =
new int [n_con];
445 for (
int i = n_con; i--;)
452 if (A_colstarts && A_vals)
453 for (
register int j = A_colstarts [n_var];
j--;) {
455 real coeff = A_vals [
j];
458 nterms [A_rownos [
j]] ++;
461 for (
register int i = 0; i < n_con; i++)
462 for (congrad = Cgrad [i];
464 congrad = congrad -> next)
472 int **indexL =
new int * [n_con];
474 for (
register int i = n_con; i--;)
482 if (A_colstarts && A_vals)
483 for (
int j = 0;
j < n_var;
j++)
484 for (
register int i = A_colstarts [
j],
k = A_colstarts [j+1] - i;
k--; i++) {
486 int rowno = A_rownos [i],
487 nt = nterms [rowno] --;
490 int **iline = indexL + rowno;
494 *iline =
new int [nt+1];
498 (*cline) [--
nt] = A_vals [i];
503 for (
int i=0; i < n_con; i++) {
508 int **iline = indexL + i;
511 *iline =
new int [nt+1];
514 for (congrad = Cgrad [i]; congrad; congrad = congrad -> next)
516 (*cline) [--
nt] = congrad -> coef;
517 (*iline) [
nt] = congrad -> varno;
524 for (
int i = 0; i < n_con; i++) {
539 if (lb > negInfinity)
553 if (indexL [i] && (*(indexL [i]) >= 0)) {
555 int code = (*nll) -> code ();
557 std::vector <std::pair <exprVar *, CouNumber> > lcoeff;
558 problem -> indcoe2vector (indexL [i], coeff [i], lcoeff);
569 (*nll) -> ArgList (NULL);
596 default:
jnlst->Printf(Ipopt::J_ERROR, Ipopt::J_INITIALIZATION,
"Error: could not recognize constraint\n");
return false;
599 delete [] indexL [i];
617 for (
int i = n_var +
problem -> nDefVars(); i--;) {
623 problem -> domain () -> push (n_var +
problem -> nDefVars(), x, lb, ub);
624 free (x); free (lb); free (ub);
635 real *Uvx_copy = Uvx;
638 for (
register int i=0; i<n_var; i++) {
640 register int j = 2*i;
646 for (
register int i=n_var; i--;) {
652 for (
register int i=n_var; i--;) {
659 for (
register int i=n_var; i--;)
661 if (X0 && havex0 [i])
problem -> X (i) = X0 [i];
671 else x = 0.5 * (l+u);
676 for (
register int i=n_var; i <
problem -> nDefVars() ; i++) {
718 case OP_tanh:
return new exprDiv
726 arg =
nl2e (e ->
L.e);
754 for (expr **ep = e->L.ep; ep < e->R.ep; ep++)
755 al [i++] =
nl2e (*ep);
770 case OPNUM:
return new exprConst (((expr_n *)e)->v);
776 int j = ((expr_v *) e) ->
a;
778 if (j >=
problem -> nOrigVars())
780 j = ((expr_v *)
e) - ((
const ASL_fg *)
asl) -> I.var_e_;
783 jnlst -> Printf (Ipopt::J_ERROR, Ipopt::J_INITIALIZATION,
"Error: unknown variable x_%d\n", j);
791 jnlst -> Printf (Ipopt::J_ERROR, Ipopt::J_INITIALIZATION,
"ERROR: unknown operator (address %p), aborting.\n",
Intcast (e -> op));
Ipopt::SmartPtr< Ipopt::OptionsList > options
CouenneProblem * getCouenneProblem()
Should return the problem to solve in algebraic form.
CouExpr & log(CouExpr &e)
bool writeSolution(Bonmin::Bab &bab)
Called after B&B finished.
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions
void fint fint fint real * a
Power of an expression (binary operator), with constant.
Ipopt::SmartPtr< Ipopt::Journalist > jnlst
bool IsValid(const OSSmartPtr< U > &smart_ptr)
Ipopt::SmartPtr< Bonmin::TMINLP > tminlp
Bonmin::BqpdSolver::fint fint
static void registerOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
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
expression * nl2e(expr *e)
bool IsNull(const OSSmartPtr< U > &smart_ptr)
int nDefVars() const
Number of def'd variables.
Class for MINLP problems with symbolic information.
expression clone (points to another expression)
Ipopt::SmartPtr< Bonmin::TMINLP > getTMINLP()
Should return the problem to solve as TMINLP.
U * GetRawPtr(const OSSmartPtr< U > &smart_ptr)
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 ()...
con_sign
sign of constraint
const double * bestSolution() const
get the best solution known to the problem (is optimal if MipStatus is FeasibleOptimal).
class for the exponential,
The in-memory representation of the variables element.
void fint fint fint real fint real * x
class for multiplications,