Моя проблема отмечена как невыполнимая, но я не могу найти противоречия в своих ограничениях,
я формулирую модель LP для минимизации общих затрат, которые включают доставку из Китая в коробках на склады в США, распространение со складов в США. в соответствующие местоположения клиентов в единицах и, возможно, любые расходы на нехватку, если спрос превышает имеющиеся запасы.
спасибо
КОД:
import pulp
def create_lp_problem(us_warehouses, china_warehouse, shipping_methods, time_periods, skus, customer_locations,
shipping_cost, admin_cost, distribution_cost, shortage_cost, units_per_box, whight_per_sku, demand,
inventory_in_us, inventory_in_china,
shipment_duration):
import os
# Set the timeout to 10 seconds
#os.environ['PYDEVD_WARN_SLOW_RESOLVE_TIMEOUT'] = '10'
# Large constant for Big-M constraints
M = 200
print('Create the LP problem')
model = pulp.LpProblem("Supply_Chain_Optimization", pulp.LpMinimize)
# Decision Variables
# inventory on the way from China to U.S. Warehouses in boxes
x = {
china_warehouse: {
u: {
s: {
t: {k: pulp.LpVariable(f"Shipment_Quantity_{china_warehouse}_{u}_{s}_{t}_{k}", 0, None, pulp.LpInteger)
for k in skus}
for t in time_periods}
for s in shipping_methods}
for u in us_warehouses}
}
# inventory on the way from U.S. Warehouses to Customer in units
y = {
u: {
l: {
t: {k: pulp.LpVariable(f"Distribution_Quantity_{u}_{l}_{t}_{k}", 0, None, pulp.LpInteger)
for k in skus}
for t in time_periods}
for l in customer_locations}
for u in us_warehouses
}
# binary variables for shipment and admin cost sku level
z_shipment = {
china_warehouse: {
u: {
s: {
t: {k: pulp.LpVariable(f"Shipment_Binary_{china_warehouse}_{u}_{s}_{t}_{k}", 0, 1, pulp.LpBinary)
for k in skus}
for t in time_periods}
for s in shipping_methods}
for u in us_warehouses}
}
# binary variables for admin cost
z_admin = {
china_warehouse: {
u: {
s: {
t: pulp.LpVariable(f"Admin_Binary_{china_warehouse}_{u}_{s}_{t}", 0, 1, pulp.LpBinary)
for t in time_periods}
for s in shipping_methods}
for u in us_warehouses}
}
china_inventory = {
t: {k: pulp.LpVariable(f"China_Inventory_{t}_{k}", 0, None, pulp.LpInteger) for k in skus}
for t in time_periods
}
us_inventory = {
u: {
t: {k: pulp.LpVariable(f"US_Inventory_{u}_{t}_{k}", 0, None, pulp.LpInteger) for k in skus}
for t in time_periods
}
for u in us_warehouses
}
# Objective Function
model += (
pulp.lpSum(
shipping_cost[china_warehouse, u, s] * x[china_warehouse][t][k] * units_per_box[k] * whight_per_sku[k]
for u in us_warehouses for s in shipping_methods for t in time_periods for k in skus
)
+ pulp.lpSum(
admin_cost[china_warehouse, u, s] * z_admin[china_warehouse][t]
for u in us_warehouses for s in shipping_methods for t in time_periods
)
+ pulp.lpSum(
distribution_cost[u, l] * y[l][t][k] * whight_per_sku[k]
for u in us_warehouses for l in customer_locations for t in time_periods for k in skus
)
+ pulp.lpSum(
shortage_cost * (demand[l, t, k] - pulp.lpSum(y[l][t][k] for u in us_warehouses))
for t in time_periods for k in skus for l in customer_locations[list(customer_locations.keys())[0]]
)
), "Total_Cost"
# Constraints
# Inventory Balance at U.S. Warehouses
for t_idx, t in enumerate(time_periods):
for u in us_warehouses:
for k in skus:
if t_idx > 0:
prev_t = time_periods[t_idx - 1]
# Shipments received at time t
shipments_received = pulp.lpSum(
x[china_warehouse][time_periods[t_idx - int(shipment_duration[(u,s)])]][k]
for s in shipping_methods if t_idx - shipment_duration[(u,s)] >= 0
)
model += (
us_inventory[t][k] == us_inventory[prev_t][k] + inventory_in_us[u, t, k] +
shipments_received - pulp.lpSum(y[l][t][k] for l in customer_locations[u])
), f"Inventory_Balance_{u}_{t}_{k}"
else:
model += (
us_inventory[u][t][k] == inventory_in_us[u, t, k]
), f"Initial_Inventory_{u}_{t}_{k}"
#Inventory Balance at China Warehouse
for t_idx, t in enumerate(time_periods):
for k in skus:
if t_idx == 0:
model += (
china_inventory[t][k] == inventory_in_china[t,k]
), f"China_Initial_Inventory_{k}"
else:
prev_t = time_periods[t_idx - 1]
model += (
china_inventory[t][k] == china_inventory[prev_t][k] +
inventory_in_china[t,k] -
pulp.lpSum(x[china_warehouse][u][t][k]* units_per_box[k] for u in us_warehouses for s in shipping_methods)
), f"China_Inventory_Balance_{t}_{k}"
# Binary Linking Constraints
for u in us_warehouses:
for s in shipping_methods:
for t in time_periods:
for k in skus:
model += z_admin[china_warehouse][u][t] >= z_shipment[china_warehouse][u][t][k], \
f"Binary_Link_{u}_{s}_{t}_{k}"
slack = pulp.LpVariable.dicts("Slack", (us_warehouses, shipping_methods, time_periods, skus), 0, None, pulp.LpContinuous)
# Big-M Constraints
for u in us_warehouses:
for s in shipping_methods:
for t in time_periods:
for k in skus:
model += x[china_warehouse][u][t][k]
Подробнее здесь: https://stackoverflow.com/questions/793 ... infeasible
Модель LP с использованием целлюлозы (оптимизация временных рядов). Проблема невыполнима. ⇐ Python
Программы на Python
1735120103
Anonymous
Моя проблема отмечена как невыполнимая, но я не могу найти противоречия в своих ограничениях,
я формулирую модель LP для минимизации общих затрат, которые включают доставку из Китая в коробках на склады в США, распространение со складов в США. в соответствующие местоположения клиентов в единицах и, возможно, любые расходы на нехватку, если спрос превышает имеющиеся запасы.
спасибо
КОД:
import pulp
def create_lp_problem(us_warehouses, china_warehouse, shipping_methods, time_periods, skus, customer_locations,
shipping_cost, admin_cost, distribution_cost, shortage_cost, units_per_box, whight_per_sku, demand,
inventory_in_us, inventory_in_china,
shipment_duration):
import os
# Set the timeout to 10 seconds
#os.environ['PYDEVD_WARN_SLOW_RESOLVE_TIMEOUT'] = '10'
# Large constant for Big-M constraints
M = 200
print('Create the LP problem')
model = pulp.LpProblem("Supply_Chain_Optimization", pulp.LpMinimize)
# Decision Variables
# inventory on the way from China to U.S. Warehouses in boxes
x = {
china_warehouse: {
u: {
s: {
t: {k: pulp.LpVariable(f"Shipment_Quantity_{china_warehouse}_{u}_{s}_{t}_{k}", 0, None, pulp.LpInteger)
for k in skus}
for t in time_periods}
for s in shipping_methods}
for u in us_warehouses}
}
# inventory on the way from U.S. Warehouses to Customer in units
y = {
u: {
l: {
t: {k: pulp.LpVariable(f"Distribution_Quantity_{u}_{l}_{t}_{k}", 0, None, pulp.LpInteger)
for k in skus}
for t in time_periods}
for l in customer_locations[u]}
for u in us_warehouses
}
# binary variables for shipment and admin cost sku level
z_shipment = {
china_warehouse: {
u: {
s: {
t: {k: pulp.LpVariable(f"Shipment_Binary_{china_warehouse}_{u}_{s}_{t}_{k}", 0, 1, pulp.LpBinary)
for k in skus}
for t in time_periods}
for s in shipping_methods}
for u in us_warehouses}
}
# binary variables for admin cost
z_admin = {
china_warehouse: {
u: {
s: {
t: pulp.LpVariable(f"Admin_Binary_{china_warehouse}_{u}_{s}_{t}", 0, 1, pulp.LpBinary)
for t in time_periods}
for s in shipping_methods}
for u in us_warehouses}
}
china_inventory = {
t: {k: pulp.LpVariable(f"China_Inventory_{t}_{k}", 0, None, pulp.LpInteger) for k in skus}
for t in time_periods
}
us_inventory = {
u: {
t: {k: pulp.LpVariable(f"US_Inventory_{u}_{t}_{k}", 0, None, pulp.LpInteger) for k in skus}
for t in time_periods
}
for u in us_warehouses
}
# Objective Function
model += (
pulp.lpSum(
shipping_cost[china_warehouse, u, s] * x[china_warehouse][u][s][t][k] * units_per_box[k] * whight_per_sku[k]
for u in us_warehouses for s in shipping_methods for t in time_periods for k in skus
)
+ pulp.lpSum(
admin_cost[china_warehouse, u, s] * z_admin[china_warehouse][u][s][t]
for u in us_warehouses for s in shipping_methods for t in time_periods
)
+ pulp.lpSum(
distribution_cost[u, l] * y[u][l][t][k] * whight_per_sku[k]
for u in us_warehouses for l in customer_locations[u] for t in time_periods for k in skus
)
+ pulp.lpSum(
shortage_cost * (demand[l, t, k] - pulp.lpSum(y[u][l][t][k] for u in us_warehouses))
for t in time_periods for k in skus for l in customer_locations[list(customer_locations.keys())[0]]
)
), "Total_Cost"
# Constraints
# Inventory Balance at U.S. Warehouses
for t_idx, t in enumerate(time_periods):
for u in us_warehouses:
for k in skus:
if t_idx > 0:
prev_t = time_periods[t_idx - 1]
# Shipments received at time t
shipments_received = pulp.lpSum(
x[china_warehouse][u][s][time_periods[t_idx - int(shipment_duration[(u,s)])]][k]
for s in shipping_methods if t_idx - shipment_duration[(u,s)] >= 0
)
model += (
us_inventory[u][t][k] == us_inventory[u][prev_t][k] + inventory_in_us[u, t, k] +
shipments_received - pulp.lpSum(y[u][l][t][k] for l in customer_locations[u])
), f"Inventory_Balance_{u}_{t}_{k}"
else:
model += (
us_inventory[u][t][k] == inventory_in_us[u, t, k]
), f"Initial_Inventory_{u}_{t}_{k}"
#Inventory Balance at China Warehouse
for t_idx, t in enumerate(time_periods):
for k in skus:
if t_idx == 0:
model += (
china_inventory[t][k] == inventory_in_china[t,k]
), f"China_Initial_Inventory_{k}"
else:
prev_t = time_periods[t_idx - 1]
model += (
china_inventory[t][k] == china_inventory[prev_t][k] +
inventory_in_china[t,k] -
pulp.lpSum(x[china_warehouse][u][s][t][k]* units_per_box[k] for u in us_warehouses for s in shipping_methods)
), f"China_Inventory_Balance_{t}_{k}"
# Binary Linking Constraints
for u in us_warehouses:
for s in shipping_methods:
for t in time_periods:
for k in skus:
model += z_admin[china_warehouse][u][s][t] >= z_shipment[china_warehouse][u][s][t][k], \
f"Binary_Link_{u}_{s}_{t}_{k}"
slack = pulp.LpVariable.dicts("Slack", (us_warehouses, shipping_methods, time_periods, skus), 0, None, pulp.LpContinuous)
# Big-M Constraints
for u in us_warehouses:
for s in shipping_methods:
for t in time_periods:
for k in skus:
model += x[china_warehouse][u][s][t][k]
Подробнее здесь: [url]https://stackoverflow.com/questions/79307096/lp-model-using-pulp-time-series-optimization-problem-is-infeasible[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия