-
Notifications
You must be signed in to change notification settings - Fork 37
implements #60 EventHandler and ConsHandler #62
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
base: master
Are you sure you want to change the base?
Conversation
| @Override | ||
| protected SCIP_Retcode scipExec(Scip scip, SCIP_Event event) { | ||
| assert (event.getEventtype() & EventType.BESTSOLFOUND) != 0 : "Unexpected event caught"; | ||
| Solution solution = new Solution(SCIPJNI.getEventDataSolution(event)); |
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 how I would envision a user to be implementing an event handler: He get's the raw SCIP_Event passed and has to call one of the SCIPJNI.getEventData*(SCIP_Event) methods to access the union member that corresponds to his event type. Would that be alright? Is it too complicated?
We could also implement custom scipExec* methods for each event type, but the documentation doesn't really say, which union member corresponds to which event type, so it would be a lot of untested code.
|
|
||
| import java.util.Objects; | ||
|
|
||
| public class ResultHolder { |
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.
I picked this pattern up from the Fico Xpress java library. It corresponds to an output pointer that is passed to the user as a call back and the user is expected to set the result of the handler there.
One could also pass an instance of SCIP and make the corresponding JNI call when the user passes the result immediately, but this would not be safe, if the user somehow leaks the ResultHolder outside of the EventHandler and calls the set method later.
| return messagehdlr; | ||
| } | ||
|
|
||
| /* BEGIN assist functions for accessing SCIP_Event data union members */ |
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.
I'm not sure if all of those helper methods are necessary, but I couldn't find a different way of accessing the SCIP_Event::data union members. The example code only uses the getEventDataSolution, but I guess the other union members would work as well.
Sorry for the large PR, but it turns out EventHandler with the SCIP_Event data union has a lot of possible types.