// Assume by the time this constructor is called, the number of parameters and constraints has been finalized
InteriorPointOptimizer::InteriorPointOptimizer( const OptimizerSystem& sys )
        : OptimizerRep( sys ) {

        int n = sys.getNumParameters();
        int m = sys.getNumConstraints();

        if( n < 1 ) {
            const char* where = " InteriorPointOptimizer Initialization";
            const char* szName = "dimension";
            SimTK_THROW5(SimTK::Exception::ValueOutOfRange, szName, 1, n, INT_MAX, where); 
        }

        // Initialize arrays to store multipliers -- will be used for warm starts
        mult_x_L = new Number[n];
        mult_x_U = new Number[n];
        mult_g = new Number[m];
        for(int i=0;i<n;i++) mult_x_L[i] = mult_x_U[i] = 0;
        for(int i=0;i<m;i++) mult_g[i] = 0;

        g_L = new Number[m];
        g_U = new Number[m];
        /* set the bounds on the equality constraint functions */
        for(int i=0;i<sys.getNumEqualityConstraints();i++){
            g_U[i] = g_L[i] = 0.0;
        }
        /* set the bounds on the inequality constraint functions */
        for(int i=sys.getNumEqualityConstraints();i<m;i++){
            g_U[i] = SimTK::Real(POSITIVE_INF);
            g_L[i] = 0.0;
        }

        firstOptimization = true;
    } 
Esempio n. 2
0
    void calcGradient(const Differentiator::DifferentiatorRep& diff, Differentiator::Method m,
                      const Vector& y0, const Real* fy0p, Vector& gf) const override 
    { 
        if (getNumFunctions() != 1)
            SimTK_THROW5(Differentiator::OpNotAllowedForFunctionOfThisShape,
                "calcGradient", "1xn", "JacobianFunction", getNumFunctions(), getNumParameters());

        Vector fy0v(1);
        if (fy0p) fy0v[0] = *fy0p;
        else {diff.nCallsToUserFunction++; call(y0, fy0v);}
        diff.calcJacobian(*this,m,y0,fy0v,gf);
    }
Esempio n. 3
0
    void calcDerivative(const Differentiator::DifferentiatorRep& diff, Differentiator::Method m,
                        Real y0, const Real* fy0p, Real& dfdy) const override
    {
        if (getNumFunctions() != 1 || getNumParameters() != 1)
            SimTK_THROW5(Differentiator::OpNotAllowedForFunctionOfThisShape,
                "calcDerivative", "1x1", "JacobianFunction", getNumFunctions(), getNumParameters());

        const Vector y0v(1, y0);
        Vector fy0v(1);
        if (fy0p) fy0v[0] = *fy0p;
        else {diff.nCallsToUserFunction++; call(y0v, fy0v);}
        Matrix dfdym(1,1, &dfdy); // refers to dfdy directly as data
        diff.calcJacobian(*this,m,y0v,fy0v,dfdym); 
    }
Esempio n. 4
0
    void calcDerivative(const Differentiator::DifferentiatorRep& diff, Differentiator::Method m,
                        Real y0, const Real* fy0p, Real& dfdy) const override
    {
        if (getNumParameters() != 1)
            SimTK_THROW5(Differentiator::OpNotAllowedForFunctionOfThisShape,
                "calcDerivative", "1x1", "GradientFunction", 1, getNumParameters());

        const Vector y0v(1, y0);
        Real fy0;
        if (fy0p) fy0 = *fy0p; 
        else {diff.nCallsToUserFunction++; call(y0v, fy0);}
        Vector dfdyv(1, &dfdy); // refers to dfdy data directly
        diff.calcGradient(*this,m,y0v,fy0,dfdyv); 
    }
Esempio n. 5
0
LBFGSBOptimizer::LBFGSBOptimizer( const OptimizerSystem& sys )
:   OptimizerRep( sys ),
    factr( 1.0e7) {
    int n,i;

    n = sys.getNumParameters();

    if( n < 1 ) {
        const char* where = "Optimizer Initialization";
        const char* szName = "dimension";
        SimTK_THROW5(SimTK::Exception::ValueOutOfRange, szName, 1,  n, INT_MAX, where);
    }

    /* We don't yet know what kinds of bounds we'll have so set the bounds
       descriptor nbd to an illegal value. */
    nbd = new int[n];
    for(i=0;i<n;i++)
        nbd[i] = -1;
}