Course policies and AI category¶
Read the Artificial Intelligence Policy and Collaboration Policy and Honor Code before starting. Assignment-specific directions control. The categories are No AI, AI permitted after independent work, and AI required.
Unless a problem says otherwise, its category is AI permitted after independent work. Spend about 30 minutes on each top-level problem without AI, solution pages, or another person’s help, stopping early if complete. You may consult lecture notes, textbooks, and nonsolution pages of the course website; bias toward those course sources. Afterward, AI and genuine collaboration, including coding together, are permitted. Everyone must contribute intellectually, understand the work, and verify it.
At the end of each top-level problem, add a concise AI disclosure: approximately how long the independent attempt took, how far you got, where you became stuck, any AI or collaborative help used afterward, and how you verified it. If you used no AI, say so. Do not submit prompts or transcripts. Time estimates help the instructor improve the assignment and are not a speed test.
Overview¶
This assignment covers nonlinear constrained optimization, specifically:
Lecture 18: Introduction to Constrained Optimization
Lecture 19: KKT Conditions, Multipliers, and Sensitivity
Lecture 20: Constraint Qualifications
You may do the derivations on paper; upload a photo or scan of that work with your notebook. The Python cells are short.
Sign convention. Use the convention from Lectures 18 and 19 throughout:
with . Problem 2 asks how Pyomo’s sign convention for duals relates to this one.
### Load Python libraries
import sys
if "google.colab" in sys.modules:
!wget "https://raw.githubusercontent.com/ndcbe/optimization/main/notebooks/helper.py"
import helper
helper.easy_install()
else:
sys.path.insert(0, "../")
import helper
helper.set_plotting_style()
import numpy as np
import sympy as sym
import pyomo.environ as pyo
x1, x2 = sym.symbols("x1 x2", real=True)Problem 1: Convexity, local minimizers and second-order conditions¶
Recall that a nonlinear program is convex when:
the objective is convex
every inequality has a convex , and
every equality is affine.
Then every local minimizer is a global minimizer. The test is sufficient, not necessary: a problem can fail it and still be convex.
1a. Is it convex?¶
For each problem below, decide whether the test certifies convexity. If it does not, decide whether the problem is nonetheless convex. To show a feasible set is not convex, give two feasible points whose midpoint is infeasible.
1a(i). s.t. , .
Answer:
1a(ii). s.t. .
Answer:
1a(iii). s.t. , , . Hint: is convex? Can the same feasible set be written with a convex constraint function?
# Optional: You can use finite difference or Sympy to compute the Hessian of the function f(x1, x2) = 1 - x1*x2.
# Add your solution hereAnswer:
1b. Classify the KKT points of the circle problem¶
For s.t. :
Find every KKT point and its multiplier , with .
At each one, find the critical directions (here, directions with ) and evaluate on them.
Use the second-order conditions to classify each point. Which is the global minimizer, and how do you know a global minimizer exists?
# Add your solution hereAnswer:
| KKT point | Critical directions | Classification | ||
|---|---|---|---|---|
1c. Replace the equality by an inequality¶
Now solve s.t. . Is this problem convex? Which of the two points from 1b is still a KKT point, and which condition does the other one fail?
Answer:
1d. What does a local solver return?¶
The code below solves the equality-constrained circle problem with Ipopt from two starting points. Run it. Which point does each run return, and what termination condition does Ipopt report? Explain the run from using 1b. Hint: what happens to along the iterates?
for start in [(1.0, 1.0), (0.5, 0.9)]:
m = pyo.ConcreteModel()
m.x1 = pyo.Var(initialize=start[0])
m.x2 = pyo.Var(initialize=start[1])
m.obj = pyo.Objective(expr=m.x1 + m.x2)
m.h = pyo.Constraint(expr=m.x1**2 + m.x2**2 == 1)
res = pyo.SolverFactory("ipopt").solve(m)
print(f"start {start}: {res.solver.termination_condition}, "
f"x = ({pyo.value(m.x1):.4f}, {pyo.value(m.x2):.4f}), f = {pyo.value(m.obj):.4f}")Answer:
| Start | Termination condition | returned | Minimizer or maximizer? | |
|---|---|---|---|---|
AI disclosure¶
Approximately how long was your independent attempt?
How far did you get? where did you get stuck?
What AI or collaborative help did you use afterward, and how did you verify it?
If you used no AI, answer “not applicable”.
Problem 2: KKT conditions for a small nonlinear program¶
Consider
Sketch the feasible region and a few contours of before you start. It will help with every part.
2a. Write the KKT conditions¶
Write the Lagrangian and all four groups of KKT conditions for this problem: stationarity, primal feasibility, dual feasibility and complementarity. Write them component by component, not only in vector form.
# Add your solution hereAnswer:
2b. Check the candidate ¶
Which constraints are active at ? Solve the stationarity equations for the multipliers. Is a KKT point? Justify each of the four groups of conditions.
# Add your solution hereAnswer:
| value at | ||
| active? | ||
| multiplier |
2c. Check the candidate ¶
Is feasible? Which constraints are active? Is it a KKT point? If not, which condition fails, and what does tell you about a better direction to move?
# Add your solution hereAnswer:
| value at | ||
| active? |
2d. Check with Pyomo and Ipopt¶
Complete the model below, solve it with Ipopt, and compare the solution to 2b. Pyomo stores the
constraint duals in the dual suffix. Compare the reported duals to your : what is the
relationship between Pyomo’s sign convention and the one in Lecture 19?
def build_problem2(epsilon=0.0):
'''Problem 2, with the second constraint perturbed to g2(x) + epsilon <= 0 (used in Problem 3).'''
m = pyo.ConcreteModel()
m.x1 = pyo.Var(initialize=0.0)
m.x2 = pyo.Var(initialize=0.0)
m.dual = pyo.Suffix(direction=pyo.Suffix.IMPORT)
# Add your solution here
return m
m1 = build_problem2()
results = pyo.SolverFactory("ipopt").solve(m1)
print("termination condition:", results.solver.termination_condition)
print("x* =", pyo.value(m1.x1), pyo.value(m1.x2), " f* =", pyo.value(m1.obj))
print("Pyomo duals: g1 ->", m1.dual[m1.g1], " g2 ->", m1.dual[m1.g2])Answer:
| Pyomo dual | ||
| Lecture 19 convention |
AI disclosure¶
Approximately how long was your independent attempt?
How far did you get? where did you get stuck?
What AI or collaborative help did you use afterward, and how did you verify it?
If you used no AI, answer “not applicable”.
Problem 3: Multipliers as sensitivities¶
Perturb the second constraint of Problem 2 as in Lecture 19:
Positive tightens the constraint; negative relaxes it.
3a. Predict the optimal objective¶
Using only your multipliers from Problem 2, predict the optimal objective for , 0.1 and 0.5. State the first-order formula you used.
Answer:
| -0.1 | 0.1 | 0.5 | |
|---|---|---|---|
| predicted |
3b. Re-solve and compare¶
Re-solve with build_problem2(epsilon) for the three values of . Tabulate the predicted
value, the re-solved value and the difference.
# Add your solution hereAnswer:
| predicted | re-solved | re-solved predicted | |
|---|---|---|---|
| -0.1 | |||
| 0.1 | |||
| 0.5 |
3c. Interpret¶
Why does the error in the prediction grow as grows?
Is the linear prediction above or below the re-solved value for both signs of ? What does that tell you about the shape of near ?
# Add your solution hereAnswer:
AI disclosure¶
Approximately how long was your independent attempt?
How far did you get? where did you get stuck?
What AI or collaborative help did you use afterward, and how did you verify it?
If you used no AI, answer “not applicable”.
Problem 4: Constraint qualifications at three points¶
Consider three problems, each with a known minimizer .
Case A. Problem 2 at .
Case B. A disk with a tangent line, at :
Case C. Two disks that touch at one point, at :
Sketch Cases B and C before you start.
4a. LICQ¶
For each case, list the active constraints, write the matrix of active constraint gradients at , and decide whether LICQ holds (Lecture 20).
# Add your solution hereAnswer:
| Case | Active constraints | Active-gradient matrix | Rank | LICQ? |
|---|---|---|---|---|
| A | ||||
| B | ||||
| C |
4b. MFCQ¶
For each case, either give a direction with for every active inequality, or explain why no such direction exists.
Answer:
| Case | Direction , or why none exists | MFCQ? |
|---|---|---|
| A | ||
| B | ||
| C |
4c. KKT multipliers¶
For each case, find all KKT multipliers at . Are they unique, a set (describe it), or nonexistent? Connect your answer to the theorems in Lecture 20.
Answer:
| Case | KKT multipliers | Unique, a set, or none? |
|---|---|---|
| A | ||
| B | ||
| C |
4d. What does a solver see?¶
The code below solves Case B from three starting points and Case C from one, reporting the termination condition, the solution, and the multipliers in the Lecture 19 sign convention. Run it. Solver versions differ, so report the values your run produces.
def solve_case(case, x_init):
m = pyo.ConcreteModel()
m.x1 = pyo.Var(initialize=x_init[0])
m.x2 = pyo.Var(initialize=x_init[1])
m.dual = pyo.Suffix(direction=pyo.Suffix.IMPORT)
if case == "B":
m.obj = pyo.Objective(expr=-m.x1 - 2 * m.x2)
m.g1 = pyo.Constraint(expr=m.x1**2 + m.x2**2 - 5 <= 0)
m.g2 = pyo.Constraint(expr=m.x1 + 2 * m.x2 - 5 <= 0)
else:
m.obj = pyo.Objective(expr=m.x1 + m.x2)
m.g1 = pyo.Constraint(expr=(m.x1 - 1) ** 2 + m.x2**2 - 1 <= 0)
m.g2 = pyo.Constraint(expr=(m.x1 + 1) ** 2 + m.x2**2 - 1 <= 0)
results = pyo.SolverFactory("ipopt").solve(m)
u = (-m.dual[m.g1], -m.dual[m.g2]) # Lecture 19 sign convention
print(f"Case {case}, start {x_init}: {results.solver.termination_condition}")
print(f" x = ({pyo.value(m.x1):.6g}, {pyo.value(m.x2):.6g}), f = {pyo.value(m.obj):.6g}")
print(f" u = ({u[0]:.6g}, {u[1]:.6g})")
if case == "B":
print(f" 2*u1 + u2 = {2 * u[0] + u[1]:.6g}")
print(f" g = ({pyo.value(m.g1.body):.3g}, {pyo.value(m.g2.body):.3g})")
for start in [(0, 0), (-1, 0), (3, 3)]:
solve_case("B", start)
solve_case("C", (0.5, 0.5))4e. Interpret the solver output¶
Case B. Do the multipliers change with the starting point? Do they satisfy your answer to 4c? Why can a solver return different multipliers for the same ?
Case C. What termination condition does Ipopt report? Which numbers in the output tell you that something is wrong anyway? Explain them using 4a--4c.
Lecture 20 describes degenerate constraints. Which of Cases B and C is degenerate, and is the degeneracy local or global?
Answer:
Case B
| Start | |||
|---|---|---|---|
Case C
| Termination condition | constraint values | |||
|---|---|---|---|---|
AI disclosure¶
Approximately how long was your independent attempt?
How far did you get? where did you get stuck?
What AI or collaborative help did you use afterward, and how did you verify it?
If you used no AI, answer “not applicable”.