Created learning script, cleaned up

This commit is contained in:
Magdalena Wilczynska 2019-06-05 18:21:27 +02:00
parent 28c6dd4744
commit 7d80f5c05f
10 changed files with 40 additions and 25363 deletions

View File

@ -148,6 +148,6 @@ def GenerateMap():
for row in grid:
map_file.write(" ".join(row)+"\n")
map_file.close()
print(name)
#print(name)
return(name)

File diff suppressed because it is too large Load Diff

View File

@ -1,22 +1,38 @@
import glob, datetime, os
from VowpalWrapper.wrapper import wrap_ex
def generate_dataset(run_count, clear):
print("Collecting data...")
def generate_dataset(run_count, clear, model_name, learn):
print("GENERATING DATASET")
if(clear == True):
print("Clearing stored data... ", end = '')
for dfile in glob.glob('./VowpalWabbit/VowpalInputData/input_map*.txt'):
if(os.path.exists(dfile)):
os.remove(dfile)
print("Done")
print("Collecting data from " + str(run_count) + " runs...")
wrap_ex("./VowpalWabbit/vowpal_auto_run.sh "+str(run_count))
print("Collected data")
filename = "./VowpalWabbit/VowpalInputData/input_dataset" + str(datetime.datetime.now().strftime("%m%d%H%M")) + model_name
print("Creating input file " + filename + ".txt... ", end = '')
input_file = open(filename,"w+")
for pfile in glob.glob('./VowpalWabbit/VowpalInputData/input_map*.txt'):
#print(pfile)
partial_input = open(pfile, "r+")
for line in partial_input:
input_file.write(line)
partial_input.close()
input_file.close()
os.rename(filename, filename + ".txt")
print("Done")
if(learn == True):
print("Learning from " + str(filename) + ".txt")
model_file = "./VowpalWabbit/VowpalModels/" + model_name + ".model"
wrap_ex("vw " + filename + ".txt -c --passes 2 -f " + model_file)
print("Learning process complete, model saved to " + model_file)
"""
filename = "./VowpalWabbit/VowPalInputData/input_dataset" + str(datetime.datetime.now().strftime("%m%d%H%M"))
input_file = open(filename,"w+")
for pfile in glob.glob('./VowpalWabbit/VowPalInputData/*.txt'):
print(pfile)
partial_input = open(pfile, "r+")
for line in partial_input:
input_file.write(line)
partial_input.close()
input_file.close()
os.rename(filename, filename + ".txt")
"""
generate_dataset(2, True)
generate_dataset(6, True, "3k_001", True)

View File

@ -1,5 +1,6 @@
#!/bin/bash
for ((i=1; i<=$1; i++))
do
echo "Run "$i"/"$1
python3 ./main.py auto true bestfs
done

View File

@ -33,7 +33,7 @@ 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)
#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":
@ -44,7 +44,7 @@ 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)
#print(moves)
MOVES_LIST = moves.copy()
generate_input(1.0)
return moves
@ -69,7 +69,7 @@ def generate_input(importance):
#save to file
tag = re.findall("(map_[0-9]+|map[0-9]+_auto)", MAP_NAME)[0]
filename = "./VowpalWabbit/VowPalInputData/input_" + str(tag) + ".txt"
filename = "./VowpalWabbit/VowpalInputData/input_" + str(tag) + ".txt"
input_file = open(filename,"w+")
for line in input_file_content:
input_file.write(line+"\n")

View File

@ -2,7 +2,7 @@ import sys, random, MapGenerator
CELL_SIZE = 64
FPS = 60
DELAY = 25
DELAY = 5
try:
map_mode = sys.argv[1]
@ -27,7 +27,7 @@ ALGORITHM = None
if(len(sys.argv)>3):
ALGORITHM = sys.argv[3]
if(ALGORITHM != "bfs" and ALGORITHM != "dfs" and ALGORITHM!= "bestfs"):
print("ERROR: Invalid agorithm statement\n Please enter \"bfs\", \"dfs\" or \"bestfs\" to specify algorithm you want to use.")
print("ERROR: Invalid algorithm statement\n Please enter \"bfs\", \"dfs\" or \"bestfs\" to specify algorithm you want to use.")
sys.exit()
map = open( MAP_NAME, 'r' )

View File

@ -80,7 +80,7 @@ for line in map_objects:
pygame_sprites.add(item)
gc = GC(GC_X, GC_Y, 200)
print("GC: " + str(GC_X) + str(GC_Y))
#print("GC: " + str(GC_X) + str(GC_Y))
pygame_sprites.add(gc)
while True: