Skip to content
DeepForgeby svx
All problems

Lagrangian Penalty Update

Problem

Take one dual ascent step on the Lagrange multiplier.

Return max(0, lambda + lr * (cost - limit)) so the multiplier grows only while the constraint is violated.

Hint

The projection onto the non-negative orthant keeps the multiplier valid.

Test cases

case 1
in: [0,2,1,0.5]
expected: 0.5
case 2
in: [1,0,1,0.5]
expected: 0.5
case 3
in: [0.5,1,1,1]
expected: 0.5
case 4
in: [0,0,1,2]
expected: 0
Starter codePython
def lagrangian_penalty_update(lambda_, cost, limit, lr):
    # Your code here
    pass

4 test cases · run your code against them in the editor