Vowpal odroznia domki nieodwiedzone

This commit is contained in:
Anna Nowak 2019-06-04 23:16:42 +02:00
parent d95378c72e
commit 113b8ebea9
14 changed files with 175 additions and 25 deletions

View File

@ -0,0 +1,7 @@
14 5
10 1
R R R R R R R R R R R R R R
R R H H R H E E E Y R B E R
E R E E R H E E E E R R E R
E R E G R E E R E E R H E E
R R R R R R R R R R R R R R

View File

@ -0,0 +1,10 @@
10 8
5 3
E R R R H R R R H E
E R E R E R R R E E
E R E R H R E R E E
E R H R E R E R E E
E R E R E R E R H Y
R R R R R R R R R R
H G B R E R E R E E
R R R R R R R R R R

View File

@ -0,0 +1,8 @@
9 6
6 3
R R R R R R R R R
E R E E R E R H R
R R R R R R R R R
Y H B E R E R E R
E E E E R E R G R
E E E E R E H E R

View File

@ -0,0 +1,7 @@
14 5
6 1
E R E E E E E R E R E E R H
R R R R R R R R R R R R R R
H E R E E H E R E H E E R E
G E E B H E E R E Y H H R E
R R R R R R R R R R R R R R

View File

@ -0,0 +1,59 @@
3 1.0 map20190603114044897991_auto|GC_Position 5,1 |GC_Area E(4,0) R(4,1) E(4,2) E(5,0) H(5,2) E(6,0) R(6,1) E(6,2)
1 1.0 map20190603114044897991_auto|GC_Position 5,1 |GC_Area E(4,0) R(4,1) E(4,2) E(5,0) H(5,2) E(6,0) R(6,1) E(6,2)
3 1.0 map20190603114044897991_auto|GC_Position 4,1 |GC_Area E(3,0) R(3,1) E(3,2) E(4,0) E(4,2) E(5,0) R(5,1) H(5,2)
3 1.0 map20190603114044897991_auto|GC_Position 3,1 |GC_Area E(2,0) R(2,1) R(2,2) E(3,0) E(3,2) E(4,0) R(4,1) E(4,2)
3 1.0 map20190603114044897991_auto|GC_Position 2,1 |GC_Area R(1,0) R(1,1) E(1,2) E(2,0) R(2,2) E(3,0) R(3,1) E(3,2)
3 1.0 map20190603114044897991_auto|GC_Position 1,1 |GC_Area E(0,0) R(0,1) H(0,2) R(1,0) E(1,2) E(2,0) R(2,1) R(2,2)
3 1.0 map20190603114044897991_auto|GC_Position 0,1 |GC_Area E(0,0) H(0,2) R(1,0) R(1,1) E(1,2)
1 1.0 map20190603114044897991_auto|GC_Position 0,1 |GC_Area E(0,0) H(0,2) R(1,0) R(1,1) E(1,2)
2 1.0 map20190603114044897991_auto|GC_Position 1,1 |GC_Area E(0,0) R(0,1) H(0,2) R(1,0) E(1,2) E(2,0) R(2,1) R(2,2)
2 1.0 map20190603114044897991_auto|GC_Position 2,1 |GC_Area R(1,0) R(1,1) E(1,2) E(2,0) R(2,2) E(3,0) R(3,1) E(3,2)
2 1.0 map20190603114044897991_auto|GC_Position 3,1 |GC_Area E(2,0) R(2,1) R(2,2) E(3,0) E(3,2) E(4,0) R(4,1) E(4,2)
2 1.0 map20190603114044897991_auto|GC_Position 4,1 |GC_Area E(3,0) R(3,1) E(3,2) E(4,0) E(4,2) E(5,0) R(5,1) H(5,2)
2 1.0 map20190603114044897991_auto|GC_Position 5,1 |GC_Area E(4,0) R(4,1) E(4,2) E(5,0) H(5,2) E(6,0) R(6,1) E(6,2)
2 1.0 map20190603114044897991_auto|GC_Position 6,1 |GC_Area E(5,0) R(5,1) H(5,2) E(6,0) E(6,2) R(7,0) R(7,1) R(7,2)
2 1.0 map20190603114044897991_auto|GC_Position 7,1 |GC_Area E(6,0) R(6,1) E(6,2) R(7,0) R(7,2) E(8,0) R(8,1) E(8,2)
2 1.0 map20190603114044897991_auto|GC_Position 8,1 |GC_Area R(7,0) R(7,1) R(7,2) E(8,0) E(8,2) R(9,0) R(9,1) H(9,2)
2 1.0 map20190603114044897991_auto|GC_Position 9,1 |GC_Area E(8,0) R(8,1) E(8,2) R(9,0) H(9,2) E(10,0) R(10,1) E(10,2)
1 1.0 map20190603114044897991_auto|GC_Position 9,1 |GC_Area E(8,0) R(8,1) E(8,2) R(9,0) H(9,2) E(10,0) R(10,1) E(10,2)
2 1.0 map20190603114044897991_auto|GC_Position 10,1 |GC_Area R(9,0) R(9,1) H(9,2) E(10,0) E(10,2) E(11,0) R(11,1) E(11,2)
2 1.0 map20190603114044897991_auto|GC_Position 11,1 |GC_Area E(10,0) R(10,1) E(10,2) E(11,0) E(11,2) R(12,0) R(12,1) R(12,2)
2 1.0 map20190603114044897991_auto|GC_Position 12,1 |GC_Area E(11,0) R(11,1) E(11,2) R(12,0) R(12,2) H(13,0) R(13,1) E(13,2)
2 1.0 map20190603114044897991_auto|GC_Position 13,1 |GC_Area R(12,0) R(12,1) R(12,2) H(13,0) E(13,2)
1 1.0 map20190603114044897991_auto|GC_Position 13,1 |GC_Area R(12,0) R(12,1) R(12,2) H(13,0) E(13,2)
3 1.0 map20190603114044897991_auto|GC_Position 12,1 |GC_Area E(11,0) R(11,1) E(11,2) R(12,0) R(12,2) H(13,0) R(13,1) E(13,2)
3 1.0 map20190603114044897991_auto|GC_Position 11,1 |GC_Area E(10,0) R(10,1) E(10,2) E(11,0) E(11,2) R(12,0) R(12,1) R(12,2)
3 1.0 map20190603114044897991_auto|GC_Position 10,1 |GC_Area R(9,0) R(9,1) H(9,2) E(10,0) E(10,2) E(11,0) R(11,1) E(11,2)
3 1.0 map20190603114044897991_auto|GC_Position 9,1 |GC_Area E(8,0) R(8,1) E(8,2) R(9,0) H(9,2) E(10,0) R(10,1) E(10,2)
3 1.0 map20190603114044897991_auto|GC_Position 8,1 |GC_Area R(7,0) R(7,1) R(7,2) E(8,0) E(8,2) R(9,0) R(9,1) H(9,2)
3 1.0 map20190603114044897991_auto|GC_Position 7,1 |GC_Area E(6,0) R(6,1) E(6,2) R(7,0) R(7,2) E(8,0) R(8,1) E(8,2)
5 1.0 map20190603114044897991_auto|GC_Position 7,2 |GC_Area R(6,1) E(6,2) E(6,3) R(7,1) R(7,3) R(8,1) E(8,2) E(8,3)
5 1.0 map20190603114044897991_auto|GC_Position 7,3 |GC_Area E(6,2) E(6,3) R(6,4) R(7,2) R(7,4) E(8,2) E(8,3) R(8,4)
5 1.0 map20190603114044897991_auto|GC_Position 7,4 |GC_Area E(6,3) R(6,4) R(7,3) E(8,3) R(8,4)
3 1.0 map20190603114044897991_auto|GC_Position 6,4 |GC_Area E(5,3) R(5,4) E(6,3) R(7,3) R(7,4)
3 1.0 map20190603114044897991_auto|GC_Position 5,4 |GC_Area H(4,3) R(4,4) E(5,3) E(6,3) R(6,4)
3 1.0 map20190603114044897991_auto|GC_Position 4,4 |GC_Area B(3,3) R(3,4) H(4,3) E(5,3) R(5,4)
1 1.0 map20190603114044897991_auto|GC_Position 4,4 |GC_Area B(3,3) R(3,4) H(4,3) E(5,3) R(5,4)
2 1.0 map20190603114044897991_auto|GC_Position 5,4 |GC_Area H(4,3) R(4,4) E(5,3) E(6,3) R(6,4)
2 1.0 map20190603114044897991_auto|GC_Position 6,4 |GC_Area E(5,3) R(5,4) E(6,3) R(7,3) R(7,4)
2 1.0 map20190603114044897991_auto|GC_Position 7,4 |GC_Area E(6,3) R(6,4) R(7,3) E(8,3) R(8,4)
2 1.0 map20190603114044897991_auto|GC_Position 8,4 |GC_Area R(7,3) R(7,4) E(8,3) Y(9,3) R(9,4)
2 1.0 map20190603114044897991_auto|GC_Position 9,4 |GC_Area E(8,3) R(8,4) Y(9,3) H(10,3) R(10,4)
2 1.0 map20190603114044897991_auto|GC_Position 10,4 |GC_Area Y(9,3) R(9,4) H(10,3) H(11,3) R(11,4)
1 1.0 map20190603114044897991_auto|GC_Position 10,4 |GC_Area Y(9,3) R(9,4) H(10,3) H(11,3) R(11,4)
2 1.0 map20190603114044897991_auto|GC_Position 11,4 |GC_Area H(10,3) R(10,4) H(11,3) R(12,3) R(12,4)
1 1.0 map20190603114044897991_auto|GC_Position 11,4 |GC_Area H(10,3) R(10,4) H(11,3) R(12,3) R(12,4)
3 1.0 map20190603114044897991_auto|GC_Position 10,4 |GC_Area Y(9,3) R(9,4) H(10,3) H(11,3) R(11,4)
3 1.0 map20190603114044897991_auto|GC_Position 9,4 |GC_Area E(8,3) R(8,4) Y(9,3) H(10,3) R(10,4)
1 1.0 map20190603114044897991_auto|GC_Position 9,4 |GC_Area E(8,3) R(8,4) Y(9,3) H(10,3) R(10,4)
3 1.0 map20190603114044897991_auto|GC_Position 8,4 |GC_Area R(7,3) R(7,4) E(8,3) Y(9,3) R(9,4)
3 1.0 map20190603114044897991_auto|GC_Position 7,4 |GC_Area E(6,3) R(6,4) R(7,3) E(8,3) R(8,4)
3 1.0 map20190603114044897991_auto|GC_Position 6,4 |GC_Area E(5,3) R(5,4) E(6,3) R(7,3) R(7,4)
3 1.0 map20190603114044897991_auto|GC_Position 5,4 |GC_Area H(4,3) R(4,4) E(5,3) E(6,3) R(6,4)
3 1.0 map20190603114044897991_auto|GC_Position 4,4 |GC_Area B(3,3) R(3,4) H(4,3) E(5,3) R(5,4)
3 1.0 map20190603114044897991_auto|GC_Position 3,4 |GC_Area E(2,3) R(2,4) B(3,3) H(4,3) R(4,4)
1 1.0 map20190603114044897991_auto|GC_Position 3,4 |GC_Area E(2,3) R(2,4) B(3,3) H(4,3) R(4,4)
3 1.0 map20190603114044897991_auto|GC_Position 2,4 |GC_Area E(1,3) R(1,4) E(2,3) B(3,3) R(3,4)
3 1.0 map20190603114044897991_auto|GC_Position 1,4 |GC_Area G(0,3) R(0,4) E(1,3) E(2,3) R(2,4)
3 1.0 map20190603114044897991_auto|GC_Position 0,4 |GC_Area G(0,3) E(1,3) R(1,4)
1 1.0 map20190603114044897991_auto|GC_Position 0,4 |GC_Area G(0,3) E(1,3) R(1,4)

View File

@ -0,0 +1,18 @@
2 1.0 map_001|GC_Position 3,1 |GC_Area E(2,0) R(2,1) E(2,2) V(3,0) R(3,2) E(4,0) E(4,1) E(4,2)
5 1.0 map_001|GC_Position 3,2 |GC_Area R(2,1) E(2,2) E(2,3) R(3,1) R(3,3) E(4,1) E(4,2) R(4,3)
5 1.0 map_001|GC_Position 3,3 |GC_Area E(2,2) E(2,3) E(2,4) R(3,2) E(3,4) E(4,2) R(4,3) R(4,4)
2 1.0 map_001|GC_Position 4,3 |GC_Area R(3,2) R(3,3) E(3,4) E(4,2) R(4,4) R(5,2) R(5,3) V(5,4)
2 1.0 map_001|GC_Position 5,3 |GC_Area E(4,2) R(4,3) R(4,4) R(5,2) V(5,4) E(6,2) R(6,3) E(6,4)
2 1.0 map_001|GC_Position 6,3 |GC_Area R(5,2) R(5,3) V(5,4) E(6,2) E(6,4) G(7,2) R(7,3) R(7,4)
2 1.0 map_001|GC_Position 7,3 |GC_Area E(6,2) R(6,3) E(6,4) G(7,2) R(7,4) E(8,2) E(8,3) E(8,4)
5 1.0 map_001|GC_Position 7,4 |GC_Area R(6,3) E(6,4) R(6,5) R(7,3) R(7,5) E(8,3) E(8,4) E(8,5)
5 1.0 map_001|GC_Position 7,5 |GC_Area E(6,4) R(6,5) R(6,6) R(7,4) V(7,6) E(8,4) E(8,5) E(8,6)
3 1.0 map_001|GC_Position 6,5 |GC_Area V(5,4) E(5,5) R(5,6) E(6,4) R(6,6) R(7,4) R(7,5) V(7,6)
5 1.0 map_001|GC_Position 6,6 |GC_Area E(5,5) R(5,6) R(5,7) R(6,5) E(6,7) R(7,5) V(7,6) E(7,7)
3 1.0 map_001|GC_Position 5,6 |GC_Area R(4,5) E(4,6) R(4,7) E(5,5) R(5,7) R(6,5) R(6,6) E(6,7)
5 1.0 map_001|GC_Position 5,7 |GC_Area E(4,6) R(4,7) V(4,8) R(5,6) R(5,8) R(6,6) E(6,7) R(6,8)
3 1.0 map_001|GC_Position 4,7 |GC_Area V(3,6) R(3,7) E(3,8) E(4,6) V(4,8) R(5,6) R(5,7) R(5,8)
3 1.0 map_001|GC_Position 3,7 |GC_Area R(2,6) R(2,7) V(2,8) V(3,6) E(3,8) E(4,6) R(4,7) V(4,8)
3 1.0 map_001|GC_Position 2,7 |GC_Area B(1,6) E(1,7) E(1,8) R(2,6) V(2,8) V(3,6) R(3,7) E(3,8)
4 1.0 map_001|GC_Position 2,6 |GC_Area R(1,5) B(1,6) E(1,7) R(2,5) R(2,7) R(3,5) V(3,6) R(3,7)
1 1.0 map_001|GC_Position 2,6 |GC_Area R(1,5) B(1,6) E(1,7) R(2,5) R(2,7) R(3,5) V(3,6) R(3,7)

View File

@ -0,0 +1,5 @@
2 1.0 map_005|GC_Position 2,6 |GC_Area R(1,5) R(1,6) E(2,5) E(3,5) R(3,6)
2 1.0 map_005|GC_Position 3,6 |GC_Area E(2,5) R(2,6) E(3,5) E(4,5) R(4,6)
2 1.0 map_005|GC_Position 4,6 |GC_Area E(3,5) R(3,6) E(4,5) R(5,5) R(5,6)
2 1.0 map_005|GC_Position 5,6 |GC_Area E(4,5) R(4,6) R(5,5) E(6,5) V(6,6)
1 1.0 map_005|GC_Position 5,6 |GC_Area E(4,5) R(4,6) R(5,5) E(6,5) V(6,6)

2
.gitignore vendored
View File

@ -5,4 +5,4 @@ env
.vscode
*.swp
linux_env
moveset_data.json
moveset_data.json

View File

@ -2,9 +2,14 @@ from DataModels.Cell import Cell
from DataModels.Road import Road
from DataModels.House import House
from DataModels.Dump import Dump
<<<<<<< Updated upstream
from config import GRID_WIDTH, GRID_HEIGHT, DELAY, CLOSE_ON_END
from utilities import movement, check_moves, save_moveset
from vowpal_utils import parse_list
from vowpal_utils import parse_list, MAP_CONTENT
=======
from config import GRID_WIDTH, GRID_HEIGHT, DELAY
from utilities import movement, check_moves, parse_list
>>>>>>> Stashed changes
from Traversal.DFS import DFS
from Traversal.BestFS import BestFS
from Traversal.BFS import BFS
@ -46,31 +51,45 @@ class GC(Cell):
x = self.x
y = self.y
whole_result=[]
result = []
whole_result=[]
element_list=[]
house_count_after_search=house_count
for home in range(house_count):
last_x = x
last_y = y
avalible_moves = check_moves(enviromnent, x,y)
if mode == "DFS":
house,[x,y],result = DFS(enviromnent,avalible_moves,[[x,y]],House)
elif mode == "BFS":
house,[x,y],result = BFS(enviromnent,avalible_moves,[[x,y]],House)
result = result[1::]
<<<<<<< Updated upstream
self.moves.extend(parse_list(result[1:], last_x,last_y))
=======
whole_result.extend(result)
>>>>>>> Stashed changes
element_list.append(house)
MAP_CONTENT[house.y][house.x] = 'V'
for dump in range(dump_count):
last_x = x
last_y = y
avalible_moves = check_moves(enviromnent, x,y)
if mode == "DFS":
dump,[x,y],result = DFS(enviromnent,avalible_moves,[[x,y]],Dump)
elif mode == "BFS":
dump,[x,y],result = BFS(enviromnent,avalible_moves,[[x,y]],Dump)
<<<<<<< Updated upstream
self.moves.extend(parse_list(result[1:], last_x,last_y))
element_list.append(dump)
=======
whole_result.extend(result)
element_list.append(dump)
self.moves.extend(parse_list(element_list))
for x in element_list:
x.unvisited = True
self.moves.extend(parse_list(whole_result))
>>>>>>> Stashed changes
self.moves.reverse()
save_moveset(self.moves)
def find_houses_BestFS(self, environment):
@ -94,21 +113,26 @@ class GC(Cell):
a += 1
x, y = self.x, self.y
print(MAP_CONTENT)
for i in range(len(houses_list)):
last_x = x
last_y = y
available_movement = check_moves(environment, x, y)
output = BestFS(environment, available_movement, [[x,y]], houses_list)
if(output != None):
[x,y],result,houses_list = output[0], output[1], output[2]
whole_result.extend(result[1:])
[x,y],result,houses_list,house = output[0], output[1], output[2], output[3]
MAP_CONTENT[house.y][house.x] = 'V'
self.moves.extend(parse_list(result[1:], last_x,last_y))
for i in range(len(dump_list)):
last_x = x
last_y = y
available_movement = check_moves(environment, x, y)
output = BestFS(environment, available_movement, [[x,y]], dump_list)
if(output != None):
[x,y],result,dump_list = output[0], output[1], output[2]
whole_result.extend(result[1:])
self.moves.extend(parse_list(whole_result,self.x,self.y))
self.moves.extend(parse_list(result[1:], last_x,last_y))
self.moves.reverse()
print(MAP_CONTENT)
save_moveset(self.moves)
def make_actions_from_list(self,environment):
@ -124,5 +148,9 @@ class GC(Cell):
self.collect(environment)
self.moves.pop()
return
<<<<<<< Updated upstream
self.move(self.moves[-1],environment)
self.moves.pop()
=======
move(self.moves.pop(),enviromnent)
>>>>>>> Stashed changes

View File

@ -5,4 +5,4 @@ class Road( pygame.sprite.Sprite ):
def __init__( self, x, y ):
pygame.sprite.Sprite.__init__( self )
self.rect = pygame.Rect( x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE )
self.image = pygame.image.load("Resources/Images/Image_Road.png")
self.image = pygame.image.load("Resources/Images/Image_Road.png")

View File

@ -15,7 +15,7 @@ def CalculateDistance(gc, object_list):
return min_distance_goal
def BestFS(grid, available_movement, gc_moveset, object_list, depth = 0):
x, y = gc_moveset[-1][0], gc_moveset[-1][1]
#calculate distance to the nearest object
@ -25,11 +25,11 @@ def BestFS(grid, available_movement, gc_moveset, object_list, depth = 0):
gc_moveset.append("pick_garbage")
cell = grid[min_distance_goal[0][0]][min_distance_goal[0][1]]
object_list.remove([cell,min_distance_goal[0]])
return([x, y], gc_moveset, object_list)
return([x, y], gc_moveset, object_list,cell)
#if depth exceeded, return
if(depth > 15 or len(available_movement) == 0):
return
return
#set preffered directions based on the closest object
preffered_directions = []
@ -65,4 +65,4 @@ def BestFS(grid, available_movement, gc_moveset, object_list, depth = 0):
gc_moveset_next.append([x_next,y_next])
result = BestFS(grid, available_movement_next, gc_moveset_next, object_list, depth + 1)
if result!= None:
return result
return result

View File

@ -2,7 +2,7 @@ import sys, random, MapGenerator
CELL_SIZE = 64
FPS = 60
DELAY = 500
DELAY = 50
try:
map_mode = sys.argv[1]

View File

@ -23,6 +23,7 @@ def check_moves(environment, x,y,direction=None):
return ([dir for dir in movement(environment, x, y)[0] if movement(environment, x,y)[0][dir] != (x,y)])
return ([dir for dir in movement(environment, x, y)[0] if movement(environment, x,y)[0][dir] != (x,y) and dir != movement(environment,x,y)[1][direction]])
<<<<<<< Updated upstream
def save_moveset(moveset):
if platform.system() == 'Windows':
path = '\moveset_data.json'
@ -49,4 +50,14 @@ def save_moveset(moveset):
results["moveset"].append(moveset)
f.seek(0)
json.dump(results, f, indent=1)
f.close()
f.close()
=======
def parse_list(whole_result):
moves = []
parser = {[0,1]:"up",[0,-1]:"down",[1,0]:"right",[-1,0]:"left"}
for x in len(whole_result)-1:
x_subtraction = whole_result[x+1][0]-whole_result[x][0]
y_subtraction = whole_result[x+1][1]-whole_result[x][1]
moves.append(parser[[x_subtraction,y_subtraction]])
return moves
>>>>>>> Stashed changes

View File

@ -20,7 +20,6 @@ def parse_list(whole_result,current_x,current_y):
global COORDINATES_LIST, MOVES_LIST
COORDINATES_LIST = whole_result.copy()
moves = []
print("x,y",current_x,current_y,"list",whole_result)
parser = {'[0,1]':"down",'[0,-1]':"up",'[1,0]':"right",'[-1,0]':"left"}
for x in range(len(whole_result)):
if whole_result[x]=="pick_garbage":
@ -31,7 +30,6 @@ def parse_list(whole_result,current_x,current_y):
current_x = whole_result[x][0]
current_y = whole_result[x][1]
moves.append(parser[f"[{x_subtraction},{y_subtraction}]"])
print(moves)
MOVES_LIST = moves.copy()
generate_input(1.0)
return moves
@ -40,7 +38,7 @@ def generate_input(importance):
i = 0 #we'll use it to map coords to moves
input_file_content = []
for position in COORDINATES_LIST:
coords = check_position(position, i) #set valid gc position
#vowpal config goes here
@ -48,22 +46,21 @@ def generate_input(importance):
tag = re.findall("(map_[0-9]+|map[0-9]+_auto)", MAP_NAME)[0]
gc_position = "|GC_Position "+str(coords[0])+","+str(coords[1])
input_line = str(label) + " " + str(importance) + " " + tag + gc_position+" |GC_Area "
area = get_gc_area(coords,1)
for a in area:
input_line += a + " "
i += 1
input_file_content.append(input_line)
#save to file
filename = ".\VowPalInputData\input_" + str(tag) + ".txt"
input_file = open(filename,"w+")
for line in input_file_content:
print(line)
input_file.write(line+"\n")
input_file.close()
def get_gc_area(position, radius):
area = []
for x in range(max(0, position[0] - radius), min(position[0] + radius + 1, GRID_WIDTH)): #prevents giong abroad
@ -82,4 +79,4 @@ def check_position(position, i):
return COORDINATES_LIST[j]
return [GC_X, GC_Y]
else: #in case sh t happened
print("An error has ocurred while processing GC position.")
print("An error has ocurred while processing GC position.")