Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
322 views
in Technique[技术] by (71.8m points)

python - Logistics Planning with 'pulp' package but cannot get the final value

I need to distribute products from 'sending plants' to 'receiving plants'

My code:

from pulp import *
import pandas as pd

sending_plants = ['PT', 'NS']
receiving_plants = ['CH', 'KR', 'SR']
sending_amount_dict = {'PT': 652.9599999999991, 'NS': 73.625}
costs = {('PT', 'CH'): 107.799, ('PT', 'KR'): 238.165, ('PT', 'NS'): 215.703, ('PT', 'SR'): 666.47, ('CH', 'PT'): 108.341, ('CH', 'KR'): 247.149, ('CH', 'NS'): 304.181, ('CH', 'SR'): 708.449, ('KR', 'PT'): 231.903, ('KR', 'CH'): 264.566, ('KR', 'NS'): 286.385, ('KR', 'SR'): 890.317, ('NS', 'PT'): 211.699, ('NS', 'CH'): 305.667, ('NS', 'KR'): 288.868, ('NS', 'SR'): 876.423, ('SR', 'PT'): 663.388, ('SR', 'CH'): 707.229, ('SR', 'KR'): 895.961, ('SR', 'NS'): 873.499}

model = LpProblem("Minimize_Transportation_Costs", sense = LpMinimize)

# Define decision variables
key = [(s,r) for s in sending_plants for r in receiving_plants]
var_dict = LpVariable.dicts('sending_product_amount', 
                            key, 
                            lowBound = 0, cat='Integer')

# Use the LpVariable dictionary variable to define objective
model += lpSum([costs[(s, r)] * var_dict[(s, r)] 
                for s in sending_plants for r in receiving_plants])

# Define Constraints
for s in sending_plants:
    model += lpSum([var_dict[(s, r)] for r in receiving_plants]) == sending_amount_dict[s]
#print(str(sending_amount_dict) + '
')
    
# Solve Model
model.solve()
print(var_dict)

The outcome that I expect is:

{('PT', 'CH'): 12, ('PT', 'KR'): 34, ('PT', 'SR'): 43, ('NS', 'CH'): 45, ('NS', 'KR'): 56, ('NS', 'SR'): 56}

But this is the current outcome that I got:

{('PT', 'CH'): sending_product_amount_('PT',_'CH'), ('PT', 'KR'): sending_product_amount_('PT',_'KR'), ('PT', 'SR'): sending_product_amount_('PT',_'SR'), ('NS', 'CH'): sending_product_amount_('NS',_'CH'), ('NS', 'KR'): sending_product_amount_('NS',_'KR'), ('NS', 'SR'): sending_product_amount_('NS',_'SR')}
question from:https://stackoverflow.com/questions/65849827/logistics-planning-with-pulp-package-but-cannot-get-the-final-value

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...