12 #include "CoinTime.hpp"
13 #include "CoinHelperFunctions.hpp"
21 using namespace Couenne;
25 #define VALID_ONLY_THRESHOLD 5
35 double *lb,
double *ub)
const {
53 *olb =
new double [ncols], *oub =
new double [ncols],
57 CoinCopyN (
Lb (), ncols, olb);
58 CoinCopyN (
Ub (), ncols, oub);
68 fixed [i] = (
Var (i) -> isDefinedInteger () &&
69 Var (i) -> Multiplicity () > 0) ?
115 "Heuristic: looking for an initial point\n");
118 printf (
"= ===========================================\n");
119 printf (
"= BEGIN ===========================================\n");
120 printf (
"= ===========================================\n");
123 printf (
"#### %4d: %d %c %2d frac %20g [%20g,%20g]\n",
127 xFrac [i],
Lb (i),
Ub (i));
129 for (
int i=nOrigVars_; i<
nVars (); i++)
131 printf (
"#### %4d: %c frac %20g [%20g,%20g]\n",
134 X (i),
Lb (i),
Ub (i));
135 printf (
"===================================================\n");
136 printf (
"===================================================\n");
137 printf (
"===================================================\n");
151 (nvars >= N_VARS_HUGE) ? 0 :
152 (nvars >= N_VARS_LARGE) ? 1 :
153 (nvars >= N_VARS_MEDIUM) ? 2 :
154 (nvars >= N_VARS_SMALL) ? 4 :
155 (nvars >= N_VARS_TINY) ? 8 : 16;
159 for (std::vector <int>::iterator rNum =
numberInRank_.begin();
165 "Analyzing %d variables with rank %d\n", *rNum, rank);
174 if ((
Var (i) -> Multiplicity () > 0) &&
175 (
Var (i) -> isDefinedInteger ()) &&
186 printf (
"= RANK LEVEL = %d [%d] ==================================\n", rank, *rNum);
188 if (
Var (i) -> Multiplicity () > 0)
189 printf (
"#### %4d: %d %c %2d frac %20g -> int %20g [%20g,%20g]\n",
193 xFrac [i], xInt [i],
Lb (i),
Ub (i));
194 printf (
"--------------------\n");
195 for (
int i=nOrigVars_; i<
nVars (); i++)
196 if (
Var (i) -> Multiplicity () > 0)
197 printf (
"#### %4d: %c frac %20g [%20g,%20g]\n",
200 X (i),
Lb (i),
Ub (i));
201 printf (
"=================================================\n");
206 int remaining = *rNum;
210 bool one_fixed =
false;
214 if ((
Var (i) -> Multiplicity () > 0) &&
217 Var (i) -> isDefinedInteger ()) {
245 int result =
testIntFix (i, xFrac [i], fixed, xInt,
246 dualL, dualR, olb, oub, ntrials < maxtrials);
249 "testing %d [%g -> %g], res = %d\n", i, xFrac [i], xInt [i], result);
254 }
else if (result < 0)
274 "none fixed, fix %d from %g [%g,%g] [L=%g, R=%g]",
275 index, xFrac [index],
Lb (index),
Ub (index),
276 dualL [index], dualR [index]);
278 Lb (index) =
Ub (index) =
X (index) = xInt [index] =
279 ((dualL [index] < dualR [index] -
COUENNE_EPS) ? floor (xFrac [index]) :
280 (dualL [index] > dualR [index] +
COUENNE_EPS) ? ceil (xFrac [index]) :
281 ((CoinDrand48 () > xFrac [index] - floor (xFrac [index])) ?
282 floor (xFrac [index]) : ceil (xFrac [index])));
286 fixed [index] =
FIXED;
294 printf (
"--- remaining = %d --------------------------- \n", remaining);
297 printf (
"#### %4d: %d %c %2d frac %20g -> int %20g [%20g,%20g]\n",
301 xFrac [i], xInt [i],
Lb (i),
Ub (i));
302 printf (
"---------------------------\n");
309 }
while (remaining > 0);
314 if (
Var (i) -> Multiplicity () > 0) {
316 if (fixed [i] ==
FIXED)
317 lb [i] = ub [i] =
X (i) = xInt [i];
319 else if (
Lb (i) >
Ub (i)) {
320 xInt [i] =
X (i) = lb [i] = ub [i] =
322 (0.5 * (
Lb (i) +
Ub (i))) :
331 if (xInt [i] < lb [i])
X (i) = xInt [i] = lb [i];
332 else if (xInt [i] > ub [i])
X (i) = xInt [i] = ub [i];
341 int objind =
Obj (0) -> Body () -> Index ();
343 CouNumber xp = objind >= 0 ?
X (objind) :
Obj (0) -> Body () -> Value ();
347 if (
checkNLP0 (x, xp,
true,
false,
true,
true)) {
356 #ifdef FM_TRACE_OPTSOL
368 "new cutoff from getIntCand: %g\n", xp);
383 xInt [
j] = ceil (xInt [
j] - 0.5);
390 printf (
"- Done: retval %d ----------------------------------------------------------------\n",
394 printf (
"#### %4d: %d %c frac %20g -> int %20g [%20g,%20g]\n",
396 xFrac [i], xInt [i], lb [i], ub [i]);
397 }
else printf (
"no good point was found\n");
405 delete [] olb;
delete [] oub;
406 delete [] dualL;
delete [] dualR;
int nVars() const
Total number of variables.
double maxCpuTime_
maximum cpu time
void update(const double *givenSol, const int givenCard, const double givenVal, const double givenMaxViol)
void fillIntegerRank() const
fill freeIntegers_ array
int * integerRank_
each element is true if variable is integer and, if auxiliary, depends on no integer ...
void setCutOff(CouNumber cutoff, const CouNumber *sol=NULL) const
Set cutoff.
bool checkNLP0(const double *solution, double &obj, bool recompute_obj=false, const bool careAboutObj=false, const bool stopAtFirstViol=true, const bool checkAll=false, const double precision=-1) const
And finally a method to get both.
CouNumber getCutOff() const
Get cutoff.
void restoreUnusedOriginals(CouNumber *=NULL) const
Some originals may be unused due to their zero multiplicity (that happens when they are duplicates)...
int ndefined_
Number of "defined variables" (aka "common expressions")
std::vector< int > numberInRank_
numberInRank_ [i] is the number of integer variables in rank i
int testIntFix(int index, CouNumber xFrac, enum fixType *fixed, CouNumber *xInt, CouNumber *dualL, CouNumber *dualR, CouNumber *olb, CouNumber *oub, bool patient) const
Test fixing of an integer variable (used in getIntegerCandidate())
void pop()
restore previous point
exprVar * Var(int i) const
Return pointer to i-th variable.
std::vector< exprVar * > variables_
Variables (original, auxiliary, and defined)
int getIntegerCandidate(const double *xFrac, double *xInt, double *lb, double *ub) const
generate integer NLP point Y starting from fractional solution using bound tightening ...
CouenneRecordBestSol * recBSol
Domain domain_
current point and bounds;
CouNumber * Ub() const
Return vector of upper bounds.
CouNumber * optimum_
Best solution known to be loaded from file – for testing purposes.
static const int infeasible
void initAuxs() const
Initialize auxiliary variables and their bounds from original variables.
double CouNumber
main number type in Couenne
fixType
structure to record fixed, non-fixed, and continuous variables
int nOrigVars_
Number of original variables.
CouNumber feas_tolerance_
feasibility tolerance (to be used in checkNLP)
const Ipopt::EJournalCategory J_NLPHEURISTIC(Ipopt::J_USER5)
CouNumber * X() const
Return vector of variables.
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.
CouenneObjective * Obj(int i) const
i-th objective
void fint fint fint real fint real * x
CouNumber * Lb() const
Return vector of lower bounds.
bool isInteger(CouNumber x)
is this number integer?