|
Revision 1, 2.1 kB
(checked in by pantley2, 4 years ago)
|
GGPA code from the good old days of SIGART
|
| Line | |
|---|
| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
#include <stdlib.h> |
|---|
| 7 |
#include <iostream> |
|---|
| 8 |
#include "State.h" |
|---|
| 9 |
#include "Sentence.h" |
|---|
| 10 |
#include "SentenceStructure.h" |
|---|
| 11 |
|
|---|
| 12 |
State::State() |
|---|
| 13 |
{ |
|---|
| 14 |
values.clear(); |
|---|
| 15 |
} |
|---|
| 16 |
|
|---|
| 17 |
State::State(int size) |
|---|
| 18 |
{ |
|---|
| 19 |
values.clear(); |
|---|
| 20 |
values.resize(size, ZERO_VALUE); |
|---|
| 21 |
} |
|---|
| 22 |
|
|---|
| 23 |
State::State(const State &state) |
|---|
| 24 |
{ |
|---|
| 25 |
values = state.values; |
|---|
| 26 |
} |
|---|
| 27 |
|
|---|
| 28 |
int State::operator=(const State &state) |
|---|
| 29 |
{ |
|---|
| 30 |
values = state.values; |
|---|
| 31 |
return 1; |
|---|
| 32 |
} |
|---|
| 33 |
|
|---|
| 34 |
bool State::operator==(const State &state) const |
|---|
| 35 |
{ |
|---|
| 36 |
return (values == state.values); |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
bool State::operator<(const State& state) const { |
|---|
| 40 |
return (values < state.values); |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
|
|---|
| 46 |
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 |
|
|---|
| 50 |
|
|---|
| 51 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
void State::addSentence(const Sentence* sentence) { |
|---|
| 57 |
if (sentence->getStructure()->isAction()) { |
|---|
| 58 |
cerr << "An action may not be an attribute in a state" << endl; |
|---|
| 59 |
exit(1); |
|---|
| 60 |
} |
|---|
| 61 |
int index = sentence->getIndex(); |
|---|
| 62 |
values[index] = ONE_VALUE; |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
const vector<double>& State::toInputs() const { |
|---|
| 66 |
return values; |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 |
|
|---|
| 72 |
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
bool State::containsSentence(const Sentence* sentence) const { |
|---|
| 77 |
int index = sentence->getIndex(); |
|---|
| 78 |
|
|---|
| 79 |
return (values[index] == ONE_VALUE); |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
unsigned int State::getSize() const { |
|---|
| 88 |
return values.size(); |
|---|
| 89 |
} |
|---|
| 90 |
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 |
void State::print() const { |
|---|
| 97 |
for (unsigned int i = 0; i < values.size(); i++) { |
|---|
| 98 |
cout << values[i]; |
|---|
| 99 |
} |
|---|
| 100 |
cout << endl; |
|---|
| 101 |
} |
|---|