From 11f73635d638c33a7d92e3ce58e90fa358f536a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksander=20Szama=C5=82ek?= Date: Sat, 16 Apr 2022 14:55:25 +0200 Subject: [PATCH] agents structure improvements --- AgentBase.py | 14 ++++++++ ForkliftAgent.py | 12 ++++--- GameModel.py | 52 ++++++++++++++++++------------ Generator.py | 43 ++++++++++++++++++++++++ PatchAgent.py | 13 +++++--- PatchType.py | 3 +- data/Game.py | 2 +- data/Item.py | 18 ++++++++--- data/{CATEGORY.py => ItemType.py} | 2 +- data/JOB.py | 7 ---- data/Order.py | 15 ++++++--- data/StockPile.py | 6 ++-- img/brick.webp | Bin 0 -> 11730 bytes main.py | 8 +++-- test/nastepnik.py | 5 +-- util/AgentIdFactory.py | 9 ++++++ util/TWOJSTARY.py | 27 ++++++++++++++++ 17 files changed, 179 insertions(+), 57 deletions(-) create mode 100644 AgentBase.py create mode 100644 Generator.py rename data/{CATEGORY.py => ItemType.py} (63%) delete mode 100644 data/JOB.py create mode 100644 img/brick.webp create mode 100644 util/AgentIdFactory.py create mode 100644 util/TWOJSTARY.py diff --git a/AgentBase.py b/AgentBase.py new file mode 100644 index 0000000..e949bc8 --- /dev/null +++ b/AgentBase.py @@ -0,0 +1,14 @@ +from mesa import Agent, Model + +from util.AgentIdFactory import AgentIdFactory + + +class AgentBase(Agent): + + def __init__(self, model: Model): + unique_id = AgentIdFactory.get_next_id() + super().__init__(unique_id, model) + self.creation_log() + + def creation_log(self): + pass diff --git a/ForkliftAgent.py b/ForkliftAgent.py index f884155..cee713c 100644 --- a/ForkliftAgent.py +++ b/ForkliftAgent.py @@ -2,17 +2,18 @@ from typing import Tuple from mesa import Agent +from AgentBase import AgentBase from data.Direction import Direction +from util.AgentIdFactory import AgentIdFactory -class ForkliftAgent(Agent): +class ForkliftAgent(AgentBase): - def __init__(self, unique_id, model): - super().__init__(unique_id, model) + def __init__(self, model): + super().__init__(model) self.movement_queue = [Tuple[int, int]] self.current_position = Tuple[int, int] self.current_rotation = Direction.right - print("Created forklift Agent with ID: {}".format(unique_id)) def assign_new_movement_task(self, movement_list): self.movement_queue = [] @@ -52,3 +53,6 @@ class ForkliftAgent(Agent): def step(self) -> None: print("forklift step") self.move() + + def creation_log(self): + print("Created Forklift Agent [id: {}]".format(self.unique_id)) diff --git a/GameModel.py b/GameModel.py index fbc983f..f1574e9 100644 --- a/GameModel.py +++ b/GameModel.py @@ -1,25 +1,28 @@ -from mesa import Model +from typing import List + +from mesa import Model, Agent from mesa.space import MultiGrid from mesa.time import RandomActivation +from AgentBase import AgentBase from ForkliftAgent import ForkliftAgent from PatchAgent import PatchAgent from PatchType import PatchType -from util.PathDefinitions import inverse_y +from util.PathDefinitions import inverse_y, GridLocation, GridWithWeights from util.PathVisualiser import draw_grid, reconstruct_path from util.Pathfinder import a_star_search class GameModel(Model): - def __init__(self, width, height, graph): + def __init__(self, width, height, graph: GridWithWeights): # self.num_agents = 5 self.running = True self.grid = MultiGrid(height, width, True) self.schedule = RandomActivation(self) - self.agents = [] + self.agents = [AgentBase] - self.forklift_agent = ForkliftAgent(0, self) + self.forklift_agent = ForkliftAgent(self) self.schedule.add(self.forklift_agent) self.agents.append(self.forklift_agent) @@ -29,34 +32,43 @@ class GameModel(Model): self.grid.place_agent(self.forklift_agent, (x, y)) self.forklift_agent.current_position = (x, y) - start, goal = (x, y), (2, 1) - came_from, cost_so_far = a_star_search(graph, start, goal) - draw_grid(graph, point_to=came_from, start=start, goal=goal) + # start, goal = (x, y), (2, 1) + # came_from, cost_so_far = a_star_search(graph, start, goal) + # draw_grid(graph, point_to=came_from, start=start, goal=goal) + # + # path = map(lambda t: (t[0], inverse_y(height, t[1])), + # reconstruct_path(came_from=came_from, start=start, goal=goal)) + # + # print("cam from: {}".format(came_from)) + # print("costerino: {}".format(cost_so_far)) + # draw_grid(graph, path=reconstruct_path(came_from, start=start, goal=goal)) + # self.forklift_agent.assign_new_movement_task(path) - path = map(lambda t: (t[0], inverse_y(height, t[1])), - reconstruct_path(came_from=came_from, start=start, goal=goal)) + self.place_patch_agents() + self.place_walls_agents(graph.walls) - print("cam from: {}".format(came_from)) - print("costerino: {}".format(cost_so_far)) - draw_grid(graph, path=reconstruct_path(came_from, start=start, goal=goal)) - - self.forklift_agent.assign_new_movement_task(path) - - agent = PatchAgent(1, self, PatchType.pickUp) - # self.schedule.add(agent) + def place_patch_agents(self): + agent = PatchAgent(self, PatchType.pickUp) + self.schedule.add(agent) self.grid.place_agent(agent, (self.grid.width - 1, self.grid.height - 1)) self.agents.append(agent) - agent = PatchAgent(2, self, PatchType.dropOff) + agent = PatchAgent(self, PatchType.dropOff) # self.schedule.add(agent) self.grid.place_agent(agent, (0, self.grid.height - 1)) self.agents.append(agent) for i in range(3): - a = PatchAgent(i + 3, self, PatchType.item) + a = PatchAgent(self, PatchType.item) self.agents.append(a) self.grid.place_agent(a, (i, 0)) + def place_walls_agents(self, walls: List[GridLocation]): + for w in walls: + agent = PatchAgent(self, PatchType.wall) + self.agents.append(agent) + self.grid.place_agent(agent, w) + def step(self): self.schedule.step() diff --git a/Generator.py b/Generator.py new file mode 100644 index 0000000..a05e805 --- /dev/null +++ b/Generator.py @@ -0,0 +1,43 @@ +import random +from data.Item import Item +from data.ItemType import ItemType +from data.Order import Order + + +class Generator: + def __init__(self, input_sequence_size: int, output_order_list_size: int): + self.input_sequence = self.generate_input_sequence(input_sequence_size) + self.output_order_list = self.generate_order_list(output_order_list_size) + + def generate_order_list(self, output_order_list_size: int): + order_list = [Order] + for i in range(0, output_order_list_size): + order_list.append(self.generate_order()) + + return order_list + + def generate_order(self) -> Order: + order_size = random.randint(1, 4) + + items = [Item] + for i in range(order_size): + items.append(self.generate_item()) + + time_base = random.randint(8, 20) + final_time = time_base * order_size + + value = sum(i.price for i in items) + + return Order(final_time, items, value) + + def generate_input_sequence(self, input_sequence_size): + sequence = [Item] + for i in range(0, input_sequence_size): + sequence.append(self.generate_item()) + + return sequence + + @staticmethod + def generate_item() -> Item: + randomly_picked_type = random.choice(list(ItemType)) + return Item(randomly_picked_type) diff --git a/PatchAgent.py b/PatchAgent.py index 4ebee70..174461d 100644 --- a/PatchAgent.py +++ b/PatchAgent.py @@ -1,11 +1,14 @@ from mesa import Agent, Model +from AgentBase import AgentBase from PatchType import PatchType -class PatchAgent(Agent): +class PatchAgent(AgentBase): - def __init__(self, unique_id, model, type: PatchType): - super().__init__(unique_id, model) - self.type = type - print("Created Patch Agent with ID: {}".format(unique_id)) \ No newline at end of file + def __init__(self, model, patch_type: PatchType): + self.patch_type = patch_type + super().__init__(model) + + def creation_log(self): + print("Created Patch Agent [id: {} ,type: {}]".format(self.unique_id, self.patch_type)) diff --git a/PatchType.py b/PatchType.py index 49f3bad..3b1bf71 100644 --- a/PatchType.py +++ b/PatchType.py @@ -4,4 +4,5 @@ import enum class PatchType(enum.Enum): dropOff = 1 pickUp = 2 - item = 3 \ No newline at end of file + item = 3 + wall = 4 diff --git a/data/Game.py b/data/Game.py index 502dfd2..92de383 100644 --- a/data/Game.py +++ b/data/Game.py @@ -1,5 +1,5 @@ from data import Direction -from data.CATEGORY import CATEGORY +from data.ItemType import ItemType from data.Item import Item from data.Order import Order from typing import Dict diff --git a/data/Item.py b/data/Item.py index 958f577..9851805 100644 --- a/data/Item.py +++ b/data/Item.py @@ -1,8 +1,16 @@ -from data.CATEGORY import CATEGORY +from itertools import count + +from data.ItemType import ItemType class Item: - def __init__(self, id: int, category: CATEGORY, price: int): - self.id = id - self.category = category - self.price = price \ No newline at end of file + id_counter = count(start=0) + + def __init__(self, type: ItemType): + self.id = next(self.id_counter) + self.category = type + self.price = self.price_factory(type) + + @staticmethod + def price_factory(self, type: ItemType): + return 1 diff --git a/data/CATEGORY.py b/data/ItemType.py similarity index 63% rename from data/CATEGORY.py rename to data/ItemType.py index cf6357d..007b743 100644 --- a/data/CATEGORY.py +++ b/data/ItemType.py @@ -1,7 +1,7 @@ from enum import Enum -class CATEGORY(Enum): +class ItemType(Enum): PIZZA = 1 PASTA = 2 EGG = 3 diff --git a/data/JOB.py b/data/JOB.py deleted file mode 100644 index 3374c0c..0000000 --- a/data/JOB.py +++ /dev/null @@ -1,7 +0,0 @@ -from enum import Enum - - -class JOB(Enum): - FISHERMAN = 1 - FIREFIGHTER = 2 - POLICEMAN = 3 \ No newline at end of file diff --git a/data/Order.py b/data/Order.py index 7407b96..5050cf0 100644 --- a/data/Order.py +++ b/data/Order.py @@ -1,8 +1,13 @@ -from data.JOB import JOB +from itertools import count + +from data.Item import Item class Order: - def __init__(self, id: int, money: int, job: JOB): - self.id = id - self.money = money - self.job = job \ No newline at end of file + id_counter = count(start=0) + + def __init__(self, time: int, items: [Item], value: int): + self.id = next(self.id_counter) + self.time = time + self.items = items + self.value = value diff --git a/data/StockPile.py b/data/StockPile.py index 4581a35..8e6c9db 100644 --- a/data/StockPile.py +++ b/data/StockPile.py @@ -1,9 +1,9 @@ -from data.CATEGORY import CATEGORY +from data.ItemType import ItemType from data.Item import Item class StockPile: - def __init__(self, id: int, category: CATEGORY, itemList: [Item]): + def __init__(self, id: ItemType, pos: (int, int), itemList: [Item], ): self.id = id - self.category = category + self.pos = pos self.itemList = itemList \ No newline at end of file diff --git a/img/brick.webp b/img/brick.webp new file mode 100644 index 0000000000000000000000000000000000000000..e07db6f50dca598a4927f72fdd5679dffab8fc6d GIT binary patch literal 11730 zcmV;@EiKYgNk&G>EdT&lMM6+kP&il$0000G0000h0RSrj06|PpNL~Q|009p${}B-a zc52(U8X*Ool5G8!WC4MxdE9&U!0#lY|7O~@*-k@f5ZvDUALu?m%(ciJ-HnuyB2Wa5 zue%#5BLwOjgnWaM5<;MU!d!lWk(vvE`VCY04Mu7z1nLZCat20fCIspnCUOo&Y9a*c z3ijm+jMTmmsB74jYcNu~LZEhFPjQE+Ehu!2xy?nbM0RmH z=0aepRZTB+$5aR`wLqM>ELG{C;>XoP1eU6rP$A`ND*{VZV5lf_bsB-CsyS5Pxtfo_Qk5Yp z7G3>FV5uq-6`rmZC9qV*ii%iQ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4`V<;}-ao>U(!iz$;E;{?Q)Le#Nj=%@rVzrJ!>L9| z&MI2JN?51=e5_K5;!eVT)gpZw>ce2=N@PI)Gh{Pw7*e2lW}ELw_gKezW_zuE3fL|z zg3gKa9W|7_qdj_f(S>GVC*+~uffpRxjO5#MRsS_p=s!Rbc^e6x^$$(~u7K6!7M?@pA)M zm+pivu++ub%BROrcA*j#tHFm-(ze`&9F#pXn?8mK4~0I0cI@Tu`hqE1vRQI)P7F~n ztnalHaFeAj+X*^%_(<#mIb|lecqHyJ6rG5^hMGE6qrA%F(03tpks?UHcIv_m9PkBo z^pO#hLE>p@9wttoKk|VOlnN|b(;8B<@kWUaJpdnBY#rc|*z~>9i)x=x6$O(sR?r)m zOo4@Rl@wYM`+)s>X{`j{wDjltz|a}NRHDs)LpzufaL+Ul@yTv-1D!Go#pKYR<-GBt zIY53L7mHg4!*qw~$)d!+N?`q=qIP!k1a8?(fb>BixX6II1RHCHm!ZHo5Dk7rS?B*q zRD& zKa01+Pqal|JiRHw9!wynxeVteF(H!*Rk1`;kiw7>cOl`<>+QEeNXLYrRlrp7UT_L& z9yQkG5BOSkTw%kNkGN8Ez4(uT8>Nbbx$)*tDG=`yiXUTu1KIEalPz8cZGyc?@EdcH zX!+XgpLRsvAAV;w7_gd463U*1?R~Fh@x-k0EUbAjfD0%g;Ob(%tWUw`E=fNFq6aK) zDZ+KGO1ipp#NVR(-~cn7jVk;wEV?6 zE4L-HqB?hf(!rw(fnzA3^qEE~NRAq0QHF7lQRq>jqUHb`x5&h@44b{2cr(o?7tH0_ zrU;=fGtcXog~vbu02he`BrE^?EsO7;bjf;wcVRPQ;fwd=I-wvvtk6!lp(AJW7P9R~ oTEI+u+O~3SYv9{I|Llz2+$$b1N67WJgVxf%JOBb#-h==E05ewZGynhq literal 0 HcmV?d00001 diff --git a/main.py b/main.py index 49ccdf4..d5babf9 100644 --- a/main.py +++ b/main.py @@ -32,9 +32,11 @@ def agent_portrayal(agent): if isinstance(agent, PatchAgent): color = colors[0] - if agent.type == PatchType.dropOff: + if agent.patch_type == PatchType.wall: + portrayal = {"Shape": "img/brick.webp", "scale": 1.0, "Layer": 0} + elif agent.patch_type == PatchType.dropOff: portrayal = {"Shape": "img/truck.png", "scale": 1.0, "Layer": 0} - elif agent.type == PatchType.pickUp: + elif agent.patch_type == PatchType.pickUp: portrayal = {"Shape": "img/okB00mer.png", "scale": 1.0, "Layer": 0} else: color = colors[random.randrange(13) + 3] @@ -53,7 +55,7 @@ gridHeight = 10 scale = base / gridWidth diagram4 = GridWithWeights(gridWidth, gridHeight) -diagram4.walls = [] +diagram4.walls = [(5, 5), (5, 6)] grid = CanvasGrid(agent_portrayal, gridWidth, gridHeight, scale * gridWidth, scale * gridHeight) diff --git a/test/nastepnik.py b/test/nastepnik.py index b610361..8c36f6d 100644 --- a/test/nastepnik.py +++ b/test/nastepnik.py @@ -41,11 +41,12 @@ def heuristic(a: Tuple[int, int], b: Tuple[int, int]) -> float: return abs(x1 - x2) + abs(y1 - y2) class PossibleMoves(Enum): - rotateTop = 1 + move = 1 rotateLeft = 2 rotateDown = 3 rotateRight = 4 - move = 5 + rotateTop = 5 + def getRotationEvaluation(direction: Direction): # get evaluationForMoveAfterRotation diff --git a/util/AgentIdFactory.py b/util/AgentIdFactory.py new file mode 100644 index 0000000..0bf988c --- /dev/null +++ b/util/AgentIdFactory.py @@ -0,0 +1,9 @@ +from itertools import count + + +class AgentIdFactory(object): + _id_counter = count(start=0) + + @staticmethod + def get_next_id() -> int: + return next(AgentIdFactory._id_counter) diff --git a/util/TWOJSTARY.py b/util/TWOJSTARY.py new file mode 100644 index 0000000..a0d9d8a --- /dev/null +++ b/util/TWOJSTARY.py @@ -0,0 +1,27 @@ +from data import Game, Order + + +def pickBestOrder(game: Game) -> Order: + maxi = game.orderList[0] + for i in range(len(game.orderList)): + if(game.orderList[i].money > maxi.money): + maxi = game.orderList[i] + + return maxi + +def realizeOrder(game: Game, orderId: int): + return 1 + +def getCorrectStockPile(game: Game) -> (int, int): + return game.stockPilePos[game.carriedItem.category].pos + +def TwojStary(game: Game) -> (int, int): + if len(game.orderList) == 0: + if game.carriedItem is None: + return game.deliveryPos + else: + return getCorrectStockPile(game) + elif game.carriedItem is None: + return realizeOrder(game, pickBestOrder(game)) + else: + return getCorrectStockPile(game) \ No newline at end of file