All problems
Complementary Slackness Check
Problem
Complementary slackness for a KKT point requires lambda_i * g_i(x) = 0 for every inequality constraint, together with nonnegative multipliers.
Given the constraint values gaps = g_i(x) and the multipliers, return True when every multiplier is nonnegative and every product is within tol (default 1e-9) of zero.
Hint
An inactive constraint must carry a zero multiplier, and an active one may carry a positive multiplier.
Test cases
case 1
in: [[0,1.5],[2,0]]
expected: true
case 2
in: [[1,1],[1,1]]
expected: false
case 3
in: [[0,0],[0,0]]
expected: true
case 4
in: [[1,0],[-1,0]]
expected: false
Starter codePython
def complementary_slackness(gaps, multipliers, tol=1e-9):
# Your code here
pass4 test cases · run your code against them in the editor