Skip to content

Commit

Permalink
Dummy UEncConstraint #232
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Jan 22, 2024
1 parent 3e76194 commit b4fc9e2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
13 changes: 10 additions & 3 deletions include/mp/flat/constr_general.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ using IndicatorConstraintQuadEQ = IndicatorConstraint<QuadConEQ>;
using IndicatorConstraintQuadGE = IndicatorConstraint<QuadConGE>;


/// Unary encoding.
/// Currently a dummy constraint just to build
/// the reformulation graph.
DEF_STATIC_CONSTR(UnaryEncodingConstraint, VarArray1,
"Unary encoding of an integer bounded variable");


////////////////////////////////////////////////////////////////////////
/// SOS1, SOS2

Expand Down Expand Up @@ -277,17 +284,17 @@ DEF_STATIC_CONSTR_WITH_PRM( QuadraticConeConstraint, VarArray, DblParamArray,
DEF_STATIC_CONSTR_WITH_PRM( RotatedQuadraticConeConstraint, VarArray, DblParamArray,
"Rotated quadratic cone "
"2 * p1*x1*p2*x2 >= (p3*x3)^2 + ...),"
" x1, x2 >= 0, with factors p1..pn");
" x1, x2 >= 0 or x1, x2 <= 0, with factors p1..pn");
/// Exponential cone
DEF_STATIC_CONSTR_WITH_PRM( ExponentialConeConstraint, VarArray3, DblParamArray3,
"Exponential cone ax >= by exp(cz / (by)),"
" where ax, by >= 0, with factors a,b,c");
/// Power cone
DEF_STATIC_CONSTR_WITH_PRM( PowerConeConstraint, VarArray, DblParamArray,
"Power cone with factors ");
"Power cone with factors");
/// Geometric cone
DEF_STATIC_CONSTR_WITH_PRM( GeometricConeConstraint, VarArray, DblParamArray,
"Geometric with factors ");
"Geometric with factors");

} // namespace mp

Expand Down
10 changes: 10 additions & 0 deletions include/mp/flat/converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,8 @@ class FlatConverter :
pre::NodeRange auto_link_src_item_; // the source item for autolinking
std::vector<pre::NodeRange> auto_link_targ_items_;

pre::Many2OneLink many2one_link_ { GetValuePresolver() }; // the many-to-one links

ConicConverter<Impl> conic_cvt_ { *static_cast<Impl*>(this) };
int nQC2SOCPAttempted_= 0;
int nQC2SOCPSucceeded_= 0;
Expand Down Expand Up @@ -1367,6 +1369,11 @@ class FlatConverter :
ExponentialConeConstraint, "acc:expcone")
STORE_CONSTRAINT_TYPE__NO_MAP(
GeometricConeConstraint, "acc:geomcone")
/// Store UEncConstr
STORE_CONSTRAINT_TYPE__NO_MAP(
UnaryEncodingConstraint, "acc:uenc")
/// Dummy conversion for UEncConstr
void Convert(const UnaryEncodingConstraint& ) { }


protected:
Expand Down Expand Up @@ -1437,6 +1444,9 @@ class FlatConverter :

/// ValuePresolve link copying values 1:many
pre::One2ManyLink& GetOne2ManyLink() { return one2many_link_; }

/// ValuePresolve link copying values many:1
pre::Many2OneLink& GetMany2OneLink() { return many2one_link_; }
};


Expand Down
2 changes: 1 addition & 1 deletion include/mp/flat/redef/MIP/cond_eq.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CondEQConverter_MIP :
!GetMC().IfMightUseEqualityEncodingForVar(
args.var(0))) {
Base::Convert(eq0c, i); // Calls ConvertCtxPos / Neg
} // else, using unary encoding whose flags are,
} // else, might use unary encoding whose flags are,
} // in the fixed case, fixed by PropagateResult()

/// Convert in positive context
Expand Down
12 changes: 11 additions & 1 deletion include/mp/flat/redef/MIP/converter_mip.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ class MIPFlatConverter
const auto ub_dbl = this->ub(var);
return (lb_dbl>std::numeric_limits<int>::min() &&
ub_dbl<std::numeric_limits<int>::max()) &&
(ub_dbl-lb_dbl <= 100000);
(ub_dbl-lb_dbl <= 10000000);
}

/// Obtain extended column \a k of ZZI encoding C^r
Expand All @@ -214,6 +214,8 @@ class MIPFlatConverter


protected:
/// Return index of CondLinEQ for this \a val,
/// if saved before
int MapFind__VarConstCmp(int var, double val) {
auto itVar = map_vars_eq_const_.find(var);
if (map_vars_eq_const_.end() != itVar) {
Expand Down Expand Up @@ -302,7 +304,15 @@ class MIPFlatConverter
CreateUnaryEncoding(var, map);
}

/// Create unary encoding once we go for it.
/// Adds a dummy UnaryEncodingConstraint for graph linking.
/// Another design would be to have an "EqualityEncodingConstraint"
/// and move all conversions there (indicators vs unary encoding.)
/// That would partially automate linking.
/// A benefit would be if some solver later supports them natively
/// (IloDistribute?), now they are always converted below.
void CreateUnaryEncoding(int var, const SingleVarEqConstMap& map) {
auto valnode = MPD( AddConstraint( UnaryEncodingConstraint{{var}} ) );
const Model& model = MP_DISPATCH( GetModel() );
if (!model.is_integer_var(var))
MP_RAISE("MP2MIP: Equality encoding: comparing non-integer variables not implemented");
Expand Down

0 comments on commit b4fc9e2

Please sign in to comment.