GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
graph_tree_creator.cpp
[詳解]
1
3
4// Copyright(c) 2023-2025 Design Engineering Laboratory, Saitama University
5// Released under the MIT license
6// https://opensource.org/licenses/mit-license.php
7
9
10#include <format>
11#include <iostream>
12#include <utility>
13
14#include "cassert_define.h"
15
16namespace designlab {
17
19 std::unique_ptr<INodeCreatorBuilder>&& node_creator_builder_ptr)
20 : node_creator_builder_ptr_(std::move(node_creator_builder_ptr)) {
21 // 引数が全て nullptr でないことを確認する.
22 assert(node_creator_builder_ptr_ != nullptr);
23}
24
26 // 現在持っているノード生成クラスを全て削除する.
27 node_creator_map_.clear();
28
29 node_creator_builder_ptr_->Build(map_state, &node_creator_map_);
30}
31
33 int start_depth, int max_depth, GaitPatternGraphTree* graph) const {
34 assert(0 <= start_depth); // start_depthは0以上である.
35 assert(start_depth < max_depth); // start_depth は max_depth より小さい.
36 assert(graph != nullptr); // nullptrでない.
37 assert(!graph->IsEmpty()); // 空でない.
38
39 int cnt = 0; // カウンタを用意.
40
41 // カウンタが vector のサイズを超えるまでループする.
42 while (cnt < graph->GetGraphSize()) {
43 // 探索深さが足りていないノードにのみ処理をする.
44 if (start_depth <= graph->GetNode(cnt).depth &&
45 graph->GetNode(cnt).depth < max_depth) {
46 std::vector<RobotStateNode>
47 res_vec; // cnt 番目のノードの子ノードを入れるベクター.
48
49 MakeNewNodesByCurrentNode(graph->GetNode(cnt), cnt,
50 &res_vec); // 子ノードを生成する.
51
52 for (const auto& i : res_vec) {
53 graph->AddNode(i); // 子ノードを追加する.
54 }
55 }
56
57 ++cnt; // カウンタを進める.
58 }
59
61 std::format("グラフのサイズ : {}", graph->GetGraphSize())};
62}
63
64void GraphTreeCreator::MakeNewNodesByCurrentNode(
65 const RobotStateNode& current_node, const int current_num,
66 std::vector<RobotStateNode>* output_graph) const {
67 assert(output_graph != nullptr); // nullptrでない.
68 assert(output_graph->empty()); // 空である.
69
70 if (node_creator_map_.count(current_node.next_move) > 0) {
71 node_creator_map_.at(current_node.next_move)
72 ->Create(current_node, current_num, output_graph);
73
74 return;
75 } else {
76 node_creator_map_.begin()->second->Create(current_node, current_num,
77 output_graph);
78
79 // assert(false && "ノード生成クラスが登録されていない.");
80
82 // RobotStateNode new_node = current_node;
83
84 // new_node.ChangeToNextNode(current_num, current_node.next_move);
85
86 // (*output_graph).emplace_back(new_node);
87 }
88}
89
90} // namespace designlab
マップを格子状に分割して管理するクラス.
RobotStateNode 構造体をノードとする木構造のグラフのクラス.
constexpr bool IsEmpty() const
グラフが空かどうかを返す.
void AddNode(const RobotStateNode &node)
ノードを追加する. 追加するノードは親ノードのインデックスと,depthの指定が適切にされている必要がある. これらが適切にされていない場合,アサーションに引っかかる....
const RobotStateNode & GetNode(const int index) const
グラフのノードの参照を返す.
constexpr int GetGraphSize() const
グラフのノードの総数を返す.
void Init(const DividedMapState &map_state)
ノード生成クラスを初期化する.
GraphTreeCreator(std::unique_ptr< INodeCreatorBuilder > &&node_creator_builder_ptr)
GraphSearchResult CreateGraphTree(int start_depth, int max_depth, GaitPatternGraphTree *graph_ptr) const
歩容パターングラフを作成する.
Definition com_type.h:21
グラフ探索の結果を表す構造体.
グラフ構造のためのノード(頂点).
int depth
[4 byte] 自身の深さ.一番上の親が深さ0となる.