我目前正在研究强化学习问题,并且尝试将浮点哦继承类的另一个向量的vector<State>
和vector<Action>
中所添加的元素的位置增加,以便我可以操纵状态和行动的价值观。返回是在主要的另一个功能上,所以我不能使用它。我正在尝试使用this->,但无法正常工作。
Gradient.h
class Gradient: virtual public Sarsa
{
public:
Gradient();
Gradient(float w);
//states with weights
std::vector<float> StateWeights(float s, float l, float a);
//from the actions vector will be created with weights
std::vector<float> ActionWeights(Action a);
void IsStateActionSeen();
private:
float w0,w1,w2,w3,w4,w5,w6;
std::vector<float> state_action_weights;
std::vector<float> StatesPos;
std::vector<float> Actions;
};
Gradintent.cpp
//returns the possition and the values of state in floationg points
std::vector<float> Gradient::StateWeights(float s, float l, float a)
{
std::vector<float> StateW;
//position of the state in the vector
int x = Sarsa::StateisNow ( s, l, a);//here i take the values of the main to find which state is not
float y = (float)(x);
std::cout<<"State found: "<<x<<std::endl;
//read the values of state from the position
State st = all_states.at(x);
std::cout<<"The State is: "<<st.get_pos()<<" "<<st.get_ang()<<" "<<st.get_spe()<<std::endl;
//create a vector with the values of the state and the weights
StateW={y, st.get_pos(),st.get_ang(),st.get_spe() };
std::cout<<"The State is: "<<StateW.at(0)<<" "<<StateW.at(1)<<" "<<StateW.at(2)<<" "<<StateW.at(3)<<std::endl;
this->StatesPos.push_back(&StateW);//i want to add it in the vector before it returns
return StateW;//return to the main
}
错误:没有匹配的函数可以调用“ std :: vector :: push_back(std :: vector *)” this-> StatesPos.push_back(&StateW);
答案 0 :(得分:1)
StatePos
是float的向量,您只能push_back浮动(或将隐式转换为float的对象。
如果需要附加两个向量,则可以执行以下操作:
StatePos.insert( StatePos.end(), StateW.begin(), StateW.end() );