How to model the production plan
AnsweredHi there, I am new to Gurobi and I want to hand this question in python/gurobi,
Here are two tables:
product_ratio = {
'ParentProduct': ['A1', 'A1', 'A2', 'A2', 'A3', 'A3', 'A3'],
'ChildProduct': ['A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8'],
'Percentage': [0.6, 0.4, 0.667, 0.333, 0.25, 0.5, 0.25]
},
profit = {
'SKU': ['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8'],
'PROFIT': [100, 50, 60, 45, 35, 20, 15, 30]
}
Product logic: A1 could be sold directly or being used for further process into A2 and A3 as the ratio in the product ratio table, here 1 unit A1 could be used to produce 0.6 unit of A2 and 0.4 unit of A3 simultaneously, the same logic for the whole product tree.
Suppose I have 100 units of A1 and I want to know how to model if I want to find the maximized profit for the whole product combination here(profit info is for the profit/unit).
Thanks a lot!
-
To model this problem in Gurobi using Python, you'll want to create variables representing the quantities of each product that are either sold directly or used in the production of other products. The goal is to maximize the total profit subject to constraints based on the product ratios and initial quantities.
Here's a basic framework for setting up your model:
-
Data Preparation:
- Convert your
product_ratioandprofittables into a format suitable for use in Gurobi.
- Convert your
-
Model Initialization:
- Initialize the Gurobi model:
model = gp.Model().
- Initialize the Gurobi model:
-
Decision Variables:
- Create variables for the quantity of each product that is sold directly.
- Create variables for the quantity of each product used in production.
-
Objective Function:
- Maximize total profit: Sum of (profit per unit * quantity sold) for each product.
-
Constraints:
- Ensure the quantity of each 'ParentProduct' used in production does not exceed the available quantity.
- The production of 'ChildProduct' must respect the product ratios.
- Total quantity used for sale and production for each product should not exceed the available quantity.
-
Optimization:
- Call
model.optimize()to solve the model. - Extract the solution to determine the optimal quantities for sale and production.
- Call
Here's a skeleton of how your code might look:
import gurobipy as gp
# Initialize Model
model = gp.Model("Maximize Profit")
# Data
product_ratio = {...} # as provided
profit = {...} # as provided
initial_quantities = {'A1': 100, ...} # Define initial quantities for each product
# Decision Variables
sell_quantities = model.addVars(profit['SKU'], name="sell")
produce_quantities = model.addVars(product_ratio['ParentProduct'], name="produce")
# Objective
model.setObjective(gp.quicksum(profit['PROFIT'][i] * sell_quantities[profit['SKU'][i]] for i in range(len(profit['SKU']))), gp.GRB.MAXIMIZE)
# Constraints
# Add constraints based on product ratios and initial quantities
# ...
# Solve
model.optimize()
# Display solution
for v in model.getVars():
print(f'{v.varName}: {v.x}')Remember, this is a high-level framework. You'll need to flesh out the constraints based on your specific problem requirements, and ensure the data from your tables is correctly incorporated into the model.
0 -
Please sign in to leave a comment.
Comments
1 comment