У меня есть 6 возможных заказов компании (a,b,c,d,e,f) в долларах. Цена меняется каждую неделю (13 недель), как показано ниже.
a1_list = [1075000, 1075000, 1072500, 1072500, 1070000, 1070000, 1050000, 1535000, 1535000, 1015000, 1015000, 1000000, 1000000]
b1_list = [1275000, 1275000, 1278000, 1278000, 1242000, 1242000, 1266000, 1806000, 1806000, 1191000, 1191000, 1191000, 1191000]
c1_list = [1530000, 1530000, 1822500, 1822500, 1813500, 1813500, 1804500, 1773000, 1773000, 1746000, 1746000, 1710000, 1710000]
d1_list = [1005000, 1005000, 1005000, 1005000, 1005000, 1005000, 1005000, 960000, 960000, 960000, 960000,
960000, 960000]
e1_list = [2436000, 2436000, 2905000, 2905000, 2877000, 2877000, 2849000, 2814000, 2814000, 2779000, 2779000, 2730000, 2730000]
f1_list = [1881000, 1881000, 1890000, 1890000, 1863000, 1863000, 1854000, 1822500, 1822500, 1804500, 1804500, 1786500, 1786500]
Каждый раз я могу выбрать только 1 заказ от компании. То есть, если я выбираю заказ на 1-ю неделю как состав А, то компании B, C, D, E и F не должны быть на неделе 1. Каждый номер в списке соответствует определенной неделе.
Например, для заказа компании А цена на 1 и 2 неделе будет 1075000. Если заказ сделан не на 1 или 2 неделе, а на 3 и 4 неделе, цена будет 1072500.
Это своего рода проблема оптимизации.
Я написал ручной расчет, чтобы рассчитать наилучшую комбинацию, которая даст мне наибольшую прибыль.
Ниже приведены мои коды:
import numpy as np
from scipy import optimize
price = np.array([
[430, 425, 340, 402, 348, 418],
[429, 426, 405, 402, 415, 420],
[428, 414, 403, 402, 411, 414],
[420, 422, 401, 402, 407, 412],
[614, 602, 394, 384, 402, 405],
[406, 397, 388, 384, 397, 401],
[400, 397, 380, 384, 390, 397],
])
a1Q = 2500
a2Q = 4000
b1Q = 3000
b2Q = 3500
c1Q = 4500
c2Q = 5500
c3Q = 4000
d1Q = 2500
d2Q = 4000
e1Q = 7000
e2Q = 2000
f1Q = 4500
f2Q = 1000
a1_price = price[:,0]*a1Q
a2_price = price[:,0]*a2Q
b1_price = price[:,1]*b1Q
b2_price = price[:,1]*b2Q
c1_price = price[:,2]*c1Q
c2_price = price[:,2]*c2Q
c3_price = price[:,2]*c3Q
d1_price = price[:,3]*d1Q
d2_price = price[:,3]*d2Q
e1_price = price[:,4]*e1Q
e2_price = price[:,4]*e2Q
f1_price = price[:,5]*f1Q
f2_price = price[:,5]*f2Q
a1_list = [a1_price[0]]*2 + [a1_price[1]]*2 + [a1_price[2]]*2 + [a1_price[3]] + [a1_price[4]]*2 + [a1_price[5]]*2 + [a1_price[6]]*2
a2_list = [a2_price[0]]*2 + [a2_price[1]]*2 + [a2_price[2]]*2 + [a2_price[3]] + [a2_price[4]]*2 + [a2_price[5]]*2 + [a2_price[6]]*2
b1_list = [b1_price[0]]*2 + [b1_price[1]]*2 + [b1_price[2]]*2 + [b1_price[3]] + [b1_price[4]]*2 + [b1_price[5]]*2 + [b1_price[6]]*2
b2_list = [b2_price[0]]*2 + [b2_price[1]]*2 + [b2_price[2]]*2 + [b2_price[3]] + [b2_price[4]]*2 + [b2_price[5]]*2 + [b2_price[6]]*2
c1_list = [c1_price[0]]*2 + [c1_price[1]]*2 + [c1_price[2]]*2 + [c1_price[3]] + [c1_price[4]]*2 + [c1_price[5]]*2 + [c1_price[6]]*2
c2_list = [c2_price[0]]*2 + [c2_price[1]]*2 + [c2_price[2]]*2 + [c2_price[3]] + [c2_price[4]]*2 + [c2_price[5]]*2 + [c2_price[6]]*2
c3_list = [c3_price[0]]*2 + [c3_price[1]]*2 + [c3_price[2]]*2 + [c3_price[3]] + [c3_price[4]]*2 + [c3_price[5]]*2 + [c3_price[6]]*2
d1_list = [d1_price[0]]*2 + [d1_price[1]]*2 + [d1_price[2]]*2 + [d1_price[3]] + [d1_price[4]]*2 + [d1_price[5]]*2 + [d1_price[6]]*2
d2_list = [d2_price[0]]*2 + [d2_price[1]]*2 + [d2_price[2]]*2 + [d2_price[3]] + [d2_price[4]]*2 + [d2_price[5]]*2 + [d2_price[6]]*2
e1_list = [e1_price[0]]*2 + [e1_price[1]]*2 + [e1_price[2]]*2 + [e1_price[3]] + [e1_price[4]]*2 + [e1_price[5]]*2 + [e1_price[6]]*2
e2_list = [e2_price[0]]*2 + [e2_price[1]]*2 + [e2_price[2]]*2 + [e2_price[3]] + [e2_price[4]]*2 + [e2_price[5]]*2 + [e2_price[6]]*2
f1_list = [f1_price[0]]*2 + [f1_price[1]]*2 + [f1_price[2]]*2 + [f1_price[3]] + [f1_price[4]]*2 + [f1_price[5]]*2 + [f1_price[6]]*2
f2_list = [f2_price[0]]*2 + [f2_price[1]]*2 + [f2_price[2]]*2 + [f2_price[3]] + [f2_price[4]]*2 + [f2_price[5]]*2 + [f2_price[6]]*2
best = 0
ind_a1,ind_b1,ind_c1,ind_d1,ind_e1,ind_f1 = 0,0,0,0,0,0
for a1 in a1_list:
# print(f'A: {ind_a}')
# ind_a+=1
ind_b1 = 0
# ind_c=0
for b1 in b1_list:
if ind_b1 != ind_a1:
# print(ind_b)
# total = a + b
ind_c1 = 0
for c1 in c1_list:
if ind_c1 != ind_a1 and ind_c1 != ind_b1:
ind_d1 = 0
for d1 in d1_list:
if ind_d1 != ind_a1 \
and ind_d1 != ind_b1 \
and ind_d1!= ind_c1:
ind_e1 = 0
for e1 in e1_list:
if ind_e1 != ind_a1 \
and ind_e1 != ind_b1 \
and ind_e1!= ind_c1 \
and ind_e1!= ind_d1:
ind_f1 = 0
for f1 in f1_list:
if ind_f1 != ind_a1 \
and ind_f1 != ind_b1 \
and ind_f1!= ind_c1 \
and ind_f1!= ind_d1 \
and ind_f1!= ind_e1:
total = a1 + b1 + c1 + d1 + e1 + f1
if total >best:
best = total
print(a1,b1,c1,d1,e1,f1, ind_a1,ind_b1,ind_c1,ind_d1,ind_e1,ind_f1)
print(best)
ind_f1 +=1
ind_e1 +=1
ind_d1 += 1
ind_c1+=1
ind_b1+=1
ind_a1+=1
Мне интересно, есть ли более простой и чистый способ решить эту проблему или использовать встроенные функции оптимизации scipy, такие как scipy.optimize.minimize или scipy.optimize.brute?
На самом деле это часть огромной задачи по оптимизации, которую я решаю.
Просто чтобы дать вам представление (но может не иметь отношения к этому вопросу), ниже приведены некоторые сюжеты. Я пытаюсь максимизировать доход.
Любая помощь будет принята с благодарностью.