Compare commits

...

9 Commits

Author SHA1 Message Date
Aliaksei Brown
06bf4fd57a added: datasets with vegies, two neural network training models 2023-06-19 16:29:20 +02:00
Aliaksei Brown
a790f0ba5a github commit 2023-06-19 16:19:06 +02:00
Aliaksei Brown
be0f333181 astar + graph search 2023-06-19 15:56:25 +02:00
Aliaksei Brown
1a0e89c1e7 new veggies changes 2023-06-19 15:44:49 +02:00
4564030f27 tractor moves using genetic_algorithm 2023-06-18 23:37:30 +02:00
Aliaksei Brown
5cfb8fdc21 strawberry correct name 2023-06-18 02:06:38 +02:00
Aliaksei Brown
ea24f48acc new: fruits icons, function locat_fruit, fruits_list 2023-06-18 01:59:54 +02:00
Aliaksei Brown
45a6113acf new foldering, eggplant image 2023-06-17 11:49:38 +02:00
Aliaksei Brown
294c0fbf73 updated version of the game. new aim to the plant. new algorithm that looking for the closest plant, new models for the plant-block and the field-block etc 2023-06-15 19:33:40 +02:00
3121 changed files with 857 additions and 775 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

9
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,9 @@
{
"python.analysis.extraPaths": [
"./sources",
"/usr/local/lib/python3.10/site-packages",
"/Users/alexeybrown/development",
"/Users/alexeybrown/development/flutter/",
"./agent"
]
}

View File

@ -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

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
agent/.DS_Store vendored Normal file

Binary file not shown.

BIN
agent/methods/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

136
agent/methods/a_star.py Normal file
View 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)

View File

@ -0,0 +1,113 @@
import numpy as np
import random
import math
def create_initial_population(num_cities, population_size, list):
population = []
for _ in range(population_size):
chromosome = list.copy()
chromosome.remove((1, 1)) # Usuń punkt (1, 1) z listy
random.shuffle(chromosome)
chromosome.insert(0, (1, 1)) # Dodaj punkt (1, 1) na początku trasy
population.append(chromosome)
return population
def calculate_distance(city1, city2):
x1, y1 = city1
x2, y2 = city2
distance = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
return distance
def calculate_fitness(individual):
total_distance = 0
num_cities = len(individual)
for i in range(num_cities - 1):
city1 = individual[i]
city2 = individual[i + 1]
distance = calculate_distance(city1, city2)
total_distance += distance
fitness = 1 / total_distance
return fitness
def crossover(parent1, parent2):
child = [(1, 1)] + [None] * (len(parent1) - 1) # Inicjalizacja dziecka z punktem (1, 1) na początku
start_index = random.randint(1, len(parent1) - 1)
end_index = random.randint(start_index + 1, len(parent1))
# Skopiuj fragment miast od parent1 do dziecka
child[start_index:end_index] = parent1[start_index:end_index]
# Uzupełnij brakujące miasta z parent2
remaining_cities = [city for city in parent2 if city not in child]
child[1:start_index] = remaining_cities[:start_index - 1]
child[end_index:] = remaining_cities[start_index - 1:]
return child
def mutate(individual, mutation_rate):
for i in range(1, len(individual)): # Rozpoczynamy od indeksu 1, aby pominąć punkt (1, 1)
if random.random() < mutation_rate:
j = random.randint(1, len(individual) - 1) # Wybieramy indeks od 1 do ostatniego indeksu
individual[i], individual[j] = individual[j], individual[i]
return individual
def genetic_algorithm(list):
chromosome_length = 21
max_generations = 200
population_size = 200
crossover_rate = 0.25
mutation_rate = 0.1
num_cities = chromosome_length
population = create_initial_population(num_cities, population_size, list)
best_individual = None
best_fitness = float('-inf')
for generation in range(max_generations):
# # Oblicz wartości fitness dla każdego osobnika w populacji
# fitness_values = [calculate_fitness(individual) for individual in population]
# population = [x for _, x in sorted(zip(fitness_values, population), reverse=True)]
# fitness_values.sort(reverse=True)
# max_fitness_index = np.argmax(fitness_values)
# # Wybierz najlepszego osobnika z ostatniej populacji
# if fitness_values[max_fitness_index] > best_fitness:
# best_fitness = fitness_values[max_fitness_index]
# best_individual = population[max_fitness_index]
# # Twórz nową populację z krzyżówek
# new_population = []
# for _ in range(int(population_size / 2)):
# parent1, parent2 = random.choices(population[:population_size // 2], k=2)
# child1 = crossover(parent1, parent2)
# child2 = crossover(parent2, parent1)
# new_population.extend([child1, child2])
# # Dokonaj mutacji na nowej populacji
# new_population = [mutate(individual, mutation_rate) for individual in new_population]
# population = new_population
# Oblicz wartości fitness dla każdego osobnika w populacji
fitness_values = [calculate_fitness(individual) for individual in population]
population = [x for _, x in sorted(zip(fitness_values, population), reverse=True)]
fitness_values.sort(reverse=True)
best_individuals = population[:10] # Wybierz k najlepszych osobników
new_population = best_individuals.copy()
# Twórz nową populację z krzyżówek i mutacji
while len(new_population) < population_size:
parent1, parent2 = random.choices(best_individuals, k=2) # Wybierz rodziców spośród najlepszych osobników
child = crossover(parent1, parent2) # Krzyżowanie
child = mutate(child, mutation_rate) # Mutacja
new_population.append(child)
for individual in best_individuals:
fitness = calculate_fitness(individual)
if fitness > best_fitness:
best_fitness = fitness
best_individual = individual
population = new_population[:population_size]
print("Best path:", best_individual)
return best_individual

View File

@ -0,0 +1,73 @@
class Node:
def __init__(self, state, parent='', action=''):
self.state = state
self.parent = parent
self.action = action
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 - self.cell_size, 'UP'])
return possible
case 'RIGHT':
possible = [['left', x, y, 'UP'], ['right', x, y, 'DOWN']]
if x != self.cell_size*(self.cell_number-1): possible.append(['move', x + self.cell_size, y, 'RIGHT'])
return possible
case 'DOWN':
possible = [['left', x, y, 'RIGHT'], ['right', x, y, 'LEFT']]
if y != self.cell_size*(self.cell_number-1): possible.append(['move', x, y + self.cell_size, 'DOWN'])
return possible
case 'LEFT':
possible = [['left', x, y, 'DOWN'], ['right', x, y, 'UP']]
if x != 0: possible.append(['move', x - self.cell_size, y, 'LEFT'])
return possible
def graphsearch(self, istate, goaltest):
x = istate[0]
y = istate[1]
angle = istate[2]
fringe = [Node([x, y, angle])] # queue (moves/states to check)
fringe_state = [fringe[0].state]
explored = []
while True:
if len(fringe) == 0:
return False
elem = fringe.pop(0)
fringe_state.pop(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):
if [state_x, state_y, state_angle] not in fringe_state and \
[state_x, state_y, state_angle] not in explored:
x = Node([state_x, state_y, state_angle])
x.parent = elem
x.action = action
fringe.append(x)
fringe_state.append(x.state)

BIN
agent/neural_network/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
agent/neural_network/images/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 69 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 49 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Some files were not shown because too many files have changed in this diff Show More