Skip to content

Commit f8fc6c3

Browse files
committed
.
1 parent a605598 commit f8fc6c3

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/solver/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,14 @@ flowchart LR
110110
创建一个新的结构体用于存储到状态的代价和启发式函数值:
111111

112112
```rs
113-
struct Node {
114-
state: State,
115-
cost: i32,
116-
heuristic: i32,
113+
pub struct Node {
114+
pub state: State,
115+
pub pushes: i32,
116+
pub moves: i32,
117117
priority: i32,
118118
}
119119
```
120120

121-
其中 `priority` 的值是根据搜索策略而计算的.
122-
123121
对于未探索的状态, 可以利用 `BinaryHeap` 容器来存储. 因为该容器能够高效地取出最大的元素.
124122

125123
通过重载 `Node``Ord` trait, 可以将状态通过优先级排序.
@@ -138,6 +136,8 @@ impl PartialOrd for Node {
138136
}
139137
```
140138

139+
其中 `priority` 的值是根据搜索策略而计算的.
140+
141141
值得注意的是, Rust 中的 `BinaryHeap` 的实现方式是最大栈(max-heap), 因此 `BinaryHeap::pop` 函数返回的是容器中最大的元素. 而优先级的值越小表示优先级越高, 因此比较后还需要调用 `Ordering::reverse` 函数.
142142
这样该便可以从容器中取出优先级最高(即最小)的状态.
143143

0 commit comments

Comments
 (0)