help-glpk
[Top][All Lists]
Advanced

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

[Help-glpk] How to return the best MIP solution when the branch & cut tr


From: Ruben Proano
Subject: [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 10:53:11 -0500

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;
}

reply via email to

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