The source code and dockerfile for the GSW2024 AI Lab.
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

244 lines
4.7 KiB

2 months ago
  1. %module IntervalRationalT
  2. %{
  3. #include <carl/interval/Interval.h>
  4. typedef mpq_class Rational;
  5. typedef unsigned int uint;
  6. %}
  7. %import "rational.i"
  8. typedef unsigned int uint;
  9. namespace carl {
  10. %include "enums.swg"
  11. %javaconst(1);
  12. enum class BoundType {
  13. /// the given bound is compared by a strict ordering relation
  14. STRICT=0,
  15. /// the given bound is compared by a weak ordering relation
  16. WEAK=1,
  17. /// the given bound is interpreted as minus or plus infinity depending on whether it is the left or the right bound
  18. INFTY=2
  19. };
  20. template<typename Number>
  21. class Interval
  22. {
  23. public:
  24. Interval(const Number& n) :
  25. mContent(n),
  26. mLowerBoundType(BoundType::WEAK),
  27. mUpperBoundType(BoundType::WEAK) { }
  28. Interval(const Number& lower, const Number& upper)
  29. {
  30. }
  31. Interval(const Number& lower, BoundType lowerBoundType, const Number& upper, BoundType upperBoundType)
  32. {
  33. }
  34. //BEWARE: in python sth with return value policy had to be changed here, so maybe problems will arise
  35. inline const Number& lower() const;
  36. inline const Number& upper() const;
  37. inline void setLower(const Number& n);
  38. inline void setUpper(const Number& n);
  39. inline bool isInfinite() const;
  40. inline bool isUnbounded() const;
  41. inline bool isHalfBounded() const;
  42. inline bool isEmpty() const;
  43. inline bool isPointInterval() const;
  44. inline bool isOpenInterval() const;
  45. inline bool isClosedInterval() const;
  46. inline bool isZero() const;
  47. inline bool isOne() const;
  48. inline bool isPositive() const;
  49. inline bool isNegative() const;
  50. inline bool isSemiPositive() const;
  51. inline bool isSemiNegative() const;
  52. Interval<Number> integralPart() const;
  53. Number diameter() const;
  54. //NOTE: this is now set for Number not being a float... needs to be changed in Interval.h otherwise
  55. Number center() const;
  56. Number sample(bool _includingBounds = true) const;
  57. bool contains(const Number& val) const;
  58. bool contains(const Interval<Number>& rhs) const;
  59. bool meets(const Number& val) const;
  60. bool isSubset(const Interval<Number>& rhs) const;
  61. bool isProperSubset(const Interval<Number>& rhs) const;
  62. Interval<Number> div(const Interval<Number>& rhs) const;
  63. Interval<Number> inverse() const;
  64. Interval<Number> abs() const;
  65. Interval<Number> pow(uint exp) const;
  66. bool intersectsWith(const Interval<Number>& rhs) const;
  67. Interval<Number> intersect(const Interval<Number>& rhs) const;
  68. bool unite(const Interval<Number>& rhs, Interval<Number>& resultA, Interval<Number>& resultB) const;
  69. bool difference(const Interval<Number>& rhs, Interval<Number>& resultA, Interval<Number>& resultB) const;
  70. bool complement(Interval<Number>& resultA, Interval<Number>& resultB) const;
  71. bool symmetricDifference(const Interval<Number>& rhs, Interval<Number>& resultA, Interval<Number>& resultB) const;
  72. std::string toString() const;
  73. %extend {
  74. /*
  75. static Interval<Number> pow(const Interval<Number>& _in, unsigned _exponent)
  76. {
  77. return carl::pow(_in,_exponent);
  78. } */
  79. static Interval<Number> floor(const Interval<Number>& _in) {
  80. return carl::floor(_in);
  81. }
  82. static Interval<Number> ceil(const Interval<Number>& _in) {
  83. return carl::ceil(_in);
  84. }
  85. /*
  86. static Interval<Number> abs(const Interval<Number>& _in) {
  87. return carl::abs(_in);
  88. }
  89. static Interval<Number> div(const Interval<Number>& _lhs, const Interval<Number>& _rhs) {
  90. return carl::div(_lhs,_rhs);
  91. } */
  92. static Interval<Number> quotient(const Interval<Number>& _lhs, const Interval<Number>& _rhs) {
  93. return carl::div(_lhs,_rhs);
  94. }
  95. static bool isInteger(const Interval<Number>&) {
  96. return false;
  97. }
  98. Interval<Number> add(const Interval<Number>& rhs) {
  99. return *$self+rhs;
  100. }
  101. Interval<Number> add(const Rational& rhs) {
  102. return *$self+rhs;
  103. }
  104. Interval<Number> neg() {
  105. return -*$self;
  106. }
  107. Interval<Number> sub(const Interval<Number>& rhs) {
  108. return *$self-rhs;
  109. }
  110. Interval<Number> sub(const Rational& rhs) {
  111. return *$self-rhs;
  112. }
  113. Interval<Number> mul(const Interval<Number>& rhs) {
  114. return *$self*rhs;
  115. }
  116. Interval<Number> mul(const Rational& rhs) {
  117. return *$self*rhs;
  118. }
  119. Interval<Number> div(const Rational& rhs) {
  120. return *$self+rhs;
  121. }
  122. //The +=, -=, *= are missing now
  123. bool equals(const Interval<Number> rhs) {
  124. return *$self==rhs;
  125. }
  126. bool notEquals(const Interval<Number> rhs) {
  127. return *$self!=rhs;
  128. }
  129. bool lessEquals(const Interval<Number> rhs) {
  130. return *$self<=rhs;
  131. }
  132. bool lessEquals(const Rational rhs) {
  133. return *$self<=rhs;
  134. }
  135. bool greaterEquals(const Interval<Number> rhs) {
  136. return *$self>=rhs;
  137. }
  138. bool greaterEquals(const Rational rhs) {
  139. return *$self>=rhs;
  140. }
  141. bool less(const Interval<Number> rhs) {
  142. return *$self<rhs;
  143. }
  144. bool less(const Rational rhs) {
  145. return *$self<rhs;
  146. }
  147. bool greater(const Interval<Number> rhs) {
  148. return *$self>rhs;
  149. }
  150. bool greater(const Rational rhs) {
  151. return *$self>rhs;
  152. }
  153. }
  154. };
  155. }
  156. %template(IntervalRational) carl::Interval<Rational>;