/
OnlineSearchProblem.cs
112 lines (101 loc) · 3.38 KB
/
OnlineSearchProblem.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System;
using System.Collections.Generic;
using aima.core.search.framework;
using aima.core.search.framework.problem;
namespace aima.core.search.online
{
/**
* Artificial Intelligence A Modern Approach (3rd Edition): page 147.<br>
* <br>
* An online search problem must be solved by an agent executing actions, rather
* than by pure computation. We assume a deterministic and fully observable
* environment (Chapter 17 relaxes these assumptions), but we stipulate that the
* agent knows only the following: <br>
* <ul>
* <li>ACTIONS(s), which returns a list of actions allowed in state s;</li>
* <li>The step-cost function c(s, a, s') - note that this cannot be used until
* the agent knows that s' is the outcome; and</li>
* <li>GOAL-TEST(s).</li>
* </ul>
*
* @author Ciaran O'Reilly
* @author Mike Stampone
*/
public class OnlineSearchProblem
{
protected ActionsFunction actionsFunction;
protected StepCostFunction stepCostFunction;
protected GoalTest goalTest;
/**
* Constructs an online search problem with the specified action function,
* goal test, and a default step cost function.
*
* @param actionsFunction
* ACTIONS(s), which returns a list of actions allowed in state s
* @param goalTest
* GOAL-TEST(s), which the agent can apply to a single state
* description to determine if it is a goal state
*/
public OnlineSearchProblem(ActionsFunction actionsFunction,
GoalTest goalTest)
{
this.actionsFunction = actionsFunction;
this.goalTest = goalTest;
this.stepCostFunction = new DefaultStepCostFunction();
}
/**
* Constructs an online search problem with the specified action function,
* goal test, and a default step cost function.
*
* @param actionsFunction
* ACTIONS(s), which returns a list of actions allowed in state s
* @param goalTest
* GOAL-TEST(s), which the agent can apply to a single state
* description to determine if it is a goal state
* @param stepCostFunction
* the step-cost function c(s, a, s') - note that this cannot be
* used until the agent knows that s' is the outcome
*/
public OnlineSearchProblem(ActionsFunction actionsFunction,
GoalTest goalTest, StepCostFunction stepCostFunction)
{
this.actionsFunction = actionsFunction;
this.goalTest = goalTest;
this.stepCostFunction = stepCostFunction;
}
/**
* Returns the action function of this online search problem.
*
* @return the action function of this online search problem.
*/
public ActionsFunction getActionsFunction()
{
return actionsFunction;
}
/**
* Returns <code>true</code> if the given state is a goal state.
*
* @param state
* an object representing a state
*
* @return <code>true</code> if the given state is a goal state.
*/
public bool isGoalState(Object state)
{
return goalTest.isGoalState(state);
}
/**
* Returns the step cost function of this online search problem.
*
* @return the step cost function of this online search problem.
*/
public StepCostFunction getStepCostFunction()
{
return stepCostFunction;
}
// PROTECTED METHODS
protected OnlineSearchProblem()
{
}
}
}