Fix decision tree
This commit is contained in:
parent
9e95c77404
commit
9c86819931
@ -24,7 +24,7 @@ class Environment:
|
|||||||
self.add_shelfs_to_enviroment_2d()
|
self.add_shelfs_to_enviroment_2d()
|
||||||
# TEST CREATE PACKAGE
|
# TEST CREATE PACKAGE
|
||||||
self.package_spawner = Packages_spawner(window, self.enviroment_2d)
|
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)
|
new_truck = Truck(window, 14, 7)
|
||||||
self.enviroment_2d[14][7] = new_truck
|
self.enviroment_2d[14][7] = new_truck
|
||||||
self.truck = new_truck
|
self.truck = new_truck
|
||||||
@ -45,7 +45,7 @@ class Environment:
|
|||||||
def update_all_elements(self):
|
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.use_astar() # wywyoływanie za każdym razem astar jest bardzo zasobożerne. Lepiej raz na przejście
|
||||||
self.update_truck()
|
self.update_truck()
|
||||||
time.sleep(0.5)
|
# time.sleep(0.5)
|
||||||
|
|
||||||
# def use_decision_tree(self):
|
# def use_decision_tree(self):
|
||||||
# marking = self.package.type
|
# 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
|
start_state = State(1,self.truck.x,self.truck.y) # sprawić aby paczka i shelf były wyszukiwane raz
|
||||||
if self.truck.has_package:
|
if self.truck.has_package:
|
||||||
end_position = self.finding_fields.find_closest_shelf(self.truck, self.truck.package_type,
|
end_position = self.finding_fields.find_closest_shelf(self.truck, self.truck.package_type,
|
||||||
self.sector_decision)
|
self.truck.sector)
|
||||||
else:
|
else:
|
||||||
end_position = self.finding_fields.find_package()
|
end_position = self.finding_fields.find_package()
|
||||||
end_state = State(1,end_position.x, end_position.y)
|
end_state = State(1,end_position.x, end_position.y)
|
||||||
|
@ -29,6 +29,7 @@ class Moving_truck:
|
|||||||
package = self.enviroment_2d[package_x][package_y]
|
package = self.enviroment_2d[package_x][package_y]
|
||||||
self.truck.has_package = True
|
self.truck.has_package = True
|
||||||
self.truck.package_type = package.type
|
self.truck.package_type = package.type
|
||||||
|
self.truck.sector = package.sector
|
||||||
self.move_without_swapping(truck_x, truck_y, package_x, package_y)
|
self.move_without_swapping(truck_x, truck_y, package_x, package_y)
|
||||||
|
|
||||||
|
|
||||||
|
15
Package.py
15
Package.py
@ -7,6 +7,7 @@ from Types_colors import Types_colors
|
|||||||
from Package_types import Package_types
|
from Package_types import Package_types
|
||||||
import math
|
import math
|
||||||
from CompanyFactory import CompanyFactory
|
from CompanyFactory import CompanyFactory
|
||||||
|
from decision_tree.Decision_tree import DecisionTree
|
||||||
|
|
||||||
|
|
||||||
class Package(Field):
|
class Package(Field):
|
||||||
@ -17,6 +18,20 @@ class Package(Field):
|
|||||||
self.company = CompanyFactory()
|
self.company = CompanyFactory()
|
||||||
self.payed_upfront = random.randint(0,1)
|
self.payed_upfront = random.randint(0,1)
|
||||||
self.is_placed = False
|
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):
|
def get_marking_photo(self):
|
||||||
file_path_type = ["resources/package_markings/*.jpg"]
|
file_path_type = ["resources/package_markings/*.jpg"]
|
||||||
|
@ -13,21 +13,9 @@ class Packages_spawner:
|
|||||||
def spawn_package(self):
|
def spawn_package(self):
|
||||||
package_x = random.randrange(22, 26)
|
package_x = random.randrange(22, 26)
|
||||||
package_y = random.randrange(1, 13)
|
package_y = random.randrange(1, 13)
|
||||||
weekend = random.randint(0,1)
|
|
||||||
package_type = random.choice(list(Package_types))
|
package_type = random.choice(list(Package_types))
|
||||||
new_package = Package(self.window, package_x, package_y, package_type)
|
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
|
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
|
|
||||||
|
2
Truck.py
2
Truck.py
@ -1,6 +1,7 @@
|
|||||||
import pygame
|
import pygame
|
||||||
from Field import Field
|
from Field import Field
|
||||||
from Global_variables import Global_variables as G_var
|
from Global_variables import Global_variables as G_var
|
||||||
|
from Sectors_types import Sectors_types
|
||||||
from Types_colors import Types_colors
|
from Types_colors import Types_colors
|
||||||
from Package_types import Package_types
|
from Package_types import Package_types
|
||||||
|
|
||||||
@ -11,6 +12,7 @@ class Truck(Field):
|
|||||||
self.image = pygame.image.load("resources/truck.jpeg").convert()
|
self.image = pygame.image.load("resources/truck.jpeg").convert()
|
||||||
self.has_package = False
|
self.has_package = False
|
||||||
self.package_type = Package_types.fragile
|
self.package_type = Package_types.fragile
|
||||||
|
self.sector = Sectors_types.fragile
|
||||||
|
|
||||||
# drawing the truck
|
# drawing the truck
|
||||||
def draw(self):
|
def draw(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user