17 mRecentlyAdded( _rAdded ),
21 mpOriginalConditions( new
carl::PointerSet<
Condition>( _oConds ) )
25 mFlag( _cond.flag() ),
26 mRecentlyAdded( false ),
27 mValuation( _cond.valuation() ),
29 mConstraint( _cond.constraint() ),
30 mpOriginalConditions( new
carl::PointerSet<
Condition>( _cond.originalConditions() ) )
35 (*mpOriginalConditions).clear();
49 double Condition::valuate(
const carl::Variable& _consideredVariable,
size_t _maxNumberOfVars,
bool _preferEquation )
const
51 if( !
constraint().variables().has( _consideredVariable ) )
53 const auto& varInfo =
constraint().var_info( _consideredVariable );
55 if( _maxNumberOfVars < 4 )
58 maximum = (double)_maxNumberOfVars * (
double)_maxNumberOfVars;
60 double relationSymbolWeight = 0;
64 relationSymbolWeight += 1;
66 case carl::Relation::GEQ:
67 relationSymbolWeight += 2;
69 case carl::Relation::LEQ:
70 relationSymbolWeight += 2;
72 case carl::Relation::LESS:
73 relationSymbolWeight += 4;
75 case carl::Relation::GREATER:
76 relationSymbolWeight += 4;
78 case carl::Relation::NEQ:
79 relationSymbolWeight += 3;
85 double degreeWeight = (double)varInfo.max_degree();
86 if( maximum <= degreeWeight )
87 degreeWeight = maximum - 1;
89 unsigned lCoeffWeight = 0;
90 unsigned lCoeffWeightB = 2;
91 if( degreeWeight <= 1 )
94 if( coeff.is_constant() )
96 if( _consideredVariable.type() == carl::VariableType::VT_INT && (coeff ==
Poly(1) || coeff ==
Poly(-1)) )
105 else if( degreeWeight == 2 )
107 bool hasRationalLeadingCoefficient =
constraint().coefficient( _consideredVariable, varInfo.max_degree() ).is_constant();
108 if( hasRationalLeadingCoefficient &&
constraint().coefficient( _consideredVariable, varInfo.max_degree() - 1 ).is_constant() )
110 else if( hasRationalLeadingCoefficient )
118 double numberOfVariableOccurencesWeight = (double)varInfo.num_occurences();
119 if( maximum <= numberOfVariableOccurencesWeight )
120 numberOfVariableOccurencesWeight = maximum - 1;
122 double otherMonomialsPositiveWeight = 2;
126 smtrat::Poly::PolyType polyExpanded = (smtrat::Poly::PolyType)
constraint().lhs();
128 typename smtrat::Poly::PolyType polyExpanded = (
typename smtrat::Poly::PolyType)
constraint().lhs();
130 if( numberOfVariableOccurencesWeight == 1 && ( polyExpanded.nr_terms() == 1 || (!carl::is_zero(
constraint().lhs().constant_part()) && polyExpanded.nr_terms() > 1) ) )
132 bool allOtherMonomialsPos =
true;
133 bool allOtherMonomialsNeg =
true;
134 for(
auto term = polyExpanded.begin(); term != polyExpanded.end(); ++term )
136 if( term->has( _consideredVariable ) )
138 if( term->num_variables() > 1 )
140 allOtherMonomialsPos =
false;
141 allOtherMonomialsNeg =
false;
147 carl::Definiteness defin = carl::definiteness(*term);
148 if( defin == carl::Definiteness::NON )
150 allOtherMonomialsPos =
false;
151 allOtherMonomialsNeg =
false;
154 else if( defin > carl::Definiteness::NON )
156 if( !allOtherMonomialsNeg )
157 allOtherMonomialsNeg =
false;
158 if( !allOtherMonomialsPos )
163 if( !allOtherMonomialsPos )
164 allOtherMonomialsPos =
false;
165 if( !allOtherMonomialsNeg )
170 if( allOtherMonomialsPos || allOtherMonomialsNeg )
172 otherMonomialsPositiveWeight = 1;
174 finitlyManySolutionsWeight = 1;
177 double weightFactorTmp = maximum;
192 double result = finitlyManySolutionsWeight;
193 if( _preferEquation )
196 result += (degreeWeight <= 2 ? 1 : 2)/weightFactorTmp;
197 weightFactorTmp *= maximum;
198 result += relationSymbolWeight/weightFactorTmp;
199 weightFactorTmp *= maximum;
202 result += degreeWeight/weightFactorTmp;
203 weightFactorTmp *= maximum;
204 result += lCoeffWeight/weightFactorTmp;
205 weightFactorTmp *= maximum;
206 if( _consideredVariable.type() == carl::VariableType::VT_INT )
208 result += lCoeffWeightB/weightFactorTmp;
209 weightFactorTmp *= maximum;
213 result += numberOfVariableOccurencesWeight/weightFactorTmp;
214 weightFactorTmp *= maximum;
215 result += otherMonomialsPositiveWeight/weightFactorTmp;
230 return mId == _condition.
id();
243 return mId < _condition.
id();
248 _condition.
print( _out );
260 _out <<
" [" <<
mId <<
"]";
268 _out <<
", recently added) {";
272 _out <<
"no original condition}";
279 _out <<
"[" << (*oCond)->id() <<
"]";
void print(std::ostream &=std::cout) const
Prints the condition to an output stream.
const smtrat::ConstraintT & constraint() const
static const double INFINITLY_MANY_SOLUTIONS_WEIGHT
bool recentlyAdded() const
double valuate(const carl::Variable &, size_t, bool) const
Valuates the constraint according to a variable (it possibly not contains).
carl::PointerSet< Condition > * mpOriginalConditions
const carl::PointerSet< Condition > & originalConditions() const
bool operator<(const Condition &) const
Checks if the given condition (right hand side) is greater than this condition (left hand side).
bool operator==(const Condition &) const
Checks the equality of a given condition (right hand side) with this condition (left hand side).
Condition(const smtrat::ConstraintT &, size_t _id, size_t=0, bool=false, const carl::PointerSet< Condition > &=carl::PointerSet< Condition >(), bool=false)
std::ostream & operator<<(std::ostream &_out, const Condition &_condition)
Class to create the formulas for axioms.
carl::MultivariatePolynomial< Rational > Poly
carl::Constraint< Poly > ConstraintT