Finished TSP, cleaning, refactoring whole project
This commit is contained in:
parent
f55886a199
commit
80e497cc59
@ -4,73 +4,46 @@
|
||||
| | | |--- class: 0
|
||||
| | |--- feature_0 > 1.50
|
||||
| | | |--- feature_3 <= 3.50
|
||||
<<<<<<< HEAD
|
||||
| | | | |--- feature_4 <= 2.50
|
||||
| | | | | |--- class: 1
|
||||
| | | | |--- feature_4 > 2.50
|
||||
| | | | | |--- feature_2 <= 2.50
|
||||
| | | | | | |--- class: 1
|
||||
| | | | | |--- feature_2 > 2.50
|
||||
=======
|
||||
| | | | |--- feature_2 <= 2.50
|
||||
| | | | | |--- class: 1
|
||||
| | | | |--- feature_2 > 2.50
|
||||
| | | | | |--- feature_4 <= 2.50
|
||||
| | | | | | |--- class: 1
|
||||
| | | | | |--- feature_4 > 2.50
|
||||
>>>>>>> a16ec52642067a2be0b41a5c3bcab24193122343
|
||||
| | | | | | |--- class: 0
|
||||
| | | |--- feature_3 > 3.50
|
||||
| | | | |--- feature_3 <= 4.50
|
||||
| | | | | |--- feature_1 <= 2.50
|
||||
| | | | | | |--- feature_0 <= 2.50
|
||||
| | | | | | | |--- feature_1 <= 1.50
|
||||
| | | | | | | | |--- feature_4 <= 2.50
|
||||
| | | | | | | | | |--- class: 1
|
||||
| | | | | | | | |--- feature_4 > 2.50
|
||||
| | | | | | | | | |--- feature_2 <= 2.00
|
||||
| | | | | | | | | | |--- class: 1
|
||||
| | | | | | | | | |--- feature_2 > 2.00
|
||||
| | | | | | | | | | |--- class: 0
|
||||
| | | | | | | |--- feature_1 > 1.50
|
||||
| | | | | | | | |--- class: 0
|
||||
| | | | | | |--- feature_0 > 2.50
|
||||
<<<<<<< HEAD
|
||||
| | | | | | | |--- feature_2 <= 2.50
|
||||
| | | | | | | | |--- class: 1
|
||||
| | | | | | | |--- feature_2 > 2.50
|
||||
| | | | | | | | |--- feature_4 <= 2.50
|
||||
| | | | | | | | | |--- class: 1
|
||||
| | | | | | | | |--- feature_4 > 2.50
|
||||
=======
|
||||
| | | | | | | |--- feature_4 <= 2.50
|
||||
| | | | | | | | |--- class: 1
|
||||
| | | | | | | |--- feature_4 > 2.50
|
||||
| | | | | | | | |--- feature_2 <= 2.50
|
||||
| | | | | | | | | |--- class: 1
|
||||
| | | | | | | | |--- feature_2 > 2.50
|
||||
>>>>>>> a16ec52642067a2be0b41a5c3bcab24193122343
|
||||
| | | | | | | | | |--- class: 0
|
||||
| | | | | |--- feature_1 > 2.50
|
||||
| | | | | | |--- feature_1 <= 3.50
|
||||
| | | | | | | |--- feature_0 <= 3.50
|
||||
| | | | | | | | |--- class: 0
|
||||
| | | | | | | |--- feature_0 > 3.50
|
||||
<<<<<<< HEAD
|
||||
| | | | | | | | |--- feature_2 <= 2.50
|
||||
| | | | | | | | | |--- class: 1
|
||||
| | | | | | | | |--- feature_2 > 2.50
|
||||
| | | | | | | | | |--- feature_4 <= 2.00
|
||||
| | | | | | | | | | |--- class: 1
|
||||
| | | | | | | | | |--- feature_4 > 2.00
|
||||
=======
|
||||
| | | | | | | | | | |--- class: 0
|
||||
| | | | | | | |--- feature_1 > 1.50
|
||||
| | | | | | | | |--- class: 0
|
||||
| | | | | | |--- feature_0 > 2.50
|
||||
| | | | | | | |--- feature_2 <= 2.50
|
||||
| | | | | | | | |--- class: 1
|
||||
| | | | | | | |--- feature_2 > 2.50
|
||||
| | | | | | | | |--- feature_4 <= 2.50
|
||||
| | | | | | | | | |--- class: 1
|
||||
| | | | | | | | |--- feature_4 > 2.50
|
||||
| | | | | | | | | |--- feature_2 <= 2.00
|
||||
| | | | | | | | | |--- class: 0
|
||||
| | | | | |--- feature_1 > 2.50
|
||||
| | | | | | |--- feature_1 <= 3.50
|
||||
| | | | | | | |--- feature_0 <= 3.50
|
||||
| | | | | | | | |--- class: 0
|
||||
| | | | | | | |--- feature_0 > 3.50
|
||||
| | | | | | | | |--- feature_2 <= 2.50
|
||||
| | | | | | | | | |--- class: 1
|
||||
| | | | | | | | |--- feature_2 > 2.50
|
||||
| | | | | | | | | |--- feature_4 <= 2.00
|
||||
| | | | | | | | | | |--- class: 1
|
||||
| | | | | | | | | |--- feature_2 > 2.00
|
||||
>>>>>>> a16ec52642067a2be0b41a5c3bcab24193122343
|
||||
| | | | | | | | | |--- feature_4 > 2.00
|
||||
| | | | | | | | | | |--- class: 0
|
||||
| | | | | | |--- feature_1 > 3.50
|
||||
| | | | | | | |--- class: 0
|
||||
@ -86,7 +59,6 @@
|
||||
| | | | | | |--- class: 1
|
||||
| | | | |--- feature_3 > 3.50
|
||||
| | | | | |--- feature_1 <= 2.50
|
||||
<<<<<<< HEAD
|
||||
| | | | | | |--- feature_0 <= 2.50
|
||||
| | | | | | | |--- class: 0
|
||||
| | | | | | |--- feature_0 > 2.50
|
||||
@ -94,15 +66,6 @@
|
||||
| | | | | | | | |--- class: 1
|
||||
| | | | | | | |--- feature_3 > 4.50
|
||||
| | | | | | | | |--- class: 0
|
||||
=======
|
||||
| | | | | | |--- feature_3 <= 4.50
|
||||
| | | | | | | |--- feature_0 <= 2.50
|
||||
| | | | | | | | |--- class: 0
|
||||
| | | | | | | |--- feature_0 > 2.50
|
||||
| | | | | | | | |--- class: 1
|
||||
| | | | | | |--- feature_3 > 4.50
|
||||
| | | | | | | |--- class: 0
|
||||
>>>>>>> a16ec52642067a2be0b41a5c3bcab24193122343
|
||||
| | | | | |--- feature_1 > 2.50
|
||||
| | | | | | |--- class: 0
|
||||
| | | |--- feature_4 > 4.50
|
||||
@ -113,7 +76,6 @@
|
||||
| |--- feature_1 <= 1.50
|
||||
| | |--- feature_4 <= 1.50
|
||||
| | | |--- feature_2 <= 4.50
|
||||
<<<<<<< HEAD
|
||||
| | | | |--- feature_0 <= 1.50
|
||||
| | | | | |--- class: 0
|
||||
| | | | |--- feature_0 > 1.50
|
||||
@ -121,15 +83,6 @@
|
||||
| | | | | | |--- class: 1
|
||||
| | | | | |--- feature_3 > 4.50
|
||||
| | | | | | |--- class: 0
|
||||
=======
|
||||
| | | | |--- feature_3 <= 4.50
|
||||
| | | | | |--- feature_0 <= 1.50
|
||||
| | | | | | |--- class: 0
|
||||
| | | | | |--- feature_0 > 1.50
|
||||
| | | | | | |--- class: 1
|
||||
| | | | |--- feature_3 > 4.50
|
||||
| | | | | |--- class: 0
|
||||
>>>>>>> a16ec52642067a2be0b41a5c3bcab24193122343
|
||||
| | | |--- feature_2 > 4.50
|
||||
| | | | |--- class: 0
|
||||
| | |--- feature_4 > 1.50
|
||||
|
Binary file not shown.
@ -190,30 +190,11 @@ def nextGeneration(currentGen, eliteSize, mutationRate, distanceArray):
|
||||
return nextGeneration
|
||||
|
||||
|
||||
def geneticAlgorithm(population, popSize, eliteSize, mutationRate, generations, distanceArray):
|
||||
pop = initialPopulation(popSize, population)
|
||||
print("Initial distance: " + str(1 / rankRoutes(pop, distanceArray)[0][1]))
|
||||
|
||||
for i in range(0, generations):
|
||||
pop = nextGeneration(pop, eliteSize, mutationRate, distanceArray)
|
||||
|
||||
print("Final distance: " + str(1 / rankRoutes(pop, distanceArray)[0][1]))
|
||||
bestRouteIndex = rankRoutes(pop, distanceArray)[0][0]
|
||||
bestRoute = pop[bestRouteIndex]
|
||||
return bestRoute
|
||||
|
||||
|
||||
# tutaj ma być lista kordów potencjalnych śmietników z drzewa decyzyjnego
|
||||
|
||||
cityList = []
|
||||
|
||||
|
||||
# for i in range(0,25):
|
||||
# cityList.append(City(x=int(random.random() * 200), y=int(random.random() * 200)))
|
||||
|
||||
# geneticAlgorithm(population=cityList, popSize=100, eliteSize=20, mutationRate=0.01, generations=1000)
|
||||
|
||||
|
||||
# plotting the progress
|
||||
|
||||
def distanceFromCityToCity(cityFrom, city, array):
|
||||
|
BIN
last_map.nparr
BIN
last_map.nparr
Binary file not shown.
19
main.py
19
main.py
@ -49,9 +49,6 @@ class Game():
|
||||
pg.display.set_caption("Trashmaster")
|
||||
self.load_data()
|
||||
self.init_game()
|
||||
# because dont work without data.txt
|
||||
# self.init_bfs()
|
||||
# self.init_a_star()
|
||||
self.t = aiPlayer.aiPlayer(self.player, game=self)
|
||||
|
||||
def init_game(self):
|
||||
@ -101,10 +98,10 @@ class Game():
|
||||
atrrs_container = i.get_attributes()
|
||||
x, y = i.get_coords()
|
||||
dec = decisionTree.decision(getTree(), *atrrs_container)
|
||||
# if dec[0] == 1:
|
||||
self.positive_decision.append(i) # zmiana po to by losowało wszystkie smietniki a nie poprawne tylko, zeby ladniej bylo widac algorytm genetyczny
|
||||
# else:
|
||||
# self.negative_decision.append(i)
|
||||
if dec[0] == 1:
|
||||
self.positive_decision.append(i) # zmiana po to by losowało wszystkie smietniki a nie poprawne tylko, zeby ladniej bylo widac algorytm genetyczny
|
||||
else:
|
||||
self.negative_decision.append(i)
|
||||
|
||||
print('positive actions')
|
||||
print(len(self.positive_decision))
|
||||
@ -121,9 +118,7 @@ class Game():
|
||||
print('action')
|
||||
|
||||
|
||||
# trash_x, trash_y = i.get_coords()
|
||||
|
||||
# for ii in self.tsp_list:
|
||||
temp_tsp = str(self.tsp_list[i])
|
||||
temp_tsp = temp_tsp.strip("()")
|
||||
temp_tsp = temp_tsp.split(",")
|
||||
@ -161,19 +156,15 @@ class Game():
|
||||
|
||||
# print(self.positive_actions[0])
|
||||
|
||||
# self.t.startAiController(self.positive_actions[0])
|
||||
def init_TSP(self):
|
||||
|
||||
city_list =[]
|
||||
|
||||
for i in self.positive_decision:
|
||||
trash_x, trash_y = i.get_coords()
|
||||
# city_list.append(TSP.City(x=int(trash_x), y=int(trash_y), array=self.mapArray))
|
||||
city_list.append(TSP.City(x=trash_x, y=trash_y, array=self.mapArray))
|
||||
|
||||
|
||||
# dist = a_star.get_cost
|
||||
self.tsp_list = TSP.geneticAlgorithmPlot(population=city_list, popSize=100, eliteSize=20, mutationRate=0.01, generations=300, array=self.mapArray)
|
||||
self.tsp_list = TSP.geneticAlgorithmPlot(population=city_list, popSize=100, eliteSize=20, mutationRate=0.01, generations=500, array=self.mapArray)
|
||||
print(self.tsp_list)
|
||||
|
||||
def load_data(self):
|
||||
|
11
map/map.py
11
map/map.py
@ -5,17 +5,6 @@ from settings import *
|
||||
|
||||
def get_tiles():
|
||||
array = map_utils.generate_map()
|
||||
# array = map_utils.get_blank_map_array()
|
||||
|
||||
# array[1][1] = 1
|
||||
# array[1][2] = 1
|
||||
# array[1][3] = 1
|
||||
# array[1][4] = 1
|
||||
# array[1][5] = 1
|
||||
# array[1][6] = 1
|
||||
|
||||
# array[2][5] = 1
|
||||
|
||||
pattern = map_pattern.get_pattern()
|
||||
tiles = map_utils.get_sprites(array, pattern)
|
||||
return tiles, array
|
||||
|
11
mapa.py
11
mapa.py
@ -2,17 +2,6 @@ import pygame as pg
|
||||
import pytmx
|
||||
|
||||
|
||||
# config
|
||||
# TILE_SIZE = 16
|
||||
|
||||
# def preparedMap(screenSize):
|
||||
# tileImage = pg.image.load('tile1.png')
|
||||
# surface = pg.Surface(screenSize)
|
||||
|
||||
# for x in range(0, screenSize[0], TILE_SIZE):
|
||||
# for y in range(0, screenSize[1], TILE_SIZE):
|
||||
# surface.blit(tileImage, (x, y))
|
||||
# return surface
|
||||
|
||||
class TiledMap:
|
||||
# loading file
|
||||
|
@ -4,11 +4,8 @@ from path_search_algorthms import a_star_utils as utils
|
||||
|
||||
def get_cost(start_x: int, start_y: int, target_x: int, target_y: int, array):
|
||||
actions = search_path(start_x, start_y, utils.Rotation.NONE, target_x, target_y, array)
|
||||
print('length')
|
||||
if actions is None:
|
||||
print('0')
|
||||
return 1
|
||||
print(len(actions))
|
||||
return len(actions)
|
||||
|
||||
|
||||
|
@ -27,12 +27,12 @@ PLAYER_WIDTH = 64
|
||||
PLAYER_HEIGHT = 32
|
||||
|
||||
#map settings x 16 y 12
|
||||
MAP_WIDTH = 20
|
||||
MAP_HEIGHT = 20
|
||||
MAP_WIDTH = 25
|
||||
MAP_HEIGHT = 25
|
||||
|
||||
TILE_SIZE_PX = 64
|
||||
MAP_WIDTH_PX = MAP_WIDTH * TILE_SIZE_PX
|
||||
MAP_HEIGHT_PX = MAP_HEIGHT * TILE_SIZE_PX
|
||||
|
||||
TRASHBIN_NUMBER = 50
|
||||
WALL_NUMBER = 40
|
||||
TRASHBIN_NUMBER = 70
|
||||
WALL_NUMBER = 50
|
Loading…
Reference in New Issue
Block a user