Compare commits
3 Commits
1583496887
...
2ed30ebefd
Author | SHA1 | Date |
---|---|---|
|
2ed30ebefd | |
|
0202dc51af | |
|
47fcbbec8f |
|
@ -172,6 +172,7 @@ public class BFS<T>
|
||||||
private List<int> _closeList = new List<int>();
|
private List<int> _closeList = new List<int>();
|
||||||
private Queue<int> _openList = new Queue<int>();
|
private Queue<int> _openList = new Queue<int>();
|
||||||
private Dictionary<Node<T>, Node<T>> _nodeMap = new Dictionary<Node<T>, Node<T>>();
|
private Dictionary<Node<T>, Node<T>> _nodeMap = new Dictionary<Node<T>, Node<T>>();
|
||||||
|
private List<int> ids = new List<int>();
|
||||||
|
|
||||||
public BFS(Graph<T> graph)
|
public BFS(Graph<T> graph)
|
||||||
{
|
{
|
||||||
|
@ -186,6 +187,10 @@ public class BFS<T>
|
||||||
|
|
||||||
public Path<T> FindPath(Node<T> begin, Node<T> end)
|
public Path<T> FindPath(Node<T> begin, Node<T> end)
|
||||||
{
|
{
|
||||||
|
if (begin == null)
|
||||||
|
throw new NullReferenceException("begin");
|
||||||
|
if (end == null)
|
||||||
|
throw new NullReferenceException("end");
|
||||||
_openList.Clear();
|
_openList.Clear();
|
||||||
_closeList.Clear();
|
_closeList.Clear();
|
||||||
_nodeMap.Clear();
|
_nodeMap.Clear();
|
||||||
|
@ -220,12 +225,6 @@ public class BFS<T>
|
||||||
{
|
{
|
||||||
if (this._nodeMap.TryGetValue(node, out node))
|
if (this._nodeMap.TryGetValue(node, out node))
|
||||||
{
|
{
|
||||||
if (node != null)
|
|
||||||
{
|
|
||||||
Debug.Log($"{node.index} is null");
|
|
||||||
isTrue = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.ids.Contains(node.index))
|
if (!this.ids.Contains(node.index))
|
||||||
{
|
{
|
||||||
|
@ -234,11 +233,10 @@ public class BFS<T>
|
||||||
path.AddNode(new PathNode<T>(node.index, node.data));
|
path.AddNode(new PathNode<T>(node.index, node.data));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node == begin)
|
if (node==null || node == begin)
|
||||||
{
|
{
|
||||||
Debug.Log("结束了");
|
Debug.Log("结束了");
|
||||||
isTrue = false;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,9 +245,6 @@ public class BFS<T>
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add
|
|
||||||
private List<int> ids = new List<int>();
|
|
||||||
|
|
||||||
private void Search(Node<T> node)
|
private void Search(Node<T> node)
|
||||||
{
|
{
|
||||||
var readOnlyList = this._graph.GetNeighbours(node);
|
var readOnlyList = this._graph.GetNeighbours(node);
|
||||||
|
|
Loading…
Reference in New Issue