I am working on a logistics supply-demand problem involving the loading of vessels over a 7-day horizon.
I am trying to define a binary variable that indicates the date
a vessel
is loaded i.e. 1 = Can load or 0 = can't load. This criteria is determined by the inventory availability: if material is available, the vessel can load.
Current output
Currently the output of the binary variable is always 1, which is incorrect because once the vessel is loaded then the shipment is complete. As a result the shipment variable (which signifies what date the vessel demand is satisfied) is at 1.0 for each day in the planned horizon
Desired Output
I need the binary variable to signify when a vessel can load (1/0). The vessel can only load after it has arrived, and if sufficient material is available in the inventory.
Code and definitions below:
Owing to the amount of code in the model (including variable formation) it is very difficult to provide an MRE, so I am hoping that someone can spot the error in the definition of the binary variable/constraint expression.
vessel_grade_demand_tonnes[vessel, grade]
: Constant. the required amount, in tonnes of each grade required by each vessel.vessel_sales_demand_vars[(vessel, grade, date)]
: Variable. The date a vessels demand requirements are fully satisfied i.e. ship is loaded with all grades it requires.vessel_load_start_date[vessel, date]
: Binary. The date indicating when a vessel can be loaded. NOTE a vessel can only load if the total amount it requires is available in the port inventory, port_inventory_vars[date, grade].
Code:
# Vessel can only load when sufficient material available.
for date, vessel, grade in vessel_sales_temp:
model += vessel_load_start_date[vessel, date] * vessel_sales_demand_tonnes[date, vessel, grade] <= port_inventory_vars[date, grade]
# All vessel requirements must be satisfied on one day, defined by loading date
for grade in grades:
for vessel, date in vessel_load_start_date:
model += vessel_load_start_date[vessel, date] * vessel_grade_demand_tonnes[vessel, grade] == pulp.lpSum(vessel_grade_demand_tonnes[vessel, grade])
model += vessel_sales_demand_vars[(vessel, grade, date)] <= vessel_load_start_date[vessel, date] * vessel_grade_demand_tonnes[vessel, grade]
# Vessel sales requirements vars must equal the total required sales tonnes
for vessel, grade, date in vessel_sales_demand_vars:
model += pulp.lpSum(vessel_sales_demand_vars[vessel, grade, date]) == vessel_grade_demand_tonnes[vessel, grade]
All help gratefully received.