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

Modifying row coefficient via the C interface #655

Open
jetuk opened this issue Jun 25, 2024 · 5 comments
Open

Modifying row coefficient via the C interface #655

jetuk opened this issue Jun 25, 2024 · 5 comments

Comments

@jetuk
Copy link

jetuk commented Jun 25, 2024

I would like to modify a row's coefficient and resolve a model via the C interface. I noticed there was a brief mention of this functionality in #339 , but I do not think that functionality has been added. Is this something of interest to the project, and could the code in #339 be a basis for a pull request? If so, I am happy to try to implement that.

@jjhforrest
Copy link
Contributor

Looking at #339, I can see problems - including large overheads. But I think you have a much simpler request if you are just modifying one coefficient - even simpler if you are not changing the coefficient to or from zero.
ClpModel.cpp has -
/// Modify one element of a matrix
inline void modifyCoefficient(int row, int column, double newElement,
bool keepZero = false)
and it should be easy to transfer functionality to the C interface.

Will this be done outside a solve - or at least before cuts have been added? Inside Cbc there are really two solvers - one as passed in and the other after cuts and fixing.

So it could be done at Osi level e.g.
CBCLIB_EXPORT void CBC_LINKAGE
Osi_modifyCoef(void *osi, int row, int column, double newValue);

or at Cbc level
CBCLIB_EXPORT void CBC_LINKAGE
Cbc_modifyCoef(Cbc_Model *model, int row, int column, double newValue );

@jetuk
Copy link
Author

jetuk commented Jun 26, 2024

Thanks for the advice. I'll take a look over the next couple of days. Will you want this against the stable or master branch (or both)?

@jetuk
Copy link
Author

jetuk commented Jun 26, 2024

Will this be done outside a solve - or at least before cuts have been added?

For my use case, the update is between solves.

@jjhforrest
Copy link
Contributor

Do it to master. Looking at code, modifyCoefficient in ClpModel doesn't do some things that would make it safer e.g. check if there is matrix stored by row which would also need updating. Also if a factorization has been saved it may not may not be valid so that should be noted. It is unlikely that any of that will matter, but I may add a safer version.

@jjhforrest
Copy link
Contributor

Only needed a tiny change to make safer - done that in master.

Also I was only looking Cbc C interface. When I looked at Clp C interface the function you need is already there.

/* Change matrix coefficients */
void CLP_LINKAGE
Clp_modifyCoefficient(Clp_Simplex *model, int row, int column, double newElement,
int keepZero)
{
model->model_->modifyCoefficient(row, column, newElement, keepZero);
}

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

No branches or pull requests

2 participants