Compare commits
27 Commits
engine_imp
...
master
Author | SHA1 | Date | |
---|---|---|---|
69df0198da | |||
|
9443c03e0a | ||
|
530b221763 | ||
|
868ba1bfd7 | ||
|
5004058725 | ||
|
b37847b304 | ||
23950ba5b5 | |||
|
153f16bcc0 | ||
|
d0cde0beab | ||
3ae78c6ee5 | |||
6866e825ce | |||
|
abd60f9c15 | ||
|
5cb4dee25e | ||
|
53cf8c9937 | ||
|
566a8cd868 | ||
|
e5a7a975e8 | ||
|
c5e0b65445 | ||
|
e67aa84f1f | ||
|
8f9d89b908 | ||
|
ff968efae6 | ||
|
84b3bd5a13 | ||
|
9fde24439c | ||
|
13e5c5d62c | ||
|
bc5bdf6fa4 | ||
|
bf4d4aaeaa | ||
|
52bfb06608 | ||
b944eab69a |
140
ForkliftAgent.py
@ -1,8 +1,10 @@
|
|||||||
|
from copy import deepcopy
|
||||||
from typing import Tuple, List
|
from typing import Tuple, List
|
||||||
|
|
||||||
from AgentBase import AgentBase
|
from AgentBase import AgentBase
|
||||||
from PatchAgent import PatchAgent
|
from PatchAgent import PatchAgent
|
||||||
from PatchType import PatchType
|
from PatchType import PatchType
|
||||||
|
from data.GameConstants import GameConstants
|
||||||
from data.Item import Item
|
from data.Item import Item
|
||||||
from data.Order import Order
|
from data.Order import Order
|
||||||
from data.enum.Direction import Direction
|
from data.enum.Direction import Direction
|
||||||
@ -16,7 +18,7 @@ from util.PathDefinitions import GridLocation, GridWithWeights
|
|||||||
|
|
||||||
class ForkliftAgent(AgentBase):
|
class ForkliftAgent(AgentBase):
|
||||||
|
|
||||||
def __init__(self, model, game_constants, client_delivery: PatchAgent, drop_off: PatchAgent,
|
def __init__(self, model, game_constants: GameConstants, client_delivery: PatchAgent, drop_off: PatchAgent,
|
||||||
graph: GridWithWeights):
|
graph: GridWithWeights):
|
||||||
super().__init__(model)
|
super().__init__(model)
|
||||||
self.action_queue: List[Action] = []
|
self.action_queue: List[Action] = []
|
||||||
@ -28,10 +30,20 @@ class ForkliftAgent(AgentBase):
|
|||||||
self.drop_off: PatchAgent = drop_off
|
self.drop_off: PatchAgent = drop_off
|
||||||
self.graph = graph
|
self.graph = graph
|
||||||
self.game_constants = game_constants
|
self.game_constants = game_constants
|
||||||
self.current_order: Order = None
|
|
||||||
self.current_item = None
|
|
||||||
self.item_station_completed = False
|
self.item_station_completed = False
|
||||||
self.provided_items: List[Item] = []
|
self.current_order_delivered_items: List[Item] = []
|
||||||
|
self.ready_for_execution = False
|
||||||
|
self.last_delviered_item = None
|
||||||
|
|
||||||
|
self.current_item: Item = None
|
||||||
|
self.current_order = None
|
||||||
|
self.base: GridLocation = None
|
||||||
|
self.goal: GridLocation = None
|
||||||
|
|
||||||
|
def set_base(self, drop_off: PatchAgent):
|
||||||
|
self.drop_off = drop_off
|
||||||
|
self.base = self.drop_off.location
|
||||||
|
self.goal = self.base
|
||||||
|
|
||||||
def queue_movement_actions(self, movement_actions: List[Action]):
|
def queue_movement_actions(self, movement_actions: List[Action]):
|
||||||
self.action_queue.extend(movement_actions)
|
self.action_queue.extend(movement_actions)
|
||||||
@ -42,120 +54,94 @@ class ForkliftAgent(AgentBase):
|
|||||||
action_type = action.action_type
|
action_type = action.action_type
|
||||||
|
|
||||||
if action_type == ActionType.ROTATE_UP:
|
if action_type == ActionType.ROTATE_UP:
|
||||||
print("rotate {} --> {}".format(self.current_rotation, action_type))
|
# print("rotate {} --> {}".format(self.current_rotation, action_type))
|
||||||
self.current_rotation = Direction.top
|
self.current_rotation = Direction.top
|
||||||
|
|
||||||
elif action_type == ActionType.ROTATE_RIGHT:
|
elif action_type == ActionType.ROTATE_RIGHT:
|
||||||
print("rotate {} --> {}".format(self.current_rotation, action_type))
|
# print("rotate {} --> {}".format(self.current_rotation, action_type))
|
||||||
self.current_rotation = Direction.right
|
self.current_rotation = Direction.right
|
||||||
|
|
||||||
elif action_type == ActionType.ROTATE_DOWN:
|
elif action_type == ActionType.ROTATE_DOWN:
|
||||||
print("rotate {} --> {}".format(self.current_rotation, action_type))
|
# print("rotate {} --> {}".format(self.current_rotation, action_type))
|
||||||
self.current_rotation = Direction.down
|
self.current_rotation = Direction.down
|
||||||
|
|
||||||
elif action_type == ActionType.ROTATE_LEFT:
|
elif action_type == ActionType.ROTATE_LEFT:
|
||||||
print("rotate {} --> {}".format(self.current_rotation, action_type))
|
# print("rotate {} --> {}".format(self.current_rotation, action_type))
|
||||||
self.current_rotation = Direction.left
|
self.current_rotation = Direction.left
|
||||||
|
|
||||||
elif action_type == ActionType.MOVE:
|
elif action_type == ActionType.MOVE:
|
||||||
if self.current_rotation == Direction.top:
|
if self.current_rotation == Direction.top:
|
||||||
print("move {} --> {}".format(self.current_position, action_type))
|
# print("move {} --> {}".format(self.current_position, action_type))
|
||||||
self.current_position = (self.current_position[0], self.current_position[1] + 1)
|
self.current_position = (self.current_position[0], self.current_position[1] + 1)
|
||||||
|
|
||||||
elif self.current_rotation == Direction.down:
|
elif self.current_rotation == Direction.down:
|
||||||
print("move {} --> {}".format(self.current_position, action_type))
|
# print("move {} --> {}".format(self.current_position, action_type))
|
||||||
self.current_position = (self.current_position[0], self.current_position[1] - 1)
|
self.current_position = (self.current_position[0], self.current_position[1] - 1)
|
||||||
|
|
||||||
elif self.current_rotation == Direction.right:
|
elif self.current_rotation == Direction.right:
|
||||||
print("move {} --> {}".format(self.current_position, action_type))
|
# print("move {} --> {}".format(self.current_position, action_type))
|
||||||
self.current_position = (self.current_position[0] + 1, self.current_position[1])
|
self.current_position = (self.current_position[0] + 1, self.current_position[1])
|
||||||
|
|
||||||
elif self.current_rotation == Direction.left:
|
elif self.current_rotation == Direction.left:
|
||||||
print("move {} --> {}".format(self.current_position, action_type))
|
# print("move {} --> {}".format(self.current_position, action_type))
|
||||||
self.current_position = (self.current_position[0] - 1, self.current_position[1])
|
self.current_position = (self.current_position[0] - 1, self.current_position[1])
|
||||||
|
|
||||||
def plan_actions(self):
|
def step(self) -> None:
|
||||||
if len(self.current_order.items) > 0:
|
if len(self.action_queue) > 0:
|
||||||
i = self.current_order.items.pop(0)
|
self.move()
|
||||||
if self.current_item is None:
|
elif self.ready_for_execution:
|
||||||
self.provided_items.clear()
|
if self.current_position != self.goal:
|
||||||
self.current_item = i
|
|
||||||
print("PLAN MOVEMENT")
|
|
||||||
|
|
||||||
# get item
|
|
||||||
pathFinder = PathFinderOnStates(
|
pathFinder = PathFinderOnStates(
|
||||||
self.game_constants,
|
self.game_constants,
|
||||||
self.drop_off.location,
|
self.goal,
|
||||||
PathFinderState(self.current_position,
|
|
||||||
self.current_rotation,
|
|
||||||
0,
|
|
||||||
Action(ActionType.NONE),
|
|
||||||
[])
|
|
||||||
)
|
|
||||||
actions = pathFinder.get_action_list()
|
|
||||||
self.queue_movement_actions(actions)
|
|
||||||
|
|
||||||
elif not self.item_station_completed:
|
|
||||||
# go through station
|
|
||||||
|
|
||||||
packing_station: GridLocation = None
|
|
||||||
stations = dict(self.graph.packingStations)
|
|
||||||
if i.real_type == ItemType.SHELF:
|
|
||||||
packing_station = stations[PatchType.packingA]
|
|
||||||
elif i.real_type == ItemType.EGG:
|
|
||||||
packing_station = stations[PatchType.packingB]
|
|
||||||
elif i.real_type == ItemType.DOOR:
|
|
||||||
packing_station = stations[PatchType.packingC]
|
|
||||||
|
|
||||||
pathFinder = PathFinderOnStates(
|
|
||||||
self.game_constants,
|
|
||||||
packing_station,
|
|
||||||
PathFinderState(self.current_position,
|
PathFinderState(self.current_position,
|
||||||
self.current_rotation,
|
self.current_rotation,
|
||||||
0,
|
0,
|
||||||
Action(
|
Action(
|
||||||
desired_item=i,
|
desired_item=None,
|
||||||
action_type=ActionType.PICK_ITEM
|
action_type=ActionType.PICK_ITEM
|
||||||
),
|
),
|
||||||
[])
|
[])
|
||||||
)
|
)
|
||||||
actions = pathFinder.get_action_list()
|
actions = pathFinder.get_action_list()
|
||||||
self.queue_movement_actions(actions)
|
self.queue_movement_actions(actions)
|
||||||
self.item_station_completed = True
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# go to client delivery area
|
if self.current_order is not None and self.goal == self.base:
|
||||||
pathFinder = PathFinderOnStates(
|
self.current_item = self.current_order.items.pop(0)
|
||||||
self.game_constants,
|
packing_station: GridLocation = None
|
||||||
self.client_delivery.location,
|
stations = dict(self.graph.packingStations)
|
||||||
PathFinderState(self.current_position,
|
|
||||||
self.current_rotation,
|
|
||||||
0,
|
|
||||||
Action(ActionType.NONE),
|
|
||||||
[])
|
|
||||||
)
|
|
||||||
actions = pathFinder.get_action_list()
|
|
||||||
self.queue_movement_actions(actions)
|
|
||||||
self.queue_movement_actions(
|
|
||||||
[Action(ActionType.DROP_ITEM)]
|
|
||||||
)
|
|
||||||
|
|
||||||
self.current_item = None
|
if self.current_item.real_type == ItemType.SHELF:
|
||||||
self.provided_items.append(self.current_item)
|
packing_station = stations[PatchType.packingShelf]
|
||||||
self.item_station_completed = False
|
elif self.current_item.real_type == ItemType.REFRIGERATOR:
|
||||||
|
packing_station = stations[PatchType.packingRefrigerator]
|
||||||
|
elif self.current_item.real_type == ItemType.DOOR:
|
||||||
|
packing_station = stations[PatchType.packingDoor]
|
||||||
|
|
||||||
def step(self) -> None:
|
self.goal = packing_station
|
||||||
if len(self.action_queue) > 0:
|
|
||||||
self.move()
|
|
||||||
elif len(self.orderList) > 0:
|
|
||||||
if (self.current_order is not None and len(self.current_order.items)) == 0:
|
|
||||||
self.fulfilled_orders.append(self.current_order)
|
|
||||||
self.current_order = None
|
|
||||||
|
|
||||||
if self.current_order is None:
|
elif self.goal in [i[1] for i in self.graph.packingStations]:
|
||||||
self.current_order = self.orderList.pop(0)
|
self.goal = self.client_delivery.location
|
||||||
|
|
||||||
self.plan_actions()
|
elif self.goal == self.client_delivery.location:
|
||||||
|
if self.current_order is not None and len(self.current_order.items) == 0:
|
||||||
|
|
||||||
|
self.current_order_delivered_items.append(self.current_item)
|
||||||
|
self.current_order.items = deepcopy(self.current_order_delivered_items)
|
||||||
|
self.fulfilled_orders.append(self.current_order)
|
||||||
|
|
||||||
|
self.current_item = None
|
||||||
|
self.current_order = None
|
||||||
|
|
||||||
|
self.goal = self.base
|
||||||
|
else:
|
||||||
|
self.current_order_delivered_items.append(self.current_item)
|
||||||
|
self.goal = self.base
|
||||||
|
self.current_item = None
|
||||||
|
|
||||||
|
elif self.goal == self.base and self.current_order is None:
|
||||||
|
self.current_order_delivered_items.clear()
|
||||||
|
self.current_order = self.orderList.pop(0)
|
||||||
|
|
||||||
def creation_log(self):
|
def creation_log(self):
|
||||||
print("Created Forklift Agent [id: {}]".format(self.unique_id))
|
print("Created Forklift Agent [id: {}]".format(self.unique_id))
|
||||||
|
151
GameModel.py
@ -1,5 +1,6 @@
|
|||||||
|
import copy
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import List
|
from typing import List, Tuple
|
||||||
|
|
||||||
from mesa import Model
|
from mesa import Model
|
||||||
from mesa.space import MultiGrid
|
from mesa.space import MultiGrid
|
||||||
@ -8,15 +9,21 @@ from mesa.time import RandomActivation
|
|||||||
from AgentBase import AgentBase
|
from AgentBase import AgentBase
|
||||||
from ForkliftAgent import ForkliftAgent
|
from ForkliftAgent import ForkliftAgent
|
||||||
from InitialStateFactory import InitialStateFactory
|
from InitialStateFactory import InitialStateFactory
|
||||||
|
from ItemDisplayAgent import ItemDisplayAgent
|
||||||
from PatchAgent import PatchAgent
|
from PatchAgent import PatchAgent
|
||||||
from PatchType import PatchType
|
from PatchType import PatchType
|
||||||
from PictureVisualizationAgent import PictureVisualizationAgent
|
from PictureVisualizationAgent import PictureVisualizationAgent
|
||||||
from data.GameConstants import GameConstants
|
from data.GameConstants import GameConstants
|
||||||
from data.Item import Item
|
from data.Item import Item
|
||||||
from data.Order import Order
|
from data.Order import Order
|
||||||
|
from data.enum.ItemType import ItemType
|
||||||
from decision.Action import Action
|
from decision.Action import Action
|
||||||
from decision.ActionType import ActionType
|
from decision.ActionType import ActionType
|
||||||
|
from genetic_order.GeneticOrder import GeneticOrder
|
||||||
|
from imageClasification.Classificator import image_classification
|
||||||
from pathfinding.PathfinderOnStates import PathFinderOnStates, PathFinderState
|
from pathfinding.PathfinderOnStates import PathFinderOnStates, PathFinderState
|
||||||
|
from tree.DecisionTree import DecisionTree
|
||||||
|
from util.PathByEnum import PathByEnum
|
||||||
from util.PathDefinitions import GridLocation, GridWithWeights
|
from util.PathDefinitions import GridLocation, GridWithWeights
|
||||||
|
|
||||||
|
|
||||||
@ -30,7 +37,9 @@ class Phase(Enum):
|
|||||||
|
|
||||||
class GameModel(Model):
|
class GameModel(Model):
|
||||||
|
|
||||||
def __init__(self, width, height, graph: GridWithWeights):
|
def __init__(self, width, height, graph: GridWithWeights, items: int, orders: int, classificator,
|
||||||
|
item_display_pos: List[GridLocation]):
|
||||||
|
|
||||||
# self.num_agents = 5
|
# self.num_agents = 5
|
||||||
self.first = True
|
self.first = True
|
||||||
self.item_recognised = False
|
self.item_recognised = False
|
||||||
@ -38,10 +47,12 @@ class GameModel(Model):
|
|||||||
self.grid = MultiGrid(height, width, True)
|
self.grid = MultiGrid(height, width, True)
|
||||||
self.schedule = RandomActivation(self)
|
self.schedule = RandomActivation(self)
|
||||||
self.current_item_recognition = None
|
self.current_item_recognition = None
|
||||||
|
self.current_item = None
|
||||||
|
|
||||||
self.client_delivery: PatchAgent = None
|
self.client_delivery: PatchAgent = None
|
||||||
self.drop_off: PatchAgent = None
|
self.drop_off: PatchAgent = None
|
||||||
self.graph = graph
|
self.graph = graph
|
||||||
|
self.cut_orders : List[Order] = []
|
||||||
|
|
||||||
self.game_constants = GameConstants(
|
self.game_constants = GameConstants(
|
||||||
width,
|
width,
|
||||||
@ -62,21 +73,26 @@ class GameModel(Model):
|
|||||||
|
|
||||||
self.schedule.add(self.forklift_agent)
|
self.schedule.add(self.forklift_agent)
|
||||||
self.agents.append(self.forklift_agent)
|
self.agents.append(self.forklift_agent)
|
||||||
|
self.item_display_agents: List[ItemDisplayAgent] = []
|
||||||
|
|
||||||
# INITIALIZATION #
|
# INITIALIZATION #
|
||||||
print("############## INITIALIZATION ##############")
|
print("############## INITIALIZATION ##############")
|
||||||
self.phase = Phase.INIT
|
self.phase = Phase.INIT
|
||||||
self.initialize_grid(graph)
|
self.initialize_grid(graph, item_display_pos)
|
||||||
self.orderList: List[Order] = InitialStateFactory.generate_order_list(3)
|
self.orderList: List[Order] = InitialStateFactory.generate_order_list(orders)
|
||||||
self.fulfilled_orders: List[Order] = []
|
self.fulfilled_orders: List[Order] = []
|
||||||
self.forklift_agent.orderList = self.orderList
|
|
||||||
self.forklift_agent.fulfilled_orders = self.fulfilled_orders
|
self.forklift_agent.fulfilled_orders = self.fulfilled_orders
|
||||||
|
self.forklift_agent.set_base(self.drop_off)
|
||||||
|
self.classificator = classificator
|
||||||
|
|
||||||
print("############## RECOGNISE ITEMS ##############")
|
print("############## RECOGNISE ITEMS ##############")
|
||||||
self.phase = Phase.ITEM_RECOGNITION
|
self.phase = Phase.ITEM_RECOGNITION
|
||||||
self.provided_items = InitialStateFactory.generate_item_list(3)
|
self.provided_items = InitialStateFactory.generate_item_list(items)
|
||||||
|
self.items_for_recognization = copy.deepcopy(self.provided_items)
|
||||||
self.recognised_items: List[Item] = []
|
self.recognised_items: List[Item] = []
|
||||||
|
|
||||||
|
self.current_order_delivered_items = self.forklift_agent.current_order_delivered_items
|
||||||
|
|
||||||
print("Relocate forklift agent to loading area for item recognition")
|
print("Relocate forklift agent to loading area for item recognition")
|
||||||
|
|
||||||
pathFinder = PathFinderOnStates(
|
pathFinder = PathFinderOnStates(
|
||||||
@ -90,8 +106,9 @@ class GameModel(Model):
|
|||||||
print("PATHFINDING")
|
print("PATHFINDING")
|
||||||
print(actions)
|
print(actions)
|
||||||
self.forklift_agent.queue_movement_actions(actions)
|
self.forklift_agent.queue_movement_actions(actions)
|
||||||
|
self.current_order = self.forklift_agent.current_order
|
||||||
|
|
||||||
def initialize_grid(self, graph: GridWithWeights):
|
def initialize_grid(self, graph: GridWithWeights, item_display_pos):
|
||||||
print("INITIALIZING GRID")
|
print("INITIALIZING GRID")
|
||||||
# Add the agent to a random grid cell
|
# Add the agent to a random grid cell
|
||||||
x = 5
|
x = 5
|
||||||
@ -112,10 +129,11 @@ class GameModel(Model):
|
|||||||
self.place_walls_agents(graph.walls)
|
self.place_walls_agents(graph.walls)
|
||||||
self.place_puddles(graph.puddles)
|
self.place_puddles(graph.puddles)
|
||||||
self.place_packing_stations(graph.packingStations)
|
self.place_packing_stations(graph.packingStations)
|
||||||
|
self.place_order_items_display(item_display_pos)
|
||||||
|
|
||||||
def place_dividers(self):
|
def place_dividers(self):
|
||||||
for i in range(0, 10):
|
for i in range(0, 10):
|
||||||
for j in range(10,13):
|
for j in range(10, 13):
|
||||||
agent = PatchAgent(self, (i, j), PatchType.divider)
|
agent = PatchAgent(self, (i, j), PatchType.divider)
|
||||||
self.agents.append(agent)
|
self.agents.append(agent)
|
||||||
self.grid.place_agent(agent, (i, j))
|
self.grid.place_agent(agent, (i, j))
|
||||||
@ -146,41 +164,138 @@ class GameModel(Model):
|
|||||||
self.agents.append(agent)
|
self.agents.append(agent)
|
||||||
self.grid.place_agent(agent, p)
|
self.grid.place_agent(agent, p)
|
||||||
|
|
||||||
def place_packing_stations(self, packing_stations: List[tuple[PatchType, GridLocation]]):
|
def place_packing_stations(self, packing_stations: List[Tuple[PatchType, GridLocation]]):
|
||||||
for p in packing_stations:
|
for p in packing_stations:
|
||||||
agent = PatchAgent(self, p[1], p[0])
|
agent = PatchAgent(self, p[1], p[0])
|
||||||
self.agents.append(agent)
|
self.agents.append(agent)
|
||||||
self.grid.place_agent(agent, p[1])
|
self.grid.place_agent(agent, p[1])
|
||||||
|
|
||||||
|
def place_order_items_display(self, item_positions: List[GridLocation]):
|
||||||
|
for p in item_positions:
|
||||||
|
agent = ItemDisplayAgent(self, p)
|
||||||
|
self.item_display_agents.append(agent)
|
||||||
|
self.grid.place_agent(agent, p)
|
||||||
|
|
||||||
|
def update_item_display(self):
|
||||||
|
self.current_item = self.forklift_agent.current_item
|
||||||
|
for i in range(4):
|
||||||
|
self.item_display_agents[i].image = None
|
||||||
|
if len(self.forklift_agent.current_order_delivered_items) > i:
|
||||||
|
self.item_display_agents[i].image = self.forklift_agent.current_order_delivered_items[i].image
|
||||||
|
|
||||||
def step(self):
|
def step(self):
|
||||||
self.schedule.step()
|
self.schedule.step()
|
||||||
self.grid.remove_agent(self.forklift_agent)
|
self.grid.remove_agent(self.forklift_agent)
|
||||||
self.grid.place_agent(self.forklift_agent, self.forklift_agent.current_position)
|
self.grid.place_agent(self.forklift_agent, self.forklift_agent.current_position)
|
||||||
|
self.update_item_display()
|
||||||
|
|
||||||
if self.phase == Phase.ITEM_RECOGNITION:
|
if self.phase == Phase.ITEM_RECOGNITION:
|
||||||
if not self.item_recognised and self.forklift_agent.current_position == self.drop_off.location:
|
if not self.item_recognised and self.forklift_agent.current_position == self.drop_off.location:
|
||||||
|
|
||||||
if len(self.provided_items) == 0:
|
if len(self.items_for_recognization) == 0:
|
||||||
print("FINISHED ITEM RECOGNITION")
|
print("FINISHED ITEM RECOGNITION")
|
||||||
self.item_recognised = True
|
self.item_recognised = True
|
||||||
self.phase = Phase.CLIENT_SORTING
|
self.phase = Phase.CLIENT_SORTING
|
||||||
|
self.forklift_agent.ready_for_execution = True
|
||||||
else:
|
else:
|
||||||
print("BEGIN ITEM RECOGNITION, left: {}".format(len(self.provided_items)))
|
print("BEGIN ITEM RECOGNITION, left: {}".format(len(self.items_for_recognization)))
|
||||||
item_to_recognise = self.provided_items.pop()
|
item_to_recognise = self.items_for_recognization.pop()
|
||||||
self.picture_visualization.img = "item_images/door/drzwi1.jpg"
|
self.picture_visualization.img = PathByEnum.get_random_path(item_to_recognise.real_type)
|
||||||
recognised = self.recognise_item(item_to_recognise)
|
recognised = self.recognise_item(item_to_recognise)
|
||||||
self.recognised_items.append(recognised)
|
self.recognised_items.append(recognised)
|
||||||
|
|
||||||
if self.phase == Phase.CLIENT_SORTING:
|
if self.phase == Phase.CLIENT_SORTING:
|
||||||
# TODO GENERICS SORTING
|
orders: [Order] = self.orderList
|
||||||
sorted(self.orderList, key=lambda x: len(x.items))
|
tree: DecisionTree = DecisionTree()
|
||||||
|
|
||||||
|
# CLIENT RECOGNITION
|
||||||
|
orders_with_prio = tree.get_data_good(orders)
|
||||||
|
|
||||||
|
# print("before:" )
|
||||||
|
# for i in range(len(orders_with_prio)):
|
||||||
|
# print("ORDER {}, PRIO: {}".format(orders_with_prio[i].id, orders_with_prio[i].priority))
|
||||||
|
|
||||||
|
# GENERICS SORTING
|
||||||
|
genericOrder: GeneticOrder = GeneticOrder(orders_with_prio)
|
||||||
|
new_orders = genericOrder.get_orders_sorted(orders)
|
||||||
|
|
||||||
|
# print("after:" )
|
||||||
|
# for i in range(len(new_orders)):
|
||||||
|
# print("ORDER {}, PRIO: {}".format(new_orders[i].id, new_orders[i].priority))
|
||||||
|
|
||||||
|
self.orderList = new_orders
|
||||||
|
self.count_recognised_items()
|
||||||
|
|
||||||
|
self.sort_orders()
|
||||||
|
|
||||||
|
self.forklift_agent.orderList = self.orderList
|
||||||
|
|
||||||
print("FINISHED CLIENT ORDER SORTING")
|
print("FINISHED CLIENT ORDER SORTING")
|
||||||
self.phase = Phase.EXECUTION
|
self.phase = Phase.EXECUTION
|
||||||
|
|
||||||
if self.phase == Phase.EXECUTION:
|
if self.phase == Phase.EXECUTION:
|
||||||
print("Execution")
|
self.current_order = self.forklift_agent.current_order
|
||||||
|
pass
|
||||||
|
# print("Execution")
|
||||||
|
|
||||||
|
def sort_orders(self):
|
||||||
|
orders_to_fill: [Order] = []
|
||||||
|
cut_orders: [Order] = []
|
||||||
|
|
||||||
|
for i in range(len(self.orderList)):
|
||||||
|
o: Order = self.orderList[i]
|
||||||
|
refrige = self.count_item_type(o, ItemType.REFRIGERATOR)
|
||||||
|
shelf = self.count_item_type(o, ItemType.SHELF)
|
||||||
|
door = self.count_item_type(o, ItemType.DOOR)
|
||||||
|
|
||||||
|
if self.count_shelf - shelf >= 0 and self.count_refrige - refrige >= 0 and self.count_door - door >= 0:
|
||||||
|
self.count_shelf -= shelf
|
||||||
|
self.count_door -= door
|
||||||
|
self.count_refrige -= refrige
|
||||||
|
orders_to_fill.append(o)
|
||||||
|
else:
|
||||||
|
cut_orders.append(o)
|
||||||
|
|
||||||
|
self.cut_orders = cut_orders
|
||||||
|
self.orderList = orders_to_fill
|
||||||
|
self.forklift_agent.orderList = orders_to_fill
|
||||||
|
|
||||||
|
def count_item_type(self, o: Order, itemType: ItemType) -> int:
|
||||||
|
res = 0
|
||||||
|
for i in range(len(o.items)):
|
||||||
|
it: Item = o.items[i]
|
||||||
|
if it.guessed_type == itemType:
|
||||||
|
res += 1
|
||||||
|
|
||||||
|
return res
|
||||||
|
|
||||||
|
def count_recognised_items(self):
|
||||||
|
count_refrige: int = 0
|
||||||
|
count_door: int = 0
|
||||||
|
count_shelf: int = 0
|
||||||
|
|
||||||
|
for i in range(len(self.recognised_items)):
|
||||||
|
item: Item = self.recognised_items[i]
|
||||||
|
if item.guessed_type == ItemType.DOOR:
|
||||||
|
count_door += 1
|
||||||
|
elif item.guessed_type == ItemType.SHELF:
|
||||||
|
count_shelf += 1
|
||||||
|
else:
|
||||||
|
count_refrige += 1
|
||||||
|
|
||||||
|
self.count_door = count_door
|
||||||
|
self.count_shelf = count_shelf
|
||||||
|
self.count_refrige = count_refrige
|
||||||
|
|
||||||
def recognise_item(self, item: Item):
|
def recognise_item(self, item: Item):
|
||||||
# TODO IMAGE PROCESSING
|
val = image_classification(self.picture_visualization.img, self.classificator)
|
||||||
item.guessed_type = item.real_type
|
print("VAL: {}".format(val))
|
||||||
|
|
||||||
|
if val == ItemType.DOOR:
|
||||||
|
item.guessed_type = ItemType.DOOR
|
||||||
|
elif val == ItemType.REFRIGERATOR:
|
||||||
|
item.guessed_type = ItemType.REFRIGERATOR
|
||||||
|
elif val == ItemType.SHELF:
|
||||||
|
item.guessed_type = ItemType.SHELF
|
||||||
|
|
||||||
return item
|
return item
|
||||||
|
@ -3,14 +3,16 @@ import random
|
|||||||
from data.Item import Item
|
from data.Item import Item
|
||||||
from data.Order import Order
|
from data.Order import Order
|
||||||
from data.enum.ItemType import ItemType
|
from data.enum.ItemType import ItemType
|
||||||
|
from data.enum.Priority import Priority
|
||||||
from util.ClientParamsFactory import ClientParamsFactory
|
from util.ClientParamsFactory import ClientParamsFactory
|
||||||
|
from util.PathByEnum import PathByEnum
|
||||||
|
|
||||||
|
|
||||||
class InitialStateFactory:
|
class InitialStateFactory:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def generate_item_list(output_list_size: int):
|
def generate_item_list(output_list_size: int):
|
||||||
item_list : [Item] = []
|
item_list: [Item] = []
|
||||||
for i in range(output_list_size):
|
for i in range(output_list_size):
|
||||||
item_list.append(InitialStateFactory.__generate_item())
|
item_list.append(InitialStateFactory.__generate_item())
|
||||||
|
|
||||||
@ -24,6 +26,38 @@ class InitialStateFactory:
|
|||||||
|
|
||||||
return order_list
|
return order_list
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def generate_order_list_XD(output_order_list_size: int):
|
||||||
|
order_list: [Order] = []
|
||||||
|
for i in range(output_order_list_size):
|
||||||
|
order_list.append(InitialStateFactory.__generate_order_XD())
|
||||||
|
|
||||||
|
return order_list
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __generate_order_XD() -> Order:
|
||||||
|
order_size = random.randint(1, 4)
|
||||||
|
|
||||||
|
items: [Item] = []
|
||||||
|
for i in range(order_size):
|
||||||
|
items.append(InitialStateFactory.__generate_item())
|
||||||
|
|
||||||
|
time_base = random.randint(8, 20)
|
||||||
|
final_time = time_base * order_size
|
||||||
|
|
||||||
|
client_params = ClientParamsFactory.get_client_params()
|
||||||
|
|
||||||
|
x = random.randint(0, 3)
|
||||||
|
type = Priority.LOW
|
||||||
|
if x == 0:
|
||||||
|
type = Priority.MEDIUM
|
||||||
|
elif x == 1:
|
||||||
|
type = Priority.HIGH
|
||||||
|
|
||||||
|
x = random.randint(20, 300)
|
||||||
|
|
||||||
|
return Order(final_time, items, type, x, client_params)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __generate_order() -> Order:
|
def __generate_order() -> Order:
|
||||||
order_size = random.randint(1, 4)
|
order_size = random.randint(1, 4)
|
||||||
@ -37,11 +71,11 @@ class InitialStateFactory:
|
|||||||
|
|
||||||
client_params = ClientParamsFactory.get_client_params()
|
client_params = ClientParamsFactory.get_client_params()
|
||||||
|
|
||||||
return Order(final_time, items, None, client_params)
|
return Order(final_time, items, Priority.LOW, 0, client_params)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def generate_input_sequence(self, input_sequence_size):
|
def generate_input_sequence(self, input_sequence_size):
|
||||||
sequence : [Item] = []
|
sequence: [Item] = []
|
||||||
for i in range(0, input_sequence_size):
|
for i in range(0, input_sequence_size):
|
||||||
sequence.append(self.__generate_item())
|
sequence.append(self.__generate_item())
|
||||||
|
|
||||||
@ -50,4 +84,6 @@ class InitialStateFactory:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def __generate_item() -> Item:
|
def __generate_item() -> Item:
|
||||||
randomly_picked_type = random.choice(list(ItemType))
|
randomly_picked_type = random.choice(list(ItemType))
|
||||||
return Item(randomly_picked_type)
|
item = Item(randomly_picked_type, PathByEnum.get_random_path(randomly_picked_type))
|
||||||
|
item.guessed_type = item.real_type
|
||||||
|
return item
|
||||||
|
10
ItemDisplayAgent.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
from PatchAgent import PatchAgent
|
||||||
|
from PatchType import PatchType
|
||||||
|
from util.PathDefinitions import GridLocation
|
||||||
|
|
||||||
|
|
||||||
|
class ItemDisplayAgent(PatchAgent):
|
||||||
|
|
||||||
|
def __init__(self, model, location: GridLocation):
|
||||||
|
self.image = None
|
||||||
|
super().__init__(model, location, patch_type=PatchType.itemDisplay)
|
@ -7,7 +7,8 @@ class PatchType(enum.Enum):
|
|||||||
item = 3
|
item = 3
|
||||||
wall = 4
|
wall = 4
|
||||||
diffTerrain = 5
|
diffTerrain = 5
|
||||||
packingA = 6
|
packingShelf = 6
|
||||||
packingB = 7
|
packingRefrigerator = 7
|
||||||
packingC = 8
|
packingDoor = 8
|
||||||
divider = 9
|
divider = 9
|
||||||
|
itemDisplay = 10
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
|
from data.Item import Item
|
||||||
|
from data.Order import Order
|
||||||
from data.enum.ItemType import ItemType
|
from data.enum.ItemType import ItemType
|
||||||
from util.PathDefinitions import GridLocation
|
from util.PathDefinitions import GridLocation
|
||||||
|
|
||||||
@ -9,16 +11,10 @@ class GameConstants:
|
|||||||
self,
|
self,
|
||||||
grid_width: int,
|
grid_width: int,
|
||||||
grid_height: int,
|
grid_height: int,
|
||||||
# delivery_pos: GridLocation,
|
|
||||||
# order_pos: GridLocation,
|
|
||||||
# special_positions: Dict[ItemType, GridLocation],
|
|
||||||
walls: [GridLocation],
|
walls: [GridLocation],
|
||||||
diffTerrain: [GridLocation]
|
diffTerrain: [GridLocation]
|
||||||
):
|
):
|
||||||
self.grid_width = grid_width
|
self.grid_width = grid_width
|
||||||
self.grid_height = grid_height
|
self.grid_height = grid_height
|
||||||
# self.delivery_pos = delivery_pos
|
|
||||||
# self.order_pos = order_pos
|
|
||||||
# self.special_positions = special_positions
|
|
||||||
self.walls = walls
|
self.walls = walls
|
||||||
self.diffTerrain = diffTerrain
|
self.diffTerrain = diffTerrain
|
||||||
|
@ -6,9 +6,10 @@ from data.enum.ItemType import ItemType
|
|||||||
class Item:
|
class Item:
|
||||||
id_counter = count(start=0)
|
id_counter = count(start=0)
|
||||||
|
|
||||||
def __init__(self, item_type: ItemType):
|
def __init__(self, item_type: ItemType, image):
|
||||||
self.id = next(self.id_counter)
|
self.id = next(self.id_counter)
|
||||||
self.real_type = item_type
|
self.real_type = item_type
|
||||||
|
self.image = image
|
||||||
self.guessed_type = None
|
self.guessed_type = None
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
|
@ -9,12 +9,18 @@ from data.enum.Priority import Priority
|
|||||||
class Order:
|
class Order:
|
||||||
id_counter = count(start=0)
|
id_counter = count(start=0)
|
||||||
|
|
||||||
def __init__(self, time: int, items: [Item], priority: Priority, client_params: ClientParams):
|
def __init__(self, time: int, items: [Item], priority: Priority, sum: int, client_params: ClientParams):
|
||||||
self.id = next(self.id_counter)
|
self.id = next(self.id_counter)
|
||||||
self.time = time
|
self.time = time
|
||||||
self.items: List[Item] = items
|
self.items: List[Item] = items
|
||||||
self.client_params = client_params
|
self.client_params = client_params
|
||||||
self.priority = priority
|
self.priority = priority
|
||||||
|
self.sum = sum
|
||||||
|
|
||||||
|
# def sum_items(self, items: [Item]):
|
||||||
|
# result = 0
|
||||||
|
# for i in range(len(items)):
|
||||||
|
# result += items[i]
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return "items: {} priority: {}".format(self.items, self.priority)
|
return "items: {} priority: {}".format(self.items, self.priority)
|
||||||
|
7
data/enum/GeneticMutationType.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
|
||||||
|
class GeneticMutationType(Enum):
|
||||||
|
MUTATION = 1
|
||||||
|
CROSS = 2
|
||||||
|
REVERSE = 3
|
@ -2,6 +2,6 @@ from enum import Enum
|
|||||||
|
|
||||||
|
|
||||||
class ItemType(Enum):
|
class ItemType(Enum):
|
||||||
DOOR = 1
|
DOOR = "door"
|
||||||
SHELF = 2
|
SHELF = "shelf"
|
||||||
EGG = 3
|
REFRIGERATOR = "refrigerator"
|
@ -1,6 +1,7 @@
|
|||||||
from data.enum.Direction import Direction
|
from data.enum.Direction import Direction
|
||||||
from data.Item import Item
|
from data.Item import Item
|
||||||
from data.Order import Order
|
from data.Order import Order
|
||||||
|
from data.enum.Priority import Priority
|
||||||
from decision.ActionType import ActionType
|
from decision.ActionType import ActionType
|
||||||
from util.PathDefinitions import GridLocation
|
from util.PathDefinitions import GridLocation
|
||||||
|
|
||||||
@ -10,7 +11,7 @@ class State:
|
|||||||
action_taken: ActionType,
|
action_taken: ActionType,
|
||||||
forklift_position: GridLocation,
|
forklift_position: GridLocation,
|
||||||
forklift_rotation: Direction,
|
forklift_rotation: Direction,
|
||||||
pending_orders: [Order],
|
pending_orders: [Priority, [Order]],
|
||||||
filled_orders: [Order],
|
filled_orders: [Order],
|
||||||
input_items: [Item]
|
input_items: [Item]
|
||||||
):
|
):
|
||||||
|
9
decision/test/ForkliftActions.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from data.GameConstants import GameConstants
|
||||||
|
|
||||||
|
|
||||||
|
class ForkliftActions:
|
||||||
|
|
||||||
|
def __init__(self, game: GameConstants,
|
||||||
|
) -> None:
|
||||||
|
self.game = game
|
||||||
|
|
218
genetic_order/GeneticOrder.py
Normal file
@ -0,0 +1,218 @@
|
|||||||
|
import itertools
|
||||||
|
import random
|
||||||
|
|
||||||
|
from data.Order import Order
|
||||||
|
from data.enum.GeneticMutationType import GeneticMutationType
|
||||||
|
from data.enum.Priority import Priority
|
||||||
|
|
||||||
|
|
||||||
|
class GeneticOrder:
|
||||||
|
mutation_chance = 10
|
||||||
|
reverse_chance = 60
|
||||||
|
cross_chance = 5
|
||||||
|
|
||||||
|
best_fit_special = 50
|
||||||
|
best_fit_super_special = 20
|
||||||
|
|
||||||
|
population_size = 200
|
||||||
|
number_of_populations = 1000
|
||||||
|
|
||||||
|
punish_low = 500
|
||||||
|
punish_med = 300
|
||||||
|
|
||||||
|
punish_sum = 50
|
||||||
|
|
||||||
|
def __init__(self, orders: [Order]) -> None:
|
||||||
|
self.orders = orders
|
||||||
|
|
||||||
|
def get_mutation_type(self) -> GeneticMutationType:
|
||||||
|
x = random.randint(0, self.mutation_chance + self.cross_chance + self.reverse_chance)
|
||||||
|
|
||||||
|
if x < self.mutation_chance:
|
||||||
|
return GeneticMutationType.MUTATION
|
||||||
|
|
||||||
|
if x > self.mutation_chance + self.cross_chance:
|
||||||
|
return GeneticMutationType.REVERSE
|
||||||
|
|
||||||
|
return GeneticMutationType.CROSS
|
||||||
|
|
||||||
|
def mutation(self, population: [int]) -> [int]:
|
||||||
|
x = random.randint(0, len(population) - 1)
|
||||||
|
y = random.randint(0, len(population) - 1)
|
||||||
|
while x == y:
|
||||||
|
y = random.randint(0, len(population) - 1)
|
||||||
|
|
||||||
|
result = population
|
||||||
|
|
||||||
|
pom = population[x]
|
||||||
|
result[x] = population[y]
|
||||||
|
result[y] = pom
|
||||||
|
|
||||||
|
if (result[x] == result[y]):
|
||||||
|
print("PIZDA I CHUJ")
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def cross(self, population: [int]) -> [int]:
|
||||||
|
x = random.randint(1, len(population) - 1)
|
||||||
|
|
||||||
|
result = []
|
||||||
|
|
||||||
|
for i in range(len(population)):
|
||||||
|
result.append(population[(i + x) % len(population)])
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def reverse(self, population: [int]) -> [int]:
|
||||||
|
x = random.randint(0, len(population))
|
||||||
|
y = random.randint(0, len(population) - 1)
|
||||||
|
while y - x > 2 or x >= y:
|
||||||
|
x = random.randint(0, len(population))
|
||||||
|
y = random.randint(0, len(population) - 1)
|
||||||
|
|
||||||
|
result = []
|
||||||
|
# print("X: ", x, " y: ", y)
|
||||||
|
|
||||||
|
for i in range(len(population)):
|
||||||
|
if x <= i <= y:
|
||||||
|
new_i = i - x
|
||||||
|
# print("len:", len(population), " new_i: ", new_i)
|
||||||
|
result.append(population[y - new_i])
|
||||||
|
else:
|
||||||
|
result.append(population[i])
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def generate_first_population(self, k: int) -> [[int]]:
|
||||||
|
result = []
|
||||||
|
|
||||||
|
s = range(len(self.orders))
|
||||||
|
p = itertools.permutations(s)
|
||||||
|
while len(result) < k:
|
||||||
|
n = p.__next__()
|
||||||
|
if n not in result:
|
||||||
|
result.append(n)
|
||||||
|
|
||||||
|
return [list(x) for x in result]
|
||||||
|
|
||||||
|
# result = itertools.permutations(range(len(self.orders)))
|
||||||
|
#
|
||||||
|
# return [list(x) for x in result]
|
||||||
|
|
||||||
|
def correct_sum(self, last_prio: Priority, last_sum: float, o: Order) -> bool:
|
||||||
|
if o.priority == last_prio:
|
||||||
|
return last_sum > o.sum / o.time
|
||||||
|
return True
|
||||||
|
|
||||||
|
def sum_wrong(self, member: [int]) -> int:
|
||||||
|
last_high = 0
|
||||||
|
last_med = 0
|
||||||
|
last_prio = Priority.HIGH
|
||||||
|
last_sum = 0
|
||||||
|
counter = 0
|
||||||
|
|
||||||
|
for i in range(len(member)):
|
||||||
|
o: Order = self.orders[member[i]]
|
||||||
|
if o.priority == Priority.HIGH:
|
||||||
|
last_high = i
|
||||||
|
elif o.priority == Priority.MEDIUM:
|
||||||
|
last_med = i
|
||||||
|
|
||||||
|
if not self.correct_sum(last_prio, last_sum, o):
|
||||||
|
counter += int(last_sum - (o.sum / o.time))
|
||||||
|
last_prio = o.priority
|
||||||
|
last_sum = o.sum / o.time
|
||||||
|
|
||||||
|
for i in range(last_high):
|
||||||
|
o: Order = self.orders[member[i]]
|
||||||
|
if o.priority == Priority.MEDIUM:
|
||||||
|
counter += self.punish_med
|
||||||
|
elif o.priority == Priority.LOW:
|
||||||
|
counter += self.punish_low
|
||||||
|
|
||||||
|
for i in range(last_med):
|
||||||
|
o: Order = self.orders[member[i]]
|
||||||
|
if o.priority == Priority.LOW:
|
||||||
|
counter += self.punish_low
|
||||||
|
|
||||||
|
return counter
|
||||||
|
|
||||||
|
def evaluate(self, member: [int]) -> int:
|
||||||
|
# result = 0
|
||||||
|
# for i in range(len(self.orders) - 1):
|
||||||
|
# x: Order = self.orders[member[i]]
|
||||||
|
# y: Order = self.orders[member[i + 1]]
|
||||||
|
#
|
||||||
|
# if ((x.priority == Priority.MEDIUM or x.priority == Priority.LOW) and y.priority == Priority.HIGH) or (x.priority == Priority.LOW and y.priority == Priority.MEDIUM):
|
||||||
|
# result += 30
|
||||||
|
#
|
||||||
|
# if x.sum / x.time < y.sum / y.time:
|
||||||
|
# result += int(y.sum / y.time)
|
||||||
|
|
||||||
|
# return result
|
||||||
|
|
||||||
|
return self.sum_wrong(member)
|
||||||
|
|
||||||
|
def mutate_population(self, order_population: [[int]]) -> [[int]]:
|
||||||
|
result = []
|
||||||
|
|
||||||
|
for i in range(len(order_population)):
|
||||||
|
member: [int] = order_population[i]
|
||||||
|
operation: GeneticMutationType = self.get_mutation_type()
|
||||||
|
|
||||||
|
if operation == GeneticMutationType.MUTATION:
|
||||||
|
member = self.mutation(member)
|
||||||
|
elif operation == GeneticMutationType.REVERSE:
|
||||||
|
member = self.reverse(member)
|
||||||
|
else:
|
||||||
|
member = self.cross(member)
|
||||||
|
|
||||||
|
result.append(member)
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def get_next_population(self, population: [[int]]) -> [[int]]:
|
||||||
|
result = []
|
||||||
|
|
||||||
|
for i in range(len(population) - self.best_fit_special - self.best_fit_super_special):
|
||||||
|
result.append(population[i])
|
||||||
|
|
||||||
|
for i in range(self.best_fit_special):
|
||||||
|
x = random.randint(0, self.best_fit_special)
|
||||||
|
result.append(population[x])
|
||||||
|
|
||||||
|
for i in range(self.best_fit_super_special):
|
||||||
|
x = random.randint(0, self.best_fit_super_special)
|
||||||
|
result.append(population[x])
|
||||||
|
|
||||||
|
return result
|
||||||
|
|
||||||
|
def get_orders_sorted(self, orders: [Order]) -> [Order]:
|
||||||
|
self.orders = orders
|
||||||
|
|
||||||
|
population: [[int]] = self.generate_first_population(self.population_size)
|
||||||
|
# print(population)
|
||||||
|
|
||||||
|
population.sort(key=self.evaluate)
|
||||||
|
best_fit: [int] = population[0]
|
||||||
|
|
||||||
|
for i in range(self.number_of_populations):
|
||||||
|
# print("population: ", i)
|
||||||
|
population = self.mutate_population(population)
|
||||||
|
population.sort(key=self.evaluate)
|
||||||
|
|
||||||
|
if self.evaluate(best_fit) > self.evaluate(population[0]):
|
||||||
|
best_fit = population[0]
|
||||||
|
|
||||||
|
# population = self.get_next_population(population).sort(key=self.evaluate)
|
||||||
|
|
||||||
|
if self.evaluate(best_fit) < self.evaluate(population[0]):
|
||||||
|
population[0] = best_fit
|
||||||
|
|
||||||
|
best: [int] = population[0]
|
||||||
|
result: [Order] = []
|
||||||
|
|
||||||
|
for i in range(len(best)):
|
||||||
|
result.append(self.orders[best[i]])
|
||||||
|
|
||||||
|
return result
|
22
imageClasification/Classificator.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import numpy as np
|
||||||
|
import tensorflow as tf
|
||||||
|
from tensorflow import keras
|
||||||
|
|
||||||
|
|
||||||
|
# loaded_model = keras.models.load_model("my_model")
|
||||||
|
|
||||||
|
def image_classification(path, model):
|
||||||
|
class_names = ['door', 'refrigerator', 'shelf']
|
||||||
|
|
||||||
|
img = tf.keras.utils.load_img(
|
||||||
|
path, target_size=(180, 180)
|
||||||
|
)
|
||||||
|
img_array = tf.keras.utils.img_to_array(img)
|
||||||
|
img_array = tf.expand_dims(img_array, 0) # Create a batch
|
||||||
|
|
||||||
|
predictions = model.predict(img_array)
|
||||||
|
score = tf.nn.softmax(predictions[0])
|
||||||
|
# print(class_names[np.argmax(score)])
|
||||||
|
return class_names[np.argmax(score)]
|
||||||
|
|
||||||
|
|
BIN
imageClasification/Images/door/02f51f018a (1).jpg
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
imageClasification/Images/door/02f51f018a (10).jpg
Normal file
After Width: | Height: | Size: 8.6 KiB |
BIN
imageClasification/Images/door/02f51f018a (100).jpg
Normal file
After Width: | Height: | Size: 7.4 KiB |
BIN
imageClasification/Images/door/02f51f018a (101).jpg
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
imageClasification/Images/door/02f51f018a (102).jpg
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
imageClasification/Images/door/02f51f018a (103).jpg
Normal file
After Width: | Height: | Size: 9.8 KiB |
BIN
imageClasification/Images/door/02f51f018a (104).jpg
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
imageClasification/Images/door/02f51f018a (105).jpg
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
imageClasification/Images/door/02f51f018a (106).jpg
Normal file
After Width: | Height: | Size: 9.3 KiB |
BIN
imageClasification/Images/door/02f51f018a (107).jpg
Normal file
After Width: | Height: | Size: 1.9 KiB |
BIN
imageClasification/Images/door/02f51f018a (108).jpg
Normal file
After Width: | Height: | Size: 3.2 KiB |
BIN
imageClasification/Images/door/02f51f018a (109).jpg
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
imageClasification/Images/door/02f51f018a (11).jpg
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
imageClasification/Images/door/02f51f018a (110).jpg
Normal file
After Width: | Height: | Size: 3.7 KiB |
BIN
imageClasification/Images/door/02f51f018a (111).jpg
Normal file
After Width: | Height: | Size: 2.8 KiB |
BIN
imageClasification/Images/door/02f51f018a (112).jpg
Normal file
After Width: | Height: | Size: 6.5 KiB |
BIN
imageClasification/Images/door/02f51f018a (12).jpg
Normal file
After Width: | Height: | Size: 3.6 KiB |
BIN
imageClasification/Images/door/02f51f018a (13).jpg
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
imageClasification/Images/door/02f51f018a (14).jpg
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
imageClasification/Images/door/02f51f018a (15).jpg
Normal file
After Width: | Height: | Size: 7.5 KiB |
BIN
imageClasification/Images/door/02f51f018a (16).jpg
Normal file
After Width: | Height: | Size: 3.4 KiB |
BIN
imageClasification/Images/door/02f51f018a (17).jpg
Normal file
After Width: | Height: | Size: 7.1 KiB |
BIN
imageClasification/Images/door/02f51f018a (18).jpg
Normal file
After Width: | Height: | Size: 4.1 KiB |
BIN
imageClasification/Images/door/02f51f018a (19).jpg
Normal file
After Width: | Height: | Size: 4.9 KiB |
BIN
imageClasification/Images/door/02f51f018a (2).jpg
Normal file
After Width: | Height: | Size: 9.2 KiB |
BIN
imageClasification/Images/door/02f51f018a (20).jpg
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
imageClasification/Images/door/02f51f018a (21).jpg
Normal file
After Width: | Height: | Size: 8.6 KiB |
BIN
imageClasification/Images/door/02f51f018a (22).jpg
Normal file
After Width: | Height: | Size: 3.6 KiB |
BIN
imageClasification/Images/door/02f51f018a (23).jpg
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
imageClasification/Images/door/02f51f018a (24).jpg
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
imageClasification/Images/door/02f51f018a (25).jpg
Normal file
After Width: | Height: | Size: 8.4 KiB |
BIN
imageClasification/Images/door/02f51f018a (26).jpg
Normal file
After Width: | Height: | Size: 3.7 KiB |
BIN
imageClasification/Images/door/02f51f018a (27).jpg
Normal file
After Width: | Height: | Size: 6.0 KiB |
BIN
imageClasification/Images/door/02f51f018a (28).jpg
Normal file
After Width: | Height: | Size: 7.0 KiB |
BIN
imageClasification/Images/door/02f51f018a (29).jpg
Normal file
After Width: | Height: | Size: 1.2 KiB |
BIN
imageClasification/Images/door/02f51f018a (3).jpg
Normal file
After Width: | Height: | Size: 6.9 KiB |
BIN
imageClasification/Images/door/02f51f018a (30).jpg
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
imageClasification/Images/door/02f51f018a (31).jpg
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
imageClasification/Images/door/02f51f018a (32).jpg
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
imageClasification/Images/door/02f51f018a (33).jpg
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
imageClasification/Images/door/02f51f018a (34).jpg
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
imageClasification/Images/door/02f51f018a (35).jpg
Normal file
After Width: | Height: | Size: 2.7 KiB |
BIN
imageClasification/Images/door/02f51f018a (36).jpg
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
imageClasification/Images/door/02f51f018a (37).jpg
Normal file
After Width: | Height: | Size: 2.6 KiB |
BIN
imageClasification/Images/door/02f51f018a (38).jpg
Normal file
After Width: | Height: | Size: 7.9 KiB |
BIN
imageClasification/Images/door/02f51f018a (39).jpg
Normal file
After Width: | Height: | Size: 12 KiB |
BIN
imageClasification/Images/door/02f51f018a (4).jpg
Normal file
After Width: | Height: | Size: 4.5 KiB |
BIN
imageClasification/Images/door/02f51f018a (40).jpg
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
imageClasification/Images/door/02f51f018a (41).jpg
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
imageClasification/Images/door/02f51f018a (42).jpg
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
imageClasification/Images/door/02f51f018a (43).jpg
Normal file
After Width: | Height: | Size: 3.3 KiB |
BIN
imageClasification/Images/door/02f51f018a (44).jpg
Normal file
After Width: | Height: | Size: 1.5 KiB |
BIN
imageClasification/Images/door/02f51f018a (45).jpg
Normal file
After Width: | Height: | Size: 7.8 KiB |
BIN
imageClasification/Images/door/02f51f018a (46).jpg
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
imageClasification/Images/door/02f51f018a (47).jpg
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
imageClasification/Images/door/02f51f018a (48).jpg
Normal file
After Width: | Height: | Size: 5.8 KiB |
BIN
imageClasification/Images/door/02f51f018a (49).jpg
Normal file
After Width: | Height: | Size: 8.4 KiB |
BIN
imageClasification/Images/door/02f51f018a (5).jpg
Normal file
After Width: | Height: | Size: 6.4 KiB |
BIN
imageClasification/Images/door/02f51f018a (50).jpg
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
imageClasification/Images/door/02f51f018a (51).jpg
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
imageClasification/Images/door/02f51f018a (52).jpg
Normal file
After Width: | Height: | Size: 6.0 KiB |
BIN
imageClasification/Images/door/02f51f018a (53).jpg
Normal file
After Width: | Height: | Size: 5.5 KiB |
BIN
imageClasification/Images/door/02f51f018a (54).jpg
Normal file
After Width: | Height: | Size: 7.1 KiB |
BIN
imageClasification/Images/door/02f51f018a (55).jpg
Normal file
After Width: | Height: | Size: 5.8 KiB |
BIN
imageClasification/Images/door/02f51f018a (56).jpg
Normal file
After Width: | Height: | Size: 6.7 KiB |
BIN
imageClasification/Images/door/02f51f018a (57).jpg
Normal file
After Width: | Height: | Size: 5.9 KiB |
BIN
imageClasification/Images/door/02f51f018a (58).jpg
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
imageClasification/Images/door/02f51f018a (59).jpg
Normal file
After Width: | Height: | Size: 6.8 KiB |
BIN
imageClasification/Images/door/02f51f018a (6).jpg
Normal file
After Width: | Height: | Size: 4.2 KiB |
BIN
imageClasification/Images/door/02f51f018a (60).jpg
Normal file
After Width: | Height: | Size: 5.7 KiB |
BIN
imageClasification/Images/door/02f51f018a (61).jpg
Normal file
After Width: | Height: | Size: 4.3 KiB |
BIN
imageClasification/Images/door/02f51f018a (62).jpg
Normal file
After Width: | Height: | Size: 8.3 KiB |
BIN
imageClasification/Images/door/02f51f018a (63).jpg
Normal file
After Width: | Height: | Size: 5.6 KiB |
BIN
imageClasification/Images/door/02f51f018a (64).jpg
Normal file
After Width: | Height: | Size: 5.8 KiB |
BIN
imageClasification/Images/door/02f51f018a (65).jpg
Normal file
After Width: | Height: | Size: 3.7 KiB |
BIN
imageClasification/Images/door/02f51f018a (66).jpg
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
imageClasification/Images/door/02f51f018a (67).jpg
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
imageClasification/Images/door/02f51f018a (68).jpg
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
imageClasification/Images/door/02f51f018a (69).jpg
Normal file
After Width: | Height: | Size: 5.4 KiB |
BIN
imageClasification/Images/door/02f51f018a (7).jpg
Normal file
After Width: | Height: | Size: 3.0 KiB |
BIN
imageClasification/Images/door/02f51f018a (70).jpg
Normal file
After Width: | Height: | Size: 8.5 KiB |
BIN
imageClasification/Images/door/02f51f018a (71).jpg
Normal file
After Width: | Height: | Size: 4.7 KiB |
BIN
imageClasification/Images/door/02f51f018a (72).jpg
Normal file
After Width: | Height: | Size: 9.8 KiB |
BIN
imageClasification/Images/door/02f51f018a (73).jpg
Normal file
After Width: | Height: | Size: 6.9 KiB |
BIN
imageClasification/Images/door/02f51f018a (74).jpg
Normal file
After Width: | Height: | Size: 9.1 KiB |
BIN
imageClasification/Images/door/02f51f018a (75).jpg
Normal file
After Width: | Height: | Size: 7.6 KiB |