Created
November 21, 2023 15:22
-
-
Save jgillis/45a408ec412c7032350668ac0aeadab2 to your computer and use it in GitHub Desktop.
is_constraint_added
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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