Browse Source

Fixes to buildInitialStates.

main
gereon 12 years ago
parent
commit
52225ecf9c
  1. 35
      src/adapters/ExplicitModelAdapter.h

35
src/adapters/ExplicitModelAdapter.h

@ -183,27 +183,27 @@ private:
*/ */
void generateInitialStates() { void generateInitialStates() {
// Create a fresh state which can hold as many boolean and integer variables as there are. // Create a fresh state which can hold as many boolean and integer variables as there are.
std::vector<StateType*> states; this->allStates.clear();
states.emplace_back(); this->allStates.push_back(new StateType());
states.back()->first.resize(this->booleanVariables.size()); this->allStates[0]->first.resize(this->booleanVariables.size());
states.back()->second.resize(this->integerVariables.size()); this->allStates[0]->second.resize(this->integerVariables.size());
// Start with boolean variables. // Start with boolean variables.
for (uint_fast64_t i = 0; i < this->booleanVariables.size(); ++i) { for (uint_fast64_t i = 0; i < this->booleanVariables.size(); ++i) {
// Check if an initial value is given // Check if an initial value is given
if (this->booleanVariables[i].getInitialValue().get() == nullptr) { if (this->booleanVariables[i].getInitialValue().get() == nullptr) {
// No initial value was given. // No initial value was given.
uint_fast64_t size = states.size(); uint_fast64_t size = this->allStates.size();
for (uint_fast64_t pos = 0; pos < size; pos++) { for (uint_fast64_t pos = 0; pos < size; pos++) {
// Duplicate each state, one with true and one with false. // Duplicate each state, one with true and one with false.
states.emplace_back(states[pos]); this->allStates.push_back(new StateType(*this->allStates[pos]));
std::get<0>(*states[pos])[i] = false; std::get<0>(*this->allStates[pos])[i] = false;
std::get<0>(*states[size + pos])[i] = true; std::get<0>(*this->allStates[size + pos])[i] = true;
} }
} else { } else {
// Initial value was given. // Initial value was given.
bool initialValue = this->booleanVariables[i].getInitialValue()->getValueAsBool(states[0]); bool initialValue = this->booleanVariables[i].getInitialValue()->getValueAsBool(this->allStates[0]);
for (auto it : states) { for (auto it : this->allStates) {
std::get<0>(*it)[i] = initialValue; std::get<0>(*it)[i] = initialValue;
} }
} }
@ -213,28 +213,27 @@ private:
// Check if an initial value was given. // Check if an initial value was given.
if (this->integerVariables[i].getInitialValue().get() == nullptr) { if (this->integerVariables[i].getInitialValue().get() == nullptr) {
// No initial value was given. // No initial value was given.
uint_fast64_t size = states.size(); uint_fast64_t size = this->allStates.size();
int_fast64_t lower = this->integerVariables[i].getLowerBound()->getValueAsInt(states[0]); int_fast64_t lower = this->integerVariables[i].getLowerBound()->getValueAsInt(this->allStates[0]);
int_fast64_t upper = this->integerVariables[i].getUpperBound()->getValueAsInt(states[0]); int_fast64_t upper = this->integerVariables[i].getUpperBound()->getValueAsInt(this->allStates[0]);
// Duplicate all states for all values in variable interval. // Duplicate all states for all values in variable interval.
for (int_fast64_t value = lower; value <= upper; value++) { for (int_fast64_t value = lower; value <= upper; value++) {
for (uint_fast64_t pos = 0; pos < size; pos++) { for (uint_fast64_t pos = 0; pos < size; pos++) {
// If value is lower bound, we reuse the existing state, otherwise we create a new one. // If value is lower bound, we reuse the existing state, otherwise we create a new one.
if (value > lower) states.emplace_back(states[pos]); if (value > lower) this->allStates.push_back(new StateType(*this->allStates[pos]));
// Set value to current state. // Set value to current state.
std::get<1>(*states[(value - lower) * size + pos])[i] = value; std::get<1>(*this->allStates[(value - lower) * size + pos])[i] = value;
} }
} }
} else { } else {
// Initial value was given. // Initial value was given.
int_fast64_t initialValue = this->integerVariables[i].getInitialValue()->getValueAsInt(states[0]); int_fast64_t initialValue = this->integerVariables[i].getInitialValue()->getValueAsInt(this->allStates[0]);
for (auto it : states) { for (auto it : this->allStates) {
std::get<1>(*it)[i] = initialValue; std::get<1>(*it)[i] = initialValue;
} }
} }
} }
} }
/*! /*!

|||||||
100:0
Loading…
Cancel
Save