8template<
typename VariableType>
10 stateMonRes = std::vector<std::shared_ptr<MonotonicityResult<VariableType>>>(numberOfStates,
nullptr);
11 globalMonotonicityResult = std::make_shared<MonotonicityResult<VariableType>>();
13 dummyPointer = std::make_shared<MonotonicityResult<VariableType>>();
17template<
typename VariableType>
19 stateMonRes = std::vector<std::shared_ptr<MonotonicityResult<VariableType>>>(numberOfStates);
20 globalMonotonicityResult = globalResult;
22 dummyPointer = std::make_shared<MonotonicityResult<VariableType>>();
23 done = globalResult->isDone();
26template<
typename VariableType>
28 VariableType var)
const {
29 if (stateMonRes[state] == dummyPointer) {
30 return Monotonicity::Constant;
31 }
else if (stateMonRes[state] !=
nullptr) {
32 auto res = stateMonRes[state]->getMonotonicity(var);
33 if (res == Monotonicity::Unknown && globalMonotonicityResult->isDoneForVar(var)) {
34 return globalMonotonicityResult->getMonotonicity(var);
38 return globalMonotonicityResult->isDoneForVar(var) ? globalMonotonicityResult->getMonotonicity(var) : Monotonicity::Unknown;
42template<
typename VariableType>
44 return globalMonotonicityResult;
47template<
typename VariableType>
50 assert(stateMonRes[state] != dummyPointer);
51 if (stateMonRes[state] ==
nullptr) {
52 stateMonRes[state] = std::make_shared<MonotonicityResult<VariableType>>();
54 stateMonRes[state]->addMonotonicityResult(var, mon);
55 globalMonotonicityResult->updateMonotonicityResult(var, mon);
56 if (mon == Monotonicity::Unknown || mon == Monotonicity::Not) {
57 statesMonotone.set(state,
false);
59 bool stateMonotone = stateMonRes[state]->isAllMonotonicity();
61 statesMonotone.set(state);
62 done |= statesMonotone.full();
65 globalMonotonicityResult->setDone();
70template<
typename VariableType>
72 std::shared_ptr<LocalMonotonicityResult<VariableType>> copy = std::make_shared<LocalMonotonicityResult<VariableType>>(stateMonRes.size());
73 for (uint_fast64_t state = 0; state < stateMonRes.size(); state++) {
74 if (stateMonRes[state] !=
nullptr) {
75 copy->setMonotonicityResult(state, stateMonRes[state]->copy());
78 copy->setGlobalMonotonicityResult(this->getGlobalMonotonicityResult()->copy());
79 copy->setStatesMonotone(statesMonotone);
83template<
typename VariableType>
88template<
typename VariableType>
90 assert(indexMinimize == -1);
91 this->indexMinimize = i;
94template<
typename VariableType>
96 this->indexMaximize = i;
99template<
typename VariableType>
101 return indexMinimize;
104template<
typename VariableType>
106 return indexMaximize;
109template<
typename VariableType>
111 return statesMonotone.empty();
114template<
typename VariableType>
116 this->stateMonRes[state] = monRes;
119template<
typename VariableType>
120void LocalMonotonicityResult<VariableType>::setGlobalMonotonicityResult(std::shared_ptr<MonotonicityResult<VariableType>> monRes) {
121 this->globalMonotonicityResult = monRes;
124template<
typename VariableType>
126 this->statesMonotone = statesMonotone;
129template<
typename VariableType>
131 if (stateMonRes[state] ==
nullptr) {
132 stateMonRes[state] = dummyPointer;
134 this->statesMonotone.
set(state);
137template<
typename VariableType>
139 globalMonotonicityResult->updateMonotonicityResult(var, Monotonicity::Incr);
140 globalMonotonicityResult->setDoneForVar(var);
141 setFixedParameters =
true;
144template<
typename VariableType>
146 globalMonotonicityResult->updateMonotonicityResult(var, Monotonicity::Decr);
147 globalMonotonicityResult->setDoneForVar(var);
148 setFixedParameters =
true;
151template<
typename VariableType>
153 std::string result =
"Local Monotonicity Result: \n";
154 for (uint_fast64_t i = 0; i < stateMonRes.size(); ++i) {
156 result += std::to_string(i);
157 if (stateMonRes[i] !=
nullptr) {
158 result += stateMonRes[i]->toString();
159 }
else if (statesMonotone[i]) {
160 result +=
"constant";
162 result +=
"not analyzed";
169template<
typename VariableType>
171 return setFixedParameters;
174template<
typename VariableType>
177 globalMonotonicityResult->setDone(done);
180template<
typename VariableType>
182 return stateMonRes[state];
int getIndexMinimize() const
void setDone(bool done=true)
void setIndexMinimize(int index)
void setIndexMaximize(int index)
void setMonotonicity(uint_fast64_t state, VariableType var, Monotonicity mon)
Sets the local Monotonicity of a parameter at a given state.
bool isNoMonotonicity() const
void setMonotoneDecreasing(VariableType var)
void setMonotoneIncreasing(VariableType var)
void setConstant(uint_fast64_t state)
LocalMonotonicityResult(uint_fast64_t numberOfStates)
Constructs a new LocalMonotonicityResult object.
std::shared_ptr< LocalMonotonicityResult< VariableType > > copy()
Constructs a new LocalMonotonicityResult object that is a copy of the current one.
bool isDone() const
Checks if the LocalMonotonicity is done yet.
int getIndexMaximize() const
std::shared_ptr< MonotonicityResult< VariableType > > getGlobalMonotonicityResult() const
Returns the Global MonotonicityResult object that corresponds to this object.
bool isFixedParametersSet() const
std::string toString() const
Constructs a string output of all variables and their corresponding Monotonicity.
Monotonicity getMonotonicity(uint_fast64_t state, VariableType var) const
Returns the local Monotonicity of a parameter at a given state.
A bit vector that is internally represented as a vector of 64-bit values.
void set(uint64_t index, bool value=true)
Sets the given truth value at the given index.
MonotonicityKind
The results of monotonicity checking for a single Parameter Region.