help-glpk
[Top][All Lists]
Advanced

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

Re: [Help-glpk] How to return the best MIP solution when the branch & cu


From: glpk xypron
Subject: Re: [Help-glpk] How to return the best MIP solution when the branch & cut tree is exceeds memory limit (API implementation)
Date: Wed, 28 Dec 2011 23:18:10 +0100

Hello Ruben,

before calling glp_intopt create a long jump, e.g.

    if (setjmp(foo1)) {
      printf("error occured");
    } else {
      glp_error_hook(error_hook, foo2);
      glp_intopt(mip, parm);
    }
    glp_error_hook(NULL, NULL);

using function glp_error_hook to register a function which will be called when 
an error occurs.

Best regards

Xypron

-------- Original-Nachricht --------
> Datum: Wed, 28 Dec 2011 10:53:11 -0500
> Betreff: [Help-glpk] How to return the best MIP solution when the branch & 
> cut tree is exceeds memory limit (API implementation)

> Hi all,
> 
> I have been using GLPK as an API to solve a MIP problem coded in C++. The
> model and glpk work well, but when the branch and cut tree is too large
> and
> it exceeds the memory I allocated in the callback function, the program
> halts. How can I change the call back function so that instead of halting
> the program, it list the best solution it has found so far and continues
> running.
> I really appreciate your help,
> 
> Here are my two functions
> 
> // 1) Callback function:
> 
> void cb_func(glp_tree *tree, void *info)
> {    if(glp_ios_reason(tree)==GLP_IBINGO)
>     { if(glp_ios_mip_gap(tree)<=0.10)
>         glp_ios_terminate(tree);
>     }
>     return;
> }
> 
> .
> .
> .
> 
> 
> // 2) The function that solves the MIP Model and data:
> 
> int SolveGLPK(list<patient> & unit, list<room> & u5400, int& clktime){
> 
> 
>     glp_prob *mip;
>     glp_tran *tran;
>     glp_iocp parm;
> 
>     int ret;
>     glp_mem_limit(1200);
>     mip = glp_create_prob();
>     tran = glp_mpl_alloc_wksp();
>     ret = glp_mpl_read_model(tran, "RGH_simulation.mod", 1);
>     if (ret != 0)
>     {
>         fprintf(stderr, "Error on translating model\n");
>         goto skip;
>     }
>     ret = glp_mpl_read_data(tran, "glpk_input.dat");
> 
>     if (ret != 0)
>     {
>         fprintf(stderr, "Error on translating data\n");
>         goto skip;
>     }
> 
>     ret = glp_mpl_generate(tran, NULL);
>     if (ret != 0)
>     {
>         fprintf(stderr, "Error on generating model\n");
>         goto skip;
>     }
>     glp_mpl_build_prob(tran, mip);
>     glp_simplex(mip, NULL);
> 
>     glp_init_iocp(&parm); // for controling MIP_gap
>     parm.cb_func=cb_func; // for controling MIP_gap
>     glp_intopt(mip, &parm); // for controling MIP_gap
>     //glp_intopt(mip, NULL);  // function used in original code instead of
> the above
>     ret = glp_mpl_postsolve(tran, mip, GLP_MIP);
>     if (ret != 0)
>         fprintf(stderr, "Error on postsolving model\n");
>     skip: glp_mpl_free_wksp(tran);
>     glp_delete_prob(mip);
>    return 0;
> }

-- 
Follow me at http://twitter.com/#!/xypron

NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!               
Jetzt informieren: http://www.gmx.net/de/go/freephone



reply via email to

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