carl  24.04
Computer ARithmetic Library
Assignment.h
Go to the documentation of this file.
1 /**
2  * @file Assignment.h
3  * @author Gereon Kremer <gereon.kremer@cs.rwth-aachen.de>
4  * @author Florian Corzilius <corzilius@cs.rwth-aachen.de>
5  * @since 2014-01-14
6  * @version 2014-10-27
7 
8  */
9 
10 #pragma once
11 
12 #include "Model.h"
13 
15 #include <carl-arith/ran/ran.h>
16 #include <carl-arith/vs/SqrtEx.h>
19 
20 #include <map>
21 
22 namespace carl
23 {
24 
25  /**
26  * Obtains all assignments which can be transformed to rationals and stores them in the passed map.
27  * @param _model The model from which to obtain the rational assignments.
28  * @param _rationalAssigns The map to store the rational assignments in.
29  * @return true, if the entire model could be transformed to rational assignments. (not possible if, e.g., sqrt is contained)
30  */
31  template<typename Rational, typename Poly>
32  bool getRationalAssignmentsFromModel( const Model<Rational,Poly>& _model, std::map<Variable,Rational>& _rationalAssigns );
33 
34  /**
35  * @param _assignment The assignment for which to check whether the given formula is satisfied by it.
36  * @param _formula The formula to be satisfied.
37  * @return 0, if this formula is violated by the given assignment;
38  * 1, if this formula is satisfied by the given assignment;
39  * 2, otherwise.
40  */
41  template<typename Rational, typename Poly>
42  unsigned satisfies( const Model<Rational,Poly>& _assignment, const Formula<Poly>& _formula );
43 
44  template<typename Rational, typename Poly>
45  bool isPartOf( const std::map<Variable,Rational>& _assignment, const Model<Rational,Poly>& _model );
46 
47  /**
48  * @param _model The assignment for which to check whether the given formula is satisfied by it.
49  * @param _assignment The map to store the rational assignments in.
50  * @param bvAssigns The map to store the bitvector assignments in.
51  * @param _formula The formula to be satisfied.
52  * @return 0, if this formula is violated by the given assignment;
53  * 1, if this formula is satisfied by the given assignment;
54  * 2, otherwise.
55  */
56  template<typename Rational, typename Poly>
57  unsigned satisfies( const Model<Rational,Poly>& _model, const std::map<Variable,Rational>& _assignment, const std::map<BVVariable, BVTerm>& bvAssigns, const Formula<Poly>& _formula );
58 
59  template<typename Rational, typename Poly>
60  void getDefaultModel( Model<Rational,Poly>& _defaultModel, const UEquality& _constraint, bool _overwrite = true, size_t _seed = 0 );
61  template<typename Rational, typename Poly>
62  void getDefaultModel( Model<Rational,Poly>& _defaultModel, const BVTerm& _constraint, bool _overwrite = true, size_t _seed = 0 );
63  template<typename Rational, typename Poly>
64  void getDefaultModel( Model<Rational,Poly>& _defaultModel, const Constraint<Poly>& _constraint, bool _overwrite = true, size_t _seed = 0 );
65  template<typename Rational, typename Poly>
66  void getDefaultModel( Model<Rational,Poly>& _defaultModel, const Formula<Poly>& _formula, bool _overwrite = true, size_t _seed = 0 );
67 
68  template<typename Rational, typename Poly>
70 
71  template<typename Rational, typename Poly>
72  std::optional<Assignment<typename Poly::RootType>> get_ran_assignment(const carlVariables& vars, const Model<Rational,Poly>& model) {
74  for (const auto& var : vars) {
75  if (model.find(var) == model.end()) return std::nullopt;
76  if (model.at(var).isRational()) {
77  result.emplace(var, typename Poly::RootType(model.at(var).asRational()));
78  } else if (model.at(var).isRAN()) {
79  result.emplace(var, model.at(var).asRAN());
80  } else {
81  return std::nullopt;
82  }
83  }
84  return result;
85  }
86 
87  template<typename Rational, typename Poly>
90  for (const auto& e : model) {
91  if (e.second.isRational()) {
92  assert(e.first.is_variable());
93  result.emplace(e.first.asVariable(), typename Poly::RootType(e.second.asRational()));
94  } else if (e.second.isRAN()) {
95  assert(e.first.is_variable());
96  result.emplace(e.first.asVariable(), e.second.asRAN());
97  }
98  }
99  return result;
100  }
101 }
102 
103 #include "Assignment.tpp"
Represent a real algebraic number (RAN) in one of several ways:
carl is the main namespace for the library.
std::optional< Assignment< typename Poly::RootType > > get_ran_assignment(const carlVariables &vars, const Model< Rational, Poly > &model)
Definition: Assignment.h:72
bool getRationalAssignmentsFromModel(const Model< Rational, Poly > &_model, std::map< Variable, Rational > &_rationalAssigns)
Obtains all assignments which can be transformed to rationals and stores them in the passed map.
Formula< Poly > representingFormula(const ModelVariable &mv, const Model< Rational, Poly > &model)
bool isPartOf(const std::map< Variable, Rational > &_assignment, const Model< Rational, Poly > &_model)
unsigned satisfies(const Model< Rational, Poly > &_assignment, const Formula< Poly > &_formula)
std::map< Variable, T > Assignment
Definition: Common.h:13
void getDefaultModel(Model< Rational, Poly > &_defaultModel, const UEquality &_constraint, bool _overwrite=true, size_t _seed=0)
Represent a polynomial (in)equality against zero.
Definition: Constraint.h:62
Represent a collection of assignments/mappings from variables to values.
Definition: Model.h:19
auto find(const typename Map::key_type &key) const
Definition: Model.h:102
auto end() const
Definition: Model.h:46
const auto & at(const key_type &key) const
Definition: Model.h:38
Represent a sum type/variant over the different kinds of variables that exist in CARL to use them in ...
Definition: ModelVariable.h:20
Implements an uninterpreted equality, that is an equality of either two uninterpreted function instan...
Definition: UEquality.h:23