Compare commits
No commits in common. "master_2.1" and "master" have entirely different histories.
master_2.1
...
master
9
.vscode/settings.json
vendored
@ -1,9 +0,0 @@
|
||||
{
|
||||
"python.analysis.extraPaths": [
|
||||
"./sources",
|
||||
"/usr/local/lib/python3.10/site-packages",
|
||||
"/Users/alexeybrown/development",
|
||||
"/Users/alexeybrown/development/flutter/",
|
||||
"./agent"
|
||||
]
|
||||
}
|
10
README.md
Normal file
@ -0,0 +1,10 @@
|
||||
# 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
__pycache__/blocks.cpython-37.pyc
Normal file
BIN
__pycache__/land.cpython-37.pyc
Normal file
BIN
__pycache__/soil.cpython-37.pyc
Normal file
BIN
__pycache__/tractor.cpython-37.pyc
Normal file
BIN
agent/.DS_Store
vendored
BIN
agent/methods/.DS_Store
vendored
@ -1,113 +0,0 @@
|
||||
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
|
BIN
agent/neural_network/.DS_Store
vendored
BIN
agent/neural_network/images/.DS_Store
vendored
BIN
agent/neural_network/images/test/.DS_Store
vendored
Before Width: | Height: | Size: 58 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 60 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 60 KiB |
Before Width: | Height: | Size: 65 KiB |
Before Width: | Height: | Size: 64 KiB |
Before Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 7.5 KiB |
Before Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 69 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 62 KiB |
Before Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 46 KiB |
Before Width: | Height: | Size: 34 KiB |
Before Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 53 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 23 KiB |
Before Width: | Height: | Size: 41 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 64 KiB |
Before Width: | Height: | Size: 18 KiB |
Before Width: | Height: | Size: 19 KiB |
Before Width: | Height: | Size: 49 KiB |
Before Width: | Height: | Size: 8.9 KiB |
Before Width: | Height: | Size: 7.6 KiB |
Before Width: | Height: | Size: 48 KiB |
Before Width: | Height: | Size: 44 KiB |
Before Width: | Height: | Size: 24 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 21 KiB |
Before Width: | Height: | Size: 66 KiB |
Before Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 65 KiB |
Before Width: | Height: | Size: 60 KiB |
Before Width: | Height: | Size: 70 KiB |
Before Width: | Height: | Size: 22 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 9.5 KiB |
Before Width: | Height: | Size: 64 KiB |
Before Width: | Height: | Size: 36 KiB |
Before Width: | Height: | Size: 8.8 KiB |
Before Width: | Height: | Size: 20 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 9.8 KiB |
Before Width: | Height: | Size: 7.6 KiB |