0
$\begingroup$

enter image description here

Q1. If bicycles of types A and H are produced, then bicycles of type C can be produced with 20% shorter working hours, while selling profit of bicycles type H can be 20% higher.

Q2: If bicycles of types B and G are produced, then a minimum of one of the types C and F should be produced, however, total personnel requirements should not exceed 180 hours.

Bicycle_Production:

# Data
types = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H']

profits = [45, 100, 65, 80, 120, 95, 70, 30]

working_hours = [20.5, 13.5, 15.0, 16.5, 24.0, 32.0, 25.5, 19.0]

steel_mass = [14.5, 22.0, 13.0, 8.0, 16.5, 9.5, 21.0, 18.5]

rental_costs = [1000, 1200, 2000, 1400, 2500, 2100, 1800, 1100]

max_hours = 200

max_steel = 770

max_rental_cost = 3500

# Decision variables
x = LpVariable.dicts("Number_of_Bicycles", types, lowBound=0, cat='Integer')

y = LpVariable.dicts("Chosen", types, cat='Binary')

# Objective function
problem += lpSum([profits[i] * x[types[i]] for i in range(len(types))]), "Total_Profit" 

# Constraints
problem += lpSum([working_hours[i] * x[types[i]] for i in range(len(types))]) <= max_hours, "Working_Hours_Constraint"

problem += lpSum([steel_mass[i] * x[types[i]] for i in range(len(types))]) <= max_steel, "Steel_Mass_Constraint"

problem += lpSum([rental_costs[i] * y[types[i]] for i in range(len(types))]) <= max_rental_cost, "Rental_Costs_Constraint"

#Linking constraints
for i in range(len(types)):
    problem += x[types[i]] <= 1000 * y[types[i]], f"Linking_Constraint_{types[i]}"
$\endgroup$
6
  • 1
    $\begingroup$ No problem in helping you with this, but ... it seems like a homework ... so, have you tried at least listing what would be the variables? $\endgroup$ Commented Jun 7 at 17:06
  • 1
    $\begingroup$ I have already formulated the structure. These are as follows: x_i >= 0 0<= y_i <= 1 MAXIMIZE 45* x_A + 100* x_B + 65* x_C + 80* x_D + 120* x_E + 95* x_F + 70* x_G + 30* x_H SUBJECT TO Working_Hours_Constraint: 20.5 x_A+ 13.5 x_B + 15 x_C+ 16.5 x_D + 24 x_E+ 32 x_F + 25.5 x_G+ 19 x_H <=200 Steel_Mass_Constraint: 14.5 x_A + 22 x_B+ 13 x_C + 8 x_D+ 16.5 x_E + 9.5 x_F+ 21 x_G + 18.5 x_H <= 770 Rental_Costs_Constraint: 1000 y_A + 1200 y_B + 2000 y_C+ 1400 y_D + 2500 y_E + 2100 y_F + 1800 y_G+ 1100 y_H <= 3500 $\endgroup$
    – Ankit Basu
    Commented Jun 7 at 17:12
  • 1
    $\begingroup$ Linking Constraints : (-) 1000 *y_i + x_i <= 0 (where i= types of bicycles). For question 2 : y_C + y_F >= y_B + y_G -1 $\endgroup$
    – Ankit Basu
    Commented Jun 7 at 17:20
  • $\begingroup$ @RobPratt have done it sir. $\endgroup$
    – Ankit Basu
    Commented Jun 7 at 18:50
  • 1
    $\begingroup$ @MatheusDiógenesAndrade, sir I have included the formulations in my question. This is a 5 question assignment and this are the last 2 questions. I have formulated the logical constraints for the 2 questions, but am unable to create the linear equations further to include the other conditions. Q1. y_A + y_H +1 >= y_C Q2. y_C + y_F >= y_B + y_G -1 $\endgroup$
    – Ankit Basu
    Commented Jun 7 at 18:55

1 Answer 1

1
$\begingroup$

For both Q1 and Q2, you need to enforce $y_i = 1 \implies x_i \ge 1$, which you can do via linear constraint $y_i \le x_i$.

For Q1:

  • Replace $15 x_C$ with $15(1 - 0.2 y_A y_H) x_C$ in the working hours constraint and then linearize.
  • Replace $30 x_H$ with $30(1 + 0.2 y_A) x_H$ in the objective and then linearize.

For Q2:

  • Impose $y_B + y_G - 1 \le y_C + y_F$ as you suggested in the comments.
  • Replace $\le 200$ with $\le 200 - 20 y_B y_G$ in the working hours constraints and then linearize.
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.