# Changeset 340

Ignore:
Timestamp:
Feb 18, 2007 6:36:33 PM (13 years ago)
Message:

modified branch point, now solve ex3_1_1. Cut most of the output

Location:
branches/Couenne/Couenne/src
Files:
25 edited

Unmodified
Removed
• ## branches/Couenne/Couenne/src/branch/CouenneBranchingObject.cpp

 r335 /* * Name:    CouenneBranchingObject.cpp * Author:  Pietro Belotti * Authors: Pierre Bonami, IBM Corp. *          Pietro Belotti, Carnegie Mellon University * Purpose: Branching object for auxiliary variables * /// make branching point $\alpha$ away from current point: /// bp = alpha * current + (1-alpha) * midpoint CouNumber CouenneBranchingObject::alpha_ = 0.9; /** \brief Constructor. Get a variable as an argument and set value_ through a call to operator () of that exprAux. CouenneBranchingObject::CouenneBranchingObject (expression *var): reference_ (var) { value_ = expression::Variable (reference_->Index()); } // set the branching value at the current point reference_ (var) { // set the branching value at the current point //  value_ = expression::Variable (reference_ -> Index ()); int index = reference_ -> Index (); CouNumber x = expression::Variable (index),   // current solution l = expression::Lbound   (index),   //         lower bound u = expression::Ubound   (index),   //         upper alpha = CouenneBranchingObject::Alpha (); if ((l > - COUENNE_INFINITY + 1) && (u <   COUENNE_INFINITY - 1)) // finite bounds, apply midpoint rule value_ = alpha * x + (1-alpha) * (l+u) / 2.; else if ((fabs (x-l) > COUENNE_EPS) && (fabs (x-u) > COUENNE_EPS)) // infinite (at least on one side) bound interval, but x is not // at the boundary value_ = x; else // infinite bound interval, x is at the boundary // push it inwards // TODO: look for a proper value for the displacement if (fabs (x-l) < COUENNE_EPS) value_ += fabs (l) / 2.; else                          value_ -= fabs (u) / 2.; } solver -> setColUpper (reference_ -> Index(), reference_ -> isInteger() ? floor (value_) : value_); printf("Branching on %d, way %d, changing %s bound to %f.", reference_ -> Index(), way, (way)?"lower":"upper", value_); printf ("Branch: x%d %c= %.12f\n", reference_ -> Index(), way ? '>' : '<', value_); branchIndex_++;
• ## branches/Couenne/Couenne/src/branch/CouenneBranchingObject.hpp

 r330 /* * Name:    CouenneBranchingObject.hpp * Author:  Pietro Belotti * Authors: Pierre Bonami, IBM Corp. *          Pietro Belotti, Carnegie Mellon University * Purpose: Branching object for auxiliary variables * public: /// return global value for convex combination between current point /// and midpoint static CouNumber Alpha () {return alpha_;} /// Constructor /// the variable which this branching object refers to expression *reference_; /// global value for convex combination between current point and /// midpoint static CouNumber alpha_; };
• ## branches/Couenne/Couenne/src/branch/CouenneChooseVariable.cpp

 r335 /* * Name:    CouenneChooseVariable.cpp * Author:  Pietro Belotti * Authors: Pierre Bonami, IBM Corp. *          Pietro Belotti, Carnegie Mellon University * Purpose: Branching object for choosing branching auxiliary variable * int CouenneChooseVariable::setupList (OsiBranchingInformation *info, bool initialize) { std::cout<<"Branching on :"< numberColumns_ ; kk++) { } std::cout< update ((CouNumber *) (info -> solution_), (CouNumber *) (info -> lower_),
• ## branches/Couenne/Couenne/src/branch/CouenneChooseVariable.hpp

 r330 /* * Name:    CouenneChooseVariable.hpp * Author:  Pietro Belotti * Authors: Pierre Bonami, IBM Corp. *          Pietro Belotti, Carnegie Mellon University * Purpose: Branching object for choosing branching auxiliary variable *
• ## branches/Couenne/Couenne/src/branch/CouenneObject.cpp

 r335 /* * Name:    CouenneObject.cpp * Author:  Pietro Belotti * Authors: Pierre Bonami, IBM Corp. *          Pietro Belotti, Carnegie Mellon University * Purpose: Base object for variables (to be used in branching) * const double & expr = (*(reference_ -> Image ())) (); const double & var = expression::Variable (reference_ -> Index ()); bool verbose = 1; bool verbose = 0; if(verbose){ reference_->print(std::cout); // int index = reference_ -> getFixVar () -> Index (); int    index = reference_ -> getFixVar () -> Index (); double val   = info -> solution_ [index]; // solver -> setColLower (index, info -> solution_ [index]); solver -> setColUpper (index, info -> solution_ [index]); solver -> setColLower (index, val); solver -> setColUpper (index, val); return 0.; const OsiBranchingInformation *, int) const { /*  printf ("create branch for aux x%d (branch on x%d)\n", reference_ -> Index(), reference_ -> Image() -> getFixVar () ->Index()); */ return new CouenneBranchingObject (reference_ -> Image () -> getFixVar ()); }
• ## branches/Couenne/Couenne/src/branch/CouenneObject.hpp

 r330 /* * Name:    CouenneObject.hpp * Author:  Pietro Belotti * Authors: Pierre Bonami, IBM Corp. *          Pietro Belotti, Carnegie Mellon University * Purpose: Object for auxiliary variables *
• ## branches/Couenne/Couenne/src/branch/getFixVarBinFun.cpp

 r330 expression *getFixVarBinFun (expression *arg0, expression *arg1) { if      (arg0 -> Type () == CONST) return arg1; // Case c*y else if (arg1 -> Type () == CONST) return arg0; // Case x*d if      (arg0 -> Type () == CONST) return arg1; // Case c*y or c/y else if (arg1 -> Type () == CONST) return arg0; // Case x*d or x/d else { // Case x*y: return variable closest to midpoint in bound interval // Case x*y, x/y: return variable closest to midpoint in bound interval // get variables' indices
• ## branches/Couenne/Couenne/src/convex/CouenneCutGenerator.cpp

 r335 // constructor /// constructor CouenneCutGenerator::CouenneCutGenerator (const ASL_pfgh *asl, bool addviolated, // destructor /// destructor CouenneCutGenerator::~CouenneCutGenerator () { // clone method /// clone method CouenneCutGenerator *CouenneCutGenerator::clone () const // copy constructor /// copy constructor CouenneCutGenerator::CouenneCutGenerator (const CouenneCutGenerator &src): CglCutGenerator (), ncuts_       (src.getncuts ()), ncuts_       (src. getncuts ()), pool_        (new OsiRowCut * [ncuts_]), bonCs_       (new OsiCuts (*(src.getBonCs ()))), bonOs_       (src.getBonOs () -> clone ()), firstcall_   (src.isFirst ()), bonOs_       (src. getBonOs () -> clone ()), firstcall_   (src. isFirst ()), addviolated_ (src. addViolated ()), convtype_    (src. ConvType ()), nSamples_    (src. nSamples ()), problem_     (src.Problem() -> clone ()) { problem_     (src. Problem() -> clone ()) { for (int i=0; i print ();} if (cut) } /// update auxiliary variables from original void CouenneCutGenerator::updateAuxs (CouNumber *x, CouNumber *l, CouNumber *u) { problem_ -> update (x,l,u); problem_ -> update (x, l, u); for (int i=0, j=problem_->nVars(); i nAuxs (); i++, j++) { x [j] = (*(problem_ -> Aux (i))) (); l [j] = (*(problem_ -> Aux (i) -> Lb ())) (); u [j] = (*(problem_ -> Aux (i) -> Ub ())) (); int nAux = problem_ -> nAuxs (); for (int i = 0, j = problem_ -> nVars (); i < nAux; i++, j++) { exprAux *aux = problem_ -> Aux (i); x [j] = (*aux)            (); l [j] = (*(aux -> Lb ())) (); u [j] = (*(aux -> Ub ())) (); } }
• ## branches/Couenne/Couenne/src/convex/conv-exprOp.cpp

 r296 /* * Name:    conv-exprOp.C * Name:    conv-exprOp.cpp * Author:  Pietro Belotti * Purpose: methods to convexify n-ary operators
• ## branches/Couenne/Couenne/src/convex/conv-exprUnary.cpp

 r296 /* * Name:    conv-exprUnary.C * Name:    conv-exprUnary.cpp * Author:  Pietro Belotti * Purpose: methods to convexify n-ary operators #include #include #include #include #include #include #include #include #include
• ## branches/Couenne/Couenne/src/convex/generateCuts.cpp

 r335 problem_ ->  update (x,l,u); //    expression:: update (x,l,u); } // end of generateCuts if (cs.sizeRowCuts ()) printf ("Couenne: %d convexifier cuts\n", cs.sizeRowCuts ()); //  if (cs.sizeRowCuts ()) //    printf ("Couenne: %d convexifier cuts\n", cs.sizeRowCuts ()); for (int i = cs.sizeRowCuts (); i--;) cs.rowCutPtr (i) -> print (); printf ("==============================================\n"); if (firstcall_) firstcall_ = false;
• ## branches/Couenne/Couenne/src/expression/expression.cpp

 r335 //  image_ -> print (std::cout); printf("\n"); int j=cs.sizeRowCuts (); int j = cs.sizeRowCuts (); image_ -> generateCuts (this, si, cs, cg); //  if (!(cg -> isFirst ())) { printf ("----------------Generated cut for "); print (std::cout);  printf (" := "); image_ -> print (std::cout); printf("\n"); for (;j < cs.sizeRowCuts ();j++) cs.rowCutPtr (j) -> print (); } //  if (j < cs.sizeRowCuts ()) if (0) { printf ("----------------Generated cut for "); print (std::cout);  printf (" := "); image_ -> print (std::cout); printf("\n"); for (;j < cs.sizeRowCuts ();j++) cs.rowCutPtr (j) -> print (); } }
• ## branches/Couenne/Couenne/src/expression/operators/exprExp.cpp

 r298 #include #include #include #include expression **arglist = new expression * [2]; arglist [0] = new exprExp (new exprCopy (argument_)); arglist [0] = new exprExp (new exprClone (argument_)); arglist [1] = argument_ -> differentiate (index);
• ## branches/Couenne/Couenne/src/expression/operators/exprLog.cpp

 r304 expression **arglist = new expression * [2]; arglist [0] = new exprInv (new exprCopy (argument_)); arglist [0] = new exprInv (new exprClone (argument_)); arglist [1] = argument_ -> differentiate (index);
• ## branches/Couenne/Couenne/src/expression/operators/exprMul.cpp

 r335 // simplify multiplications /// simplify multiplications expression *exprMul::simplify () { // print /// print void exprMul::print (std::ostream& out) const // in a branching rule for solving a nonconvexity gap expression *exprMul::getFixVar () {printf ("...................using correct getFixVar for" ); print(std::cout); std::cout << " ---> "; expression *ret =  getFixVarBinFun (arglist_ [0], arglist_ [1]); ret -> print (std::cout); return ret; } {return getFixVarBinFun (arglist_ [0], arglist_ [1]);}
• ## branches/Couenne/Couenne/src/include/exprClone.h

 r310 // expression clone (points to VALUE and EXPRESSION of another expression) /// expression clone (points to VALUE and EXPRESSION of another expression) class exprClone: public exprCopy { public: // Constructor, destructor /// Constructor exprClone  (expression *copy): exprCopy (copy) {} /// destructor ~exprClone () {} // copy constructor /// copy constructor exprClone (const exprClone &e): exprCopy (e) {} // cloning method /// cloning method exprClone *clone () const {return new exprClone (*this);} // I/O /// I/O void print (std::ostream &out) const //  {out << "{"; copy_ -> Original () -> print (out); out << "}";} {copy_ -> Original () -> print (out);} //{out << "{"; copy_ -> Original () -> print (out); out << "}";} {copy_ -> Original () -> print (out);} //{copy_ -> print (out);} //{out << ",";} // value (empty) /// value inline CouNumber Value () const {return copy_ -> Value ();} // null function for evaluating the expression /// null function for evaluating the expression inline CouNumber operator () () {return (currValue_ = (*copy_) ());}
• ## branches/Couenne/Couenne/src/include/exprConst.h

 r298 #include #include #include #include // Get lower and upper bound of an expression (if any) inline void getBounds (expression *&lower, expression *&upper) { lower = new exprCopy (this); upper = new exprCopy (this); lower = new exprClone (this); upper = new exprClone (this); } // construct linear under-estimator for expression within problem *p // (p is used to add convexification constraints) //  int lowerLinearHull (exprAux *, int *&, expression ***&, //                   int **&, expression **&, enum con_sign *&); // Create standard formulation of this expression
• ## branches/Couenne/Couenne/src/include/exprCopy.h

 r330 // simplify expression (useful for derivatives) inline expression *simplify () {return NULL;} {return copy_ -> simplify ();} // get a measure of "how linear" the expression is:
• ## branches/Couenne/Couenne/src/include/exprOp.h

 r335 // return an index to the variable's argument that is better fixed // in a branching rule for solving a nonconvexity gap virtual expression *getFixVar () {printf ("////////////////////////\n\n");return arglist_ [0];} virtual expression *getFixVar () {return arglist_ [0];} };
• ## branches/Couenne/Couenne/src/include/operators/exprMax.h

 r304 #include #include exprMax  (expression *el0, expression *el1): exprOp (new expression * [4], 4) { arglist_ [0] = el0; arglist_ [1] = new exprCopy (el0); arglist_ [2] = el1; arglist_ [3] = new exprCopy (el1); arglist_ [0] = el0; arglist_ [1] = new exprClone (el0); arglist_ [2] = el1; arglist_ [3] = new exprClone (el1); }
• ## branches/Couenne/Couenne/src/include/operators/exprMin.h

 r330 exprMin  (expression *el0, expression *el1): exprOp (new expression * [4], 4) { arglist_ [0] = el0; arglist_ [1] = new exprCopy (el0); arglist_ [2] = el1; arglist_ [3] = new exprCopy (el1); arglist_ [0] = el0; arglist_ [1] = new exprClone (el0); arglist_ [2] = el1; arglist_ [3] = new exprClone (el1); }
• ## branches/Couenne/Couenne/src/problem/problem.cpp

 r312 void CouenneProblem::addEQConstraint (expression *body, expression *rhs = NULL) { if (!rhs) rhs = new exprConst (0); constraints_ . push_back (new CouenneConstraint (body, rhs, new exprCopy (rhs))); constraints_ . push_back (new CouenneConstraint (body, rhs, new exprClone (rhs))); } if (curr_size < nvars) { x_   = (CouNumber *) realloc (x_,  nvars * sizeof (CouNumber)); lb_  = (CouNumber *) realloc (lb_, nvars * sizeof (CouNumber)); } register int i; for (i=nvars; i--;) { for (register int i=nvars; i--;) { x_  [i] = x [i]; lb_ [i] = l [i];