2020-05-19 17:45:15 +02:00
|
|
|
from supply import *
|
|
|
|
|
2020-06-08 18:26:34 +02:00
|
|
|
allProducts = supply()
|
2020-05-19 17:45:15 +02:00
|
|
|
|
2020-06-08 18:26:34 +02:00
|
|
|
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}
|
2020-05-19 17:45:15 +02:00
|
|
|
size = {'small': 7, 'medium': 16, 'big': 13}
|
|
|
|
|
|
|
|
def sizeValue(X):
|
|
|
|
if X.size == 'small':
|
|
|
|
return X.mass/5
|
|
|
|
if X.size == 'medium':
|
|
|
|
return X.mass/10
|
|
|
|
if X.size == 'big':
|
|
|
|
return X.mass/20
|
|
|
|
parameters = {
|
|
|
|
'color': {'weights': 3, 'q': 1, 'p': 5},
|
|
|
|
'shape': {'weights': 4, 'q': 1, 'p': 6},
|
|
|
|
'mass': {'weights': 0.5, 'q': 2, 'p': 10},
|
|
|
|
'size': {'weights': 1, 'q': 1, 'p': 8}
|
|
|
|
|
|
|
|
}
|
|
|
|
def getConcordance(gA, gB, q, p):
|
|
|
|
if gB <= gA + q:
|
|
|
|
return 1
|
|
|
|
if gB <= gA + p:
|
|
|
|
return (p - gB + gA) / (p - q)
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def getAllTypeConcordance(A, B):
|
|
|
|
concordance = 0.0
|
|
|
|
weight_sum = 0
|
|
|
|
|
|
|
|
parameter = parameters['color']
|
|
|
|
w, q, p = parameter['weights'], parameter['q'], parameter['p']
|
|
|
|
concordance += getConcordance(color[A.color], color[B.color], q, p) * w
|
|
|
|
weight_sum += w
|
|
|
|
|
|
|
|
parameter = parameters['shape']
|
|
|
|
w, q, p = parameter['weights'], parameter['q'], parameter['p']
|
|
|
|
concordance += getConcordance(shape[A.shape], shape[B.shape], q, p) * w
|
|
|
|
weight_sum += w
|
|
|
|
|
|
|
|
parameter = parameters['mass']
|
|
|
|
w, q, p = parameter['weights'], parameter['q'], parameter['p']
|
|
|
|
concordance += getConcordance(sizeValue(A), sizeValue(B), q, p) * w
|
|
|
|
weight_sum += w
|
|
|
|
|
|
|
|
parameter = parameters['size']
|
|
|
|
w, q, p = parameter['weights'], parameter['q'], parameter['p']
|
|
|
|
concordance += getConcordance(size[A.size], size[B.size], q, p) * w
|
|
|
|
weight_sum += w
|
|
|
|
|
|
|
|
concordance /= weight_sum
|
|
|
|
return concordance
|
|
|
|
|
|
|
|
def getConcordanceAllProducts():
|
|
|
|
C = []
|
|
|
|
|
|
|
|
for i in range(len(allProducts)):
|
|
|
|
c = 0
|
|
|
|
for j in range(len(allProducts)):
|
|
|
|
if j==i:
|
|
|
|
continue
|
|
|
|
else:
|
|
|
|
c += getAllTypeConcordance(allProducts[i], allProducts[j])
|
|
|
|
c /= len(allProducts)-1
|
|
|
|
C.append(c)
|
|
|
|
return C
|
|
|
|
|
2020-06-08 18:26:34 +02:00
|
|
|
def choseProducts():
|
|
|
|
number = 20
|
2020-05-19 17:45:15 +02:00
|
|
|
C = getConcordanceAllProducts()
|
|
|
|
products = []
|
|
|
|
prev = -1
|
|
|
|
while number > 0:
|
|
|
|
max = -1
|
|
|
|
if prev == -1:
|
|
|
|
max = 0
|
|
|
|
for j in range(len(allProducts)):
|
|
|
|
if prev == -1:
|
|
|
|
if C[max]<C[j]:
|
|
|
|
max = j
|
|
|
|
elif max == -1:
|
|
|
|
if C[prev]>C[j]:
|
|
|
|
max = j
|
|
|
|
elif C[max] < C[j] and C[j] < C[prev]:
|
|
|
|
max = j
|
|
|
|
prev = max
|
|
|
|
for j in range(len(allProducts)):
|
2020-06-08 18:26:34 +02:00
|
|
|
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
|