help-glpk
[Top][All Lists]
Advanced

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

Re: [Help-glpk] [Fwd: Get the MIp relative gap at the end of the optimiz


From: oguyon
Subject: Re: [Help-glpk] [Fwd: Get the MIp relative gap at the end of the optimization]
Date: Wed, 20 Jul 2011 08:09:21 -0700 (PDT)


Andrew Makhorin wrote:
> 
> 
> If at least one integer feasible solution was found and you terminated
> the search with glp_ios_terminate, glp_intopt must return GLP_ESTOP and
> glp_mip_status must return GLP_FEAS (even if the mip preprocessor is
> enabled). Please check your code.
> 
> 

Thant you Andrew, you were right. I was confusing different status
(glp_intopt status, glp_mip_status and glp_status and generic basus of the
current solution).

So, now, it works well. If someone is intersted in, here is my code:

public class MyClass MIP implements GlpkCallbackListener{

long start; 

static int maxTime = 5000;
        
static double mipRelativeGap = 0.01;

protected double solve(){
double resu=-1;

glp_prob model = GLPK.glp_create_prob();

//create here the model !

glp_iocp iocp = new glp_iocp();
GLPK.glp_init_iocp(iocp);

start = System.currentTimeMillis(); 
GlpkCallback.addListener(this);
int solveStatus = GLPK.glp_intopt(model, iocp); 
GlpkCallback.removeListener(this);

int mipStatus = GLPK.glp_mip_status(model);
boolean success = (mipStatus == GLPKConstants.GLP_OPT || mipStatus ==
GLPKConstants.GLP_FEAS);                

if(success){
        resu = GLPK.glp_mip_obj_val(model);
} 

return resu;
}
        
@Override
public void callback(glp_tree tree) {
        long now = System.currentTimeMillis();
        if(now - start >= maxTime){
                double mipGap = GLPK.glp_ios_mip_gap(tree);
                if(mipGap <= mipRelativeGap){
                        GLPK.glp_ios_terminate(tree);
                }
        }               
}
}

-- 
View this message in context: 
http://old.nabble.com/-Fwd%3A-Get-the-MIp-relative-gap-at-the-end-of-the%09optimization--tp32094140p32100043.html
Sent from the Gnu - GLPK - Help mailing list archive at Nabble.com.




reply via email to

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