Create variable that prevents infeasible solutions

38 views
Skip to first unread message

Chris Price

unread,
May 14, 2020, 10:46:01 AM5/14/20
to pulp-or-discuss
Hello,

I am currently modelling a supply problem that attempts to optimise a rail schedule which moves products from a production plant, to a warehouse to satisfy sales.

The model is working fine, however I would like to create a variable that shows the extent of a supply shortfall i.e. if the current inventory is 0, and demand is > 0, then the model is unable to satisfy the constrains and returns 'unfeasible'.

I would like to define a variable to captures the shortfall so that the end result is always 'optimal' even though a shortfall is realised, and shows the extent.

i.e. 

desired_output_df.head(10)

>>>

date            product      current_inventory     sales_demand     inventory_shortfall
'2020-01-01'    'AFM'        10000                 5000             0
'2020-01-02'    'AFM'        5000                  5000             0
'2020-01-03'    'AFM'        0                     6000             6000



My attempt to model this can be found below. As there is a significantly large amount of code, it is very difficult to create a MRE, so I am hoping that I could just get a steer on the best way to attempt this :)



# Objective Function
model
+= pulp.lpSum([
    storage_inventory_target_overage
[(date, product)]
   
+ storage_inventory_target_shortage[(date, product)]
   
+ storage_inventory_shortage[(date, product)]
   
for date, product in storage_inventory_vars]
), 'Minimise stockpile shortfalls'

# Port stockpile target, max/min and shortage constraints
for date, product in storage_inventory_vars:
  max_level
= storage_stockpile_max[grade]
  min_level
= 0
  target_level
= storage_stockpile_target[grade]
  model
+= storage_inventory_vars[(date, product)] <= max_level
 
 
# Storage Inventory Target Constraints
  model
+= storage_inventory_target_overage[(date, product)] >= 0
  model
+= storage_inventory_target_overage[(date, product)] - binary[(date, product)] * 100000000 <= 0
  model
+= storage_inventory_target_shortage[(date, product)] >= 0
  model
+= storage_inventory_target_shortage[(date, product)] - (1 - binary[(date, product)]) * 10000000 <= 0
  model
+= storage_inventory_vars[(date, product)] >= target_level \
   
+ storage_inventory_target_overage[(date, product)] \
   
- storage_inventory_target_shortage[(date, product)]
 
 
# storage Inventory Shortages
  model
+= storage_stockpile_shortage[(date, product)] >= 0
  model
+= storage_inventory_vars[(date, product)] <= 0 == storage_stockpile_shortage[(date, product)]  

# Sales Demand
# storage stockpile levels must meet sales demand
for date, product in storage_inventory_vars:
  pulp
.lpSum(storage_inventory_vars[date, product]) >= sales_demand[date][product]




All help greatly appreciated, thank you.



Stuart Mitchell

unread,
May 14, 2020, 6:18:24 PM5/14/20
to pulp-or...@googlegroups.com
Hi two ways you can do this, both don't involve integer variables

you can either add the shortage variables to your constraints and then price them something extremely large so that any solution that uses them will be more expensive than one that doesn't.

OR
solve the problem twice, 
once to minimise the shortage variables (i.e. they are the only thing in you objective)
then if they are non zero add a constraint that limits them to the amount in a previous solution and solve again with your original objective.

try googling for elastic constraints for more information.
Stu

Stuart Mitchell
PhD Engineering Science
Extraordinary Freelance Programmer and Optimisation Guru


--
New posters to this group are moderated which can take up to 48 hours, so please be patient if your first post takes a while to turn up.
---
You received this message because you are subscribed to the Google Groups "pulp-or-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pulp-or-discuss/11b8ac10-fee0-4777-b702-105b741f1d73%40googlegroups.com.

Chris Price

unread,
May 18, 2020, 4:13:45 AM5/18/20
to pulp-or-discuss
Many thanks for this Stuart, I am very grateful.

Would you/anyone have a short code example of this please? I am quite new to Pulp so a lot of these concepts are unfamiliar.

Thank you,
Chris


To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages