Skip to content

Commit

Permalink
#382 IbexOpt is now fully compatible with AMPL
Browse files Browse the repository at this point in the history
You can directly call ibexopt from AMPL
  • Loading branch information
Jordan08 committed Jun 4, 2019
1 parent 4bf5305 commit 2db158b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
29 changes: 14 additions & 15 deletions plugins/ampl/src/system/ibex_AmplInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@


// The different option of IBEXOPT in Ampl
double rel_eps_f,abs_eps_f,eps_h, eps_x, initial_loup, timeout;
int random_seed, trace, rigor;
double rel_eps_f=0,abs_eps_f=0,eps_h=0, eps_x=0, initial_loup=0, timeout=0;
int random_seed=0, trace2=0, rigor=0;

static
keyword keywds[] = { // must be alphabetical order
Expand All @@ -42,7 +42,7 @@ keyword keywds[] = { // must be alphabetical order
KW(const_cast<char*>("rel_eps_f"), D_val, &rel_eps_f, const_cast<char*>("Relative precision on the objective.")),
KW(const_cast<char*>("rigor"), I_val, &rigor, const_cast<char*>("Activate rigor mode (certify feasibility of equalities).")),
KW(const_cast<char*>("timeout"), D_val, &timeout, const_cast<char*>("Timeout (time in seconds). Default value is +oo.")),
KW(const_cast<char*>("trace"), I_val, &trace, const_cast<char*>("Activate trace. Updates of lower and upper bound are printed while minimizing."))
KW(const_cast<char*>("trace"), I_val, &trace2, const_cast<char*>("Activate trace. Updates of lower and upper bound are printed while minimizing."))
};

static
Expand Down Expand Up @@ -199,39 +199,38 @@ AmplInterface::~AmplInterface() {
#ifdef _IBEX_WITH_OPTIM_
bool AmplInterface::writeSolution(Optimizer& o) {
std::stringstream message;
message << "IBEXOPT "<< _IBEX_RELEASE_ << std::endl;
message << "IBEXOPT "<< _IBEX_RELEASE_ << " finish : ";
Optimizer::Status status =o.get_status();
switch(status) {
case Optimizer::SUCCESS:
message << " optimization successful!" << std::endl;
message << " optimization successful!" ;
solve_result_num=0;
break;
case Optimizer::INFEASIBLE:
message << " infeasible problem" << std::endl;
message << " infeasible problem" ;
solve_result_num=200;
break;
case Optimizer::NO_FEASIBLE_FOUND:
message << " no feasible point found (the problem may be infeasible)" << std::endl;
message << " no feasible point found (the problem may be infeasible)";
solve_result_num=201;
break;
case Optimizer::UNBOUNDED_OBJ:
message << " possibly unbounded objective (f*=-oo)" << std::endl;
message << " possibly unbounded objective (f*=-oo)";
solve_result_num=300;
break;
case Optimizer::TIME_OUT:
message << " time limit " << o.timeout << "s. reached" << std::endl;
message << " time limit " << o.timeout << "s. reached";
solve_result_num=400;
break;
case Optimizer::UNREACHED_PREC:
message << " unreached precision" << std::endl;
message << " unreached precision" ;
solve_result_num=402;
break;
}


const char* mes = message.str().c_str();
std::string tmp = message.str();
Vector sol = o.get_loup_point().mid();
write_sol(mes, sol.raw(), NULL, NULL);
write_sol(tmp.c_str(), sol.raw(), NULL, NULL);

return true;
}
Expand All @@ -256,6 +255,7 @@ bool AmplInterface::readASLfg() {
asl = (ASL*) ASL_alloc (ASL_read_fg);

char* stub = getstub (&argv, &Oinfo);
getopts (argv, &Oinfo);
//getstops = getstub + getopts

// Although very intuitive, we shall explain why the second argument
Expand All @@ -281,14 +281,13 @@ bool AmplInterface::readASLfg() {

// Reads the solver option from the .nl file through the ASL methods
bool AmplInterface::readoption() {

if (abs_eps_f) {
option.abs_eps_f = abs_eps_f;
}
if (rel_eps_f) {
option.rel_eps_f = rel_eps_f;
}
if (trace) {
if (trace2) {
option.trace = true;
}
if (rigor) {
Expand Down
3 changes: 2 additions & 1 deletion plugins/optim/main/ibexopt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ int main(int argc, char** argv) {
System *sys;
#ifdef _IBEX_WITH_AMPL_
AmplInterface *ampl;

cout << "IBEXOPT "<< _IBEX_RELEASE_ << " is running..."<< endl;
#endif

string extension = filename.Get().substr(filename.Get().find_last_of('.')+1);
Expand Down Expand Up @@ -313,7 +315,6 @@ int main(int argc, char** argv) {
#ifdef _IBEX_WITH_AMPL_
// si l'option -AMPL est présent, ecrire le fichier .sol pour ampl

cout << "IBEXOPT "<< _IBEX_RELEASE_ << endl;
// cout << o.get_nb_cells() << " iterations, objective in [" << o.get_uplo() <<"," << o.get_loup() << "]" << endl;

Optimizer::Status status =o.get_status();
Expand Down
2 changes: 1 addition & 1 deletion wscript
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ from waflib import Scripting, Logs, Options, Utils
import ibexutils

# The following variable is used to build ibex.pc and by "waf dist"
VERSION="2.8.0"
VERSION="2.8.2"
# The following variable is used only by "waf dist"
APPNAME='ibex-lib'

Expand Down

0 comments on commit 2db158b

Please sign in to comment.