You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
3.8 KiB

3 months ago
  1. %module ConstraintRationalT
  2. %{
  3. #include <carl/formula/Constraint.h>
  4. #include <carl/core/SimpleConstraint.h>
  5. #include <carl/formula/Formula.h>
  6. #include "gmpxx.h"
  7. #include <carl/core/RationalFunction.h>
  8. #include <carl/core/Relation.h>
  9. typedef mpq_class Rational;
  10. typedef carl::Monomial::Arg Monomial;
  11. typedef carl::Term<Rational> Term;
  12. typedef carl::MultivariatePolynomial<Rational> Polynomial;
  13. typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial;
  14. typedef carl::RationalFunction<Polynomial> RationalFunction;
  15. typedef carl::RationalFunction<FactorizedPolynomial> FactorizedRationalFunction;
  16. typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair;
  17. %}
  18. %import "formula.i"
  19. %include "std_string.i"
  20. %import "variable.i"
  21. %import "polynomial.i"
  22. %import "rationalfunction.i"
  23. %import "factorizedpolynomial.i"
  24. %include "std_vector.i"
  25. %include "std_map.i"
  26. typedef carl::MultivariatePolynomial<Rational> Polynomial;
  27. typedef mpq_class Rational;
  28. typedef carl::Monomial::Arg Monomial;
  29. typedef carl::Term<Rational> Term;
  30. typedef carl::FactorizedPolynomial<Polynomial> FactorizedPolynomial;
  31. typedef carl::RationalFunction<Polynomial> RationalFunction;
  32. typedef carl::RationalFunction<FactorizedPolynomial> FactorizedRationalFunction;
  33. typedef carl::PolynomialFactorizationPair<Polynomial> FactorizationPair;
  34. namespace carl {
  35. enum Relation { EQ = 0, NEQ = 1, LESS = 2, LEQ = 4, GREATER = 3, GEQ = 5 };
  36. template<typename Pol> class Constraint {
  37. public:
  38. Constraint( bool _valid = true );
  39. explicit Constraint( carl::Variable::Arg _var, carl::Relation _rel, const typename Pol::NumberType& _bound = constant_zero<typename Pol::NumberType>::get() );
  40. explicit Constraint( const Pol& _lhs, carl::Relation _rel );
  41. unsigned satisfiedBy( const std::map<Variable,Rational>& _assignment ) const;
  42. std::string toString( unsigned _unequalSwitch = 0, bool _infix = true, bool _friendlyVarNames = true ) const;
  43. const Pol& lhs() const;
  44. carl::Relation relation() const;
  45. //TODO: maybe find fix for the weird underscore names
  46. %extend {
  47. carl::Formula<Pol> not_() {
  48. return carl::Formula<Pol>(carl::FormulaType::NOT, carl::Formula<Pol>(*$self));
  49. }
  50. carl::Formula<Pol> and_(const Constraint& rhs) {
  51. return carl::Formula<Pol>(carl::FormulaType::AND, carl::Formula<Pol>(*$self), carl::Formula<Pol>(rhs));
  52. }
  53. carl::Formula<Pol> and_(const carl::Formula<Pol>& rhs) {
  54. return carl::Formula<Pol>(carl::FormulaType::AND, carl::Formula<Pol>(*$self), rhs);
  55. }
  56. carl::Formula<Pol> or_(const Constraint& rhs) {
  57. return carl::Formula<Pol>(carl::FormulaType::OR, carl::Formula<Pol>(*$self), carl::Formula<Pol>(rhs));
  58. }
  59. carl::Formula<Pol> or_(const carl::Formula<Pol>& rhs) {
  60. return carl::Formula<Pol>(carl::FormulaType::OR, carl::Formula<Pol>(*$self), rhs);
  61. }
  62. carl::Formula<Pol> xor_(const Constraint& rhs) {
  63. return carl::Formula<Pol>(carl::FormulaType::XOR, carl::Formula<Pol>(*$self), carl::Formula<Pol>(rhs));
  64. }
  65. carl::Formula<Pol> xor_(const carl::Formula<Pol>& rhs) {
  66. return carl::Formula<Pol>(carl::FormulaType::XOR, carl::Formula<Pol>(*$self), rhs);
  67. }
  68. }
  69. };
  70. template<typename LhsType> class SimpleConstraint {
  71. public:
  72. SimpleConstraint(bool v) : mLhs(v ? 0 : 1), mRelation(carl::Relation::EQ) {}
  73. SimpleConstraint(const LhsType& lhs, carl::Relation rel) : mLhs(lhs), mRelation(rel)
  74. {}
  75. const LhsType& lhs() const {return mLhs;}
  76. const carl::Relation& rel() const {return mRelation;}
  77. %extend {
  78. std::string toString() {
  79. std::stringstream ss;
  80. ss << *$self;
  81. return ss.str();
  82. }
  83. }
  84. };
  85. }
  86. %include "std_map.i"
  87. %template(ConstraintRational) carl::Constraint<Polynomial>;
  88. %template(SimpleConstraintRational) carl::SimpleConstraint<Polynomial>;
  89. %template(SimpleConstraintFunc) carl::SimpleConstraint<FactorizedRationalFunction>;