Skip to content

Commit 13465cb

Browse files
committed
Documentation improved.
1 parent b01dc7f commit 13465cb

5 files changed

Lines changed: 107 additions & 103 deletions

File tree

aima-core/src/main/java/aima/core/search/framework/PrioritySearch.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@
88
import aima.core.search.framework.qsearch.QueueSearch;
99

1010
/**
11-
* Maintains a {@link QueueSearch} implementation and a node comparator. Search
12-
* is performed by creating a priority queue based on the given comparator and
13-
* feeding it to the QueueSearch implementation which finally controls the
14-
* simulated search space exploration.
11+
* Performs search by creating a priority queue based on a given
12+
* <code>Comparator</code> and feeding it to a given <code>QueueSearch</code>
13+
* implementation which finally controls the simulated search space exploration.
1514
*
1615
* @author Ravi Mohan
1716
* @author Ruediger Lunde
@@ -31,7 +30,7 @@ public List<Action> findActions(Problem p) {
3130
Node node = implementation.findNode(p, QueueFactory.<Node>createPriorityQueue(comparator));
3231
return node == null ? SearchUtils.failure() : SearchUtils.getSequenceOfActions(node);
3332
}
34-
33+
3534
@Override
3635
public Object findState(Problem p) {
3736
implementation.getNodeExpander().useParentLinks(false);
@@ -47,7 +46,7 @@ public Comparator<Node> getComparator() {
4746
public NodeExpander getNodeExpander() {
4847
return implementation.getNodeExpander();
4948
}
50-
49+
5150
@Override
5251
public Metrics getMetrics() {
5352
return implementation.getMetrics();

aima-core/src/main/java/aima/core/search/framework/ProblemSolvingAgent.java

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@
1111
import aima.core.util.Util;
1212

1313
/**
14-
* Modified copy of class {@code aima.search.framework.SimpleProblemSolvingAgent}.
15-
* Here, attribute {@link #plan} (original: <code>seq</code>) is protected.
16-
* Static pseudo code variable state is used in a more general
17-
* sense including world state as well as agent state aspects.
18-
* This allows the agent to change the plan, if unexpected percepts
19-
* are observed. In the concrete java code, state corresponds with
20-
* the agent instance itself (this).
21-
* <pre><code>
14+
* Modified copy of class
15+
* {@link aima.search.framework.SimpleProblemSolvingAgent} which can be used for
16+
* online search, too. Here, attribute {@link #plan} (original:
17+
* <code>seq</code>) is protected. Static pseudo code variable state is used in
18+
* a more general sense including world state as well as agent state aspects.
19+
* This allows the agent to change the plan, if unexpected percepts are
20+
* observed. In the concrete java code, state corresponds with the agent
21+
* instance itself (this).
22+
*
23+
* <pre>
24+
* <code>
2225
* function PROBLEM-SOLVING-AGENT(percept) returns an action
2326
* inputs: percept, a percept
2427
* static: state, some description of current agent and world state
@@ -36,23 +39,25 @@
3639
* action <- FIRST(state.plan)
3740
* plan <- REST(state.plan)
3841
* return action
39-
* </code></pre>
42+
* </code>
43+
* </pre>
4044
*
4145
* @author Ruediger Lunde
4246
*
4347
*/
4448
public abstract class ProblemSolvingAgent extends AbstractAgent {
45-
46-
/** plan, an action sequence, initially empty. */
49+
50+
/** Plan, an action sequence, initially empty. */
4751
protected List<Action> plan = new ArrayList<Action>();
48-
52+
4953
public ProblemSolvingAgent() {
5054
}
5155

5256
/**
5357
* Template method, which corresponds to pseudo code function
54-
* <code>MY-PROBLEM-SOLVING-AGENT(percept)</code>.
55-
* returns an action
58+
* <code>PROBLEM-SOLVING-AGENT(percept)</code>.
59+
*
60+
* @return an action
5661
*/
5762
public Action execute(Percept p) {
5863
Action action;
@@ -89,47 +94,45 @@ public Action execute(Percept p) {
8994
/**
9095
* Primitive operation, which decides after a search for a plan failed,
9196
* whether to stop the whole task with a failure, or to go on with
92-
* formulating another goal. This implementation always returns false.
93-
* If the agent defines local goals to reach an externally specified
94-
* global goal, it might be interesting, not to stop when the first
95-
* local goal turns out to be unreachable.
97+
* formulating another goal. This implementation always returns false. If
98+
* the agent defines local goals to reach an externally specified global
99+
* goal, it might be interesting, not to stop when the first local goal
100+
* turns out to be unreachable.
96101
*/
97102
protected boolean tryWithAnotherGoal() {
98103
return false;
99104
}
100-
105+
101106
//
102107
// ABSTRACT METHODS
103108
//
104109
/**
105-
* Primitive operation, responsible for updating
106-
* the state of the agent with respect to
107-
* latest feedback from the world. In this version,
108-
* implementations have access to the agent's current goal
109-
* and plan, so they can modify them if needed. For
110-
* example, if the plan didn't work because the model
111-
* of the world proved to be wrong, implementations
112-
* could update the model and also clear the plan.
110+
* Primitive operation, responsible for updating the state of the agent with
111+
* respect to latest feedback from the world. In this version,
112+
* implementations have access to the agent's current goal and plan, so they
113+
* can modify them if needed. For example, if the plan didn't work because
114+
* the model of the world proved to be wrong, implementations could update
115+
* the model and also clear the plan.
113116
*/
114117
protected abstract Object updateState(Percept p);
115118

116119
/**
117-
* Primitive operation, responsible for goal generation. In this
118-
* version, implementations are allowed to return null to indicate
119-
* that the agent has finished the job an should die.
120-
* Implementations can access the current goal (which is
121-
* a possibly modified version of the last formulated goal).
122-
* This might be useful in situations in which plan execution
123-
* has failed.
120+
* Primitive operation, responsible for goal generation. In this version,
121+
* implementations are allowed to return null to indicate that the agent has
122+
* finished the job an should die. Implementations can access the current
123+
* goal (which is a possibly modified version of the last formulated goal).
124+
* This might be useful in situations in which plan execution has failed.
124125
*/
125126
protected abstract Object formulateGoal();
127+
126128
/**
127129
* Primitive operation, responsible for search problem generation.
128130
*/
129131
protected abstract Problem formulateProblem(Object goal);
132+
130133
/**
131-
* Primitive operation, responsible for the generation of an action
132-
* list (plan) for the given search problem.
134+
* Primitive operation, responsible for the generation of an action list
135+
* (plan) for the given search problem.
133136
*/
134137
protected abstract List<Action> search(Problem problem);
135138
}
Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
package aima.core.search.framework;
2-
3-
import java.util.List;
4-
5-
import aima.core.agent.Action;
6-
import aima.core.search.framework.problem.GoalTest;
7-
8-
/**
9-
* A specialization of the GoalTest interface so that it is possible to check
10-
* the solution once a Goal has been identified to determine if it is
11-
* acceptable. This allows you to continue searching for alternative solutions
12-
* without having to restart the search.<br>
13-
* <br>
14-
* However, care needs to be taken when doing this as it does not always make
15-
* sense to continue with a search once an initial goal is found, for example if
16-
* using a heuristic targeted at a single goal.
17-
*
18-
* @author Ciaran O'Reilly
19-
*/
20-
public interface SolutionChecker extends GoalTest {
21-
/**
22-
* This method is only called if GoalTest.isGoalState() returns true.
23-
*
24-
* @param actions
25-
* the list of actions to get to the goal state.
26-
*
27-
* @param goal
28-
* the goal the list of actions will reach.
29-
*
30-
* @return true if the solution is acceptable, false otherwise, which
31-
* indicates the search should be continued.
32-
*/
33-
boolean isAcceptableSolution(List<Action> actions, Object goal);
34-
}
1+
package aima.core.search.framework;
2+
3+
import java.util.List;
4+
5+
import aima.core.agent.Action;
6+
import aima.core.search.framework.problem.GoalTest;
7+
8+
/**
9+
* A specialization of the <code>GoalTest<code> interface so that it is possible
10+
* to check the solution once a goal has been identified to determine if it is
11+
* acceptable. This allows you to continue searching for alternative solutions
12+
* without having to restart the search.<br>
13+
* <br>
14+
* However, care needs to be taken when doing this as it does not always make
15+
* sense to continue with a search once an initial goal is found, for example if
16+
* using a heuristic targeted at a single goal.
17+
*
18+
* @author Ciaran O'Reilly
19+
*/
20+
public interface SolutionChecker extends GoalTest {
21+
/**
22+
* This method is only called if GoalTest.isGoalState() returns true.
23+
*
24+
* @param actions
25+
* the list of actions to get to the goal state.
26+
*
27+
* @param goal
28+
* the goal the list of actions will reach.
29+
*
30+
* @return true if the solution is acceptable, false otherwise, which
31+
* indicates the search should be continued.
32+
*/
33+
boolean isAcceptableSolution(List<Action> actions, Object goal);
34+
}

aima-core/src/main/java/aima/core/search/framework/package-info.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/**
22
* This package (together with its subpackages) contains base classes for search
33
* algorithm implementations. Common interfaces are defined by
4-
* {@link SearchForActions} and {@link SearchForStates}. Most of the concrete
4+
* {@link aima.core.search.framework.SearchForActions} and
5+
* {@link aima.core.search.framework.SearchForStates}. Most of the concrete
56
* algorithms implement both of them. Many search algorithms are basically
67
* queue-based algorithms. They construct a tree of nodes which represents the
78
* possible sequences of actions and the corresponding resulting states. A queue
@@ -20,26 +21,27 @@
2021
* <br>
2122
* To support arbitrary combinations of different strategies for (A) and (B),
2223
* the bridge pattern is used here. Different abstractions of search (so called
23-
* search strategies) are provided as specializations of {@link PrioritySearch}.
24-
* They delegate the work of controlling the actual search to some
24+
* search strategies) are provided as specializations of
25+
* {@link aima.core.search.framework.PrioritySearch}. They delegate the work of
26+
* controlling the actual search to some
2527
* {@link aima.core.search.framework.qsearch.QueueSearch} implementation. The
2628
* most important concrete implementations are TreeSearch, GraphSearch, and
2729
* BidirectionalSearch.
2830
*
2931
* <br>
3032
* Here, all search strategies explore the search space by expanding nodes. A
31-
* central {@link NodeExpander} class is used for this purpose. The default
32-
* implementation should work for most purposes, but it is possible to equip
33-
* search algorithms with specialized versions (e.g. which modify path cost
34-
* computation - extra costs for move direction changes). The node structure is
35-
* needed when searching for sequences of actions (just follow parent links
36-
* after a goal state node was found). Defining search for states (e.g. in a
37-
* local search strategy) based on nodes makes sense, too. Nodes do not
38-
* necessary increase space complexity as long as parent links can be switched
39-
* off. However, by switching on parent links, those algorithms can be turned
40-
* into search for actions algorithms. Additionally, the common node expander
41-
* interface unifies progress tracing for all search algorithms (just add a node
42-
* listener to get notifications about expanded nodes).
33+
* central {@link aima.core.search.framework.NodeExpander} class is used for
34+
* this purpose. The default implementation should work for most purposes, but
35+
* it is possible to equip search algorithms with specialized versions (e.g.
36+
* which modify path cost computation - extra costs for move direction changes).
37+
* The node structure is needed when searching for sequences of actions (just
38+
* follow parent links after a goal state node was found). Defining search for
39+
* states (e.g. in a local search strategy) based on nodes makes sense, too.
40+
* Nodes do not necessary increase space complexity as long as parent links can
41+
* be switched off. However, by switching on parent links, those algorithms can
42+
* be turned into search for actions algorithms. Additionally, the common node
43+
* expander interface unifies progress tracing for all search algorithms (just
44+
* add a node listener to get notifications about expanded nodes).
4345
*
4446
* @author Ruediger Lunde
4547
*/
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
/**
2-
* This package contains different queue search implementations and a common
3-
* interface for them, which is implicitly defined by abstract class
4-
* {@link QueueSearch}. Given a problem and a non-empty queue of nodes (which is
5-
* defined and initialized by some search strategy), the implementations control
6-
* search space exploration and return a non-empty list of actions if a goal
7-
* state was found.
8-
*
9-
* @author Ruediger Lunde
10-
*/
11-
12-
package aima.core.search.framework.qsearch;
1+
/**
2+
* This package contains different queue search implementations and a common
3+
* interface for them, which is implicitly defined by abstract class
4+
* {@link aima.core.search.framework.qsearch.QueueSearch}. Given a problem and a
5+
* non-empty queue of nodes (which is defined and initialized by some search
6+
* strategy), the implementations control search space exploration and return a
7+
* non-empty list of actions if a goal state was found.
8+
*
9+
* @author Ruediger Lunde
10+
*/
11+
12+
package aima.core.search.framework.qsearch;

0 commit comments

Comments
 (0)