Przystosowanie algorytmu MCDA

This commit is contained in:
Tomek 2020-06-08 18:26:34 +02:00
parent 1bf69a4dda
commit 6aee933c0b
8 changed files with 118 additions and 22 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

29
data.py
View File

@ -32,7 +32,7 @@ learning_data = [
# kolor, kształt, waga, rozmiar, nazwa
['black', 'rectangle', 51, 'small', 'Mars'],
['gold', 'pack', 100, 'big', 'Haribo'],
['purple', 'rectangle', 100, 'big', 'Milka'],
['purple', 'rectangle', 100, 'big', 'Milka-czekolada'],
['brown', 'pack', 45, 'small', 'M&M'],
['blue', 'rectangle', 50, 'medium', 'Bounty'],
['blue', 'square', 40, 'small', 'Knoppers'],
@ -40,10 +40,10 @@ learning_data = [
['gold', 'rectangle', 40, 'medium', 'Twix'],
['gold', 'rectangle', 50, 'medium', 'Prince-polo'],
['brown', 'rectangle', 55, 'medium', 'Snickers'],
['brown', 'rectangle', 45, 'medium', 'Lion'],
['brown', 'rectangle', 45, 'medium', 'Lion'],
['white', 'rectangle', 40, 'medium', 'Kinder-bueno'],
['red', 'rectangle', 50, 'medium', 'Kit-kat'],
['blue', 'rectangle', 115, 'big', 'Wedel'],
['blue', 'rectangle', 115, 'big', 'Wedel-czekolada'],
['white', 'rectangle', 15, 'small', 'Krowka'],
['red', 'pack', 70, 'medium', 'Skittles'],
['orange', 'rectangle', 45, 'medium', 'Reeses'],
@ -57,6 +57,29 @@ learning_data = [
['red', 'jar', 250, 'medium', 'Strawberry Jam'],
['black', 'jar', 250, 'medium', 'Blackberry Jam'],
['orange', 'jar', 250, 'medium', 'Peach Jam'],
['brown', 'rectangle', 140, 'big', 'Jezyki classic'],
['blue', 'rectangle', 140, 'big', 'Jezyki kokos'],
['white', 'rectangle', 100, 'big', 'Kinder Chocolate'],
['yellow', 'rectangle', 300, 'big', 'belVita'],
['blue', 'rectangle', 380, 'big', 'Wedel-Ptasie Mleczko'],
['purple', 'rectangle', 330, 'big', 'Milka-Alpejskie Mleczko'],
['blue', 'rectangle', 294, 'big', 'Delicje'],
['silver', 'pack', 280, 'big', 'Wawel-Michalki'],
['red', 'rectangle', 50, 'medium', 'Krakuski Petit Beurre'],
['white', 'egg', 20, 'small', 'Kinder Niespodzianka'],
['brown', 'rectangle', 180, 'big', 'Familijne Wafle'],
['red', 'rectangle', 235, 'big', 'dr Gerard PryncyPałki'],
['white', 'rectangle', 25, 'medium', 'Nestlé Cini Minis Batonik'],
['black', 'pack', 70, 'big', 'Korsarz Draże'],
['white', 'rectangle', 50, 'medium', 'Góralki'],
['white', 'rectangle', 24, 'medium', 'Kinder Country'],
['red', 'rectangle', 46, 'medium', '3Bit'],
['yellow', 'rectangle', 25, 'medium', 'Nestlé Nesquik Batonik'],
['yellow', 'rectangle', 47, 'medium', 'Wedel WW'],
['brown', 'rectangle', 30, 'medium', 'Lubisie'],
['purple', 'rectangle', 22, 'small', 'Maoam'],
['brown', 'rectangle', 294, 'medium', 'Grześki'],
['white', 'rectangle', 250, 'big', 'merci'],
]

View File

@ -9,7 +9,7 @@ from agent import Agent
from settings import Settings
from board import create_board, draw_board
from random import randint, choice
from mcda import choseProducts
from mcda import selectedSupply
# Inicjalizacja programu i utworzenie obiektu ekrany
def run():
@ -21,7 +21,7 @@ def run():
board = create_board(screen)
my_tree = decision_tree.build_tree(data.learning_data)
produsctsFromSupply = choseProducts(5)
produsctsFromSupply = selectedSupply()
# for row in board:
# for field in row:

44
mcda.py
View File

@ -1,9 +1,9 @@
from supply import *
allProducts = create_data_products()
allProducts = supply()
color = {'black': 16, 'gold': 10, 'purple': 5, 'brown': 7, 'blue': 12, 'white': 14, 'red': 13, 'orange': 11}
shape = {'rectangle': 15, 'pack': 19, 'square': 9, 'jar': 7}
color = {'black': 16, 'gold': 10, 'purple': 12, 'brown': 7, 'blue': 12, 'white': 14, 'red': 13, 'orange': 11, 'yellow': 8, 'silver': 15}
shape = {'rectangle': 15, 'pack': 19, 'square': 9, 'jar': 7, 'egg': 12}
size = {'small': 7, 'medium': 16, 'big': 13}
def sizeValue(X):
@ -68,12 +68,11 @@ def getConcordanceAllProducts():
C.append(c)
return C
def choseProducts(number):
def choseProducts():
number = 20
C = getConcordanceAllProducts()
products = []
prev = -1
if number > len(allProducts):
return allProducts
while number > 0:
max = -1
if prev == -1:
@ -89,11 +88,28 @@ def choseProducts(number):
max = j
prev = max
for j in range(len(allProducts)):
if C[max] == C[j]:
products.append(allProducts[j])
print(C[j])
number -= 1
if number == 0:
break
print(C)
return products
if C[max] > 0.8:
if C[max] == C[j]:
products.append(allProducts[j])
print(C[j])
number -= 1
if number == 0:
break
else:
number = 0
return products
def selectedSupply():
products = choseProducts()
supply = []
product = ['-', '-', 0, '-', '-']
for i in range(len(products)):
product[0] = products[i].color
product[1] = products[i].shape
product[2] = products[i].mass
product[3] = products[i].size
supply.append(product)
product = ['-', '-', 0, '-', '-']
supply.append(product)
print(supply)
return supply

View File

@ -1,11 +1,10 @@
from product import Product
import random
def create_data_products():
allProducts = []
product = Product('black', 'rectangle', 51, 'small')
allProducts.append(product)
product = Product('black', 'rectangle', 51, 'small')
allProducts.append(product)
product = Product('gold', 'pack', 100, 'big')
@ -60,5 +59,63 @@ def create_data_products():
allProducts.append(product)
product = Product('orange', 'jar', 250, 'medium')
allProducts.append(product)
product = Product('brown', 'rectangle', 140, 'big')
allProducts.append(product)
product = Product('blue', 'rectangle', 140, 'big')
allProducts.append(product)
product = Product('white', 'rectangle', 100, 'big')
allProducts.append(product)
product = Product('yellow', 'rectangle', 300, 'big')
allProducts.append(product)
product = Product('blue', 'rectangle', 380, 'big')
allProducts.append(product)
product = Product('purple', 'rectangle', 330, 'big')
allProducts.append(product)
product = Product('blue', 'rectangle', 294, 'big')
allProducts.append(product)
product = Product('silver', 'pack', 280, 'big')
allProducts.append(product)
product = Product('red', 'rectangle', 50, 'medium')
allProducts.append(product)
product = Product('white', 'egg', 20, 'small')
allProducts.append(product)
product = Product('brown', 'rectangle', 180, 'big')
allProducts.append(product)
product = Product('red', 'rectangle', 235, 'big')
allProducts.append(product)
product = Product('white', 'rectangle', 25, 'medium')
allProducts.append(product)
product = Product('black', 'pack', 70, 'big')
allProducts.append(product)
product = Product('white', 'rectangle', 50, 'medium')
allProducts.append(product)
product = Product('white', 'rectangle', 24, 'medium')
allProducts.append(product)
product = Product('red', 'rectangle', 46, 'medium')
allProducts.append(product)
product = Product('yellow', 'rectangle', 25, 'medium')
allProducts.append(product)
product = Product('yellow', 'rectangle', 47, 'medium')
allProducts.append(product)
product = Product('brown', 'rectangle', 30, 'medium')
allProducts.append(product)
product = Product('purple', 'rectangle', 22, 'small')
allProducts.append(product)
product = Product('brown', 'rectangle', 294, 'medium')
allProducts.append(product)
product = Product('white', 'rectangle', 250, 'big')
allProducts.append(product)
return allProducts
def supply():
allProducts = create_data_products()
R = []
supply = []
while len(R)<20:
rand = random.randint(0, 49)
if R.count(rand) == 0:
R.append(rand)
supply.append(allProducts[rand])
return supply
return allProducts