Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update num_nz in getCols #466

Merged
merged 1 commit into from
Feb 17, 2021
Merged

Update num_nz in getCols #466

merged 1 commit into from
Feb 17, 2021

Conversation

odow
Copy link
Collaborator

@odow odow commented Feb 17, 2021

Closes #465

Copy link
Member

@jajhall jajhall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see that the test in TestCAPI.c is useful, but I don't see what is achieved in the change to HighsSimplexInterface.cpp. Note that refactoring means that HighsSimplexInterface.cpp will soon no longer exist in master, but I can propagate the change to the new file that carries out the same actions - if I understand what they achieve!

@odow
Copy link
Collaborator Author

odow commented Feb 17, 2021

I wanted something like the Gurobi GRBgetvars: https://www.gurobi.com/documentation/9.0/refman/c_getvars.html

Retrieve the non-zeros for a set of variables from the constraint matrix. Typical usage is to call this routine twice. In the first call, you specify the requested set of variables, with NULL values for vbeg, vind, and vval. The routine returns the number of non-zero values for the specified variables in numnzP. That allows you to make certain that vind and vval are of sufficient size to hold the result of the second call.

The key bit is

     int num_cols;
     int num_nz;
     int matrix_start[2] = {-1, -1};
     Highs_getColsByRange(highs, 0, 1, &num_cols, NULL, NULL, NULL, &num_nz,
                          matrix_start, NULL, NULL);
     assert( num_nz == 2 );
     # Now we know what num_nz is, so we can allocate arrays for `matrix_indices` and `matrix_value`.

At present, num_nz is only updated if matrix_indices or matrix_value is non-null. That means you have to be defensive and allocate a vector that is getNumRows long.

@jajhall
Copy link
Member

jajhall commented Feb 17, 2021

I wanted something like the Gurobi GRBgetvars: https://www.gurobi.com/documentation/9.0/refman/c_getvars.html

Retrieve the non-zeros for a set of variables from the constraint matrix. Typical usage is to call this routine twice. In the first call, you specify the requested set of variables, with NULL values for vbeg, vind, and vval. The routine returns the number of non-zero values for the specified variables in numnzP. That allows you to make certain that vind and vval are of sufficient size to hold the result of the second call.

The key bit is

     int num_cols;
     int num_nz;
     int matrix_start[2] = {-1, -1};
     Highs_getColsByRange(highs, 0, 1, &num_cols, NULL, NULL, NULL, &num_nz,
                          matrix_start, NULL, NULL);
     assert( num_nz == 2 );
     # Now we know what num_nz is, so we can allocate arrays for `matrix_indices` and `matrix_value`.

At present, num_nz is only updated if matrix_indices or matrix_value is non-null. That means you have to be defensive and allocate a vector that is getNumRows long.

Great: now I understand completely!

Copy link
Member

@jajhall jajhall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense now!

@jajhall jajhall merged commit ed3a64f into ERGO-Code:master Feb 17, 2021
@jajhall
Copy link
Member

jajhall commented Feb 17, 2021

Makes sense now!

I guess that there's an analogous change to make to getRows in HiGHS. I'm on it.

@odow odow deleted the od/getCols branch February 17, 2021 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ENH: update num_nnz in getCols regardless
2 participants