usingnamespace std;
Solver* Solver::current_ = NULL;
State::State() {
}
State::State(int _state_id) {
state_id = _state_id;
}
State::~State() {
}
Solver::Solver() {
current_ = this;
}
void Solver::store(unsignedlong &n, unsigned x) const{
n = (n << BitsPerValue) | x;
}
unsigned Solver::get_max(unsignedlong n) const{
unsigned m = 0;
for ( ; n; n >>= BitsPerValue)
if ((n & Mask) > m)
m = n & Mask;
return m;
}
double Solver::ObsProb(OBS_TYPE obs, const State& state,
ACT_TYPE action) const {
store(histObs,obs_[state.state_id]);
return obs == get_max(histObs);
}
I am getting these errors:
1 2 3 4 5 6 7 8 9 10 11
src/solver.cpp:334:19: error: binding reference of type 'unsigned long' to value of type 'const unsigned long' drops 'const' qualifier
store(histObs,obs_[state.state_id]);
^~~~~~~
src/solver.cpp:48:44: note: passing argument to parameter 'n' here
void Solver::store(unsignedlong &n, unsigned x) const{
^
src/solver.cpp:358:13: error: binding reference of type 'unsigned long' to value of type 'const unsigned long' drops 'const' qualifier
store(histObs,obs_[state.state_id]);
^~~~~~~
src/solver.cpp:48:44: note: passing argument to parameter 'n' here
void Solver::store(unsignedlong &n, unsigned x) const{
^
I am trying to define the variable histObs inside the class which can be used in different methods of the class and keep track of all the changes made in the obs_vector. I don't know how it should be implemented in a right and efficient way?!! How can I fix these errors and correctly set up histObs variable?
Solver::ObsProb() is a const function, but Solver::store() changes the value of its first parameter. If you need to call store() from there then ObsProb() should be non-const.
@helios but I can not change the definition of ObsProb() because it should be used with other classes that I didn't write in the DSPOMDP class. Is there anyway I can fix my problem?
Also, store and get_max should be static functions (not const members) since they don't need access to the object (they could be separate functions). Just remove the const in both the declarations and definitions and put static before their declarations.
void Solver::store(unsignedlong &n, unsigned x) {
n = (n << BitsPerValue) | x;
}
unsigned Solver::get_max(unsignedlong n){
values from 0 to 7.
unsigned m = 0;
for ( ; n; n >>= BitsPerValue)
if ((n & Mask) > m)
m = n & Mask;
return m;
}
BTW, it may not be useful to pack the 3-bit values into an unsigned long. which can therefore only hold up to 21 of them. Maybe a vector (or possibly array) of chars would be better. Although this takes 2.5 times as much space per state, it allows you to store more than 21 states. It depends on how many states you might need to store and how much overall space they will take up.
@dutch that is the right code and basically it shouldn't go beyond 5,6 states. I am not comfortable coding in c++ but I was forced because I wanted to use this code. Well another errors now I am running to are
src/solver.cpp:50:15: error: invalid use of member 'BitsPerValue' in static member function
n = (n << BitsPerValue) | x;
^~~~~~~~~~~~
src/solver.cpp:57:22: error: invalid use of member 'BitsPerValue' in static member function
for ( ; n; n >>= BitsPerValue)
^~~~~~~~~~~~
src/solver.cpp:58:18: error: invalid use of member 'Mask' in static member function
if ((n & Mask) > m)
^~~~
src/solver.cpp:59:20: error: invalid use of member 'Mask' in static member function
m = n & Mask;
^~~~
src/solver.cpp:335:19: error: binding reference of type 'unsigned long' to value of type 'const unsigned long' drops 'const' qualifier
store(histObs,obs_[state.state_id]);
^~~~~~~
src/solver.cpp:48:44: note: passing argument to parameter 'n' here
void StarMazeProblem::store(unsignedlong &n, unsigned x) {
^
src/solver.cpp:359:13: error: binding reference of type 'unsigned long' to value of type 'const unsigned long' drops 'const' qualifier
store(histObs,obs_[state.state_id]);
^~~~~~~
src/solver.cpp:48:44: note: passing argument to parameter 'n' here
void Solver::store(unsignedlong &n, unsigned x) {
^
In file included from src/solver.cpp:1:
src/solver.h:72:22: warning: private field 'Mask' is not used [-Wunused-private-field]
constunsigned Mask = (1u << BitsPerValue) - 1;
I think I should change how I defined Mask and BitsPerValue in my class too, right?
Yeah, BitsPerValue and Mask also need to be static, so just add "static" before their declarations.
Some of those errors still seem to be related to the "const" problem, so make sure you do what helios said, too.
@dutch thanks for answering my questions. Your suggestion partially reduced the errors. As I already asked @helios, I wrote down the ObsProb function because POMDP solver use it with this given structure. Don't you think changing its type would cause a conflict and leads to more errors?
1 2 3 4 5 6 7 8 9 10 11 12
src/solver.cpp:335:19: error: binding reference of type 'unsigned long' to value of type 'const unsigned long' drops 'const' qualifier
store(histObs,obs_[state.state_id]);
^~~~~~~
src/solver.cpp:48:44: note: passing argument to parameter 'n' here
void Solver::store(unsignedlong &n, unsigned x) {
^
src/solver.cpp:359:13: error: binding reference of type 'unsigned long' to value of type 'const unsigned long' drops 'const' qualifier
store(histObs,obs_[state.state_id]);
^~~~~~~
src/solver.cpp:48:44: note: passing argument to parameter 'n' here
void Solver::store(unsignedlong &n, unsigned x) {
^
Either way you're getting errors. You seem to be in a catch-22. Generally this indicates a design issue. I don't really have the time to look into how you should fix it. I would need to see your full code and also read up on the other code you are using.
It's possible you could make histObs static, too. It depends on how exactly you are using this class.
@dutch exactly I fix some problem another one pops up. Well, if someone professional could take a look at my whole code everything could be easily solved.