18 template<
typename Rational,
typename Poly>
23 using Map = std::map<key_type,mapped_type>;
24 static_assert(std::is_same<key_type, typename Map::key_type>::value,
"Should be the same type");
25 static_assert(std::is_same<mapped_type, typename Map::mapped_type>::value,
"Should be the same type");
30 for (
const auto& d:
mData) {
31 if (d.second.isSubstitution()) {
32 d.second.asSubstitution()->resetCache();
63 return mData.insert(pair);
66 auto insert(
typename Map::const_iterator it,
const P& pair) {
68 return mData.insert(it, pair);
70 template<
typename... Args>
73 return mData.emplace(key,std::forward<Args>(args)...);
75 template<
typename... Args>
78 return mData.emplace_hint(it, key,std::forward<Args>(args)...);
84 typename Map::iterator
erase(
const typename Map::iterator& it) {
86 return erase(
typename Map::const_iterator(it));
88 typename Map::iterator
erase(
const typename Map::const_iterator& it) {
90 return mData.erase(it);
93 for (
auto& m:
mData) {
94 const auto& val = m.second;
95 if (!val.isSubstitution())
continue;
96 const auto& subs = val.asSubstitution();
97 CARL_LOG_DEBUG(
"carl.formula.model",
"Evaluating " << m.first <<
" -> " << subs <<
" as.");
98 m.second = subs->evaluate(*
this);
102 auto find(
const typename Map::key_type& key)
const {
103 return mData.find(key);
105 auto find(
const typename Map::key_type& key) {
106 return mData.find(key);
111 Model(
const std::map<Variable, Rational>& assignment) {
112 for (
const auto& a: assignment) {
113 mData.emplace(a.first, a.second);
116 template<
typename Container>
118 for (
const auto& var: c) {
119 if (
mData.find(var) ==
mData.end())
return false;
124 void assign(
const typename Map::key_type& key,
const T& t) {
125 auto it =
mData.find(key);
130 for (
const auto& m: model) {
131 auto res =
mData.insert(m);
136 res.first->second = m.second;
147 const auto& it =
at(key);
148 if (it.isSubstitution())
return it.asSubstitution()->evaluate(*
this);
151 void print(std::ostream& os,
bool simple =
true)
const {
152 os <<
"(model" << std::endl;
153 for (
const auto& ass:
mData) {
154 auto value = ass.second;
155 if (simple) value =
evaluated(ass.first);
157 if (ass.first.is_variable()) {
158 os <<
"\t(define-fun " << ass.first <<
" () " << ass.first.asVariable().type() << std::endl;
159 os <<
"\t\t" << value <<
")" << std::endl;
160 }
else if (ass.first.isBVVariable()) {
161 os <<
"\t(define-fun " << ass.first <<
" () " << ass.first.asBVVariable().sort() << std::endl;
162 os <<
"\t\t" << value <<
")" << std::endl;
163 }
else if (ass.first.isUVariable()) {
164 os <<
"\t(define-fun " << ass.first <<
" () " << ass.first.asUVariable().domain() << std::endl;
165 os <<
"\t\t" << value <<
")" << std::endl;
166 }
else if (ass.first.isFunction()) {
169 CARL_LOG_ERROR(
"carl.model",
"Encountered an unknown type of ModelVariable: " << ass.first);
173 os <<
")" << std::endl;
178 for (
const auto& ass:
mData) {
179 if (!first) os <<
", ";
180 auto value = ass.second;
181 if (simple) value =
evaluated(ass.first);
183 if (ass.first.is_variable()) {
184 os << ass.first <<
" = " << value;
185 }
else if (ass.first.isBVVariable()) {
186 os << ass.first <<
" = " << ass.first.asBVVariable().sort() <<
"(" << value <<
")";
187 }
else if (ass.first.isUVariable()) {
188 os << ass.first <<
" = " << ass.first.asUVariable().domain() <<
"(" << value <<
")";
189 }
else if (ass.first.isFunction()) {
192 CARL_LOG_ERROR(
"carl.model",
"Encountered an unknown type of ModelVariable: " << ass.first);
201 template<
typename Rational,
typename Poly>
A small wrapper that configures logging for carl.
#define CARL_LOG_ERROR(channel, msg)
#define CARL_LOG_DEBUG(channel, msg)
carl is the main namespace for the library.
std::ostream & operator<<(std::ostream &os, const BasicConstraint< Poly > &c)
Prints the given constraint on the given stream.
Represent a collection of assignments/mappings from variables to values.
std::map< key_type, std::size_t > mUsedInSubstitution
auto find(const typename Map::key_type &key) const
Map::iterator erase(const typename Map::iterator &it)
Map::iterator erase(const typename Map::const_iterator &it)
void update(const Model &model, bool disjoint=true)
std::map< key_type, mapped_type > Map
void printOneline(std::ostream &os, bool simple=false) const
Model(const std::map< Variable, Rational > &assignment)
auto emplace_hint(typename Map::const_iterator it, const key_type &key, Args &&...args)
void print(std::ostream &os, bool simple=true) const
auto emplace(const key_type &key, Args &&...args)
auto insert(const P &pair)
void assign(const typename Map::key_type &key, const T &t)
const ModelValue< Rational, Poly > & evaluated(const typename Map::key_type &key) const
Return the ModelValue for the given key, evaluated if it's a ModelSubstitution and evaluatable,...
bool contains(const Container &c) const
auto insert(typename Map::const_iterator it, const P &pair)
Map::iterator erase(const ModelVariable &variable)
auto find(const typename Map::key_type &key)
const auto & at(const key_type &key) const
Represent a sum type/variant over the different kinds of values that can be assigned to the different...
Represent a sum type/variant over the different kinds of variables that exist in CARL to use them in ...