简体   繁体   中英

Demand optimization planning using PULP

Need help in solving a demand-optimiztion planning for factories. Factories have Machines which can make one or more Products in it. Each Product takes time to make 1 unit which is known as 'Cycle-Time'. So, to make 10 units of product/component on a machine with cycle-time of 5, it will take 5*10=50 seconds in total. Not all products can be made in all machines. So, we need to make products on valid machines and in the most effective manner. Also, each machine has an availability limit (in seconds) and we can't go over it.

What we need to do is:

  • apply a "cost" of running a machine to make one or more products.
  • apply a "cost" in case the demand of a product is NOT met.
  • Objective is to Minimize this cost.

I'm also happy if we are able to solve this using equations as constraints (like model += ( x 1 * 0.055555555555556 <= 10000, "material_300005551211-2" )). but unable to do so at the moment.

Sample data:

工厂机器设置

产品需求

I tried optimizing PULP, but this approach isn't working correctly - for example, in case of demand being too high, it doens't max upto the limit of machine's availability but unsure where i'm going wrong.

import pandas as pd
import pulp


factories = pd.read_csv('factory_machines_small.csv', index_col=['Component', 'Machine'])
print(factories)


demand = pd.read_csv('component_demand_small.csv', index_col=['Component'])
print(demand)


production = pulp.LpVariable.dicts("production",
                                     ((component, machine) for component, machine in factories.index),
                                     lowBound=0,
                                     #upBound=1,
                                     cat='Integer')

factory_status = pulp.LpVariable.dicts("factory_status",
                                     ((component, machine) for component, machine in factories.index),
                                     cat='Binary')

model = pulp.LpProblem("Cost minimising scheduling problem", pulp.LpMinimize)

model += pulp.lpSum(
    [production[component, machine] * factories.loc[(component, machine), 'Cycle_Time'] for component, machine in factories.index]
)

# Production in any month must be equal to demand
components = demand.index
for component in components :
    model += production[(component, 'IP01')] + production[(component, 'IP02')] + production[(component, 'IP03')] \
             + production[(component, 'IP04')] + production[(component, 'IP05')] == demand.loc[component, 'Demand']


# Production in any month must be between minimum and maximum capacity, or zero.
for component, machine in factories.index:
    min_production = factories.loc[(component, machine), 'Min_Capacity']
    max_production = factories.loc[(component, machine), 'Max_Capacity']
    model += production[(component, machine)] >= min_production * factory_status[component, machine]
    model += production[(component, machine)] <= max_production * factory_status[component, machine]


model.solve()
print(pulp.LpStatus[model.status])

output = []
for component, machine in production:
    var_output = {
        'Component': component,
        'Machine': machine,
        'Production': production[(component, machine)].varValue,
        'Machine Status': factory_status[(component, machine)].varValue
    }
    output.append(var_output)
    #print(output)
output_df = pd.DataFrame.from_records(output).sort_values(['Component', 'Machine'])
output_df.set_index(['Component', 'Machine'], inplace=True)
print(output_df)
output_df.to_csv('OUTPUT.csv')

# Print our objective function value (Total Costs)
print (pulp.value(model.objective))

The first thing to do is to get rid of production[(component, 'IP01')]+production[(component, 'IP02')]+production[(component, 'IP03')]+production[(component, 'IP04')]+production[(component, 'IP05')] . I hope you realize how bad this type of hardcoding is. This only works if you only have machines IP01..IP05. Indeed for the example data, this is not the case. You need to make this data-driven. We have a sum construct for that.

To model shortage, the rhs of the supply=demand constraint needs to become

production == demand - shortage

where shortage is an additional nonnegative variable. You also need to add a cost term to the objective for this variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM