'aktualizacja cech paczki + src dla drzewa decyzyjnego' Merge pull request (#15) from deciosion_tree_table into master

Reviewed-on: s474139/Inteligentny_Wozek#15
This commit is contained in:
Wojciech Medenecki 2023-05-25 20:03:15 +02:00
commit 18b18bd29a
5 changed files with 92 additions and 5 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 504 KiB

View File

@ -0,0 +1,84 @@
def read_text_document(file_path): # read given amount of lines (lines of 8 integers)
string_array = []
try:
with open(file_path, 'r') as file:
# Read each line of the document
for line in file:
# Remove trailing newline characters and append to the array
string_array.append(line.rstrip('\n'))
except FileNotFoundError:
print("File not found.")
return string_array # returns array of lines from the file
def gen_output(array, second_array): # transcribes line of integers into elemental decisions of shelf "g" and "d"
if array[0] == 0 or array[0] == 1:
second_array[0] = "g"
else:
second_array[0] = "d"
if array[1] == 1 or array[1] == 2:
second_array[1] = "d"
else:
second_array[1] = "g"
if array[2] == 0:
second_array[2] = "g"
else:
second_array[2] = "d"
if array[3] == 0:
second_array[3] = "g"
else:
second_array[3] = "d"
if array[4] == 0:
second_array[4] = "d"
else:
second_array[4] = "g"
if array[5] == 0:
second_array[5] = "g"
else:
second_array[5] = "d"
if array[6] == 0:
second_array[6] = "d"
else:
second_array[6] = "g"
if array[7] == 0:
second_array[7] = "d"
else:
second_array[7] = "g"
def count(array): # count number of g and d and make decision, if same number return 2 instead
d = 0
g = 0
for digit in array:
if digit == "g":
g += 1
else:
d += 1
if d > g:
return 0 # lower shelf
elif g > d:
return 1 # upper shelf
else:
return 2 # optimisation of space, goes to more empty shelf overall
file_path = 'file/path/to/input/lines/of/integers'
examples = read_text_document(file_path) # array of given number of examples from file
for input in examples:
digit_array = []
for char in input:
# Convert the character to an integer and add it to the array
digit_array.append(int(char))
output_array = [None] * 8
gen_output(digit_array, output_array)
decision_output = count(output_array)
if decision_output == 2: # in case d == g, check which shelf is more empty
if output_array[7] == "g":
decision_output = 1
elif output_array[7] == "d":
decision_output = 0
print(decision_output) # final decision

View File

@ -1,10 +1,11 @@
import secrets, string
class Etykieta:
def __init__(self, nadawca, adres, imie, nazwisko, telefon):
def __init__(self, nadawca, adres, imie, nazwisko, telefon, priorytet):
self.nadawca = nadawca
self.adres = adres
self.imie = imie
self.nazwisko = nazwisko
self.telefon = telefon
self.priorytet = priorytet
self.id = ''.join(secrets.choice(string.ascii_uppercase + string.digits) for _ in range(9))

View File

@ -11,6 +11,6 @@ class listOfPackages:
def zainicjuj_liste_paczek():
from paczka import Paczka
packageList = listOfPackages()
demo_paczka = Paczka('duzy', 10, any, False, any, any, any, any, any)
demo_paczka = Paczka('duzy', 10, any, False, True, False, any, any, any, any, any)
packageList.add(demo_paczka)
return packageList

View File

@ -4,7 +4,7 @@ import pygame
class Paczka:
def __init__(self, rozmiar, waga, kategoria, czy_krucha, nadawca, adres, imie, nazwisko, telefon):
def __init__(self, rozmiar, waga, kategoria, priorytet, ksztalt, kruchosc, nadawca, adres, imie, nazwisko, telefon):
self.rozmiar = rozmiar
self.image = pygame.image.load("images/paczka.png")
if rozmiar == 'duzy':
@ -26,10 +26,12 @@ class Paczka:
self.rozmiar = 'undefined'
self.waga = waga
self.kategoria = kategoria
self.czy_krucha = czy_krucha
self.priorytet = priorytet
self.ksztalt = ksztalt
self.kruchosc = kruchosc
self.x = 430
self.y = 400
self.label = Etykieta(nadawca, adres, imie, nazwisko, telefon)
self.label = Etykieta(nadawca, adres, imie, nazwisko, telefon, priorytet)
# zmienia rozmiar obrazka w zaleznosci od rozmiaru
def __dobierz_rozmiar_obrazka(self):