23 using namespace Ipopt;
28 "Hit iteration limit" ,
29 "Some error was made in computations." ,
30 "Problem has more equations than free variables." ,
31 "Problem is not well defined.",
32 "Illegal option set.",
33 "Exception in some the third-party code used by solver." ,
34 "Unrecognized exception.",
35 "Problem solved to optimality",
36 "Problem solvedd to acceptable level of tolerance",
37 "Problem is infeasible" ,
38 "Problem is unbounded", };
52 const std::string &
prefix):
53 journalist_(journalist),
63 journalist_(other.journalist_),
65 roptions_(other.roptions_),
66 prefix_(other.prefix_),
67 start_time_(other.start_time_),
68 time_limit_(other.time_limit_){
82 Ipopt::TNLP::IndexStyleEnum dum3;
83 tnlp->get_nlp_info(n,m,dum1, dum2, dum3);
84 double * x_l =
new double[
n];
85 double * x_u =
new double[
n];
87 double * g_l = (m>0) ?
new double[m] : NULL;
88 double * g_u = (m >0) ?
new double[m] : NULL;
90 tnlp->get_bounds_info(n, x_l, x_u, m, g_l , g_u);
93 for(
int i = 0 ; i <
n ; i++) {
94 if(x_u[i] - x_l[i] > 1
e-5)
110 tnlp->eval_f(n, x_l,
true, obj_value);
112 double * x_sol =
new double[
n];
115 IpBlasDcopy(n, x_l, 1, x_sol, 1);
120 double * g_sol = (m > 0) ?
new double [m] : NULL;
122 tnlp->eval_g(n, x_sol,
true, m, g_sol);
125 for(
int i = 0 ; i <
m ; i++) {
126 if(g_sol[i] - g_l[i] < - 1
e-07 || g_sol[i] - g_u[i] > 1
e-07) {
131 double *
lam = (m > 0) ?
new double[m]: NULL;
133 double * z =
new double[
n];
135 tnlp->finalize_solution(Ipopt::LOCAL_INFEASIBILITY,
136 n, x_sol, NULL, NULL,
137 m, g_sol, NULL, obj_value, NULL, NULL);
138 if (m > 0)
delete []
lam;
140 if (m > 0)
delete [] g_sol;
146 if (m > 0)
delete [] g_l;
147 if (m > 0)
delete [] g_u;
149 double *
lam = (m > 0) ?
new double[m] : NULL;
151 double * z =
new double[
n];
153 tnlp->finalize_solution(Ipopt::SUCCESS,
155 m, g_sol, lam, obj_value, NULL, NULL);
156 if (m > 0)
delete []
lam;
158 if (m > 0)
delete [] g_sol;
171 const int numcols = model_->num_variables();
172 const int numrows = model_->num_constraints();
174 const double * currentLower = model_->x_l();
175 const double * currentUpper = model_->x_u();
177 const double * originalLower = model_->orig_x_l();
178 const double * originalUpper = model_->orig_x_u();
180 std::string fBoundsName = prefix + name_;
181 fBoundsName+=
"_bounds";
183 std::string fModName = fBoundsName +
".mod";
184 std::ofstream fBounds;
188 bool hasVarNames = 0;
194 fMod.open(fModName.c_str());
195 fBounds.open(fBoundsName.c_str());
197 for(
int i = 0 ; i < numcols ; i++)
199 if(!eq(currentLower[i],originalLower[i]))
202 fMod<<
"bounds"<<i<<
": "
203 <<reader.
name(i)<<
" >= "
204 <<currentLower[i]<<
";\n";
207 fBounds<<
"LO"<<
"\t"<<i<<
"\t"<<currentLower[i]<<std::endl;
209 if(!eq(currentUpper[i],originalUpper[i]))
212 fMod<<
"bounds"<<i<<
": "
213 <<reader.
name(i)<<
" <= "
214 <<currentUpper[i]<<
";\n";
216 fBounds<<
"UP"<<
"\t"<<i<<
"\t"<<currentUpper[i]<<std::endl;
221 std::string fStartPointName = name_;
222 fStartPointName+=
"_start";
226 const double * primals = model_->x_init();
227 const double * duals = model_->duals_init();
231 std::cerr<<
"A failure has occured but no starting point exists"<<std::endl;
235 std::ofstream fStartPoint(fStartPointName.c_str());
236 fStartPoint.precision(17);
237 fStartPoint<<numcols<<
"\t"<<2*numcols+numrows<<std::endl;
238 for(
int i = 0 ; i < numcols ; i++)
239 fStartPoint<<primals[i]<<std::endl;
240 int end = 2*numcols + numrows;
243 for(
int i = 0 ; i <
end; i++)
244 fStartPoint<<duals[i]<<std::endl;
261 options_ =
new Ipopt::OptionsList();
268 journalist_->AddFileJournal(
"console",
"stdout", Ipopt::J_ITERSUMMARY);
273 catch (Ipopt::IpoptException &E){
277 catch(std::bad_alloc){
278 journalist_->Printf(Ipopt::J_ERROR, Ipopt::J_MAIN,
"\n Not enough memory .... EXIT\n");
279 throw CoinError(
"TNLPSolver",
"initializeOptionsAndJournalist",
"Not enough memory");
283 Ipopt::IpoptException E(
"Uncaught exception in FilterSolver::FilterSolver()",
284 "BonFilterSolver.cpp",-1);
void initializeOptionsAndJournalist()
Initializes options and journalist.
Ipopt::SmartPtr< Ipopt::Journalist > journalist_
Storage of Journalist for output.
std::string prefix_
Prefix to use for reading bonmin's options.
void writeDiffFiles(const std::string prefix=std::string()) const
write files with differences between input model and this one
This is a generic class for calling an NLP solver to solve a TNLP.
bool readFile()
Reads the .col file.
virtual const std::string & errorName() const =0
Get the string corresponding to error.
void fint fint fint real fint real real real real real real real real real * e
int errorNum_
Error code (solver dependent).
virtual const std::string & solverName() const =0
Return the name of the solver.
void printError(std::ostream &os)
Print error message.
void fint fint fint real fint real real real real real real real * r
U * GetRawPtr(const OSSmartPtr< U > &smart_ptr)
Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions_
Registered Options.
ReturnStatus
Standard return statuses for a solver.
bool isRecoverable(ReturnStatus &r)
Say if an optimization status for a problem which failed is recoverable (problem may be solvable)...
A class for reading a .col or .row file containing name for variables and constraints (usually ampl g...
void fint fint fint fint fint fint fint fint fint fint real real real real real real real real real fint real fint real * lam
TNLPSolver()
default Constructor
bool zeroDimension(const Ipopt::SmartPtr< Ipopt::TNLP > &tnlp, ReturnStatus &optimization_status)
Determine if problem is of dimension zero and if it is check if solution is feasible.
Ipopt::SmartPtr< Ipopt::OptionsList > options_
List of Options.
const char * prefix()
Get the prefix.
const std::string & name(int i)
Access Names of indexed by i.
Fake member to know size.
virtual ~TNLPSolver()
Virtual destructor.
Class to add a few more information to Ipopt::RegisteredOptions.