I am struggling to select the correct cost_coefficient that is dependent on lpSum of the decision variables. I need to compare the lpSum(binary_option[option] for option in options) against the elements in threshold. The first element which is greater than lpSum(binary_option[option] for option in options), its corresponding cost coefficient (with the same index) should be used as the multiplier for the objective function. The following is what i have so far.
Please let me know how i can correctly formulate this.
``from pulp import LpProblem, LpVariable, lpSum, LpMinimize
# Define the options
options = ['A', 'B', 'C', 'D', 'E', 'F']
# Define the thresholdsand their associated cost coefficients
cost_coefficient = [2, 6, 8, 11, 16, 20, 34]
threshold = [1, 2, 3, 4, 5, 6, 7]
# Create a PuLP ILP problem
model = LpProblem("Minimize_Cost", LpMinimize)
# Decision Variables: binary variables for each option
binary_option = {option: LpVariable(f"{option}", cat='Binary') for option in options}
# Decision Variables: binary variables for each cost coefficient
cost_coefficient_selection = []
for i in range(len(threshold)):
var_name = f"cost_sel_{i}"
cost_coefficient_selection.append(LpVariable(var_name, cat='Binary'))
# Total requirement is the sum of selected options
requirement = lpSum(binary_option[option] for option in options)
# Constraints: coefficient[i] ==1 for first threshold[i] that is greater than requirement
for i, t in enumerate(threshold):
model += requirement >= t, f"Threshold_{i}"
# Objective: Minimize the total cost
model += lpSum(requierment * cost_coefficient_selection[i] *cost_coefficient[i] )for i in range(len(threshold))
# Solve the ILP problem
model.solve()`
enter image description here
Emma Shibata is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.