Skip to content

Instantly share code, notes, and snippets.

@jgillis
Created November 21, 2023 15:22
Show Gist options
  • Save jgillis/45a408ec412c7032350668ac0aeadab2 to your computer and use it in GitHub Desktop.
Save jgillis/45a408ec412c7032350668ac0aeadab2 to your computer and use it in GitHub Desktop.
is_constraint_added
from casadi import *
opti = Opti()
x = opti.variable(10)
y = opti.variable(10)
opti.subject_to(x>=0)
opti.subject_to(x+y==0)
opti.subject_to(y>=0)
def is_constraint_added(opti,g):
# Was g already added?
for c in opti.debug.constraints():
try:
res = evalf(cse(c-g))
if norm_2(res)==0:
print("Allready added!")
print(opti.debug.describe(c))
return True
except:
pass
return False
is_constraint_added(opti,x+y==0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment