help-glpk
[Top][All Lists]
Advanced

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

Re: [Help-glpk] Get number of columns from callback routine


From: glpk xypron
Subject: Re: [Help-glpk] Get number of columns from callback routine
Date: Fri, 21 Sep 2012 07:02:38 +0200

Hello Patrik,

 for branching down on the most fractional variable you could use:

    @Override
    public void callback(glp_tree tree) {
        int reason = GLPK.glp_ios_reason(tree);
        if (reason == GLPKConstants.GLP_IBRANCH) {
            glp_prob lp  = GLPK.glp_ios_get_prob(tree);
            double n = GLPK.glp_get_num_cols(lp);
            double frac = -1;
            int ifrac = 0;
            for (int i = 1; i <= n; i++) {
                if (0 != GLPK.glp_ios_can_branch(tree, i)) {
                    double value = GLPK.glp_mip_col_val(lp, i);
                    if (frac <= value - Math.floor(value)) {
                        ifrac = i;
                        frac = value - Math.floor(value);
                    }
                    if (frac <= Math.ceil(value) - value) {
                        ifrac = i;
                        frac = Math.ceil(value) - value;
                    }
                }
            }
            GLPK.glp_ios_branch_upon(tree, ifrac, GLPKConstants.GLP_DN_BRNCH);
        }
    }

Best regards

Xypron



-------- Original-Nachricht --------
> Datum: Thu, 20 Sep 2012 13:37:43 -0400
> Von: Patrik Dufresne <address@hidden>
> An: address@hidden
> Betreff: [Help-glpk] Get number of columns from callback routine

> Hi,
> 
> I want to implement a simple always-down branching heuristic in GLPK. So I
> need to call the function glp_ios_can_branch() to check if the column is
> the right candidate for branching. But I'm wondering how to I determine
> the
> maximum number of column since my original problem may be changed by the
> pre-processor. Reading the documentation the following line should do it:
> 
> GLPK.glp_get_num_cols(GLPK.glp_ios_get_prob(tree));
> 
> Am I right ?
> 
> Thanks
> 
> Patrik Dufresne



reply via email to

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