carl  24.04
Computer ARithmetic Library
SymmetryBreaker.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../formula/Formula.h"
4 
5 #include <vector>
6 
7 namespace carl {
8 namespace formula {
9 namespace symmetry {
10 
11 template<typename Poly>
13  assert(x.type() == y.type());
14  switch (x.type()) {
16  switch (rel) {
17  case Relation::EQ:
19  case Relation::LEQ:
21  case Relation::GEQ:
23  default:
24  assert(false);
25  }
28  return Formula<Poly>(Constraint<Poly>(Poly(x) - y, rel));
29  default:
30  CARL_LOG_INFO("carl.formula.symmetry", "Tried to break symmetry on unsupported variable type " << x.type());
31  }
33 }
34 
35 /**
36  * Creates symmetry breaking constraints from the passed symmetries in the spirit of @cite Crawford1996.
37  */
38 template<typename Poly>
40  constexpr bool eliminateTrue = true;
41  Formulas<Poly> eq;
42  Formulas<Poly> res;
43  std::set<std::pair<Variable,Variable>> inEq;
44  for (const auto& v: vars) {
45  if (v.first == v.second) continue;
46  if (eliminateTrue && inEq.find(v) != inEq.end()) continue;
47  Formula<Poly> cur = createComparison<Poly>(v.first, v.second, Relation::LEQ);
49  eq.emplace_back(createComparison<Poly>(v.first, v.second, Relation::EQ));
50  if (eliminateTrue) inEq.emplace(v.second, v.first);
51  }
52  return Formula<Poly>(FormulaType::AND, std::move(res));
53 }
54 
55 }
56 }
57 }
#define CARL_LOG_INFO(channel, msg)
Definition: carl-logging.h:42
carl is the main namespace for the library.
std::vector< Formula< Poly > > Formulas
Relation
Definition: Relation.h:20
std::vector< std::pair< Variable, Variable > > Symmetry
A symmetry represents a bijection on a set of variables.
Definition: symmetry.h:14
Formula< Poly > lexLeaderConstraint(const Symmetry &vars)
Creates symmetry breaking constraints from the passed symmetries in the spirit of .
Formula< Poly > createComparison(Variable x, Variable y, Relation rel)
A Variable represents an algebraic variable that can be used throughout carl.
Definition: Variable.h:85
constexpr VariableType type() const noexcept
Retrieves the type of the variable.
Definition: Variable.h:131
Represent a polynomial (in)equality against zero.
Definition: Constraint.h:62