/
DTAgent.java
77 lines (68 loc) · 2.49 KB
/
DTAgent.java
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
package aima.core.agent;
import aima.core.agent.impl.SimpleAgent;
import aima.core.probability.BeliefState;
import aima.core.util.datastructure.Pair;
import java.util.List;
/**
* Artificial Intelligence A Modern Approach (3rd Edition): Figure 13.1, page 484.<br>
*
* Figure 13.1 A decision-theoretic agent that selects rational actions.
* <br>
*
* <pre>
* function DT-AGENT(percept) returns an action
* persistent: belief_state, probabilistic beliefs about the current state of the world
* action, the agent's action
*
* update belief_state based on action and percept
* calculate outcome probabilities for actions
* given action descriptions and current belief state
* select action with highest expected utility
* given probabilities of outcomes and utility information
* return action
*
* </pre>
*
* @author Ritwik Sharma
* @author samagra
*/
public abstract class DTAgent extends SimpleAgent {
/**
* @param belief_state
* probabilistic beliefs about the current state of the world.
* @param action
* the agent's action
*/
BeliefState<Action,Percept> belief_state;
Action action;
List<Action> action_descriptions;
public Action perceive(Percept percept) {
// update belief_state based on action and percept
belief_state.update(action,percept);
/**
* calculate outcome probabilities for actions,
* given action descriptions and current belief_state
*/
List<Pair<Action,Double>> action_probabilities = cal_action_probabilities(action_descriptions,belief_state);
/**
* select action with highest expected utility
* given probabilities of outcomes and utility information
*/
Action finalAction = action_with_highest_expected_utility(action_probabilities);
return finalAction;
}
/**
* @param action_description
* permissible action descriptions
* @param belief_state
* current belief state of the agent about the world
* @return The next action to be taken.
*/
abstract List<Pair<Action,Double>> cal_action_probabilities(List<Action> action_description, BeliefState belief_state);
/**
* @param action_probabilities
* Probabilities of various outcomes
* @return Action with the highest probability.
*/
public abstract Action action_with_highest_expected_utility(List<Pair<Action,Double>> action_probabilities);
}