Skip to content

Commit

Permalink
fixed bug in nl expressions, missing coefs
Browse files Browse the repository at this point in the history
  • Loading branch information
hhijazi committed May 1, 2024
1 parent 216087e commit 0e0a59e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ set(THIRDPARTY_INSTALL_PATH ${THIRDPARTY_BASE_PATH})

if(NOT WIN32)
#CoinUtils
if (CoinUtils or MP)
if (CoinUtils)
include(ExternalProject)
#CoinUtils
message(STATUS "Enable CoinUtils")
Expand Down
21 changes: 20 additions & 1 deletion examples/Gravity_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,30 @@
using namespace std;
using namespace gravity;

TEST_CASE("testing Gurobi's compound NL") {
Model<> M;
M.set_name("M");
var<> x("x", -2,2);
var<> y("y", 0,0);
var<> z("z", pi/2.,pi/2.);
var<> resvar("resvar", -10,10);
M.add(resvar);
M.add(x);
M.add(y);
M.add(z);
Constraint<> C("C");
C = cos(cos(y) - sin(z + cos(y))) - x - 2 - resvar;
M.add(C==0);
M.max(resvar);
solver<> GRB(M,gurobi);
double solver_time_start = get_wall_time();
GRB.run();
}

#ifdef USE_MP
TEST_CASE("testing readNL() function") {
Model<> M;
string NL_file = string(prj_dir)+"/data_sets/NL/hvycrash.nl";
string NL_file = string(prj_dir)+"/data_sets/NL/camshape100.nl";
int status = M.readNL(NL_file);
solver<> GRB(M,gurobi);
double solver_time_start = get_wall_time();
Expand Down
9 changes: 9 additions & 0 deletions include/gravity/func.h
Original file line number Diff line number Diff line change
Expand Up @@ -4810,6 +4810,15 @@ namespace gravity {

}
if(_expr){
if(_expr->_coef != unit<type>().eval()){
str += " ( PLUS , -1 , +"+to_string(current_root_id)+" )\n";
parent_id++;
str += " ( MULTIPLY , -1 , +"+to_string(parent_id)+" )\n";
parent_id++;
current_root_id = parent_id;
str += " ( CONSTANT , " + to_string(_expr->_coef) + " , +"+to_string(parent_id)+" )\n";
parent_id++;
}
str += getNLexpr(_expr, current_root_id, parent_id, i);
}
return str;
Expand Down

0 comments on commit 0e0a59e

Please sign in to comment.