Zaktualizuj 'src/decisionTree.py'
This commit is contained in:
parent
d89e37e6eb
commit
2abfdf6239
@ -2,6 +2,7 @@ import numpy as np
|
||||
import pandas as pd
|
||||
import pprint
|
||||
|
||||
from .matrix import Matrix
|
||||
from src.graphics import *
|
||||
from .waiter import Waiter
|
||||
|
||||
@ -9,15 +10,17 @@ eps = np.finfo(float).eps
|
||||
tasksList = []
|
||||
tasksQueue = []
|
||||
|
||||
|
||||
class DecisionTree:
|
||||
def __init__(self):
|
||||
graphics = Graphics()
|
||||
self.waiter = Waiter(graphics)
|
||||
self.matrix = Matrix(graphics=graphics)
|
||||
|
||||
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,2,2,2,2,2,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,2,2,2,2,3,3,3,3,3,3,3,4,4,4,4,4,4,4'.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(',')
|
||||
|
||||
dataset ={'actionName':actionName,'distance':distance,'priority':priority}
|
||||
df = pd.DataFrame(dataset,columns=['actionName','distance','priority'])
|
||||
@ -81,18 +84,40 @@ class DecisionTree:
|
||||
return tree
|
||||
|
||||
|
||||
|
||||
#Dodawanie zadan do listy zadan
|
||||
def TasksList(self, name, coordinate):
|
||||
waiterNode = self.waiter.Node()
|
||||
distance = abs(waiterNode[0] - coordinate[0]) + abs(waiterNode[1] - coordinate[1])
|
||||
distance = []
|
||||
waiterNode = [self.waiter.X, self.waiter.Y]
|
||||
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]])
|
||||
|
||||
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]])
|
||||
|
||||
distance.sort(key=lambda x: x[0])
|
||||
tasksList.append([name, distance[0][0], distance[0][1]])
|
||||
|
||||
tasksList.append([name, distance])
|
||||
|
||||
#Kolejkowanie zadan
|
||||
def Queue(self, tasksList):
|
||||
df = self.BuildDf()
|
||||
tree = self.BuildTree(df)
|
||||
|
||||
winnerNode = self.FindWinner(df)
|
||||
|
||||
for i in tasksList:
|
||||
@ -100,26 +125,34 @@ class DecisionTree:
|
||||
|
||||
subtable = tree[winnerNode][i[0]]
|
||||
if subtable in ['0','1','2','3']:
|
||||
tasksQueue.append([i[0], i[1], subtable])
|
||||
tasksQueue.append([i[0], i[1], i[2], subtable])
|
||||
else:
|
||||
tasksQueue.append([i[0], i[1], tree[winnerNode][i[0]]['distance'][str(i[1])]])
|
||||
tasksQueue.append([i[0], i[1], i[2], tree[winnerNode][i[0]]['distance'][str(i[1])]])
|
||||
elif winnerNode is "distance":
|
||||
|
||||
subtable = tree[winnerNode][i[1]]
|
||||
if subtable in ['0','1','2','3']:
|
||||
tasksQueue.append([i[0], i[1], subtable])
|
||||
tasksQueue.append([i[0], i[1], i[2], subtable])
|
||||
else:
|
||||
tasksQueue.append([i[0], i[1], tree[winnerNode][i[1]]['actionName'][str(i[0])]])
|
||||
tasksQueue.append([i[0], i[1], i[2], tree[winnerNode][i[1]]['actionName'][str(i[0])]])
|
||||
|
||||
|
||||
tasksQueue.sort(key=lambda x: x[2])
|
||||
print(tasksQueue)
|
||||
tasksQueue.sort(key=lambda x: x[3])
|
||||
return tasksQueue
|
||||
|
||||
|
||||
def ReturnQueueList(self):
|
||||
if tasksQueue == []:
|
||||
queue = self.Queue(tasksList)
|
||||
else:
|
||||
queue = tasksQueue
|
||||
|
||||
while queue[0][3] == '0':
|
||||
queue.pop(0)
|
||||
|
||||
print(queue)
|
||||
return queue
|
||||
|
||||
def print(self):
|
||||
df = self.BuildDf()
|
||||
#a_entropy = {k:self.FindAttributesEntropy(df,k) for k in df.keys()[:-1]}
|
||||
#print(a_entropy)
|
||||
#print('\n Info Gain: ', self.FindWinner(df))
|
||||
print(tasksList)
|
||||
self.Queue(tasksList)
|
||||
|
Loading…
Reference in New Issue
Block a user