-
Notifications
You must be signed in to change notification settings - Fork 1
/
Ellie.elm
120 lines (88 loc) · 2.52 KB
/
Ellie.elm
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
module Main exposing (main)
import Problem exposing (Problem)
import Problem.Example exposing (..)
import Problem.Search as Search exposing (Result(..))
import Problem.Search.Dashboard as Dashboard exposing (Search(..), Visual(..))
main =
Dashboard.document
{ problem = simpleEightPuzzle
-- problemStateToHtml = Nothing
, problemStateToHtml = Just slidingPuzzleVisual
, searches = [ Greedy ]
, visuals = [ Scatter, Tree, TreeMap, Graph ]
}
{-
Example problems:
- simpleEightPuzzle, mediumEightPuzzle, complexEghtPuzzle
- slidingPuzzle 15 [ 1, 2, 3, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
- queens 4, queens 8
- simpleKnuthm, complexKnuth
- simpleRouteFinding
- simpleMotionPlanning
(For the problems other than the sliding puzzle, we need to set `problemStateToHtml` to `Nothing`,
because I have not yet coded visualizations of their states.)
Search techniques (graph and tree search):
- DepthFirst, TreeDepthFirst
- BreadthFirst, TreeBreadthFirst
- UniformCost, TreeUniformCost (=Dijkstra)
- Greedy, TreeGreedy
- BestFirst, TreeBestFirst
Visuals:
- Scatter (x-axis: depth, y-axis: heuristic)
- Tree
- TreeMap
- Graph
Documentation:
https://package.elm-lang.org/packages/davidpomerenke/elm-problem-solving/latest/
Github:
https://github.com/davidpomerenke/elm-problem-solving
-}
--
--
--
-- Example implementation of a problem: Vacuum world.
type Location
= A
| B
type Condition
= Clean
| Dirty
type alias State =
{ location : Location
, a : Condition
, b : Condition
}
type alias Action =
State -> State
left : Action
left state =
{ state | location = A }
right : Action
right state =
{ state | location = B }
suck : Action
suck state =
case state.location of
A ->
{ state | a = Clean }
B ->
{ state | b = Clean }
vacuumWorld : Problem State
vacuumWorld =
{ initialState =
{ location = A
, a = Dirty
, b = Dirty
}
, actions =
\state ->
[ { stepCost = 1, result = left state }
, { stepCost = 1, result = right state }
, { stepCost = 1, result = suck state }
]
, heuristic = \_ -> 0
, goalTest = \state -> state.a == Clean && state.b == Clean
, stateToString = Debug.toString
}
-- Learn Elm: https://elmprogramming.com/
-- Elm core documentation: https://package.elm-lang.org/packages/elm/core/latest/