-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem.py
More file actions
36 lines (31 loc) · 1.48 KB
/
Copy pathproblem.py
File metadata and controls
36 lines (31 loc) · 1.48 KB
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
class Problem:
"""Abstract Class that describes the fucntionality of a search problem"""
def __init__(self, initial, goal_func=None):
"""Constructor function that takes in the intial state of the problem
and the function that describes a succesful goal. If no goal_func
is given it will be assumed there is no goal function."""
self.initial = initial
self.goal_func = goal_func
self.time = 0
self.visited = 0
self.frontier = 0
def actions(self, state):
"""Returns the possible actions that can be executed from the
state passed in here."""
raise NotImplementedError
def resulting_state(self, state, action):
"""Returns the resulting state spawns from the state passed in
and the action passed in to this function."""
raise NotImplementedError
def goal_test(self, state):
"""Runs the state throught the goal state lambda function,
returns true if it is a goal state, false otherwise"""
return self.goal_func(state)
def path_cost(self, state1, current_cost, action, state2):
"""Currently just adds 1 to the current_cost. Only works for
uniform cost graphs. Expected override for non-uniform costs"""
return current_cost + 1
def value(self, state):
"""For optimization problems, each state has a value. Hill-climbing
and related algorithms try to maximize this value."""
raise NotImplementedError