From 9acdfc0cc8498c049a01876f0ffa9c45a12f73c7 Mon Sep 17 00:00:00 2001 From: Dominik Zawadzki Date: Tue, 9 Jun 2020 12:24:41 +0000 Subject: [PATCH 1/2] Zaktualizuj 'src/decisionTree.py' --- src/decisionTree.py | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/decisionTree.py b/src/decisionTree.py index 1ea08c0..73bed34 100644 --- a/src/decisionTree.py +++ b/src/decisionTree.py @@ -16,11 +16,12 @@ class DecisionTree: graphics = Graphics() self.waiter = Waiter(graphics) self.matrix = Matrix(graphics=graphics) + self.tree = self.BuildTree(self.BuildDf()) def BuildDf(self): - actionName = 'order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check'.split(',') - distance = '1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27'.split(',') - priority = '1,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4'.split(',') + actionName = 'order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,order,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,goToBar,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,eat,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check,check'.split(',') + distance = '0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27'.split(',') + priority = '1,1,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4'.split(',') dataset ={'actionName':actionName,'distance':distance,'priority':priority} df = pd.DataFrame(dataset,columns=['actionName','distance','priority']) @@ -83,41 +84,32 @@ class DecisionTree: return tree + #Dodawanie zadan do listy zadan - def TasksList(self, name, coordinate): + def TasksList(self, name, coordinate, waiterPos): distance = [] - waiterNode = [self.waiter.X, self.waiter.Y] + print(waiterPos) if name != "goToBar": - if self.matrix.matrix[coordinate[0] - 1][coordinate[1] - 1].walk_through == 1: - distance.append([abs(waiterNode[0] - (coordinate[0] - 1)) + abs(waiterNode[1] - (coordinate[1] - 1)), [coordinate[0] - 1, coordinate[1] - 1]]) - if self.matrix.matrix[coordinate[0] + 1][coordinate[1] - 1].walk_through == 1: - distance.append([abs(waiterNode[0] - (coordinate[0] + 1)) + abs(waiterNode[1] - (coordinate[1] - 1)), [coordinate[0] + 1, coordinate[1] - 1]]) if self.matrix.matrix[coordinate[0] + 1][coordinate[1]].walk_through == 1: - distance.append([abs(coordinate[0] - (coordinate[0] + 1)) + abs(waiterNode[1] - coordinate[1]), [coordinate[0] + 1, coordinate[1] ]]) - if self.matrix.matrix[coordinate[0] + 1][coordinate[1] - 1].walk_through == 1: - distance.append([abs(waiterNode[0] - (coordinate[0] + 1)) + abs(waiterNode[1] - (coordinate[1] - 1)), [coordinate[0] + 1, coordinate[1] - 1]]) - if self.matrix.matrix[coordinate[0] - 1][coordinate[1] + 1].walk_through == 1: - distance.append([abs(waiterNode[0] - (coordinate[0] - 1)) + abs(waiterNode[1] - (coordinate[1] + 1)), [coordinate[0] - 1, coordinate[1] + 1]]) + distance.append([abs(coordinate[0] - (coordinate[0] + 1)) + abs(waiterPos[1] - coordinate[1]), [coordinate[0] + 1, coordinate[1] ]]) + if self.matrix.matrix[coordinate[0] - 1][coordinate[1]].walk_through == 1: + distance.append([abs(coordinate[0] - (coordinate[0] - 1)) + abs(waiterPos[1] - coordinate[1]), [coordinate[0] - 1, coordinate[1] ]]) else: - distance.append([abs(waiterNode[0] - 0) + abs(waiterNode[1] - 12), [0, 12]]) - distance.append([abs(waiterNode[0] - 1) + abs(waiterNode[1] - 12), [1, 12]]) - distance.append([abs(waiterNode[0] - 2) + abs(waiterNode[1] - 12), [2, 12]]) - distance.append([abs(waiterNode[0] - 3) + abs(waiterNode[1] - 12), [3, 12]]) - distance.append([abs(waiterNode[0] - 4) + abs(waiterNode[1] - 12), [4, 12]]) - distance.append([abs(waiterNode[0] - 5) + abs(waiterNode[1] - 13), [5, 13]]) - distance.append([abs(waiterNode[0] - 5) + abs(waiterNode[1] - 14), [5, 14]]) + if self.matrix.matrix[coordinate[0] + 1][coordinate[1]].walk_through == 1: + distance.append([abs(waiterPos[0] - 3) + abs(waiterPos[1] - 12), [coordinate[0] + 1, coordinate[1] ]]) + if self.matrix.matrix[coordinate[0] - 1][coordinate[1]].walk_through == 1: + distance.append([abs(waiterPos[0] - 3) + abs(waiterPos[1] - 12), [coordinate[0] - 1, coordinate[1] ]]) distance.sort(key=lambda x: x[0]) tasksList.append([name, distance[0][0], distance[0][1]]) - #Kolejkowanie zadan def Queue(self, tasksList): df = self.BuildDf() - tree = self.BuildTree(df) + tree = self.tree winnerNode = self.FindWinner(df) for i in tasksList: @@ -153,6 +145,10 @@ class DecisionTree: print(queue) return queue + def RemoveTask(self): + tasksList.remove(tasksList[0]) + + def print(self): print(tasksList) \ No newline at end of file From b1c7b70aced064611adf8569349202abc313eec8 Mon Sep 17 00:00:00 2001 From: Dominik Zawadzki Date: Tue, 9 Jun 2020 12:26:23 +0000 Subject: [PATCH 2/2] Zaktualizuj 'main.py' --- main.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index e402baa..988c84d 100644 --- a/main.py +++ b/main.py @@ -32,6 +32,9 @@ if __name__ == "__main__": # Dominik check = 0 queue = [] + fromBar = 0 + barNode = (3, 12) + node = () # Marcin Dobrowolski suggestionTreeRoot = SuggestionTree.buildTree(trainingData) @@ -165,17 +168,31 @@ if __name__ == "__main__": path = waiter.translatePath(path) # Dominik - if check == 1: + if path == '' and fromBar == 0 and check == 1: task = queue.pop(0) - goal = (task[2][0], task[2][1]) - print(goal) - path = waiter.findPath(goal) - print(path) + tree.RemoveTask() + node = (task[2][0], task[2][1]) + if task[0] == "goToBar": + path = waiter.findPath(barNode) + fromBar = 1 + else: + path = waiter.findPath(node) path = waiter.translatePath(path) - print(path) - check = 0 + if fromBar == 1: + check = 0 - if len(queue) != 0 and check == 0 and path == '': + if path == '' and fromBar == 1: + path = waiter.findPath(node) + path = waiter.translatePath(path) + fromBar = 0 + + + if path != '': + nextStep = path[0] + path = path[1:] + waiter.travel(nextStep, graphics) + + if len(queue) != 0 and check == 0 and path == '' and fromBar == 0: check = 1 # AStar