メインコンテンツへスキップ

How to model the production plan

回答済み

コメント

1件のコメント

  • Gurobot (AI-generated response)
    • Gurobi Staff

    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:

    1. Data Preparation:

      • Convert your product_ratio and profit tables into a format suitable for use in Gurobi.
    2. Model Initialization:

      • Initialize the Gurobi model: model = gp.Model().
    3. 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.
    4. Objective Function:

      • Maximize total profit: Sum of (profit per unit * quantity sold) for each product.
    5. 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.
    6. Optimization:

      • Call model.optimize() to solve the model.
      • Extract the solution to determine the optimal quantities for sale and production.

    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

サインインしてコメントを残してください。