This file contains hidden or 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
import casadi | |
from casadi import * | |
from casadi.casadi import OPTI_INEQUALITY, Opti_bounded | |
import matplotlib.pyplot as plt | |
# https://epubs.siam.org/doi/pdf/10.1137/16M1062569 | |
m1 = 1 | |
m2 = 0.3 |
This file contains hidden or 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
class Node: | |
def __init__(self,val): | |
self.val = val | |
self.nodes = [] | |
class AutoBrancher: | |
OPEN = 0 | |
DONE = 1 | |
def __init__(self): |
This file contains hidden or 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
Find and replace in casadi file: | |
casadi.Function('f',{x},{x},struct('dump_dir','matching_string')).save('test.casadi') | |
casadi.Function('f',{x},{x},struct('dump_dir','replace__string')).save('test2.casadi') | |
Check the difference in test and test2 to see the replacement. | |
Preservation of length only. |
This file contains hidden or 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 * | |
x = MX.sym('x') | |
y = MX.sym('y') | |
p = MX.sym('p') | |
nlp = {"x":vertcat(x,y),"p":p,"f":(x-2)**4+(y-3)**2} | |
solver = nlpsol('solver','ipopt',nlp) |
This file contains hidden or 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
# | |
# This file is part of rockit. | |
# | |
# rockit -- Rapid Optimal Control Kit | |
# Copyright (C) 2019 MECO, KU Leuven. All rights reserved. | |
# | |
# Rockit is free software; you can redistribute it and/or | |
# modify it under the terms of the GNU Lesser General Public | |
# License as published by the Free Software Foundation; either | |
# version 3 of the License, or (at your option) any later version. |
This file contains hidden or 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
import casadi.* | |
x = MX.sym('x'); | |
y = MX.sym('y'); | |
xy = [x;y]; | |
p = MX.sym('p'); | |
nlp = struct; | |
nlp.x = xy; |
This file contains hidden or 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 SX, vertcat, inf | |
# Declare variables | |
x = SX.sym("x") | |
y = SX.sym("y") | |
z = SX.sym("z") | |
# Formulate the NLP | |
f = x**2 + 100*z**2 | |
g = z + (1-x)**2 - y |
This file contains hidden or 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
import numpy as np | |
from ctypes import * | |
class CasadiSparsity: | |
""" | |
Compressed Columun storage sparsity pattern | |
""" | |
def __init__(self,sp): | |
self.n_row = sp[0] | |
self.n_col = sp[1] |
This file contains hidden or 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 * | |
x=SX.sym("x") | |
y=SX.sym("y") | |
f = (1-x)**2+100*(y-x**2)**2 | |
nlp={'x':vertcat(x,y), 'f':f,'g':x+y} | |
fcn = Function('f', [x, y], [f]) | |
callback_inputs = dict() |
This file contains hidden or 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
import casadi.* | |
opti = Opti(); | |
x = opti.variable(2); | |
fx = sin(x)-[2;0.3]; | |
opti.minimize(sumsqr(fx)); |