12 #include "OsiClpSolverInterface.hpp"
14 #include "IpIpoptApplication.hpp"
23 #ifdef COIN_HAS_FILTERSQP
27 #include "CoinError.hpp"
31 using namespace Bonmin;
33 void MyAssertFunc(
bool c,
const std::string &
s,
const std::string& file,
unsigned int line){
35 fprintf(stderr,
"Failed MyAssertion: %s in %s line %i.\n", s.c_str(), file.c_str(), line);
40 void DblEqAssertFunc(
const double&
a,
const std::string &a_s,
const double&
b,
const std::string& b_s,
41 const std::string& file,
unsigned int line){
44 fprintf(stderr,
"Failed comparison: %s = %f != %s =%f in %s line %i.\n", a_s.c_str(),
45 a, b_s.c_str(),
b, file.c_str(), line);
50 #define MAKE_STRING(exp) std::string(#exp)
51 #define MyAssert(exp) MyAssertFunc(exp, MAKE_STRING(exp), __FILE__, __LINE__);
52 #define DblEqAssert(a,b) DblEqAssertFunc(a,MAKE_STRING(a),b,MAKE_STRING(b), __FILE__, __LINE__);
62 std::cout<<
"Checking get functions"<<std::endl;
120 std::cout<<
"Test passed"<<std::endl;
124 CoinRelFltEq eq(1
e-07);
125 std::cout<<
"Testing optimization methods and solution query"<<std::endl;
134 if(!eq(si.
getObjValue(),-( (3./2.) + sqrt(5.)/2.)))
135 std::cout<<
"Error in objective : "<<fabs(si.
getObjValue()+( (3./2.) + sqrt(5.0)/2.))<<std::endl;
139 if(!eq(colsol[0],( (1./2.) + 1/sqrt(5.0))))
140 std::cout<<
"Error for y[1] : "<<fabs(colsol[0]-( (1./2.) + 1/sqrt(5.0)))<<std::endl;
141 if(!eq(colsol[1],( (1./2.) + 1/(2.*sqrt(5.0)))))
142 std::cout<<
"Error for y[2] : "<<fabs(colsol[1]-( (1./2.) + 1/(2*sqrt(5.0))))<<std::endl;
143 if(!eq(colsol[2],( (1./2.) + 1/sqrt(5.))))
144 std::cout<<
"Error for x : "<<fabs(colsol[2]-( (1./2.) + 1/sqrt(5.0)))<<std::endl;
149 if(!eq(rowAct[0],1./4.))
150 std::cout<<
"Error for row activity of c1 : "<<fabs(rowAct[0]-1./4.)<<std::endl;
151 if(!eq(rowAct[1],0.))
152 std::cout<<
"Error for row activity of c2 : "<<fabs(rowAct[1])<<std::endl;
156 if(!eq(duals[0],sqrt(5.0)))
157 std::cout<<
"Error dual of c1 : "<<fabs(duals[0]-sqrt(5.))<<std::endl;
159 std::cout<<
"Error dual of c2 : "<<fabs(duals[0]-1.)<<std::endl;
161 std::cout<<
"Test passed successfully"<<std::endl;
167 CoinRelFltEq eq(1
e-07);
193 CoinRelFltEq eq(1
e-07);
194 OsiClpSolverInterface
lp;
198 double tiny, very_tiny, rhs_relax,
infty;
199 si.get_tolerances(tiny, very_tiny, rhs_relax, infty);
205 const double * colLow = lp.getColLower();
211 const double * colUp = lp.getColUpper();
212 MyAssert(colUp[0]>=lp.getInfinity());
213 MyAssert(colUp[1]>=lp.getInfinity());
217 const double * rowLow = lp.getRowLower();
218 std::cout<<rowLow[0]<<
"\t"<<lp.getInfinity()<<std::endl;
219 MyAssert(rowLow[0]<= -lp.getInfinity());
220 MyAssert(rowLow[1]<= -lp.getInfinity());
221 MyAssert(rowLow[2]<= -lp.getInfinity());
223 const double * rowUp = lp.getRowUpper();
224 double sqrt5 = sqrt(5.);
225 if(!eq(rowUp[0], 1./2. + 3./(2 * sqrt5))){
226 double error = fabs(rowUp[0] - 1./2. - 3./(2 * sqrt5));
227 std::cout<<
"Error in OA for rowUp[0]: "
245 const CoinPackedMatrix * mat = lp.getMatrixByCol();
246 int inds[7] = {0, 1, 0, 2, 1, 2, 2};
247 double vals[7] = {2. / sqrt(5.) , -1., 1./sqrt(5.), 1. , 1. , 1., 1.};
252 for(
int j = mat->getVectorStarts()[i] ;
j < mat->getVectorStarts()[i] + mat->getVectorLengths()[i] ;
j++)
255 if(!eq(vals[k],mat->getElements()[
j])){
256 double error = fabs(vals[k] - mat->getElements()[
j]);
257 std::cout<<
"Error in OA for element of constraint matrix "<<k<<
": "
259 if(error > 1
e-06)
throw -1;
268 CoinRelFltEq eq(1
e-07);
281 std::cout<<
"Test OsiTMINLPInterface with "
282 <<solver->solverName()<<
" solver"<<std::endl;
301 const char * args[3] ={
"name",
"mytoy",NULL};
302 const char ** argv = args;
307 bonmin.
initialize(amplSi,const_cast<char **&>(argv));
310 std::cout<<
"---------------------------------------------------------------------------------------------------------------------------------------------------------"
311 <<std::endl<<
"Testing useful constructor"<<std::endl
312 <<
"---------------------------------------------------------------------------------------------------------------------------------------------------------"<<std::endl;
336 const char * args[3] ={
"name",
"mytoy",NULL};
337 const char ** argv = args;
341 bonmin.
initialize(amplSi,const_cast<char **&>(argv));
346 std::cout<<
"---------------------------------------------------------------------------------------------------------------------------------------------------------"
347 <<std::endl<<
"Testing copy constructor"<<std::endl
348 <<
"---------------------------------------------------------------------------------------------------------------------------------------------------------"<<std::endl;
358 const char * args[3] ={
"name",
"mytoy",NULL};
359 const char ** argv = args;
363 bonmin.
initialize(amplSi,const_cast<char **&>(argv));
366 std::cout<<
"---------------------------------------------------------------------------------------------------------------------------------------------------------"
367 <<std::endl<<
"Testing outer approximations related methods"<<std::endl
368 <<
"---------------------------------------------------------------------------------------------------------------------------------------------------------"<<std::endl;
386 #endif // COIN_HAS_ASL
387 std::cout<<
"All test passed successfully"<<std::endl;
392 WindowsErrorPopupBlocker();
397 #ifdef COIN_HAS_FILTERSQP
void initialize(char **&argv)
initialize bonmin with ampl model using the command line arguments.
virtual double getInfinity() const
Get solver's value for infinity.
virtual const double * getColLower() const
Get pointer to array[getNumCols()] of column lower bounds.
void testSetMethods(OsiTMINLPInterface &si)
Test set methods.
int main(int argc, char *argv[])
This is class provides an Osi interface for a Mixed Integer Linear Program expressed as a TMINLP (so ...
virtual bool isInteger(int columnNumber) const
Return true if column is integer.
void fint fint fint real * a
virtual int getNumRows() const
Get number of rows.
void MyAssertFunc(bool c, const std::string &s, const std::string &file, unsigned int line)
void testOptimAndSolutionQuery(OsiTMINLPInterface &si)
virtual int getNumCols() const
Get number of columns.
virtual bool isProvenOptimal() const
Is optimality proven?
virtual void initialSolve()
Solve initial continuous relaxation.
virtual double getObjValue() const
Get objective function value (can't use default)
void DblEqAssertFunc(const double &a, const std::string &a_s, const double &b, const std::string &b_s, const std::string &file, unsigned int line)
void testFp(Bonmin::AmplInterface &si)
Class for providing an Osi interface to Ipopt with an ampl nl file as input.
double solveFeasibilityProblem(size_t n, const double *x_bar, const int *ind, double a, double s, int L)
Given a point x_bar this solves the problem of finding the point which minimize a convex combination ...
virtual const double * getColSolution() const
Get pointer to array[getNumCols()] of primal solution vector.
void fint fint fint real fint real real real real real real real real real * e
virtual void setColUpper(int elementIndex, double elementValue)
Set a single column upper bound.
virtual double getObjSense() const
Get objective function sense (1 for min (default), -1 for max) Always minimizes.
#define DblEqAssert(a, b)
static void registerAllOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Register all bonmin type executable options.
void fint fint fint real fint real real real real real real real real real fint real fint * lp
virtual void resolve()
Resolve the continuous relaxation after problem modification.
void setSolver(Ipopt::SmartPtr< TNLPSolver > app)
Set the solver to be used by interface.
void testGetMethods(OsiTMINLPInterface &si)
Test function for the Osi interface to Ipopt (or any nlp solver).
virtual bool isFreeBinary(int columnNumber) const
Return true if column is binary and not fixed at either bound.
virtual const double * getRowUpper() const
Get pointer to array[getNumRows()] of row upper bounds.
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real * s
void testOa(Bonmin::OsiTMINLPInterface &si)
void setWarmStartMode(int mode)
Get an empty warm start object.
U * GetRawPtr(const OSSmartPtr< U > &smart_ptr)
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real * ws
virtual bool isContinuous(int colNumber) const
Return true if column is continuous.
void interfaceTest(Ipopt::SmartPtr< TNLPSolver > solver)
virtual int getIterationCount() const
Get how many iterations it took to solve the problem (whatever "iteration" mean to the solver...
virtual bool isIntegerNonBinary(int columnNumber) const
Return true if column is general integer.
virtual CoinWarmStart * getWarmStart() const
Get warmstarting information.
virtual const double * getRowPrice() const
Get pointer to array[getNumRows()] of dual prices.
virtual const double * getRowActivity() const
Get pointer to array[getNumRows()] of row activity levels (constraint matrix times the solution vecto...
virtual const double * getColUpper() const
Get pointer to array[getNumCols()] of column upper bounds.
OsiTMINLPInterface * nonlinearSolver()
Pointer to the non-linear solver used.
virtual const double * getRowLower() const
Get pointer to array[getNumRows()] of row lower bounds.
virtual bool isBinary(int columnNumber) const
Return true if column is binary.
virtual bool setWarmStart(const CoinWarmStart *warmstart)
Set warmstarting information.
virtual void setColLower(int elementIndex, double elementValue)
Set a single column lower bound.
virtual void extractLinearRelaxation(OsiSolverInterface &si, const double *x, bool getObj=1)
Extract a linear relaxation of the MINLP.
void fint fint fint real fint real * x