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#include "graph_search_const.h"
16
17
18namespace designlab
19{
20
21GraphTreeCreator::GraphTreeCreator(std::unique_ptr<INodeCreatorBuilder>&& node_creator_builder_ptr) :
22 node_creator_builder_ptr_(std::move(node_creator_builder_ptr))
23{
24 // 引数が全て nullptr でないことを確認する.
25 assert(node_creator_builder_ptr_ != nullptr);
26}
27
29{
30 // 現在持っているノード生成クラスを全て削除する.
31 node_creator_map_.clear();
32
33 node_creator_builder_ptr_->Build(map_state, &node_creator_map_);
34}
35
37{
38 assert(0 <= start_depth); // start_depthは0以上である.
39 assert(start_depth < max_depth); // start_depth は max_depth より小さい.
40 assert(graph != nullptr); // nullptrでない.
41 assert(!graph->IsEmpty()); // 空でない.
42
43 int cnt = 0; // カウンタを用意.
44
45 // カウンタが vector のサイズを超えるまでループする.
46 while (cnt < graph->GetGraphSize())
47 {
48 // 探索深さが足りていないノードにのみ処理をする.
49 if (start_depth <= graph->GetNode(cnt).depth && graph->GetNode(cnt).depth < max_depth)
50 {
51 std::vector<RobotStateNode> res_vec; // cnt 番目のノードの子ノードを入れるベクター.
52
53 MakeNewNodesByCurrentNode(graph->GetNode(cnt), cnt, &res_vec); // 子ノードを生成する.
54
55 for (const auto& i : res_vec)
56 {
57 graph->AddNode(i); // 子ノードを追加する.
58 }
59 }
60
61 ++cnt; // カウンタを進める.
62 }
63
64 return { enums::Result::kSuccess, std::format("グラフのサイズ : {}",graph->GetGraphSize()) };
65}
66
67
68void GraphTreeCreator::MakeNewNodesByCurrentNode(const RobotStateNode& current_node, const int current_num, std::vector<RobotStateNode>* output_graph) const
69{
70 assert(output_graph != nullptr); // nullptrでない.
71 assert(output_graph->empty()); // 空である.
72
73 if (node_creator_map_.count(current_node.next_move) > 0)
74 {
75 node_creator_map_.at(current_node.next_move)->Create(current_node, current_num, output_graph);
76
77 return;
78 }
79 else
80 {
81 node_creator_map_.begin()->second->Create(current_node, current_num, output_graph);
82
83 // assert(false && "ノード生成クラスが登録されていない.");
84
86 // RobotStateNode new_node = current_node;
87
88 // new_node.ChangeToNextNode(current_num, current_node.next_move);
89
90 // (*output_graph).emplace_back(new_node);
91 }
92}
93
94} // 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:24
グラフ探索の結果を表す構造体.
グラフ構造のためのノード(頂点).旧名 LNODE
int depth
[4 byte] 自身の深さ.一番上の親が深さ0となる.