Skip to content

Commit

Permalink
NLW C++: 0 expressions by default #30
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Nov 14, 2023
1 parent d431e0e commit 357dc02
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
7 changes: 6 additions & 1 deletion nl-writer2/include/api/c/nl-feeder2-c-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ namespace mp {
class NLFeeder2_C_Impl
: public NLFeeder2<NLFeeder2_C_Impl, void*> {
public:
/// typedef base class
using Base = NLFeeder2<NLFeeder2_C_Impl, void*>;

/// Construct
NLFeeder2_C_Impl(NLFeeder2_C* pnlf2)
: nlf2_c_(*pnlf2) { }
Expand Down Expand Up @@ -123,7 +126,9 @@ class NLFeeder2_C_Impl
*
* Details of ObjExprWriter: see NLWriter2. */
template <class ObjExprWriter>
void FeedObjExpression(int i, ObjExprWriter& ) { }
void FeedObjExpression(int i, ObjExprWriter& ew) {
Base::FeedObjExpression(i, ew); // reuse default
}


///////////////////// 3. DEFINED VARIABLES /////////////////////
Expand Down
11 changes: 8 additions & 3 deletions nl-writer2/include/mp/nl-feeder2.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,16 @@ class NLFeeder2 {

/** Feed nonlinear expression of objective \a i.
*
* The default implementation below feeds constant 0
* (linear models.)
*
* Implementation example:
* ew.EPut(obj_root_expr[i]);
*
* Details of ObjExprWriter: see NLWriter2. */
template <class ObjExprWriter>
void FeedObjExpression(int i, ObjExprWriter& ) { }
void FeedObjExpression(int , ObjExprWriter& ew)
{ ew.NPut(0.0); }


///////////////////// 3. DEFINED VARIABLES /////////////////////
Expand Down Expand Up @@ -334,10 +338,11 @@ class NLFeeder2 {
* Algebraic constraints (num_algebraic_cons)
* come before logical (num_logical_cons).
* For linear constraints, the expression should be
* constant 0.
* constant 0, which is implemented as default.
*/
template <class ConExprWriter>
void FeedConExpression(int i, ConExprWriter& ) { }
void FeedConExpression(int , ConExprWriter& ew)
{ ew.NPut(0.0); }


///////////////////// 7. EXPRESSIONS /////////////////////
Expand Down
2 changes: 1 addition & 1 deletion nl-writer2/include/mp/nl-header.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ struct NLInfo : NLInfo_C {
/// Construct default
NLInfo() {
format = BINARY;
prob_name = "default_instance";
prob_name = "nl_instance";
num_ampl_options = 3;
ampl_vbtol = 0.0;
arith_kind = NL_ARITH_IEEE_LITTLE_ENDIAN;
Expand Down

0 comments on commit 357dc02

Please sign in to comment.