Quiz on Linear Programming
1. Which of the following describes the simplex method for linear programming?
- Incorrect. This describes the interior point method
- Correct. The simplex method is an effective strategy for linear programming problems where the solution is always at the intersection of constraints. The interior point method takes a different approach by starting with a feasible initial guess and iteratively reducing the barrier term until reaching the solution.
- Incorrect. This is a description of particle swarm optimization
- Incorrect. This is a description of a genetic algorithm
2. The soft drink production exercise is revisited, but from the perspective of a consumer trying to minimize cost. The consumer must buy at least 2 units of Product 1 and 3 units of Product 2. Change the lower bounds for x1 and x2 and change the Maximize to Minimize. Solve the problem to find the optimal cost.
from gekko import GEKKO
m = GEKKO()
x1 = m.Var(lb=0, ub=5) # Product 1
x2 = m.Var(lb=0, ub=4) # Product 2
m.Maximize(100*x1+125*x2) # Profit function
m.Equation(3*x1+6*x2<=30) # Units of A
m.Equation(8*x1+4*x2<=44) # Units of B
m.solve(disp=False)
p1 = x1.value[0]; p2 = x2.value[0]
print ('Product 1 (x1): ' + str(p1))
print ('Product 2 (x2): ' + str(p2))
print ('Profit : ' + str(100*p1+125*p2))
- Incorrect. This is the maximum. Switch to m.Minimize().
- Correct. Lower bounds changed to 2 and 3 and Maximize changed to Minimizefrom gekko import GEKKO
m = GEKKO()
x1 = m.Var(lb=2, ub=5) # Product 1
x2 = m.Var(lb=3, ub=4) # Product 2
m.Minimize(100*x1+125*x2) # Profit function
m.Equation(3*x1+6*x2<=30) # Units of A
m.Equation(8*x1+4*x2<=44) # Units of B
m.solve(disp=False)
p1 = x1.value[0]; p2 = x2.value[0]
print ('Product 1 (x1): ' + str(p1))
print ('Product 2 (x2): ' + str(p2))
print ('Profit : ' + str(100*p1+125*p2))
- Incorrect. Change the lower bounds and change Maximize to Minimize
- Incorrect. Change the lower bounds and change Maximize to Minimize
3. Ingredients (A and B) are used to make 2 products (Products 1 and 2). Production requires:
- 1 unit of A and 4 units of B for Product 1
- 2 units of A and 6 units of B for Product 2
The available supply is A = 20 and B = 40. Choose the Python code that defines the E matrix and b vector for the supply constraints in this linear programming problem.
$$\mathrm{minimize} \quad c\,x$$ $$\quad\quad\quad\quad E \, x<b$$
- Incorrect. Missing the matrix brackets and incorrect numbers
- Incorrect. The values in vector b need to be switched
- Correct. The two inequality equations are for supply limitations for A: `x_1 + 2 x_2 \le 40` and for B: `6 x_1 + 4 x_2 \le 20`
- Incorrect. Answer is C
4. Select the code that expresses the matrix as a sparse matrix in coordinate index form with row, column, value rows with index-1 that starts at 1 instead of the typical Python convention of 0.
$$E = \begin{bmatrix} 2 & 4 \\ 1 & 0 \end{bmatrix}$$
- Incorrect. The zeros entries are omitted for a sparse matrix
- Correct. The index and values for the three non-zero matrix entries with index-1.
- Incorrect. The three rows are row, column, value. The index is incorrect and zeros are omitted in a sparse matrix.
- Incorrect. This is the transpose of the correct answer.