14#include <boost/thread.hpp>
28 std::unique_ptr<GraphTreeCreator>&& graph_tree_creator_ptr,
29 std::unique_ptr<IGraphSearcher>&& graph_searcher_ptr,
31 const int max_node_num) :
32 graph_tree_creator_ptr_(
std::move(graph_tree_creator_ptr)),
33 graph_searcher_ptr_(
std::move(graph_searcher_ptr)),
35 graph_tree_array_(InitializeGraphTreeArray(kThreadNum, max_node_num)),
38 assert(graph_tree_creator_ptr_ !=
nullptr);
39 assert(graph_searcher_ptr_ !=
nullptr);
40 assert(max_depth_ > 0);
41 assert(max_node_num > 0);
42 assert(graph_tree_array_.size() == kThreadNum);
52 assert(output_node !=
nullptr);
58 graph_tree_creator_ptr_->Init(divided_map);
62 graph_tree_.
AddNode(current_node);
65 graph_tree_creator_ptr_->CreateGraphTree(0, 1, &graph_tree_);
71 "The number of nodes in the graph tree is {}.",
75 for (
int i = 0; i < kThreadNum; i++)
77 graph_tree_array_[i].Reset();
78 graph_tree_array_[i].AddNode(current_node);
87 graph_tree_array_[i % kThreadNum].AddNode(graph_tree_.
GetNode(i));
92 boost::thread_group thread_group;
94 for (
size_t i = 0; i < kThreadNum; i++)
96 if (graph_tree_array_[i].GetGraphSize() > 1)
100 "Starts graph tree generation in thread {}.", i);
103 "The number of nodes explored in thread {} is {}.",
104 i, graph_tree_array_[i].GetGraphSize());
106 thread_group.create_thread(
109 graph_tree_creator_ptr_.get(),
112 &graph_tree_array_[i]));
116 thread_group.join_all();
120 for (
size_t i = 0; i < kThreadNum; i++)
124 "The number of nodes created in thread {} is {}.",
125 i, graph_tree_array_[i].GetGraphSize());
132 const auto [search_result, _, next_node] =
133 graph_searcher_ptr_->SearchGraphTreeVector(
134 graph_tree_array_, operation, divided_map, max_depth_);
139 return search_result;
142 (*output_node) = next_node;
145 "Graph tree evaluation is completed. Graph search succeeded.");
150std::vector<GaitPatternGraphTree>
151GaitPatternGeneratorThread::InitializeGraphTreeArray(
152 const int thread_num,
const int max_node_num)
const
154 std::vector<GaitPatternGraphTree> graph_tree_array;
156 for (
int i = 0; i < thread_num; i++)
158 graph_tree_array.emplace_back(max_node_num / thread_num);
161 return graph_tree_array;
static void FormatOutput(OutputDetail detail, const std::format_string< Args... > str, Args &&... args)
コマンドラインに文字を出力する関数. SetOutputLimit() で設定した出力の許可範囲内であれば出力される. 必ず SetOutputLimit() を呼び出してから使うこと.
static void DebugOutput(const std::string &str)
コマンドラインに文字を出力する関数.Debug用の出力.
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
歩容パターングラフを作成する.
@ kDebug
デバッグ時のみ出力,一番優先度が低い.
enums::Result result
成功か失敗か.
探索において目標となる座標や角度,評価する値についてまとめた構造体.
グラフ構造のためのノード(頂点).旧名 LNODE
constexpr bool IsLootNode() const
自身が根ノードであるか判定する.
Vector3 center_of_mass_global_coord
[4 * 3 = 12byte] グローバル座標系における重心の位置.旧名 GCOM
int depth
[4 byte] 自身の深さ.一番上の親が深さ0となる.