6 #include <carl-arith/core/Variable.h>
13 namespace variableordering {
17 using carl::operator<<;
25 template<
typename Objects>
27 using Extractor = std::function<double(Objects, carl::Variable)>;
29 std::vector<std::tuple<Extractor, std::size_t, double>>
mFeatures;
32 mFeatures.emplace_back(std::move(e), level, weight);
38 if (res.size() <= std::get<1>(f)) {
39 res.resize(std::get<1>(f) + 1);
41 res[std::get<1>(f)] += std::get<2>(f) * std::get<0>(f)(o, v);
43 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.variableorder",
"Valuation of " << v <<
" is " << res);
46 std::vector<carl::Variable>
sortVariables(
const Objects& o, std::vector<carl::Variable>
vars)
const {
47 std::vector<std::pair<Valuation, carl::Variable>> valuations;
51 std::sort(valuations.begin(), valuations.end());
52 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.variableorder",
"Evaluated to " << valuations);
53 std::transform(valuations.begin(), valuations.end(),
vars.begin(), [](
const auto& p) { return p.second; });
58 template<
typename Constra
ints,
typename Calculator>
59 double abstract_feature(
const Constraints& constraints,
double initial, std::function<
double(
double,
double)>&& comb, Calculator&& calc) {
60 return std::accumulate(constraints.begin(), constraints.end(), initial,
61 [&comb, &calc](
double cur,
const auto& c) { return comb(cur, calc(c)); }
66 template<
typename Constra
ints>
67 double max_degree(
const Constraints& constraints, carl::Variable v) {
70 [](
double a,
double b) {
return std::max(a, b); },
71 [v](
const auto& c) {
return static_cast<double>(c.maxDegree(v)); }
76 template<
typename Constra
ints>
80 [](
double a,
double b) {
return std::max(a, b); },
83 for (
const auto& t : c.lhs()) {
84 if (t.has(v)) max = std::max(max,
static_cast<double>(t.tdeg()));
91 template<
typename Constra
ints>
95 [](
double a,
double b) {
return std::max(a, b); },
98 for (
const auto& t : c.lhs()) {
101 return static_cast<double>(max);
106 template<
typename Constra
ints>
110 [](
double a,
double b) {
return a + b; },
112 if (c.variables().has(v)) {
121 template<
typename Constra
ints>
125 [](
double a,
double b) {
return std::max(a, b); },
127 return double(c.lhs().lcoeff(v).total_degree());
133 template<
typename Constra
ints>
136 [](
double a,
double b){
return a+b; },
137 [v](
const auto& c){
return static_cast<double>(c.maxDegree(v)); }
141 template<
typename Constra
ints>
144 [](
double a,
double b){
return a+b; },
147 for (
const auto& t: c.lhs()) {
148 if (t.monomial() ==
nullptr)
continue;
149 std::size_t c = t.monomial()->exponent_of_variable(v);
152 return static_cast<double>(sum);
157 template<
typename Constra
ints>
159 auto num_constr = constraints.size();
161 [num_constr](
double a,
double b){
return a + b / (double)num_constr; },
164 std::size_t count = 0;
165 for (
const auto& t: c.lhs()) {
166 if (t.monomial() ==
nullptr)
continue;
167 std::size_t c = t.monomial()->exponent_of_variable(v);
171 return static_cast<double>(sum)/
static_cast<double>(count);
178 template<
typename Constra
ints>
182 features.
addFeature(detail::max_degree<Constraints>, 0, -1.0);
183 features.
addFeature(detail::max_term_total_degree<Constraints>, 0, -0.5);
184 features.
addFeature(detail::max_coefficient<Constraints>, 1, 1);
186 carl::carlVariables
vars;
191 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.variableorder",
"Calculated variable ordering " << orderedVars);
195 template<
typename Constra
ints>
199 features.
addFeature(detail::max_degree<Constraints>, 0, -1.0);
200 features.
addFeature(detail::num_occurrences<Constraints>, 1, -1.0);
202 carl::carlVariables
vars;
207 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.variableorder",
"Calculated variable ordering " << orderedVars);
214 template<
typename Constra
ints>
218 features.
addFeature(detail::max_degree<Constraints>, 0, -1.0);
219 features.
addFeature(detail::max_term_total_degree<Constraints>, 1, -1.0);
220 features.
addFeature(detail::num_occurrences<Constraints>, 2, -1.0);
222 carl::carlVariables
vars;
227 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.variableorder",
"Calculated variable ordering " << orderedVars);
231 template<
typename Constra
ints>
235 features.
addFeature(detail::max_degree<Constraints>, 0, -1.0);
236 features.
addFeature(detail::max_lcoeff_total_degree<Constraints>, 1, -1.0);
237 features.
addFeature(detail::num_occurrences<Constraints>, 2, -1.0);
239 carl::carlVariables
vars;
243 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.variableorder",
"Calculated variable ordering " << orderedVars);
252 template<
typename Constra
ints>
256 features.
addFeature(detail::sum_max_degree<Constraints>, 0, -1.0);
257 features.
addFeature(detail::avg_avg_degree<Constraints>, 1, -1.0);
258 features.
addFeature(detail::sum_sum_degree<Constraints>, 2, -1.0);
260 carl::carlVariables
vars;
264 SMTRAT_LOG_DEBUG(
"smtrat.mcsat.variableorder",
"Calculated variable ordering " << orderedVars);
268 template<
typename Constra
ints>
270 carl::carlVariables
vars;
272 auto var_order =
vars.as_vector();
274 std::sort(var_order.begin(), var_order.end(), [](
const auto& lhs,
const auto& rhs) {
275 const auto& lhs_name = lhs.name();
276 const auto& rhs_name = rhs.name();
277 return std::lexicographical_compare(lhs_name.begin(), lhs_name.end(), rhs_name.begin(), rhs_name.end()); });
void sort(T *array, int size, LessThan lt)
Numeric abs(const Numeric &_value)
Calculates the absolute value of the given Numeric.
double max_degree(const Constraints &constraints, carl::Variable v)
The maximum degree of this variable.
double abstract_feature(const Constraints &constraints, double initial, std::function< double(double, double)> &&comb, Calculator &&calc)
double max_term_total_degree(const Constraints &constraints, carl::Variable v)
The maximum total degree of a term involving this variable.
double max_coefficient(const Constraints &constraints, carl::Variable v)
double sum_max_degree(const Constraints &constraints, carl::Variable v)
double sum_sum_degree(const Constraints &constraints, carl::Variable v)
double avg_avg_degree(const Constraints &constraints, carl::Variable v)
double max_lcoeff_total_degree(const Constraints &constraints, carl::Variable v)
double num_occurrences(const Constraints &constraints, carl::Variable v)
std::vector< carl::Variable > feature_based_lexicographic(const Constraints &c)
void gatherVariables(carl::carlVariables &vars, const Constraints &constraints)
std::vector< carl::Variable > feature_based_z3(const Constraints &c)
std::vector< carl::Variable > feature_based_pickering(const Constraints &c)
According to Pickering, Lynn, Tereso Del Rio Almajano, Matthew England, and Kelly Cohen.
std::vector< carl::Variable > feature_based_brown(const Constraints &c)
According to https://www.usna.edu/Users/cs/wcbrown/research/ISSAC04/handout.pdf.
std::vector< carl::Variable > feature_based(const Constraints &c)
std::vector< carl::Variable > feature_based_triangular(const Constraints &c)
std::vector< carl::Variable > vars(const std::pair< QuantifierType, std::vector< carl::Variable >> &p)
Class to create the formulas for axioms.
#define SMTRAT_LOG_DEBUG(channel, msg)
This class manages features that are used to valuate variables on objects.
std::vector< double > Valuation
Valuation valuateVariable(const Objects &o, carl::Variable v) const
std::vector< carl::Variable > sortVariables(const Objects &o, std::vector< carl::Variable > vars) const
void addFeature(Extractor &&e, std::size_t level, double weight)
std::function< double(Objects, carl::Variable)> Extractor
std::vector< std::tuple< Extractor, std::size_t, double > > mFeatures