forked from Rishav159/aima-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
problem.js
77 lines (67 loc) · 2.2 KB
/
problem.js
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
/**
* The abstract class for a formal problem. You should subclass
* this and implement the methods actions and result, and possibly
* constructor, goalTest, and pathCost. Then you will create instances
* of your subclass and solve them with the various search functions
*/
export class Problem {
/**
* The constructor specifies the initial state, and possibly a goal
* state, if there is a unique goal. Your subclass's constructor can add
* other arguments.
* @param initial
* @param goal
*/
consturctor(initial, goal = null) {
this.initial = initial;
this.goal = goal;
}
/**
* Return the actions that can be executed in the given
* state. The result would typically be a list, but if there are
* many actions, consider yielding them one at a time in an
* iterator, rather than building them all at once
* @param state
*/
actions(state) {
}
/**
* Return the state that results from executing the given
* action in the given state. The action must be one of
* this.actions.state
* @param state
* @param action
*/
result(state, action) {
}
/**
* Return True if the state is a goal. The default method compares the
* state to self.goal, as specified in the constructor. Override this
* method if checking against a single this.goal is not enough
* @param state
* @returns {boolean}
*/
goalTest(state) {
return state == this.goal;
}
/**
* Return the cost of a solution path that arrives at state2 from
* state1 via action, assuming cost c to get up to state1. If the problem
* is such that the path doesn't matter, this function will only look at
* state2. If the path does matter, it will consider c and maybe state1
* and action. The default method costs 1 for every step in the path
* @param c
* @param state1
* @param action
* @param state2
*/
pathCost(c, state1, action, state2) {
}
/**
* For optimization problems, each state has a value. Hill-climbing
* and related algorithms try to maximize this value.
* @param state
*/
value(state) {
}
}