SimpleAI 是 Python 实现的人工智能算法工具包,示例代码:
01 | from simpleai.search import SearchProblem, astar |
05 | class HelloProblem(SearchProblem): |
06 | def actions( self , state): |
07 | if len (state) < len (GOAL): |
08 | return list ( ' ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) |
12 | def result( self , state, action): |
15 | def is_goal( self , state): |
18 | def heuristic( self , state): |
19 | # how far are we from the goal? |
20 | wrong = sum ([ 1 if state[i] ! = GOAL[i] else 0 |
21 | for i in range ( len (state))]) |
22 | missing = len (GOAL) - len (state) |
23 | return wrong + missing |
26 | problem = HelloProblem(initial_state = '') |
27 | result = astar(problem) |
项目主页:http://www.open-open.com/lib/view/home/1358383704246