14template<
typename VariableType>
17 this->somewhereMonotonicity =
true;
18 this->allMonotonicity =
true;
21template<
typename VariableType>
26template<
typename VariableType>
28 assert(!isDoneForVar(var));
31 if (monotonicityResult.find(var) == monotonicityResult.end()) {
32 addMonotonicityResult(std::move(var), std::move(mon));
34 monotonicityResult[var] = mon;
41 if (monotonicityResult.find(var) == monotonicityResult.end()) {
42 addMonotonicityResult(std::move(var), std::move(mon));
44 auto monRes = monotonicityResult[var];
49 monotonicityResult[var] = mon;
55 setAllMonotonicity(
false);
56 setSomewhereMonotonicity(
false);
58 setSomewhereMonotonicity(
true);
63template<
typename VariableType>
65 auto itr = monotonicityResult.find(var);
66 if (itr != monotonicityResult.end()) {
69 return Monotonicity::Unknown;
72template<
typename VariableType>
74 return monotonicityResult;
77template<
typename VariableType>
79 std::set<VariableType>
const& consideredVariables)
const {
80 std::set<VariableType> nonMonotoneVariables;
81 std::set<VariableType> monotoneVariables;
82 for (
auto var : consideredVariables) {
83 if (isDoneForVar(var)) {
84 auto res = getMonotonicity(var);
85 if (res == Monotonicity::Not || res == Monotonicity::Unknown) {
86 nonMonotoneVariables.insert(var);
88 monotoneVariables.insert(var);
91 nonMonotoneVariables.insert(var);
94 return std::make_pair(std::move(monotoneVariables), std::move(nonMonotoneVariables));
97template<
typename VariableType>
99 std::stringstream stream;
102 for (
auto res : getMonotonicityResult()) {
103 stream << res.first.name() <<
" " << res.second <<
"; ";
104 countIncr += (res.second == Monotonicity::Incr) ? 1 : 0;
105 countDecr += (res.second == Monotonicity::Decr) ? 1 : 0;
107 return "#Incr: " + std::to_string(countIncr) +
" #Decr: " + std::to_string(countDecr) +
"\n" + stream.str();
110template<
typename VariableType>
115template<
typename VariableType>
117 doneVariables.insert(variable);
120template<
typename VariableType>
125template<
typename VariableType>
127 return doneVariables.find(var) != doneVariables.end();
130template<
typename VariableType>
132 this->somewhereMonotonicity = somewhereMonotonicity;
135template<
typename VariableType>
137 if (!somewhereMonotonicity) {
138 for (
auto itr : monotonicityResult) {
141 setSomewhereMonotonicity(
true);
146 return monotonicityResult.size() > 0 && somewhereMonotonicity;
149template<
typename VariableType>
151 this->allMonotonicity = allMonotonicity;
154template<
typename VariableType>
156 return allMonotonicity;
159template<
typename VariableType>
161 std::shared_ptr<MonotonicityResult<VariableType>> copy = std::make_shared<MonotonicityResult<VariableType>>();
162 copy->monotonicityResult = std::map<VariableType, Monotonicity>(monotonicityResult);
163 copy->setAllMonotonicity(allMonotonicity);
164 copy->setSomewhereMonotonicity(somewhereMonotonicity);
166 copy->setDoneVariables(doneVariables);
170template<
typename VariableType>
172 this->doneVariables = doneVariables;
175template<
typename VariableType>
177 std::set<VariableType>& monotoneDecr, std::set<VariableType>& notMonotone)
const {
178 for (
auto& var : consideredVariables) {
179 if (!isDoneForVar(var)) {
180 notMonotone.insert(var);
182 auto mon = getMonotonicity(var);
183 if (mon == Monotonicity::Unknown || mon == Monotonicity::Not) {
184 notMonotone.insert(var);
185 }
else if (mon == Monotonicity::Incr) {
186 monotoneIncr.insert(var);
188 monotoneDecr.insert(var);
194template<
typename VariableType>
196 if (monotonicityResult.find(var) == monotonicityResult.end()) {
199 auto monRes = monotonicityResult.at(var);
200 return isDoneForVar(var) && (monRes == Monotonicity::Incr || monRes == Monotonicity::Decr || monRes == Monotonicity::Constant);
std::map< VariableType, Monotonicity > const & getMonotonicityResult() const
Returns the results so far.
void splitBasedOnMonotonicity(std::set< VariableType > const &consideredVariables, std::set< VariableType > &monotoneIncr, std::set< VariableType > &monotoneDecr, std::set< VariableType > ¬Montone) const
void setDone(bool done=true)
Sets the done bool to the given truth value.
MonotonicityResult()
Constructs a new MonotonicityResult object.
void addMonotonicityResult(VariableType var, Monotonicity mon)
Adds a new variable with a given Monotonicity to the map.
void setAllMonotonicity(bool done=true)
Sets the allMonotonicity bool to the given truth value.
Monotonicity getMonotonicity(VariableType var) const
Returns the current monotonicity of a given parameter.
void setSomewhereMonotonicity(bool done=true)
Sets the somewhereMonotonicity bool to the given truth value.
void updateMonotonicityResult(VariableType var, Monotonicity mon, bool force=false)
Updates the Monotonicity of a variable based on its value so far and a new value.
std::pair< std::set< VariableType >, std::set< VariableType > > splitVariables(std::set< VariableType > const &consideredVariables) const
bool isAllMonotonicity() const
Returns if all Variables are monotone.
std::string toString() const
Constructs a string output of all variables and their corresponding Monotonicity.
std::shared_ptr< MonotonicityResult< VariableType > > copy() const
Constructs a new MonotonicityResult object that is a copy of the current one.
void setDoneVariables(std::set< VariableType > doneVariables)
bool existsMonotonicity()
Checks if there is any variable that is monotone.
bool isDoneForVar(VariableType) const
bool isMonotone(VariableType var) const
bool isDone() const
Checks if the result is complete.
void setDoneForVar(VariableType)
MonotonicityKind
The results of monotonicity checking for a single Parameter Region.