-
Notifications
You must be signed in to change notification settings - Fork 0
/
GreedyBFS.cs
44 lines (42 loc) · 1.45 KB
/
GreedyBFS.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
using FlashPlanner.Core.Heuristics;
using PDDLSharp.Models.FastDownward.Plans;
namespace FlashPlanner.Core.Search
{
/// <summary>
/// Greedy Best First Search
/// </summary>
public class GreedyBFS : BaseHeuristicPlanner
{
/// <summary>
/// Main constructor
/// </summary>
/// <param name="heuristic"></param>
public GreedyBFS(IHeuristic heuristic) : base(heuristic)
{
}
internal override ActionPlan? Solve()
{
while (!Abort && _openList.Count > 0)
{
var stateMove = ExpandBestState();
foreach (var opID in _context.ApplicabilityGraph[stateMove.Operator])
{
var op = _context.SAS.GetOperatorByID(opID);
if (Abort) break;
if (stateMove.State.IsApplicable(op))
{
var newMove = GenerateNewState(stateMove, op);
if (!IsVisited(newMove))
{
newMove.hValue = Heuristic.GetValue(stateMove, newMove.State, _context.SAS.Operators);
QueueOpenList(stateMove, newMove, op);
if (newMove.State.IsInGoal())
return GeneratePlanChain(newMove);
}
}
}
}
return null;
}
}
}