Compare commits
5 Commits
master
...
master_2.0
Author | SHA1 | Date | |
---|---|---|---|
|
3652f6ba78 | ||
|
5cfb8fdc21 | ||
|
ea24f48acc | ||
|
45a6113acf | ||
|
294c0fbf73 |
9
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"python.analysis.extraPaths": [
|
||||
"./sources",
|
||||
"/usr/local/lib/python3.10/site-packages",
|
||||
"/Users/alexeybrown/development",
|
||||
"/Users/alexeybrown/development/flutter/",
|
||||
"./agent"
|
||||
]
|
||||
}
|
10
README.md
@ -1,10 +0,0 @@
|
||||
# si23traktor
|
||||
|
||||
Projekt zaliczeniowy przedmiotu Sztuczna Inteligencja w semestrze letnim 2023.
|
||||
|
||||
Skład zespołu:
|
||||
- Jakub Chmielecki
|
||||
- Mikołaj Mazur
|
||||
- Szymon Szczubkowski
|
||||
- Tobiasz Przybylski
|
||||
- Aliaksei Shauchenka
|
BIN
agent/.DS_Store
vendored
Normal file
BIN
agent/methods/.DS_Store
vendored
Normal file
BIN
agent/methods/__pycache__/graph_search.cpython-310.pyc
Normal file
136
agent/methods/graph_search.py
Normal file
@ -0,0 +1,136 @@
|
||||
class Node:
|
||||
def __init__(self, state, parent='', action='', distance=0):
|
||||
self.state = state
|
||||
self.parent = parent
|
||||
self.action = action
|
||||
self.distance = distance
|
||||
|
||||
class Search:
|
||||
def __init__(self, cell_size, cell_number):
|
||||
self.cell_size = cell_size
|
||||
self.cell_number = cell_number
|
||||
|
||||
def succ(self, state):
|
||||
x = state[0]
|
||||
y = state[1]
|
||||
angle = state[2]
|
||||
match(angle):
|
||||
case 'UP':
|
||||
possible = [['left', x, y, 'LEFT'], ['right', x, y, 'RIGHT']]
|
||||
if y != 0: possible.append(['move', x, y - 1, 'UP'])
|
||||
return possible
|
||||
case 'RIGHT':
|
||||
possible = [['left', x, y, 'UP'], ['right', x, y, 'DOWN']]
|
||||
if x != (self.cell_number-1): possible.append(['move', x + 1, y, 'RIGHT'])
|
||||
return possible
|
||||
case 'DOWN':
|
||||
possible = [['left', x, y, 'RIGHT'], ['right', x, y, 'LEFT']]
|
||||
if y != (self.cell_number-1): possible.append(['move', x, y + 1, 'DOWN'])
|
||||
return possible
|
||||
case 'LEFT':
|
||||
possible = [['left', x, y, 'DOWN'], ['right', x, y, 'UP']]
|
||||
if x != 0: possible.append(['move', x - 1, y, 'LEFT'])
|
||||
return possible
|
||||
|
||||
def cost(self, node, stones, goal, flowers):
|
||||
# cost = node.distance
|
||||
cost = 0
|
||||
# cost += 10 if stones[node.state[0], node.state[1]] == 1 else 1
|
||||
cost += 1000 if (node.state[0], node.state[1]) in stones else 1
|
||||
cost += 10 if ((node.state[0]), (node.state[1])) in flowers else 1
|
||||
|
||||
if node.parent:
|
||||
node = node.parent
|
||||
cost += node.distance # should return only elem.action in prod
|
||||
return cost
|
||||
|
||||
def heuristic(self, node, goal):
|
||||
return abs(node.state[0] - goal[0]) + abs(node.state[1] - goal[1])
|
||||
|
||||
#bandaid to know about stones
|
||||
def astarsearch(self, istate, goaltest, stone_list, plant_list):
|
||||
|
||||
#to be expanded
|
||||
def cost_old(x, y):
|
||||
if (x, y) in stones:
|
||||
return 10
|
||||
else:
|
||||
return 1
|
||||
|
||||
x = istate[0]
|
||||
y = istate[1]
|
||||
angle = istate[2]
|
||||
stones = []
|
||||
flowers = []
|
||||
|
||||
for obj in stone_list:
|
||||
stones.append((obj.xy[0]*50, obj.xy[1]*50))
|
||||
for obj in plant_list:
|
||||
if obj.name == 'flower':
|
||||
flowers.append((obj.xy[0]*50, obj.xy[1]*50))
|
||||
|
||||
# stones = [(x*50, y*50) for (x, y) in stone_list]
|
||||
# flowers = [(x*50, y*50) for (x, y) in plant_list]
|
||||
|
||||
print(stones)
|
||||
|
||||
# fringe = [(Node([x, y, angle]), cost_old(x, y))] # queue (moves/states to check)
|
||||
fringe = [(Node([x, y, angle]))] # queue (moves/states to check)
|
||||
fringe[0].distance = self.cost(fringe[0], stones, goaltest, flowers)
|
||||
fringe.append((Node([x, y, angle]), self.cost(fringe[0], stones, goaltest, flowers)))
|
||||
fringe.pop(0)
|
||||
|
||||
explored = []
|
||||
|
||||
while True:
|
||||
if len(fringe) == 0:
|
||||
return False
|
||||
|
||||
fringe.sort(key=lambda x: x[1])
|
||||
elem = fringe.pop(0)[0]
|
||||
|
||||
# if goal_test(elem.state):
|
||||
# return
|
||||
# print(elem.state[0], elem.state[1], elem.state[2])
|
||||
if elem.state[0] == goaltest[0] and elem.state[1] == goaltest[1]: # checks if we reached the given point
|
||||
steps = []
|
||||
while elem.parent:
|
||||
steps.append([elem.action, elem.state[0], elem.state[1]]) # should return only elem.action in prod
|
||||
elem = elem.parent
|
||||
|
||||
steps.reverse()
|
||||
print(steps) # only for dev
|
||||
return steps
|
||||
|
||||
explored.append(elem.state)
|
||||
|
||||
for (action, state_x, state_y, state_angle) in self.succ(elem.state):
|
||||
x = Node([state_x, state_y, state_angle], elem, action)
|
||||
x.parent = elem
|
||||
|
||||
priority = self.cost(elem, stones, goaltest, flowers) + self.heuristic(elem, goaltest)
|
||||
elem.distance = priority
|
||||
# priority = cost_old(x, y) + self.heuristic(elem, goaltest)
|
||||
fringe_states = [node.state for (node, p) in fringe]
|
||||
|
||||
if x.state not in fringe_states and x.state not in explored:
|
||||
fringe.append((x, priority))
|
||||
elif x.state in fringe_states:
|
||||
for i in range(len(fringe)):
|
||||
if fringe[i][0].state == x.state:
|
||||
if fringe[i][1] > priority:
|
||||
fringe[i] = (x, priority)
|
||||
|
||||
|
||||
def closest_point(self, x, y, name, plant_list):
|
||||
self.max_distance = self.cell_number*self.cell_number
|
||||
for obj in plant_list:
|
||||
if obj.name == name:
|
||||
if obj.state == 0:
|
||||
self.distance = (abs(obj.xy[0] - x) + abs(obj.xy[1] - y))
|
||||
if self.distance <= self.max_distance:
|
||||
self.max_distance = self.distance
|
||||
x_close = obj.xy[0]
|
||||
y_close = obj.xy[1]
|
||||
#print("distance: ",self.distance, obj.xy[0], "+", obj.xy[1], "-" ,x, "+",y)
|
||||
return (x_close, y_close)
|
BIN
agent/neural_network/.DS_Store
vendored
Normal file
BIN
agent/neural_network/__pycache__/inference.cpython-310.pyc
Normal file
BIN
agent/neural_network/__pycache__/model.cpython-310.pyc
Normal file
BIN
agent/neural_network/images/.DS_Store
vendored
Normal file
BIN
agent/neural_network/images/test/Apple/Apple (1133).jpeg
Normal file
After Width: | Height: | Size: 5.0 KiB |
BIN
agent/neural_network/images/test/Apple/Apple (1153).jpeg
Normal file
After Width: | Height: | Size: 4.2 KiB |
BIN
agent/neural_network/images/test/Apple/Apple (12).png
Normal file
After Width: | Height: | Size: 7.9 KiB |
BIN
agent/neural_network/images/test/Apple/Apple (1348).jpeg
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
agent/neural_network/images/test/Apple/Apple (1413).jpeg
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
agent/neural_network/images/test/Apple/Apple (1415).jpeg
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
agent/neural_network/images/test/Apple/Apple (1423).jpeg
Normal file
After Width: | Height: | Size: 5.2 KiB |
BIN
agent/neural_network/images/test/Apple/Apple (1526).jpeg
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
agent/neural_network/images/test/Apple/Apple (1555).jpeg
Normal file
After Width: | Height: | Size: 9.3 KiB |
BIN
agent/neural_network/images/test/Apple/Apple (1624).jpeg
Normal file
After Width: | Height: | Size: 9.2 KiB |
BIN
agent/neural_network/images/test/Apple/Apple (1729).jpeg
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
agent/neural_network/images/test/Apple/Apple (1750).jpeg
Normal file
After Width: | Height: | Size: 4.0 KiB |
BIN
agent/neural_network/images/test/Apple/Apple (1789).jpeg
Normal file
After Width: | Height: | Size: 8.9 KiB |
BIN
agent/neural_network/images/test/Apple/Apple (1809).jpeg
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
agent/neural_network/images/test/Apple/Apple (1976).jpeg
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
agent/neural_network/images/test/Apple/Apple (233).jpeg
Normal file
After Width: | Height: | Size: 7.6 KiB |
BIN
agent/neural_network/images/test/Apple/Apple (27).jpeg
Normal file
After Width: | Height: | Size: 6.7 KiB |
BIN
agent/neural_network/images/test/Apple/Apple (28).jpeg
Normal file
After Width: | Height: | Size: 7.2 KiB |
BIN
agent/neural_network/images/test/Apple/Apple (420).jpeg
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
agent/neural_network/images/test/Apple/Apple (545).jpeg
Normal file
After Width: | Height: | Size: 8.6 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (2044).jpeg
Normal file
After Width: | Height: | Size: 3.6 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (2067).jpeg
Normal file
After Width: | Height: | Size: 8.2 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (2120).jpeg
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (2121).jpeg
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (2179).jpeg
Normal file
After Width: | Height: | Size: 9.9 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (2279).jpeg
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (2291).jpeg
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (2448).jpeg
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (2580).jpeg
Normal file
After Width: | Height: | Size: 4.4 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (2712).jpeg
Normal file
After Width: | Height: | Size: 7.6 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (2727).jpeg
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (2845).jpeg
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (2928).jpeg
Normal file
After Width: | Height: | Size: 6.2 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (3362).jpeg
Normal file
After Width: | Height: | Size: 5.3 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (3449).jpeg
Normal file
After Width: | Height: | Size: 4.0 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (3597).jpeg
Normal file
After Width: | Height: | Size: 8.9 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (3652).jpeg
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (3813).jpeg
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (3901).jpeg
Normal file
After Width: | Height: | Size: 9.2 KiB |
BIN
agent/neural_network/images/test/Banana/Banana (3939).jpeg
Normal file
After Width: | Height: | Size: 9.0 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (1073).jpeg
Normal file
After Width: | Height: | Size: 6.1 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (1090).jpeg
Normal file
After Width: | Height: | Size: 8.7 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (1222).jpeg
Normal file
After Width: | Height: | Size: 9.1 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (1266).jpeg
Normal file
After Width: | Height: | Size: 7.0 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (1335).jpeg
Normal file
After Width: | Height: | Size: 3.7 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (1470).jpeg
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (1521).jpeg
Normal file
After Width: | Height: | Size: 7.2 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (1575).jpeg
Normal file
After Width: | Height: | Size: 7.0 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (1656).jpeg
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (1751).jpeg
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (1793).jpeg
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (1902).jpeg
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (1910).jpeg
Normal file
After Width: | Height: | Size: 8.9 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (1973).jpeg
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (286).jpeg
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (387).jpeg
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (54).jpeg
Normal file
After Width: | Height: | Size: 8.4 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (567).jpeg
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (710).jpeg
Normal file
After Width: | Height: | Size: 4.0 KiB |
BIN
agent/neural_network/images/test/Grape/Grape (909).jpeg
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (1287).jpeg
Normal file
After Width: | Height: | Size: 7.8 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (1415).jpeg
Normal file
After Width: | Height: | Size: 9.4 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (1463).jpeg
Normal file
After Width: | Height: | Size: 3.7 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (1477).jpeg
Normal file
After Width: | Height: | Size: 11 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (1669).jpeg
Normal file
After Width: | Height: | Size: 4.8 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (1718).jpeg
Normal file
After Width: | Height: | Size: 22 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (1746).jpeg
Normal file
After Width: | Height: | Size: 18 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (1855).jpeg
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (1862).jpeg
Normal file
After Width: | Height: | Size: 5.8 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (275).jpeg
Normal file
After Width: | Height: | Size: 7.1 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (314).jpeg
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (535).jpeg
Normal file
After Width: | Height: | Size: 9.3 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (540).jpeg
Normal file
After Width: | Height: | Size: 8.8 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (566).jpeg
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (58).jpeg
Normal file
After Width: | Height: | Size: 8.6 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (70).jpeg
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (733).jpeg
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (768).jpeg
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (900).jpeg
Normal file
After Width: | Height: | Size: 6.0 KiB |
BIN
agent/neural_network/images/test/Mango/Mango (906).jpeg
Normal file
After Width: | Height: | Size: 9.6 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 9.4 KiB |
After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 7.0 KiB |