Skip to content

Commit

Permalink
Marking: prepare for new expressions #237
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed May 3, 2024
1 parent f6e14cb commit d5b26c0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
2 changes: 2 additions & 0 deletions include/mp/flat/constr_2_expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class Constraints2Expr {

protected:
/// Algebraic cons: no marking (when NLConstraint accepted?)
/// @todo Do we need to consider NLConstraint / NLObjective at this step?
/// Are they added during marking?
template <class Body, class RhsOrRange>
void DoMarkArgsAsVars( // needs to appear before the most generic template
const AlgebraicConstraint<Body, RhsOrRange>& , int ) { }
Expand Down
11 changes: 7 additions & 4 deletions include/mp/flat/converter_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <cmath>
#include <cfloat>

#include "mp/utils-vec.h"

#include "mp/flat/obj_std.h"
#include "mp/flat/constr_std.h"
#include "mp/flat/constr_keeper.h"
Expand Down Expand Up @@ -235,18 +237,19 @@ class FlatModel
}

/// Mark as an explicit result variable
/// @todo AutoExpand fills 'false' for new elements...
void MarkAsResultVar(int v) {
var_result_.at(v) = true;
AutoExpand(var_result_, v) = true;
}

/// Mark as a proper expression
void MarkAsExpression(int v) {
var_result_.at(v) = false;
AutoExpand(var_result_, v) = false;
}

/// Is the variable an explicit result var?
bool IsResultVar(int v) const {
return var_result_.at(v);
bool IsResultVar(int v) {
return AutoExpand(var_result_, v);
}

///////////////////////////// OBJECTIVES ////////////////////////////
Expand Down
12 changes: 12 additions & 0 deletions include/mp/utils-vec.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

namespace mp {

/// Grow vector capacity by a factor if needed.
/// @return reference to the element at \a i.
template <class Vec>
auto AutoExpand(Vec& vec, typename Vec::size_type i) {
if (vec.size()<=i) {
if (vec.capacity()<=i)
vec.reserve(((i+1)*13)/10);
vec.resize(i+1);
}
return vec[i];
}

} // namespace mp


Expand Down
3 changes: 2 additions & 1 deletion solvers/scipmp/scipmpmodelapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ class ScipModelAPI :
/// For each expression,
/// say ACCEPT_EXPRESSION(Recommended)
/// or ACCEPT_EXPRESSION(AcceptedButNotRecommended).
/// This can be user-configured via options 'acc:exp' etc.
ACCEPT_EXPRESSION(ExpExpression, Recommended)
void AddExpression(const ExpExpression& );
SCIP_EXPR* AddExpression(const ExpExpression& );

/// The linear range constraint, if fully supported with basis info etc.
ACCEPT_CONSTRAINT(LinConRange, Recommended, CG_Linear)
Expand Down

0 comments on commit d5b26c0

Please sign in to comment.