Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AI Progamming Exercises
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michael Mutote
AI Progamming Exercises
Commits
a4ee4776
Commit
a4ee4776
authored
1 year ago
by
Michael Mutote
Browse files
Options
Downloads
Patches
Plain Diff
22202956 - touch up on testing functions
parent
5d796d50
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Search_Algorithms/Heuristics.py
+4
-9
4 additions, 9 deletions
Search_Algorithms/Heuristics.py
Search_Algorithms/solution testing.py
+11
-16
11 additions, 16 deletions
Search_Algorithms/solution testing.py
with
15 additions
and
25 deletions
Search_Algorithms/Heuristics.py
+
4
−
9
View file @
a4ee4776
...
...
@@ -3,10 +3,11 @@ import Sucessors
def
queens_opt
(
path
):
"""
Heuristic for the N-Queens problem that calculates the minimum number of moves
required to move each queen to a position where it is not in conflict with any other queen.
Args:
path (list): The path taken so far, where the last element is the current state of the N-Queens board.
...
...
@@ -27,7 +28,7 @@ def queens_opt(path):
conflict
=
False
# Check row and diagonals for conflict
for
k
in
range
(
n
):
if
state
[
y
][
k
]
==
1
and
k
!=
x
:
if
state
[
y
][
k
]
and
k
!=
x
:
conflict
=
True
break
if
y
+
(
col
-
x
)
<
n
and
y
+
(
col
-
x
)
>=
0
and
state
[
y
+
(
col
-
x
)][
col
]
==
1
:
...
...
@@ -43,12 +44,10 @@ def queens_opt(path):
return
total_moves
def
maze_opt
(
path
):
"""
maze search heuristic going to have to use the euclidian distance, so it works for any maze
"""
state
=
path
[
-
1
]
return
(
is_goal
.
MAZE_GOAL
[
0
]
-
state
[
0
])
**
2
+
(
is_goal
.
MAZE_GOAL
[
1
]
-
state
[
1
])
**
2
return
(
is_goal
.
MAZE_GOAL
[
0
]
-
state
[
0
])
**
2
+
(
is_goal
.
MAZE_GOAL
[
1
]
-
state
[
1
])
**
2
def
puzzle_opt
(
path
):
...
...
@@ -65,7 +64,3 @@ def sudoku_opt(path):
Sucessors
.
choose_best_column
(
path
[
-
1
])]
return
max
(
starting_point
,
key
=
lambda
w
:
w
[
2
])[
-
1
]
def
queens_opt
(
path
):
pass
This diff is collapsed.
Click to expand it.
Search_Algorithms/solution testing.py
+
11
−
16
View file @
a4ee4776
...
...
@@ -40,7 +40,7 @@ import time
# for rows in sln:
# print(rows)
#
# board = ((False, False, False, False, False, False, False, False, False, False),
# (False, False, False, False, False, False, False, False, False, False),
# (False, False, False, False, False, False, False, False, False, False),
...
...
@@ -57,19 +57,19 @@ import time
# # ===============================================================================================================
# sln = (Search_Algorithms.BreadthFirstSearch(
# board, Sucessors.queens_successor, is_goal.is_goal_queens)[-1])
#
# output_tuple = tuple(tuple("Q" if value else "." for value in sln)
# for sln in sln)
# for rows in output_tuple:
# print(rows)
#
# ===============================================================================================================
#
# BREAD
TH FIRST SEARCH
PUZZLE PROBLEM
#
# ===============================================================================================================
# ===============================================================================================================
#
DEP
TH FIRST SEARCH
N-QUEENS
# ===============================================================================================================
# sln = (Search_Algorithms.DepthFirstSearch(
# board, Sucessors.queens_successor, is_goal.is_goal_queens)[-1])
#
# output_tuple = tuple(tuple("Q" if value else "." for value in sln)
# for sln in sln)
# for rows in output_tuple:
...
...
@@ -151,20 +151,15 @@ import time
board
=
((
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
),
(
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
),
(
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
),
(
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
),
(
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
),
(
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
),
(
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
),
(
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
),
(
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
),
(
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
,
False
))
board
=
((
False
,
False
,
False
,
False
),
(
False
,
False
,
False
,
False
),
(
False
,
False
,
False
,
False
),
(
False
,
False
,
False
,
False
))
sln
=
(
Search_Algorithms
.
A_StarSearch
(
board
,
Sucessors
.
queens_successor
,
is_goal
.
is_goal_queens
,
Heuristics
.
queens_opt
))[
-
1
]
print
(
sln
)
output_tuple
=
tuple
(
tuple
(
"
Q
"
if
value
else
"
.
"
for
value
in
sln
)
for
sln
in
sln
)
for
rows
in
output_tuple
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment