Podpięcie drzewa do agenta, podpięcie klasyfikatora do agenta
This commit is contained in:
parent
b78f57386e
commit
3a4fcf611e
Binary file not shown.
Binary file not shown.
117
src/agent.py
117
src/agent.py
@ -1,6 +1,10 @@
|
||||
import random
|
||||
import pygame as pg
|
||||
import heapq
|
||||
from decisiontree import decision
|
||||
from trashtype import trash_type_def
|
||||
|
||||
HOUSE_NUMBER = {'House_number': 0}
|
||||
|
||||
|
||||
class Node:
|
||||
@ -12,11 +16,13 @@ class Node:
|
||||
def __lt__(self, other):
|
||||
return self.cost < other.cost
|
||||
|
||||
|
||||
class State:
|
||||
def __init__(self, position, house_list):
|
||||
self.position = position
|
||||
self.house_list = house_list
|
||||
|
||||
|
||||
def vector_to_tuple(vector):
|
||||
tup = (int(vector.x), int(vector.y))
|
||||
return tup
|
||||
@ -24,10 +30,109 @@ def vector_to_tuple(vector):
|
||||
|
||||
class HousePOI:
|
||||
def __init__(self):
|
||||
self.bins = None
|
||||
from simulation import Interface
|
||||
self.season = Interface.season.season
|
||||
self.day = Interface.day.day
|
||||
self.truck_fullness = None
|
||||
self.payment = None
|
||||
self.bin_fullness = None
|
||||
self.trash_type = None
|
||||
self.trash = 1
|
||||
self.dump_fullness = 0
|
||||
|
||||
def discover_bins(self, bins):
|
||||
self.bins = bins
|
||||
def discover_bins(self, bin_fullness, trash_type, payment):
|
||||
from simulation import Interface
|
||||
|
||||
season_autumn = 0
|
||||
season_spring = 0
|
||||
season_summer = 0
|
||||
season_winter = 0
|
||||
day_friday = 0
|
||||
day_monday = 0
|
||||
day_wednesday = 0
|
||||
trash_types_glass = 0
|
||||
trash_types_biological = 0
|
||||
trash_types_paper = 0
|
||||
trash_types_plastic = 0
|
||||
truck_fullness = 0
|
||||
|
||||
guessed_trash_type = trash_type_def(trash_type)
|
||||
|
||||
self.truck_fullness = Interface.truck_fullness.fullness
|
||||
self.payment = payment
|
||||
self.bin_fullness = bin_fullness
|
||||
self.trash_type = guessed_trash_type
|
||||
|
||||
if self.season == 'autumn':
|
||||
season_autumn = 1
|
||||
if self.season == 'spring':
|
||||
season_spring = 1
|
||||
if self.season == 'summer':
|
||||
season_summer = 1
|
||||
if self.season == 'winter':
|
||||
season_winter = 1
|
||||
if self.day == 'friday':
|
||||
day_friday = 1
|
||||
if self.day == 'monday':
|
||||
day_monday = 1
|
||||
if self.day == 'wednesday':
|
||||
day_wednesday = 1
|
||||
if self.trash_type == 'glass':
|
||||
trash_types_glass = 1
|
||||
truck_fullness = self.truck_fullness["glass"]
|
||||
if self.trash_type == 'biological':
|
||||
trash_types_biological = 1
|
||||
truck_fullness = self.truck_fullness["biological"]
|
||||
if self.trash_type == 'paper':
|
||||
trash_types_paper = 1
|
||||
truck_fullness = self.truck_fullness["paper"]
|
||||
if self.trash_type == 'plastic':
|
||||
trash_types_plastic = 1
|
||||
truck_fullness = self.truck_fullness["plastic"]
|
||||
if truck_fullness < 1:
|
||||
truck_fullness = 0
|
||||
if truck_fullness == 1:
|
||||
truck_fullness = 1
|
||||
dec_tree = {'dump_fullness': [self.dump_fullness],
|
||||
'truck_fullness': [truck_fullness],
|
||||
'trash': [self.trash],
|
||||
'payment': [payment],
|
||||
'bin_fullness': [bin_fullness],
|
||||
'trash_types_glass': [trash_types_glass],
|
||||
'trash_types_mixed': [trash_types_biological],
|
||||
'trash_types_paper': [trash_types_paper],
|
||||
'trash_types_plastic': [trash_types_plastic],
|
||||
'season_autumn': [season_autumn],
|
||||
'season_spring': [season_spring],
|
||||
'season_summer': [season_summer],
|
||||
'season_winter': [season_winter],
|
||||
'day_friday': [day_friday],
|
||||
'day_monday': [day_monday],
|
||||
'day_wednesday': [day_wednesday]
|
||||
}
|
||||
outcome = decision(dec_tree)
|
||||
if outcome == 1:
|
||||
Interface.truck_fullness.fullness[trash_type] += 0.25 # 0.25
|
||||
|
||||
debug(dec_tree, outcome, trash_type, guessed_trash_type, self.season, self.day, self.bin_fullness,
|
||||
self.truck_fullness)
|
||||
|
||||
|
||||
def debug(dec_tree, outcome, trash_type, guessed_trash_type, season, day, bin_fullness, truck_fullness):
|
||||
HOUSE_NUMBER['House_number'] += 1
|
||||
print("Domek nr: " + str(HOUSE_NUMBER['House_number']))
|
||||
if outcome == 1:
|
||||
print("Odebrano śmieci")
|
||||
if outcome == 0:
|
||||
print("Nie odebrano śmieci")
|
||||
print("Pora: " + season)
|
||||
print("Dzień: " + day)
|
||||
print("Typ śmieci: " + trash_type)
|
||||
print("Zaobserwowane: " + guessed_trash_type)
|
||||
print("Zapełnienie domu: " + str(bin_fullness))
|
||||
print(truck_fullness)
|
||||
print(dec_tree)
|
||||
print("####################################################################################")
|
||||
|
||||
|
||||
class Agent:
|
||||
@ -234,5 +339,7 @@ class Agent:
|
||||
if entity.entity_type == 'house' and vector_to_tuple(entity.position) == self.current_pos:
|
||||
current_house = entity
|
||||
break
|
||||
if current_house is not None:
|
||||
self.houses[self.current_pos].discover_bins(current_house.bins)
|
||||
if current_house is not None and current_house.visited == False:
|
||||
current_house.visited = True
|
||||
self.houses[self.current_pos].discover_bins(current_house.bins[0], current_house.bins[1],
|
||||
current_house.bins[2])
|
||||
|
@ -1,5 +1,6 @@
|
||||
from pathlib import Path
|
||||
from random import randint
|
||||
import random
|
||||
|
||||
import pygame as pg
|
||||
from agent import Agent
|
||||
@ -26,7 +27,24 @@ DUMP_SPRITES = {'paper': PAPER_DUMP_SPRITE,
|
||||
'plastic': PLASTIC_DUMP_SPRITE,
|
||||
'mixed': MIXED_DUMP_SPRITE}
|
||||
|
||||
TRASH_TYPES = ['paper', 'plastic', 'glass', 'mixed']
|
||||
TRASH_TYPES = ['paper', 'plastic', 'glass', 'biological']
|
||||
DAYS = ['friday', 'monday', 'wednesday']
|
||||
SEASONS = ['autumn', 'spring', 'summer', 'winter']
|
||||
|
||||
|
||||
class Season:
|
||||
def __init__(self, season):
|
||||
self.season = season
|
||||
|
||||
|
||||
class Day:
|
||||
def __init__(self, day):
|
||||
self.day = day
|
||||
|
||||
|
||||
class TruckFullness:
|
||||
def __init__(self, fullness):
|
||||
self.fullness = fullness
|
||||
|
||||
|
||||
class Entity:
|
||||
@ -40,10 +58,7 @@ class TruckEntity(Entity):
|
||||
super().__init__(state, position)
|
||||
self.entity_type = 'truck'
|
||||
self.tile = TRUCK_SPRITE_R
|
||||
self.fullness = {'paper': 0,
|
||||
'glass': 0,
|
||||
'plastic': 0,
|
||||
'mixed': 0}
|
||||
self.fullness = None
|
||||
self.orientation = 90
|
||||
|
||||
def rotate_img(self, orientation):
|
||||
@ -76,13 +91,11 @@ class TruckEntity(Entity):
|
||||
|
||||
|
||||
class Bin:
|
||||
def __init__(self, size, trash_type):
|
||||
self.size = size
|
||||
self.trash_type = trash_type
|
||||
self.fullness = randint(0, 100)
|
||||
def __init__(self, items):
|
||||
self.items = items
|
||||
|
||||
def __str__(self):
|
||||
return self.trash_type + " bin"
|
||||
def __getitem__(self, index):
|
||||
return self.items[index]
|
||||
|
||||
|
||||
class HouseEntity(Entity):
|
||||
@ -90,7 +103,8 @@ class HouseEntity(Entity):
|
||||
super().__init__(state, position)
|
||||
self.tile = HOUSE_SPRITES[0]
|
||||
self.entity_type = 'house'
|
||||
self.bins = [Bin(randint(1, 2), trash_type) for trash_type in TRASH_TYPES]
|
||||
self.visited = False
|
||||
self.bins = Bin([randint(0, 1), random.choice(TRASH_TYPES), randint(0, 1)])
|
||||
|
||||
|
||||
class DumpEntity(Entity):
|
||||
@ -176,7 +190,6 @@ class Layer:
|
||||
self.sim.cell_size.x,
|
||||
self.sim.cell_size.y)
|
||||
|
||||
|
||||
# render
|
||||
surface.blit(self.texture_atlas, sprite_pos, texture)
|
||||
|
||||
@ -211,6 +224,13 @@ class StructureLayer(Layer):
|
||||
|
||||
|
||||
class Interface:
|
||||
truck_fullness = TruckFullness({'paper': 0,
|
||||
'glass': 0,
|
||||
'plastic': 0,
|
||||
'biological': 0})
|
||||
season = Season(random.choice(SEASONS))
|
||||
day = Day(random.choice(DAYS))
|
||||
|
||||
def __init__(self):
|
||||
pg.init()
|
||||
|
||||
@ -276,6 +296,7 @@ class Interface:
|
||||
def update(self):
|
||||
self.state.update(self.move_truck)
|
||||
self.agent.update()
|
||||
self.agent.discover()
|
||||
'''if isinstance(self.move_truck, int):
|
||||
self.state.update(self.move_truck)
|
||||
self.agent.update()'''
|
||||
@ -298,5 +319,5 @@ class Interface:
|
||||
self.processAgentInput()
|
||||
self.update()
|
||||
self.render()
|
||||
self.clock.tick(12)
|
||||
self.clock.tick(50)
|
||||
pg.quit()
|
||||
|
Loading…
Reference in New Issue
Block a user