-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add methods to remove unused symbols from a model #161
Add methods to remove unused symbols from a model #161
Conversation
// This method will reset the topological sort if there is one. | ||
// | ||
// A node is considered unused if all of the following are true: | ||
// * It is not a decision. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is currently a constraint because of the difficulty of removing some types of decisions, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not actually difficult to implement but there are a few reasons:
- I can see how symbols might be accidentally added to the model, but for decisions I think there is a high chance they are there deliberately anyway. I.e. i doubt we'd be removing decisions often.
- This way if one was to use this method as part of a presolve step, the serialized states of the model after presolve would still be relevant to the original model.
It's a simple enough thing to add a toggle for at some later date if we really want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I didn't think about the presolve angle.
// For performance we store a signalling value in the topological_index of the | ||
// nodes. We need to take some care to not override the topological index of | ||
// any decisions. | ||
constexpr ssize_t keep = -2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is set to -2
because -1
already has a meaning of "unsorted", correct? But at this point you've topologically sorted so it should be guaranteed all nodes have an index >= 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's right. I just need a negative number. I chose -2
because -1
already has meaning as unsorted. Should never matter but 🤷
What about the case of an unused |
Ah! Good catch. Yes. Need to think about how to handle that. |
Ok, added a mechanism for nodes to opt out of removal. Probably good for decisions as well (for safety). |
Closes #41