Skip to content

Commit

Permalink
working on the bonmin interface
Browse files Browse the repository at this point in the history
  • Loading branch information
hhijazi committed Dec 20, 2017
1 parent 6ebc7f9 commit 5555a53
Show file tree
Hide file tree
Showing 10 changed files with 554 additions and 217 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Hassan Hijazi, Los Alamos National Laboratory, The Australian National Universit

Guanglei Wang, The Australian National University | guanglei.wang@anu.edu.au

Ksenia Bestuzheva, The Australian National University | k_best_7@mail.ru

Carleton Coffrin, Los Alamos National Laboratory,| cjc@lanl.gov

*****************************
See [INSTALL.md](INSTALL.md) for instructions on compiling Gravity

Expand Down
2 changes: 1 addition & 1 deletion cmake/FindBONMIN.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
set(BONMIN_ROOT_DIR "/home/kbestuzheva/Bonmin-1.8.4" CACHE PATH "BONMIN root directory.")
set(BONMIN_ROOT_DIR "$ENV{BONMIN_ROOT_DIR}" CACHE PATH "BONMIN root directory.")

message("Looking for Bonmin in ${BONMIN_ROOT_DIR}")

Expand Down
12 changes: 5 additions & 7 deletions include/gravity/BonminProgram.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
#include <coin/BonTMINLP.hpp>
#include <coin/IpIpoptApplication.hpp>
#include <coin/IpTNLP.hpp>
#include <Gravity/model.h>
#include <gravity/model.h>

using Ipopt::IpoptApplication;
using namespace Ipopt;
using namespace Bonmin;
using namespace gravity;

class BonminProgram : public TMINLP {
public:
Expand Down Expand Up @@ -67,12 +68,9 @@ class BonminProgram : public TMINLP {
Index* jCol, Number* values);

/** Method called by Ipopt */
virtual void finalize_solution(
TMINLP::SolverReturn status ,
Index n ,
const Number* x ,
Number obj_value
);
virtual void finalize_solution(TMINLP::SolverReturn status,
Index n, const Number* x, Number obj_value);


virtual bool get_variables_linearity(Index n, TNLP::LinearityType* var_types);
virtual bool get_constraints_linearity(Index m, TNLP::LinearityType* const_types);
Expand Down
10 changes: 3 additions & 7 deletions include/gravity/IpoptProgram.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
//
// IpoptProgram.h
// PowerTools++
//
// Created by Hassan on 30/01/2015.
// Copyright (c) 2015 NICTA. All rights reserved.
//

#ifndef __PowerTools____IpoptProgram__
#define __PowerTools____IpoptProgram__
#ifndef __Gravity____IpoptProgram__
#define __Gravity____IpoptProgram__

#include <stdio.h>
#include <assert.h>
Expand Down Expand Up @@ -101,4 +97,4 @@ class IpoptProgram : public TNLP {



#endif /* defined(__PowerTools____IpoptProgram__) */
#endif /* defined(__Gravity____IpoptProgram__) */
17 changes: 15 additions & 2 deletions include/gravity/func.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ namespace gravity {
}

string to_str() const;
string to_str(size_t) const;
void print(bool endline = true) const;
func_ get_derivative(const param_ &v) const;
vector<shared_ptr<param_>> get_nl_vars() const;
Expand Down Expand Up @@ -185,8 +186,18 @@ namespace gravity {


string to_str() const;
string to_str(size_t) const;
void print(size_t inst) const{
cout << to_str(inst) << endl;
}
void print_expanded() const{
auto nb_inst = get_nb_instances();
for (unsigned inst = 0; inst<nb_inst; inst++) {
print(inst);
}
}

void print(bool endline = true) const;
void print() const;

void print_tree() const;

Expand Down Expand Up @@ -1572,7 +1583,8 @@ namespace gravity {
Real eval(){ return eval(0);};
string to_str(bool display_input=false) const;
void print(bool endline=false, bool display_input=false);

void print(size_t index);

};


Expand All @@ -1590,6 +1602,7 @@ namespace gravity {
void poly_print(const constant_* c);

string poly_to_str(const constant_* c);
string poly_to_str(const constant_* c, size_t inst);


func_ operator+(const constant_& c1, const constant_& c2);
Expand Down
42 changes: 31 additions & 11 deletions include/gravity/param.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ class param_: public constant_ {
void set_name(const string s) {
_name = s;
};

string get_name(size_t inst) const {
string name = _name;
if (_is_indexed) {
name += to_string(_ids->at(inst));
}
else {
name += to_string(inst);
}
return name;
};


NType get_intype() const {
return _intype;
}
Expand Down Expand Up @@ -1366,10 +1379,21 @@ class param: public param_ {
}

/** Output */
void print(bool vals=false) const {
cout << this->to_str(vals);


string to_str(size_t index) const {
if (_is_indexed) {
return to_string(_val->at(_ids->at(index)));
}
else {
return to_string(_val->at(index));
}
}

void print(size_t index) const {
cout << to_str(index);
}

string to_str(bool vals=false) const {
string str = get_name();
if (vals) {
Expand All @@ -1380,18 +1404,14 @@ class param: public param_ {
}
str += "];\n";
}
// if(vals) {
// str += " = [ ";
// for(int i = 0 ; i < get_dim(); i++) {
// str += "(" + ;
// str += std::to_string(eval(i));
// str += " ";
// }
// str += "];";
// }
return str;
}

void print(bool vals=false) const {
cout << this->to_str(vals);
}


type getvalue() const {
if (_is_indexed) {
return (_val->at(_indices->begin()->second));
Expand Down
Loading

0 comments on commit 5555a53

Please sign in to comment.