SlideShare a Scribd company logo
1 of 30
Game of eight chips
Ло Вэйчжи
Luo Weizhi
CONTENTS
0
1
Task introduction
Heuristic function analysis
Algorithm design
UML interpretation
0
2
0
3
0
4
0
5
Performance Evaluation & Test Cases
0
6
Conclusion
Task introduction
0
1
Task introduction
The puzzle "The Game of Eight Chips" is a heuristic search task. Chips will be
moved in order (right, left, up, down) to adjacent spaces. The goal is to reach the final
state with ordered chips.
Feasible heuristic function:
1.The heuristic function H1 characterizes number of chips shifted from optimal final state. For the state
(a) heuristic function H1=8.
2.The heuristic function H2 characterizes sum of distances between current (a) and target (b) chip
positions. For the state (a) heuristic function H2=3+1+2+2+2+3+3+2=18.
Heuristic function analysis
0
2
Heuristic function analysis
The requirement of the task is to implement a path shortest path search using the A* algorithm.The
A* algorithm is a heuristic graph search algorithm characterized by the definition of the valuation
function.
f(n) = g(n) + h(n)
The heuristic function f(n) is the key function used to evaluate nodes in the A* algorithm and
consists of two parts: g(n) and h(n).
g(n): this is the distance from the starting node to node n at actual cost. It reflects the cost of
reaching the current node n. For example, in an octet problem, it could be the number of steps
required to reach the current state from the initial state.
h(n): this is the estimated cost of traveling from node n to the goal node. This is a heuristic estimate
of the cost required to reach the goal node from the current node n to the goal node. In the octet
problem, this can be the estimated number of steps from the current state to the goal state, computed
by the heuristics H1, H2.
Algorithm design
0
3
Judgment of solutions
Conclusion of the eight-digit problem with and without solutions:
A state is represented in one-dimensional form by finding the sum of the inverse order of all the digits
except 0. That is, If a larger number precedes a smaller number, the two numbers are said to form an
inverse order, and the total number of inverses in an arrangement is called the number of inverses in that
arrangement.
Two states are mutually reachable if their inverse order parity is the same, otherwise they are not
mutually reachable.
Examples from the task,such as:
For the initial state, the one-dimensional array becomes: 724596831, Sum of inverses = 1 + 1 + 1 +
2 + 1 + 6 + 8 = 20(even).
For the final state, the one-dimensional array becomes: 912345678, Sum of inverses = 1 + 1 + 1 +
1+ 1 + 1+ 1 + 1 = 8(even).
So these two states are interchangeable.
Heuristic function H1
Heuristic is the number of misplaced digits.
f(n) = g(n) + h(n)
g(n) represents the depth
h(n) represents the total number of absent arrays
The following figure shows the specific operation of the heuristic strategy H1: the numbers circled
in red indicate the order of expansion.
Heuristic function H1
Heuristic function H2
Heuristic is the Manhattan distance.
f(n) = g(n) + h(n)
h(n) denotes the Manhattan distance. Using the Manhattan distance as heuristic information, it is the
sum of the distances required for misplaced digits to reach the target state compared to the current
state and the target state. For example the initial state in the example: h(n) = 3+1+2+2+2+3+3+2 =
18.The specific operation is the same, except that the value calculated for each h(n) is different.
Data Structure
In fact, in the BFS search algorithm, if the nodes in the Open table (queue) can be sorted
using the valuation function f(n) = g(n) + h(n) at each step of the search, then the search
algorithm is Algorithm A*.
The A* algorithm needs to maintain two data structures: the OPEN set and the CLOSED
set.The OPEN set and the COLED set of this implementation are realized using Map.The OPEN
set contains all the nodes to be detected that have been searched. In the initial state, the OPEN set
contains only one element: the start node.The CLOSED set contains the detected nodes. The
initial state CLOSED set is empty. Each node also contains a pointer to the parent node to
determine the tracking relationship.
Main loop
1.Each time an optimal node n (i.e., the node
with the smallest F-value) is taken from the
OPEN set to be tested.
2.If the OPEN table is empty, the search fails
and the program exits.
3.Remove node n from the OPEN set and add it
to the CLOSED set.
4.If n is the target node, the search succeeds and
the program exits.
Main loop
5. Otherwise try to add all neighbor nodes n of node n:
 Neighbor node in CLOSED set means it has already
been detected, then no need to add it again.
 Neighboring nodes are again in the OPEN set:
 If the recalculated G-value is smaller than the G-
value saved by the neighboring node, then the G-
value amount F-value of this neighboring node needs
to be updated, as well as the parent node.
 Otherwise, no operation is done.
 Otherwise, add this neighbor node to the OPEN set,
set its parent node to n, and set its G value and F
value.

UML interpretation
0
4
UML1: Diagram of precedents
Users can choose the calculation algorithm, and after using the corresponding algorithm
to calculate, they can view the results of the algorithm and get the path to the final state.
The user can control the movement of the queen. Before controlling the movement of the
queen, the user needs to input or generate the starting state or ending state of the queen.
UML2: Diagram of activity
Enter the starting state and ending state,
and the misunderstanding ends directly.
If you have a solution, select the
corresponding algorithm and click the
corresponding button to calculate.
View the path to the final state and
control the movement of the queen.
UML3: Class diagram
Algorithm.java--algorithm file, is
a tool class that implements all
algorithms. Of course, I also added
the DFS and BFS algorithms for
performance comparison.
State.java---node class, stores
the nine-square grid sequence,
real cost, real cost + heuristic
cost of each state.
GUI.java--entry file
GUI file
CalThread.java--for
multi-threaded
calculations
LimitedTextField.java
--limit the input of
TextField.
UML3: Class diagram
UML4: Diagram of interactions
The user needs to input or randomly
generate an initial state or state, then
submit the initial state and final state to
the corresponding algorithm and then
call the corresponding algorithm. After
the Algorithm calculation is completed,
the corresponding calculation result is
returned.
UML5: Diagram of states
At the beginning, the
program waits for input or
generates the initial state and
final state. If there is no
solution to the two, it ends
directly.
If there is a solution, select
the corresponding algorithm
and perform the calculation.
According to the calculation
results, control the movement
of the queen.
UML6: Diagram of components
The LimitedField component and the
CalThread component are inserted into the
GUI. The Algorithm component is called in
the CalThread component.
The smallest unit of calculation in the
Algorithm component is the State
component.
Performance Evaluation & Test Cases
0
5
Performance Evaluation Metrics & Test Cases
Performance Evaluation:
 Consumption time (ms)
 Comparison times
 Path length
Performance Evaluation Metrics & Test Cases
Performance Evaluation Metrics & Test Cases
Performance Evaluation Metrics & Test Cases
Performance Evaluation Metrics & Test Cases
Conclusion
0
6
Conclusion
 DFS is not necessarily faster than BFS, and vice versa.
 DFS may not necessarily find the shortest path.
 BFS can definitely find the shortest path if the search depth is not limited.
The choice of heuristic function h(n) in the A* algorithm is crucial. h*(n) represents the
actual minimum cost from node n to the target node.
h(n) < h*(n), in this case, there are many points to search, the search range is large,
and the efficiency is low. But the optimal solution can be obtained.
h(n)=h*(n), the search efficiency is the highest at this time.
h(n)>h*(n), the number of search points is small, the search range is small, and the
efficiency is high, but the optimal solution cannot be guaranteed.

More Related Content

Similar to Implementing an 8-chip game based on the A algorithm.pptx

Analysis and Design of Algorithms notes
Analysis and Design of Algorithms  notesAnalysis and Design of Algorithms  notes
Analysis and Design of Algorithms notesProf. Dr. K. Adisesha
 
introduction to algorithm for beginneer1
introduction to algorithm for beginneer1introduction to algorithm for beginneer1
introduction to algorithm for beginneer1ranjankumarbehera14
 
lecture 1
lecture 1lecture 1
lecture 1sajinsc
 
State-Space Realizations Using Control Canonical Form and Simulation Diagram
State-Space Realizations Using Control Canonical Form and Simulation DiagramState-Space Realizations Using Control Canonical Form and Simulation Diagram
State-Space Realizations Using Control Canonical Form and Simulation DiagramMIbrar4
 
Simplex Algorithm
Simplex AlgorithmSimplex Algorithm
Simplex AlgorithmAizaz Ahmad
 
Insersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in AlgoritmInsersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in AlgoritmEhsan Ehrari
 
2. Linear regression with one variable.pptx
2. Linear regression with one variable.pptx2. Linear regression with one variable.pptx
2. Linear regression with one variable.pptxEmad Nabil
 
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaAlgorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaPriyanka Rana
 
Chp-1 Quick Review of basic concepts.pdf
Chp-1 Quick Review of basic concepts.pdfChp-1 Quick Review of basic concepts.pdf
Chp-1 Quick Review of basic concepts.pdfSolomonMolla4
 
Parallel algorithms
Parallel algorithmsParallel algorithms
Parallel algorithmsguest084d20
 
Parallel algorithms
Parallel algorithmsParallel algorithms
Parallel algorithmsguest084d20
 

Similar to Implementing an 8-chip game based on the A algorithm.pptx (20)

Analysis and Design of Algorithms notes
Analysis and Design of Algorithms  notesAnalysis and Design of Algorithms  notes
Analysis and Design of Algorithms notes
 
Unit ii algorithm
Unit   ii algorithmUnit   ii algorithm
Unit ii algorithm
 
introduction to algorithm for beginneer1
introduction to algorithm for beginneer1introduction to algorithm for beginneer1
introduction to algorithm for beginneer1
 
lecture 1
lecture 1lecture 1
lecture 1
 
State-Space Realizations Using Control Canonical Form and Simulation Diagram
State-Space Realizations Using Control Canonical Form and Simulation DiagramState-Space Realizations Using Control Canonical Form and Simulation Diagram
State-Space Realizations Using Control Canonical Form and Simulation Diagram
 
Matlab Sample Assignment Solution
Matlab Sample Assignment SolutionMatlab Sample Assignment Solution
Matlab Sample Assignment Solution
 
Simplex Algorithm
Simplex AlgorithmSimplex Algorithm
Simplex Algorithm
 
L1803016468
L1803016468L1803016468
L1803016468
 
Insersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in AlgoritmInsersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in Algoritm
 
frozen_lake_rl_report.pdf
frozen_lake_rl_report.pdffrozen_lake_rl_report.pdf
frozen_lake_rl_report.pdf
 
3 analysis.gtm
3 analysis.gtm3 analysis.gtm
3 analysis.gtm
 
2. Linear regression with one variable.pptx
2. Linear regression with one variable.pptx2. Linear regression with one variable.pptx
2. Linear regression with one variable.pptx
 
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/ThetaAlgorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
Algorithm analysis basics - Seven Functions/Big-Oh/Omega/Theta
 
Chp-1 Quick Review of basic concepts.pdf
Chp-1 Quick Review of basic concepts.pdfChp-1 Quick Review of basic concepts.pdf
Chp-1 Quick Review of basic concepts.pdf
 
Slide2
Slide2Slide2
Slide2
 
DATA STRUCTURE.pdf
DATA STRUCTURE.pdfDATA STRUCTURE.pdf
DATA STRUCTURE.pdf
 
DATA STRUCTURE
DATA STRUCTUREDATA STRUCTURE
DATA STRUCTURE
 
Parallel algorithms
Parallel algorithmsParallel algorithms
Parallel algorithms
 
Design & Analysis Of Algorithm
Design & Analysis Of AlgorithmDesign & Analysis Of Algorithm
Design & Analysis Of Algorithm
 
Parallel algorithms
Parallel algorithmsParallel algorithms
Parallel algorithms
 

Recently uploaded

Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConNatan Silnitsky
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMarkus Moeller
 
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio, Inc.
 
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...drm1699
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdftimtebeek1
 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfWSO2
 
From Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptxFrom Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptxNeo4j
 
Novo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMsNovo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMsNeo4j
 
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale IbridaUNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale IbridaNeo4j
 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024SimonedeGijt
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypseTomasz Kowalczewski
 
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with GraphGraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with GraphNeo4j
 
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Lisi Hocke
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)Roberto Bettazzoni
 
Incident handling is a clearly defined set of procedures to manage and respon...
Incident handling is a clearly defined set of procedures to manage and respon...Incident handling is a clearly defined set of procedures to manage and respon...
Incident handling is a clearly defined set of procedures to manage and respon...Varun Mithran
 
A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfICS
 
Rapidoform for Modern Form Building and Insights
Rapidoform for Modern Form Building and InsightsRapidoform for Modern Form Building and Insights
Rapidoform for Modern Form Building and Insightsrapidoform
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...naitiksharma1124
 

Recently uploaded (20)

Effective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeConEffective Strategies for Wix's Scaling challenges - GeeCon
Effective Strategies for Wix's Scaling challenges - GeeCon
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdf
 
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
 
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdf
 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdf
 
From Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptxFrom Knowledge Graphs via Lego Bricks to scientific conversations.pptx
From Knowledge Graphs via Lego Bricks to scientific conversations.pptx
 
Novo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMsNovo Nordisk: When Knowledge Graphs meet LLMs
Novo Nordisk: When Knowledge Graphs meet LLMs
 
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale IbridaUNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
 
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with GraphGraphSummit Milan - Neo4j: The Art of the Possible with Graph
GraphSummit Milan - Neo4j: The Art of the Possible with Graph
 
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
Abortion Clinic In Springs ](+27832195400*)[ 🏥 Safe Abortion Pills in Springs...
 
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)
 
Incident handling is a clearly defined set of procedures to manage and respon...
Incident handling is a clearly defined set of procedures to manage and respon...Incident handling is a clearly defined set of procedures to manage and respon...
Incident handling is a clearly defined set of procedures to manage and respon...
 
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Turfloop ](+27832195400*)[ 🏥 Women's Abortion Clinic in ...
 
A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdf
 
Rapidoform for Modern Form Building and Insights
Rapidoform for Modern Form Building and InsightsRapidoform for Modern Form Building and Insights
Rapidoform for Modern Form Building and Insights
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 

Implementing an 8-chip game based on the A algorithm.pptx

  • 1. Game of eight chips Ло Вэйчжи Luo Weizhi
  • 2. CONTENTS 0 1 Task introduction Heuristic function analysis Algorithm design UML interpretation 0 2 0 3 0 4 0 5 Performance Evaluation & Test Cases 0 6 Conclusion
  • 4. Task introduction The puzzle "The Game of Eight Chips" is a heuristic search task. Chips will be moved in order (right, left, up, down) to adjacent spaces. The goal is to reach the final state with ordered chips. Feasible heuristic function: 1.The heuristic function H1 characterizes number of chips shifted from optimal final state. For the state (a) heuristic function H1=8. 2.The heuristic function H2 characterizes sum of distances between current (a) and target (b) chip positions. For the state (a) heuristic function H2=3+1+2+2+2+3+3+2=18.
  • 6. Heuristic function analysis The requirement of the task is to implement a path shortest path search using the A* algorithm.The A* algorithm is a heuristic graph search algorithm characterized by the definition of the valuation function. f(n) = g(n) + h(n) The heuristic function f(n) is the key function used to evaluate nodes in the A* algorithm and consists of two parts: g(n) and h(n). g(n): this is the distance from the starting node to node n at actual cost. It reflects the cost of reaching the current node n. For example, in an octet problem, it could be the number of steps required to reach the current state from the initial state. h(n): this is the estimated cost of traveling from node n to the goal node. This is a heuristic estimate of the cost required to reach the goal node from the current node n to the goal node. In the octet problem, this can be the estimated number of steps from the current state to the goal state, computed by the heuristics H1, H2.
  • 8. Judgment of solutions Conclusion of the eight-digit problem with and without solutions: A state is represented in one-dimensional form by finding the sum of the inverse order of all the digits except 0. That is, If a larger number precedes a smaller number, the two numbers are said to form an inverse order, and the total number of inverses in an arrangement is called the number of inverses in that arrangement. Two states are mutually reachable if their inverse order parity is the same, otherwise they are not mutually reachable. Examples from the task,such as: For the initial state, the one-dimensional array becomes: 724596831, Sum of inverses = 1 + 1 + 1 + 2 + 1 + 6 + 8 = 20(even). For the final state, the one-dimensional array becomes: 912345678, Sum of inverses = 1 + 1 + 1 + 1+ 1 + 1+ 1 + 1 = 8(even). So these two states are interchangeable.
  • 9. Heuristic function H1 Heuristic is the number of misplaced digits. f(n) = g(n) + h(n) g(n) represents the depth h(n) represents the total number of absent arrays The following figure shows the specific operation of the heuristic strategy H1: the numbers circled in red indicate the order of expansion.
  • 11. Heuristic function H2 Heuristic is the Manhattan distance. f(n) = g(n) + h(n) h(n) denotes the Manhattan distance. Using the Manhattan distance as heuristic information, it is the sum of the distances required for misplaced digits to reach the target state compared to the current state and the target state. For example the initial state in the example: h(n) = 3+1+2+2+2+3+3+2 = 18.The specific operation is the same, except that the value calculated for each h(n) is different.
  • 12. Data Structure In fact, in the BFS search algorithm, if the nodes in the Open table (queue) can be sorted using the valuation function f(n) = g(n) + h(n) at each step of the search, then the search algorithm is Algorithm A*. The A* algorithm needs to maintain two data structures: the OPEN set and the CLOSED set.The OPEN set and the COLED set of this implementation are realized using Map.The OPEN set contains all the nodes to be detected that have been searched. In the initial state, the OPEN set contains only one element: the start node.The CLOSED set contains the detected nodes. The initial state CLOSED set is empty. Each node also contains a pointer to the parent node to determine the tracking relationship.
  • 13. Main loop 1.Each time an optimal node n (i.e., the node with the smallest F-value) is taken from the OPEN set to be tested. 2.If the OPEN table is empty, the search fails and the program exits. 3.Remove node n from the OPEN set and add it to the CLOSED set. 4.If n is the target node, the search succeeds and the program exits.
  • 14. Main loop 5. Otherwise try to add all neighbor nodes n of node n:  Neighbor node in CLOSED set means it has already been detected, then no need to add it again.  Neighboring nodes are again in the OPEN set:  If the recalculated G-value is smaller than the G- value saved by the neighboring node, then the G- value amount F-value of this neighboring node needs to be updated, as well as the parent node.  Otherwise, no operation is done.  Otherwise, add this neighbor node to the OPEN set, set its parent node to n, and set its G value and F value. 
  • 16. UML1: Diagram of precedents Users can choose the calculation algorithm, and after using the corresponding algorithm to calculate, they can view the results of the algorithm and get the path to the final state. The user can control the movement of the queen. Before controlling the movement of the queen, the user needs to input or generate the starting state or ending state of the queen.
  • 17. UML2: Diagram of activity Enter the starting state and ending state, and the misunderstanding ends directly. If you have a solution, select the corresponding algorithm and click the corresponding button to calculate. View the path to the final state and control the movement of the queen.
  • 18. UML3: Class diagram Algorithm.java--algorithm file, is a tool class that implements all algorithms. Of course, I also added the DFS and BFS algorithms for performance comparison. State.java---node class, stores the nine-square grid sequence, real cost, real cost + heuristic cost of each state.
  • 20. UML4: Diagram of interactions The user needs to input or randomly generate an initial state or state, then submit the initial state and final state to the corresponding algorithm and then call the corresponding algorithm. After the Algorithm calculation is completed, the corresponding calculation result is returned.
  • 21. UML5: Diagram of states At the beginning, the program waits for input or generates the initial state and final state. If there is no solution to the two, it ends directly. If there is a solution, select the corresponding algorithm and perform the calculation. According to the calculation results, control the movement of the queen.
  • 22. UML6: Diagram of components The LimitedField component and the CalThread component are inserted into the GUI. The Algorithm component is called in the CalThread component. The smallest unit of calculation in the Algorithm component is the State component.
  • 23. Performance Evaluation & Test Cases 0 5
  • 24. Performance Evaluation Metrics & Test Cases Performance Evaluation:  Consumption time (ms)  Comparison times  Path length
  • 30. Conclusion  DFS is not necessarily faster than BFS, and vice versa.  DFS may not necessarily find the shortest path.  BFS can definitely find the shortest path if the search depth is not limited. The choice of heuristic function h(n) in the A* algorithm is crucial. h*(n) represents the actual minimum cost from node n to the target node. h(n) < h*(n), in this case, there are many points to search, the search range is large, and the efficiency is low. But the optimal solution can be obtained. h(n)=h*(n), the search efficiency is the highest at this time. h(n)>h*(n), the number of search points is small, the search range is small, and the efficiency is high, but the optimal solution cannot be guaranteed.