Fix decision tree

This commit is contained in:
tonywesoly 2022-05-12 23:19:46 +02:00
parent 9e95c77404
commit 9c86819931
5 changed files with 23 additions and 17 deletions

View File

@ -24,7 +24,7 @@ class Environment:
self.add_shelfs_to_enviroment_2d()
# TEST CREATE PACKAGE
self.package_spawner = Packages_spawner(window, self.enviroment_2d)
self.sector_decision = self.package_spawner.spawn_package()
self.package_spawner.spawn_package()
new_truck = Truck(window, 14, 7)
self.enviroment_2d[14][7] = new_truck
self.truck = new_truck
@ -45,7 +45,7 @@ class Environment:
def update_all_elements(self):
self.use_astar() # wywyoływanie za każdym razem astar jest bardzo zasobożerne. Lepiej raz na przejście
self.update_truck()
time.sleep(0.5)
# time.sleep(0.5)
# def use_decision_tree(self):
# marking = self.package.type
@ -63,7 +63,7 @@ class Environment:
start_state = State(1,self.truck.x,self.truck.y) # sprawić aby paczka i shelf były wyszukiwane raz
if self.truck.has_package:
end_position = self.finding_fields.find_closest_shelf(self.truck, self.truck.package_type,
self.sector_decision)
self.truck.sector)
else:
end_position = self.finding_fields.find_package()
end_state = State(1,end_position.x, end_position.y)

View File

@ -29,6 +29,7 @@ class Moving_truck:
package = self.enviroment_2d[package_x][package_y]
self.truck.has_package = True
self.truck.package_type = package.type
self.truck.sector = package.sector
self.move_without_swapping(truck_x, truck_y, package_x, package_y)

View File

@ -7,6 +7,7 @@ from Types_colors import Types_colors
from Package_types import Package_types
import math
from CompanyFactory import CompanyFactory
from decision_tree.Decision_tree import DecisionTree
class Package(Field):
@ -17,7 +18,21 @@ class Package(Field):
self.company = CompanyFactory()
self.payed_upfront = random.randint(0,1)
self.is_placed = False
weekend = random.randint(0,1)
self.sector = self.use_decision_tree(weekend)
def use_decision_tree(self, weekend):
marking = self.type
if marking == Package_types.fragile:
marking = 0
elif marking == Package_types.priority:
marking = 1
tree = DecisionTree(marking, weekend, self.company.popularity,
self.company.payment_delay, self.payed_upfront,
self.company.shipping_type)
decision = tree.decision
return decision
def get_marking_photo(self):
file_path_type = ["resources/package_markings/*.jpg"]
images = glob2.glob(random.choice(file_path_type))

View File

@ -13,21 +13,9 @@ class Packages_spawner:
def spawn_package(self):
package_x = random.randrange(22, 26)
package_y = random.randrange(1, 13)
weekend = random.randint(0,1)
package_type = random.choice(list(Package_types))
new_package = Package(self.window, package_x, package_y, package_type)
# sector_type = self.use_decision_tree(new_package, weekend)
self.enviroment_2d[package_x][package_y] = new_package
sector_type = self.use_decision_tree(new_package, weekend)
return sector_type
# return sector_type
def use_decision_tree(self, package, weekend):
marking = package.type
if marking == Package_types.fragile:
marking = 0
elif marking == Package_types.priority:
marking = 1
tree = DecisionTree(marking, weekend, package.company.popularity,
package.company.payment_delay, package.payed_upfront,
package.company.shipping_type)
decision = tree.decision
return decision

View File

@ -1,6 +1,7 @@
import pygame
from Field import Field
from Global_variables import Global_variables as G_var
from Sectors_types import Sectors_types
from Types_colors import Types_colors
from Package_types import Package_types
@ -11,6 +12,7 @@ class Truck(Field):
self.image = pygame.image.load("resources/truck.jpeg").convert()
self.has_package = False
self.package_type = Package_types.fragile
self.sector = Sectors_types.fragile
# drawing the truck
def draw(self):