How to handle two ways of shipping for supply network problem
回答済みI am trying to create a model in which for each arc there are two carrier options to deliver with different costs associated with the carrier options. I created dictionaries for the demand from customers and the supply of the products, demand for express delivery option as well as a multidict for the arcs and the different costs which looks like this:
arcs,cost0,cost1=gp.multidict({
('s0','c0s0'):[28.536319,0.323409],
('s1','c0s1'):[0.786101,0.258617],
('s4','c0s4'):[2.0,0.418180],
('s0','c1s0'):[42.701323,1.256058],
('s1','c1s1'):[1.7,0.651774],
('s4','c1s4'):[2.108387,0.406466],
('s0','c2s0'):[44.812141,2.332005],
('s1','c2s1'):[0.788449,1.665496],
('s0','c3s0'):[73.373559,1.294359],
('s1','c3s1'):[80,4.572656],
('s4','c3s4'):[80,12.418360],
('s0','c6s0'):[37.286300,1.312147],
('s1','c6s1'):[1.116815,1.365350],
('s4','c6s4'):[1.697969,0.45]
})
In which si represents the supply of the product and cisi represents the customer
the Objective function is to minimize sum(Cijk+Xijk) in which cijk is the cost of shipping product i to customer j through delivery option k and X is the flow of product to ship that way.
I created variables for the two delivery options this way
carrier1flow=model.addVars(arcs, obj=cost1, name='carrier1')
carrier0flow=model.addVars(arcs, obj=cost0, name='carrier0')
and supply and demand constraints this way:
##### supply constraints
segments=supply_dict.keys()
supply_flow= model.addConstrs((gp.quicksum(carrier1flow.select(segment)+carrier0flow.select(segment))<=supply_dict[segment]
for segment in segments), name='segment')
# #####demand constraints
customers=demand_dict.keys()
demand_flow= model.addConstrs((gp.quicksum(carrier1flow.select('*',customer)+carrier0flow.select('*',customer))==demand_dict[customer]########de demand is not getting through!!!!!!!!!
for customer in customers), name='customer')
Besides, there are other constraints associated with the different carriers. carrier 0 has to fulfill a certain portion of the demand and carrier 1 flows have to be greater than a minimum weight those look like this
express_flow=model.addConstrs((gp.quicksum(carrier0flow.select('*',customer))>=express_demand[customer]
for customer in customers), name='customer')
carrier_flow=model.addConstrs((gp.quicksum(carrier1flow.select('*',customer))>=minweight####carrier minimum
for customer in customers), name='customer')
If I include only the first three constraints I get a solution but in the solution, only one carrier is chosen to fulfill the demand of one customer and I want the demand to be split amongst carriers due to the express demand. Moreover, when I add the minimum flow, the model becomes unfeasible and I wonder if that is because I have the variables set wrong. I would appreciate any help, it is my first time using gurobi
-
正式なコメント
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Ok so I was able to solve the first portion. I changed my multidict to the following:
arcs,cost=gp.multidict({
('s0','c0s0','r0'):[28.536319],
('s0','c0s0','r1'):[0.323409],
('s1','c0s1','r0'):[0.786101],
('s1','c0s1','r1'):[0.258617],
('s4','c0s4','r0'):[2.0],
('s4','c0s4','r1'):[0.418180],####carrier 0 cost assumed no data
('s0','c1s0','r0'):[42.701323],
('s0','c1s0','r1'):[1.256058],
('s1','c1s1','r0'):[1.7],
('s1','c1s1','r1'):[0.651774],####carrier 0 cost assumed no data
('s4','c1s4','r0'):[2.108387],
('s4','c1s4','r1'):[0.406466],
('s0','c2s0','r0'):[44.812141],
('s0','c2s0','r1'):[2.332005],
('s1','c2s1','r0'):[0.788449],
('s1','c2s1','r1'):[1.665496],
('s0','c3s0','r0'):[73.373559],
('s0','c3s0','r1'):[1.294359],
('s1','c3s1','r0'):[80],
('s1','c3s1','r1'):[4.572656],####carrier 0 cost assumed no data
('s4','c3s4','r0'):[80],
('s4','c3s4','r1'):[12.418360],####carrier 0 cost assumed no data
('s0','c6s0','r0'):[37.286300],
('s0','c6s0','r1'):[1.312147],
('s1','c6s1','r0'):[1.116815],
('s1','c6s1','r1'):[1.365350],
('s4','c6s4','r0'):[1.697969],
('s4','c6s4','r1'):[0.45]####carrier 1 cost assumed no data
})and the constraints to the following
##### supply constraints
segments=supply_dict.keys()
supply_flow= model.addConstrs((gp.quicksum(flow.select(segment))<=supply_dict[segment]
for segment in segments), name='segment')
# #####demand constraints
customers=demand_dict.keys()
demand_flow= model.addConstrs((gp.quicksum(flow.select('*',customer,'*'))==demand_dict[customer]
for customer in customers), name='customer')
# ######## Carrier constraints
express_flow=model.addConstrs((gp.quicksum(flow.select('*',customer,'r0'))>=express_demand[customer]
for customer in customers), name='express')And that works just like I wanted!
However, this last constraint is giving me an infeasible solution and I am not sure whycarrier_flow=model.addConstrs((gp.quicksum(flow.select('*',customer,'r1'))>=minweight####carrier minimum
for customer in customers), name='minimum')0 -
Hi Nestor,
The Knowledge Base article How do I determine why my model is infeasible? might come in handy.
Best regards,
Jaromił0
投稿コメントは受け付けていません。
コメント
3件のコメント