10#include <boost/thread.hpp>
23 std::unique_ptr<GraphTreeCreator>&& graph_tree_creator_ptr,
24 std::unique_ptr<IGraphSearcher>&& graph_searcher_ptr,
const int max_depth,
25 const int max_node_num)
26 : graph_tree_creator_ptr_(
std::move(graph_tree_creator_ptr)),
27 graph_searcher_ptr_(
std::move(graph_searcher_ptr)),
29 graph_tree_array_(InitializeGraphTreeArray(kThreadNum, max_node_num)),
30 max_depth_(max_depth) {
31 assert(graph_tree_creator_ptr_ !=
nullptr);
32 assert(graph_searcher_ptr_ !=
nullptr);
33 assert(max_depth_ > 0);
34 assert(max_node_num > 0);
35 assert(graph_tree_array_.size() == kThreadNum);
42 assert(output_node !=
nullptr);
48 graph_tree_creator_ptr_->Init(divided_map);
52 graph_tree_.
AddNode(current_node);
55 graph_tree_creator_ptr_->CreateGraphTree(0, 1, &graph_tree_);
63 "The number of nodes in the graph tree is {}.",
67 for (
int i = 0; i < kThreadNum; i++) {
68 graph_tree_array_[i].Reset();
69 graph_tree_array_[i].AddNode(current_node);
76 graph_tree_array_[i % kThreadNum].AddNode(graph_tree_.
GetNode(i));
81 boost::thread_group thread_group;
83 for (
size_t i = 0; i < kThreadNum; i++) {
84 if (graph_tree_array_[i].GetGraphSize() > 1) {
86 "Starts graph tree generation in thread {}.", i);
88 "The number of nodes explored in thread {} is {}.", i,
89 graph_tree_array_[i].GetGraphSize());
91 thread_group.create_thread(boost::bind(
93 max_depth_, &graph_tree_array_[i]));
97 thread_group.join_all();
101 for (
size_t i = 0; i < kThreadNum; i++) {
103 "The number of nodes created in thread {} is {}.", i,
104 graph_tree_array_[i].GetGraphSize());
110 const auto [search_result, _, next_node] =
111 graph_searcher_ptr_->SearchGraphTreeVector(graph_tree_array_, operation,
112 divided_map, max_depth_);
116 return search_result;
119 (*output_node) = next_node;
122 "Graph tree evaluation is completed. Graph search succeeded.");
127std::vector<GaitPatternGraphTree>
128GaitPatternGeneratorThread::InitializeGraphTreeArray(
129 const int thread_num,
const int max_node_num)
const {
130 std::vector<GaitPatternGraphTree> graph_tree_array;
132 for (
int i = 0; i < thread_num; i++) {
133 graph_tree_array.emplace_back(max_node_num / thread_num);
136 return graph_tree_array;
void Init(const MapState &map_state, const Vector3 global_robot_com)
マップのデータを初期化する. ロボットの重心座標を中心にマップのデータを格子状に分割し, その中に存在する脚設置可能点を集める.
GaitPatternGeneratorThread()=delete
デフォルトコンストラクタは禁止.
GraphSearchResult GetNextNodeByGraphSearch(const RobotStateNode ¤t_node, const MapState &map_ref, const RobotOperation &operation, RobotStateNode *output_node) override
グラフ探索を行い,次の動作として最適なノードを返す.
constexpr void Reset()
グラフをリセットする.
void AddNode(const RobotStateNode &node)
ノードを追加する. 追加するノードは親ノードのインデックスと,depthの指定が適切にされている必要がある. これらが適切にされていない場合,アサーションに引っかかる....
const RobotStateNode & GetNode(const int index) const
グラフのノードの参照を返す.
constexpr int GetGraphSize() const
グラフのノードの総数を返す.
GraphSearchResult CreateGraphTree(int start_depth, int max_depth, GaitPatternGraphTree *graph_ptr) const
歩容パターングラフを作成する.
void OutputF(OutputDetail detail, const std::format_string< Args... > str, Args &&... args)
コマンドラインに文字を出力する関数, format した文字列を出力する. SetOutputLimit() で設定した出力の許可範囲内であれば出力される.
void DebugOutput(const std::string &str)
コマンドラインに文字を出力する関数. Debug 用の出力.
@ kDebug
デバッグ時のみ出力,一番優先度が低い.
enums::Result result
成功か失敗か.
探索において目標となる座標や角度,評価する値についてまとめた構造体.
constexpr bool IsLootNode() const
自身が根ノードであるか判定する.
Vector3 center_of_mass_global_coord
[4 * 3 = 12byte] グローバル座標系における重心の位置.旧名 GCOM
int depth
[4 byte] 自身の深さ.一番上の親が深さ0となる.