Попытка push_back вектора <float>в частный вектор <float>того же класса без функции возврата - PullRequest
0 голосов
/ 12 апреля 2019

В настоящее время я работаю над проблемой обучения с подкреплением и пытаюсь добавить в положение элементов fount в vector<State> и vector<Action> другой вектор с плавающей точкой унаследованного класса, чтобы я мог манипулировать значениями состояния и акция фонд Возврат находится в другой функции в main, поэтому я не могу его использовать. я пытаюсь использовать это-> но не работает.

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
}

ошибка: нет соответствующей функции для вызова forstd :: vector :: push_back (std :: vector *) ’ этом-> StatesPos.push_back (& ​​StateW);

1 Ответ

1 голос
/ 12 апреля 2019

StatePos - это вектор с плавающей точкой, вы можете push_back только с плавающей точкой (или объекты, которые будут неявно преобразованы в числа с плавающей точкой.

Если вам нужно добавить два вектора, вы можете сделать что-то вроде этого:

StatePos.insert( StatePos.end(), StateW.begin(), StateW.end() ); 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...