# # Code written by Jingwen Feng 02/28/2024. All rights reserved. #
The set of all possible arrangements of the pancakes. Each state s is a permutation of the stack [p1, p2, p3 ... p10]. pi is the size of ith pancake from top.
The original disordered list (permutation) of pancakes. For example: [3, 6, 7, 2, 5, 4, 9, 10, 1, 8]
The set of action A = [a1, a2, a3 ... a9], where ai is the action that inserted under ith pancake in the stack and used to flip all pancakes above it. (a10 is just flipping the whole set, so I only set to a9).
T(s,a) -> s' returns new stack (new permutation) of pancakes Goal s*: permutation [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
g(i) = total flips from initial state to state i.
Ci = total flips from initial state to state i. If from initial state to state i has actions [ai], 1
3. Possible Heuristic Function (Forward Cost)
h(n) = Number of pancakes that are not in the correct descending order, ignoring the bottom pancake if it's correctly placed.
For UCS, f(n) = g(n) For A*; f(n) = g(n) + h(n)
In terminal, enter main.py
Do you want to input your own pancake stack? YES/NO:
if YES, enter own set such as '1 2 3 4 5 6 7 8 9 10'
if NO, use default set.
The result show:
A*: solution set, steps, time and space
ucs: solution set, steps, time and space
A*
running time: 0.011997461318969727
Space: 531
UCS:
running Time: 0.010999917984008789
Space: 1278
A*
running time: 0.0
Space: 25
UCS:
running Time: 0.0
Space: 17
Use the webpage:
In terminal run:
pip install flask
then run:
app2.py
click on the http://
enter the set and get result
To exist, enter [Control C]