Skip to content

Find a way to calculate sparsity from NLP module definition #5

Description

@rads2995

There is, ideally, a better way to achieve the following:

    pub fn jacobian_constraint_elements(i_row: &mut [ipopt::ipindex], j_col: &mut [ipopt::ipindex]) -> () {

        i_row[0] = 0;
        j_col[0] = 0;
        i_row[1] = 0;
        j_col[1] = 1;
        i_row[2] = 0;
        j_col[2] = 2;
        i_row[3] = 0;
        j_col[3] = 3;
        i_row[4] = 1;
        j_col[4] = 0;
        i_row[5] = 1;
        j_col[5] = 1;
        i_row[6] = 1;
        j_col[6] = 2;
        i_row[7] = 1;
        j_col[7] = 3; 
    }

Which does not involve having to manually type the index for each specific component of this matrix.
I would prefer to obtain the information above directly from the function definition, such as the following:

    pub fn jacobian_constraint_function(x: &[ipopt::ipnumber], jac_g: &mut [ipopt::ipnumber]) -> () {

        jac_g[0] = x[1] * x[2] * x[3];
        jac_g[1] = x[0] * x[2] * x[3];
        jac_g[2] = x[0] * x[1] * x[3];
        jac_g[3] = x[0] * x[1] * x[2];
        jac_g[4] = 2.0 * x[0];
        jac_g[5] = 2.0 * x[1];
        jac_g[6] = 2.0 * x[2];
        jac_g[7] = 2.0 * x[3];
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions