[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## [Help-glpk] Beginner questions (MIP model)

**From**: |
Denis Debarbieux |

**Subject**: |
[Help-glpk] Beginner questions (MIP model) |

**Date**: |
Tue, 24 Feb 2009 16:37:18 +0300 |

Dear GLPK users,
I am a new GLPK user and I develop under Java. I would like to write a
simple MIP model but I do not get the good answer. Could you help me please?
I send you: my model, my code and the print problem.
/**
*
* integer variable: 0 <= x <= 10;
* constraint: x >= 7.2;
* minimize x;
*
* Expected solution: x = 8
* Return value: x = 7.2
*/
public static void main (String[] args) {
// initialization of solver
GlpkSolver solver = new GlpkSolver();
solver.addCols(1);
solver.addRows(1);
solver.setClss(GlpkSolver.LPX_MIP);
// integer variable: 0 <= x <= 10;
int x = 1;
solver.setColName(x, "x");
solver.setColBnds(1, GlpkSolver.LPX_DB, 0, 10);
solver.setColKind(x, GlpkSolver.LPX_IV);
// constraint: x >= 7.2;
solver.setMatCol(x, 1, new int[]{NOT_USED, 1}, new
double[]{NOT_USED, 1});
solver.setRowBnds(x, GlpkSolver.LPX_LO, 7.2, NOT_USED);
// minimize x;
solver.setObjCoef(x, 1);
// print the problem
solver.printProb("pb.txt");
// solve
solver.simplex(); // if I remove this line, I get an error:
optimal solution of LP relaxation required
solver.integer();
// print the solution
System.out.println("x= "+solver.getColPrim(x));
}
Here is the pb.txt file:
Problem: (unnamed)
Class: MIP
Rows: 1
Columns: 1 (1 integer, 0 binary)
Non-zeros: 1
*** OBJECTIVE FUNCTION ***
Minimize: (unnamed)
1 x
*** ROWS (CONSTRAINTS) ***
Row 1: R.1 >= 7.2
1 x
*** COLUMNS (VARIABLES) ***
Col 1: x integer >= 0 <= 10
1 (objective)
1 R.1
End of output
Regards,
Denis

**[Help-glpk] Beginner questions (MIP model)**,
*Denis Debarbieux* **<=**