help-glpk
[Top][All Lists]
Advanced

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

Re: [Help-glpk] Trouble with integer variables


From: Andrew Makhorin
Subject: Re: [Help-glpk] Trouble with integer variables
Date: Thu, 13 Jul 2006 21:02:16 +0400

> First of all, I must say I'm  a newbee to linear programing and GLPK.
> I want to solve a problem forcing the sctructural variables to be integer, 
> but the result has no 
> integers, using simplex o interiro point. I?m using the java interface to 4.8 
> version. 
> 
> Here's the code: 
> 
> 
> GlpkSolver solver = new GlpkSolver();                 
>                 solver.setObjDir(GlpkSolver.LPX_MAX); 
>                 solver.setClss(GlpkSolver.LPX_MIP); 
>                 solver.addRows(auxVars.length); 
>                 for (int i = 1; i <= auxVars.length; i++) { 
>                         solver.setRowName(i, "p" + i); 
>                         solver.setRowBnds(i, GlpkSolver.LPX_UP, 0, auxVars[i 
> - 1]); 
>                 } 
>                 solver.addCols(objCoefs.length); 
>                 for (int j = 1; j <= objCoefs.length; j++) { 
>                         solver.setColName(j, "x" + j); 
>                         solver.setColKind(j, GlpkSolver.LPX_IV); 
>                         solver.setColBnds(j, GlpkSolver.LPX_DB, 0, 17); 
>                         //solver.setColBnds(j, GlpkSolver.LPX_LO, 0, 0); 
>                         solver.setObjCoef(j, objCoefs[j - 1]); 
>                 } 
>                 //int n=constrCoefs.length*constrCoefs[0].length; 
>                 
>                 int nonzeroscounter=0; 
>                 for(int k=0;k<constrCoefs.length;k++){ 
>                         for(int m=0;m<constrCoefs[k].length;m++){             
>                     
>                                 if(constrCoefs[k][m]!=0.0) nonzeroscounter++; 
>                                         
>                         } 
>                 } 
>                 System.out.println("nonzeroscounter..."+nonzeroscounter); 
>                 int ia[]= new int[nonzeroscounter+1]; 
>                 int ja[] =new int[nonzeroscounter+1]; 
>                 double ar[]= new double[nonzeroscounter+1]; 
>                 int index=0; 
>                 for(int k=0;k<constrCoefs.length;k++){ 
>                         System.out.println("k..."+k); 
>                         for(int m=0;m<constrCoefs[k].length;m++){ 
>                                 System.out.println("m..."+m); 
>                                 if(constrCoefs[k][m]!=0.0){ 
>                                 ia[index+1]=k+1; 
>                                 ja[index+1]=m+1; 
>                                 ar[index+1]=constrCoefs[k][m]; 
>                                 index++; 
>                                 System.out.println("index..."+index); 
>                                 } 
>                                 
>                                         
>                         } 
>                 }                 
>                 solver.loadMatrix(nonzeroscounter, ia, ja, ar); 
>                 solver.simplex() 
> 
> and the solution is: 
> x1=3.333333333333333 
> x2=6.666666666666667 
> x3=0.0 
> so, not integers at all, any suggestions????

Probably you used wrong api routines to obtain mip solution, i.e.
you obtained solution of lp relaxation.
You should use lpx_mip_status, lpx_mip_obj_val, lpx_mip_row_val, and
lpx_mip_col_val.





reply via email to

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