Home > front end >  Creating a conditional constraint for a specific Python Pulp Maximization problem
Creating a conditional constraint for a specific Python Pulp Maximization problem

Time:12-19

I can't manage to find a way to create a constraint that sounds like this: for example I have 2 variables, one is a regular product and the other one is a super rare product. In order to have a super rare product, you will need to have already 25 of the regular version of that product. This can be stackable (e.g. if the algorithm select 75 of that regular product, it can have 3 super rare). The reason for this is that the super rare is more profitable, so if I place it without any constraints, it will select only the super rare ones. Any ideas on how to write such a constraint?

Thanks in advance!

Part of the code:

hwProblem = LpProblem("HotWheels", LpMaximize)

# Variables
jImportsW_blister = LpVariable("HW J-Imports w/ blister", lowBound=20, cat=LpInteger)  # regular product
jImportsTH = LpVariable("HW J-Imports treasure hunt", lowBound=None, cat=LpInteger)  # super rare product

# Objective Function
hwProblem  = 19 * jImportsW_blister   350 * jImportsTH  # profit for each type of product

# Constraints
hwProblem  = jImportsW_blister <= 50, "HW J-Imports maximum no. of products"
hwProblem  = jImportsTH <= jImportsW_blister / 25
                            # ^this is where the error is happening

CodePudding user response:

There's a few "missing pieces" here regarding the structure of your model, but in general, you can limit the "super rare" (SR) by doing something like:

prob  = SR <= R / 25
  • Related