Giter Site home page Giter Site logo

Comments (1)

ernestds avatar ernestds commented on June 1, 2024

Even simpler example:

import casadi as ca
x = ca.MX.sym("x",1)
p = ca.MX.sym("p",1)
g = -x
print(ca.detect_simple_bounds(x,p,g,ca.MX([-2]),ca.MX([-2])))

g = x
print(ca.detect_simple_bounds(x,p,g,ca.MX([-2]),ca.MX([-2])))

Half assed hacky fix?

x = ca.MX.sym("x",2)
p = ca.MX.sym("p",2)
lbg = ca.MX([-2, -2])
ubg = ca.MX([2, -1])

g = p[0] * x + p[1]
[gi,lbx,ubx,lam_f,lam_b] = ca.detect_simple_bounds(x,p,g,lbg,ubg)
dx = 1.
simple_bounds_idx = list(set(range(g.numel())) - set(gi))
f_g = ca.Function('x',[x,p], [g[simple_bounds_idx]],)
f_lbg = ca.Function('x',[x,p], [lbg[simple_bounds_idx]],)
f_ubg = ca.Function('x',[x,p], [ubg[simple_bounds_idx]],)
constant = f_g(0,p)
coeff = (f_g(dx,p) - constant)/dx

lbg = f_lbg(0,p)
ubg = f_ubg(0,p)

lbx_f = ca.Function('lbx',[p],[ca.if_else(coeff >= 0, (lbg - constant)/coeff,(ubg - constant)/coeff)])
ubx_f = ca.Function('ubx',[p],[ca.if_else(coeff >= 0, (ubg - constant)/coeff,(lbg - constant)/coeff)])
p0 = [-1,2]
print(lbx_f(p0))
print(ubx_f(p0))

p0 = [1,2]
print(lbx_f(p0))
print(ubx_f(p0))

from casadi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.