мне нужно искать вектор State_actions, если значения IsNow.get_pos (), IsNow.get_ang (), IsNow.get_spe (), ToBeDone.ste (), ToBeDone.acc (), ToBeDone.bra () существуют в это, но они не единственные значения в нем, он также содержит w0 ... w6. есть ли способ найти эти конкретные значения
пробовал std :: search и std :: find
.h
class Sarsa:virtual public State,virtual public Action, public Agent {
public:
std::vector<float> ActionWeights(Action a);
bool IsStateActionSeen(int st, int y);
void AddStateAction(std::vector<float> statess);
private:
float reward;
float w0,w1,w2,w3,w4,w5,w6;
std::vector<float> state_action_weights;
std::vector<float> States_Actions;
//sensor for lap
tCarRaceInfo time;
};
.cpp
Sarsa::Sarsa()
{
State();
Agent();
Action();
this->e = 0.0f;
this->loadpolicy="Q.txt";
this->savepolicy="";
this->w0=0.2f;
this->w1=0.2f;
this->w2=0.2f;
this->w3=0.2f;
this->w4=0.2f;
this->w5=0.2f;
this->w6=0.2f;
std::cout<<"Sarsa initialized \n";
}
bool Sarsa::IsStateActionSeen(int st, int y)//x is state and y is action too many abriviations..
{
//The position of state and action in their respected vectors
State IsNow = all_states.at(st);
Action ToBeDone = all_actions.at(y);
std::cout<<"The State is: "<<IsNow.get_pos()<<" "<<IsNow.get_ang()<<" "<<IsNow.get_spe()<<std::endl;
std::cout<<"The Action is: "<<ToBeDone.ste()<<" "<<ToBeDone.acc()<<" "<<ToBeDone.bra()<<std::endl;
//create a vector with values of both current state and action
std::vector<float> State_action;
std::vector<float> State_action_w;
State_action={IsNow.get_pos(),IsNow.get_ang(),IsNow.get_spe(),ToBeDone.ste(),ToBeDone.acc(),ToBeDone.bra()};
State_action_w={w0,IsNow.get_pos(),w1,IsNow.get_ang(),w2,IsNow.get_spe(),w3,ToBeDone.ste(),w4,ToBeDone.acc(),w5,ToBeDone.bra(),w6};
//read the state actions from vector and check if they are seen, if not insert them.
auto it = std::search(States_Actions.begin(), States_Actions.end(), State_action.begin(), State_action.end());
if (it != States_Actions.end())
{
std::cout<<"Action found: "<<e<<"\n";
}
else
{
std::cout<<"Action not fount.\n";
States_Actions.insert(States_Actions.end(),State_action_w.begin(),State_action_w.end());
}
}