Skip to content

Commit

Permalink
Fix writing non-func constraints #232
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Mar 19, 2024
1 parent c11c1d6 commit c13addb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion include/mp/flat/constr_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class BasicConstraint {
void SetContext(Context ) const { }
/// Add (merge) context, if meaningful
void AddContext(Context ) const { }
/// Has result var (is functional)?
bool HasResultVar() const { return false; }
/// For functional constraints, result variable index
int GetResultVar() const { return -1; }
/// Compute violation
Expand Down Expand Up @@ -83,6 +85,9 @@ class FunctionalConstraint : public BasicConstraint {
bool operator==(const FunctionalConstraint& dc) const {
return result_var_==dc.result_var_;
}
/// Has result var (is functional)?
/// We don't store this info in the type (yet.)
bool HasResultVar() const { return result_var_>=0; }
/// Get result variable
int GetResultVar() const { return result_var_; }
/// Set result variable
Expand Down Expand Up @@ -225,7 +230,8 @@ inline void WriteModelItem(
Writer& wrt,
const CustomFunctionalConstraint<A,P,N,I>& cfc,
const std::vector<std::string>& vnam) {
wrt << vnam.at(cfc.GetResultVar()) << " == ";
if (cfc.HasResultVar()) // really functional
wrt << vnam.at(cfc.GetResultVar()) << " == ";
wrt << cfc.GetTypeName();
wrt << '(';
WriteModelItem(wrt, cfc.GetArguments(), vnam);
Expand Down

0 comments on commit c13addb

Please sign in to comment.