diff --git a/DataModels/GC.py b/DataModels/GC.py index 6b72a0f..041b37b 100644 --- a/DataModels/GC.py +++ b/DataModels/GC.py @@ -120,7 +120,7 @@ class GC(Cell): def run_vw(self): print("VOWPAL WABBIT") x, y = self.x, self.y - for i in range(20): + for i in range(1): action, position = get_predicted_move([x, y]) if(action != "pick_garbage"): x, y = position diff --git a/VowpalWabbit/VowpalDataCache/constant_input.txt b/VowpalWabbit/VowpalDataCache/constant_input.txt index f169e72..56913f3 100644 --- a/VowpalWabbit/VowpalDataCache/constant_input.txt +++ b/VowpalWabbit/VowpalDataCache/constant_input.txt @@ -1 +1 @@ -0 1.0 map20190605103058832675_auto|GC_Position 4,1 |GC_Area G(2,0) R(2,1) E(2,2) E(2,3) R(3,0) R(3,1) R(3,2) R(3,3) H(4,0) E(4,2) H(4,3) \ No newline at end of file +1 | F00:0 F01:5 F02:1 F03:0 F10:1 F11:1 F12:1 F13:1 F20:4 F21:0 F23:2 \ No newline at end of file diff --git a/VowpalWabbit/VowpalDataCache/constant_output.txt b/VowpalWabbit/VowpalDataCache/constant_output.txt index b7866b1..fd2880f 100644 --- a/VowpalWabbit/VowpalDataCache/constant_output.txt +++ b/VowpalWabbit/VowpalDataCache/constant_output.txt @@ -1 +1 @@ -2.412344 map20190605103058832675_auto +2.731161 diff --git a/VowpalWabbit/VowpalModels/1k_001.model b/VowpalWabbit/VowpalModels/1k_001.model deleted file mode 100644 index cb88880..0000000 Binary files a/VowpalWabbit/VowpalModels/1k_001.model and /dev/null differ diff --git a/VowpalWabbit/VowpalModels/25k_002.model b/VowpalWabbit/VowpalModels/25k_002.model deleted file mode 100644 index da36ffe..0000000 Binary files a/VowpalWabbit/VowpalModels/25k_002.model and /dev/null differ diff --git a/VowpalWabbit/VowpalModels/teraz.model b/VowpalWabbit/VowpalModels/teraz.model new file mode 100644 index 0000000..a301baf Binary files /dev/null and b/VowpalWabbit/VowpalModels/teraz.model differ diff --git a/VowpalWabbit/generate_dataset.py b/VowpalWabbit/generate_dataset.py index 2d0b1bc..99a8a97 100644 --- a/VowpalWabbit/generate_dataset.py +++ b/VowpalWabbit/generate_dataset.py @@ -18,7 +18,7 @@ def generate_dataset(run_count, clear, model_name, learn): 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+") + input_file = open(filename,"a+") for pfile in glob.glob('./VowpalWabbit/VowpalInputData/input_map*.txt'): #print(pfile) partial_input = open(pfile, "r+") @@ -35,4 +35,4 @@ def generate_dataset(run_count, clear, model_name, learn): wrap_ex("vw " + filename + ".txt -c --passes 2 -f " + model_file) print("Learning process complete, model saved to " + model_file) -generate_dataset(6, True, "3k_001", True) \ No newline at end of file +generate_dataset(200, True, "teraz", True) \ No newline at end of file diff --git a/VowpalWabbit/vowpal_utils.py b/VowpalWabbit/vowpal_utils.py index 8b5a2e3..e7232b7 100644 --- a/VowpalWabbit/vowpal_utils.py +++ b/VowpalWabbit/vowpal_utils.py @@ -1,9 +1,9 @@ -import re +import re, os from config import MAP_NAME, GRID_WIDTH, GRID_HEIGHT, GC_X, GC_Y from VowpalWabbit.VowpalWrapper import wrapper #const -RADIUS = 1 +RADIUS = 2 ## COORDINATES_LIST = [] @@ -55,10 +55,10 @@ def parse_list(whole_result,current_x,current_y): moves.append(parser[f"[{x_subtraction},{y_subtraction}]"]) #print(moves) MOVES_LIST = moves.copy() - generate_input(1.0) + generate_input() return moves -def generate_input(importance): +def generate_input(): i = 1 #we'll use it to map coords to moves input_file_content = [] for position in COORDINATES_LIST[:len(COORDINATES_LIST)-1]: @@ -66,9 +66,13 @@ def generate_input(importance): coords = check_position(position, i) #set valid gc position #vowpal config goes here + importance = 1.0 label = moves_mapping[MOVES_LIST[i]] - #" " + str(importance) + - input_line = str(label) + " | " + if(label == 4 or label == 5): + importance = 3.0 + elif(label == 1): + importance = 15.0 + input_line = str(label) + " " + str(importance) + " | " area = get_gc_area(coords, RADIUS) for a in area: @@ -80,15 +84,13 @@ 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" - input_file = open(filename,"w+") + input_file = open(filename,"a+") for line in input_file_content: input_file.write(line+"\n") input_file.close() def pass_input(position): - label = 0 - gc_position = "|GC_Position "+str(position[0])+","+str(position[1]) - input_line = str(label) + " 1.0 " + tag + gc_position+" | " + input_line = "1 | " area = get_gc_area(position, RADIUS) for a in area: input_line += a + " " @@ -128,7 +130,7 @@ def check_position(position, i): def get_predicted_move(position): input_filename = pass_input(position) output_filename = "./VowpalWabbit/VowpalDataCache/constant_output.txt" - wrapper.wrap_ex("vw -i ./VowpalWabbit/VowpalModels/25k_002.model -t "+input_filename+" -p "+output_filename+" --quiet") + wrapper.wrap_ex("vw -i ./VowpalWabbit/VowpalModels/teraz.model -t "+input_filename+" -p "+output_filename+" ") with open( output_filename, 'r' ) as fout: prediction = float(list(fout.readline().split())[0]) move = make_move_from_prediction(prediction)