[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-glpk] [Fwd: Re: [Fwd: Terminating GLPK early]]

From: Andrew Makhorin
Subject: [Help-glpk] [Fwd: Re: [Fwd: Terminating GLPK early]]
Date: Thu, 25 Aug 2011 17:14:01 +0400

-------- Forwarded Message --------
From: Jonathan Currie <address@hidden>
To: Xypron <address@hidden>
Cc: address@hidden, Andrew Makhorin <address@hidden>
Subject: Re: [Help-glpk] [Fwd: Terminating GLPK early]
Date: Thu, 25 Aug 2011 14:46:52 +1200

Hi Xypron,
Thank you very much for your reply, and suggestions! Your error hook
works perfectly, thank you! I will have a look at implementing the iocp
callback tonight.

>>> Xypron <address@hidden> 25/08/2011 4:25 a.m. >>>
Hello Jonathan,

there are two solutions:

1) Implement the terminal hook function. This hook function is called
regular intervals by the solver. In the hook function call
glp_error("%s\n", "Aborting due to user request");

Implement the error_hook function to gracefully catch the produced

The following code snippets are taken from GLPK for Java:

     jmp_buf glp_java_env;

     glp_java_callback_env[glp_java_callback_level] = &glp_java_env;
     if (setjmp(glp_java_env)) {
       glp_java_throw(jenv, "function glp_simplex failed");
     } else {
       glp_error_hook(glp_java_error_hook, &glp_java_env);
       result = (int)glp_simplex(arg1,(glp_smcp const *)arg2);;
     glp_java_callback_env[glp_java_callback_level] = NULL;
     glp_error_hook(NULL, NULL);

  * This hook function will be processed if an error occured
  * calling the glpk library
  * @param in pointer to long jump environment
void glp_java_error_hook(void *in) {
     glp_java_error_occured = 1;
     /* free GLPK memory */
     /* safely return */
     longjmp(*((jmp_buf*)in), 1);

2) If you are solving a MIP problem, and want to get the best solution 
yet found, implement a callback routine the address of which you pass 
with the iocp structure. In the callback routine call

Both has been implemented successfully in example/java/
GLPK for Java.

You can download GLPK for Java from

It is included in GLPK for Windows available at

Best regards


On 24.08.2011 14:25, Andrew Makhorin wrote:
> -------- Forwarded Message --------
> Subject: Terminating GLPK early
> Date: Wed, 24 Aug 2011 12:34:40 +1200
> Dear Andrew,
> I am currently modifying the GLPKMEX interface to GLPK (Matlab
> interface) and wish to be able to terminate a call to GLPK if a user
> to say push Ctrl-C, and return the current best solution. I have read
> through the documentation and have tried glp_error() however this also
> causes Matlab to crash (not sure if I have done something wrong), but
> wondered if there was a cleaner way?
> I am imagining an event handler which could be passed to GLPK before
> glp_simplex() or another solver is called, which is then called by the
> solver each iteration (with perhaps some runtime information), and a
> return code passed back to indicate whether to continue or stop.
> I apologize if this already exists in GLPK however I have been unable
> find it!
> Kind Regards,
> Jonathan Currie
> _______________________________________________
> Help-glpk mailing list
> address@hidden

reply via email to

[Prev in Thread] Current Thread [Next in Thread]