当前位置: 首页>>代码示例>>C++>>正文


C++ States::GetReward方法代码示例

本文整理汇总了C++中States::GetReward方法的典型用法代码示例。如果您正苦于以下问题:C++ States::GetReward方法的具体用法?C++ States::GetReward怎么用?C++ States::GetReward使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在States的用法示例。


在下文中一共展示了States::GetReward方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: timer_cb

void Experiment::timer_cb(const ros::TimerEvent& event)
{  
	switch(mode_)
	{
	case MODE_REP_START:
	  actions_->Start();
	  last_time_ = ros::Time::now().toSec();
		state_ = states_->GetState();
		action_ = qobj_->GetAction(state_);
		actions_->Move(action_);
		ROS_INFO("Starting rep: %d", cnt_rep_);
		mode_ = MODE_REP;
		cnt_timesteps_++;
		break;
	case MODE_REP:
    state_p_ = (int)states_->GetState();

		if (learn_)
		{
			reward_ = states_->GetReward();
			qobj_->Update(reward_, state_, state_p_, action_);
			ROS_INFO("Action: %d, produced state: %d with reward: %f", action_, state_p_, reward_);
			ROS_INFO("Table: \n%s", qobj_->PrintTable().c_str());
		}

		state_ = state_p_;

    action_ = qobj_->GetAction(state_);
		actions_->Move(action_);
		
		cnt_timesteps_++;

		if (getDistance() < goal_radius_ || outOfBounds())
		{
      stopAndMoveToStart();
		}
		break;
	case MODE_RETURN:
  	if (move_stopped_ == true)
		{
			move_stopped_ = false;
			mode_ = MODE_REP_START;
      qobj_->DecreaseTemp();
			cnt_rep_++;
		}

		if (cnt_rep_ > num_reps_)
			mode_ = MODE_DONE;
		break;
	case MODE_DONE:
	  //lc_->ShowImage();
	  exit(1);
		break;
	}
}
开发者ID:smilingpaul,项目名称:marhes-ros-pkg,代码行数:55,代码来源:experiment_stage.cpp

示例2: timer_cb

void Experiment::timer_cb(const ros::TimerEvent& event)
{
	switch(mode_)
	{
	case MODE_REP_START:
		state_ = (int)states_->GetState();
		ROS_INFO("Starting rep: %d", cnt_rep_);
		mode_ = MODE_REP;
		break;
	case MODE_REP:
		action_ = qobj_->GetAction(state_);
		actions_->Move((Actions::moveType)action_);
		state_p_ = (int)states_->GetState();

		ROS_INFO("Action: %d, produced state: %d", action_, state_p_);

		if (learn_)
		{
			reward_ = states_->GetReward();
			qobj_->Update(reward_, state_, state_p_, action_);
			ROS_INFO("Action: %d, produced state: %d with reward: %f", action_, state_p_, reward_);
			ROS_INFO("Table: \n%s", qobj_->PrintTable().c_str());
		}

		state_ = state_p_;

		if (states_->GetDistance() < radius_)
		{
			mode_ = MODE_RETURN;
			ROS_INFO("Completed rep: %d, returning to start location", cnt_rep_);

			// Move to starting spot
			srv_.request.pose.position.x = start_x_;
			srv_.request.pose.position.y = start_y_;
			client_.call(srv_);
		}
		break;
	case MODE_RETURN:
		if (move_stopped_ == true)
		{
			move_stopped_ = false;
			mode_ = MODE_REP_START;
			cnt_rep_++;
		}

		if (cnt_rep_ > num_reps_)
			mode_ = MODE_DONE;
		break;
	case MODE_DONE:
		break;
	}
}
开发者ID:smilingpaul,项目名称:marhes-ros-pkg,代码行数:52,代码来源:experiment.cpp


注:本文中的States::GetReward方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。