Last active
March 15, 2016 12:43
-
-
Save adbuerger/ee5c4de0f8eeec5d29b0 to your computer and use it in GitHub Desktop.
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
import numpy as np | |
# Tested with CasADi 2.4.4 | |
import casadi as ca | |
# Optimization variables | |
x = ca.MX.sym("x", 1, 2) | |
# Objective | |
f = x[0]**2 + x[1]**2 | |
# Constraints | |
a = ca.MX.sym("a", 1) | |
b = ca.MX.sym("b", 1) | |
g = 2*a -1 + b | |
g_fcn = ca.MXFunction("a", [a, b], [g]) | |
g_fcn = g_fcn.expand() | |
# Set up optimization variable y | |
REPEATED = 1 | |
# Both versions lead to the same result | |
if REPEATED: | |
# This one works with OpenMP | |
y = ca.MX.sym("y", 1, 1) | |
Y = ca.repmat(y, 1, 2) | |
else: | |
# This one does not, and causes: | |
# | |
# CasADi warning: "OpenMP not yet supported for reduced outputs. | |
# Falling back to serial mode." issued on line 73 of file | |
# "/home/ab/casadi-src/casadi/core/function/map_internal.cpp". | |
y = ca.MX.sym("y", 1, 1) | |
Y = y | |
[g] = g_fcn.map([x, Y], "openmp") | |
nlp = ca.MXFunction("nlp", \ | |
ca.nlpIn(x = ca.horzcat([x, y])), \ | |
ca.nlpOut(f = f, g = g)) | |
nlpsolver = ca.NlpSolver("nlpsolver", "ipopt", nlp) | |
x0 = np.ones((1, x.shape[1] + y.shape[1])) | |
sol = nlpsolver(x0 = x0, lbg = 0, ubg = 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment