help-glpk
[Top][All Lists]
Advanced

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

Re: [Help-glpk] use GLPK to solve LP without printing anything on termin


From: Nigel Galloway
Subject: Re: [Help-glpk] use GLPK to solve LP without printing anything on terminal
Date: Mon, 13 Apr 2015 03:42:41 -0700

Have you considered looking at t1.cs from glpk's example directory and glpk's API documentation?
 
Let us look now at t1.cs.
 
First the example was written for Linux so we change the line
 
    const string glpkLibrary = "libglpk.so";
to
    const string glpkLibrary = "glpk.dll";    //***
 
and run it as is "t1.exe 98 1001" produces:

a = 98, b = 1001
Hello Nigel
Trying 98
GLPK Simplex Optimizer, v4.55
1 row, 2 columns, 2 non-zeros
      0: obj =  0.000000000e+000  infeas = 1.000e+000 (0)
*     1: obj =  0.000000000e+000  infeas = 0.000e+000 (0)
OPTIMAL LP SOLUTION FOUND
GLPK Integer Optimizer, v4.55
1 row, 2 columns, 2 non-zeros
2 integer variables, none of which are binary
Integer optimization begins...
+     1: mip =     not found yet >=              -inf        (1; 0)
Solution found by heuristic: 0
+     2: mip =  0.000000000e+000 >=     tree is empty   0.0% (0; 5)
INTEGER OPTIMAL SOLUTION FOUND
x = -10, y = 1, a*x + b*y = 21
Trying 21
GLPK Simplex Optimizer, v4.55
1 row, 2 columns, 2 non-zeros
*     2: obj =  0.000000000e+000  infeas = 0.000e+000 (0)
OPTIMAL LP SOLUTION FOUND
GLPK Integer Optimizer, v4.55
1 row, 2 columns, 2 non-zeros
2 integer variables, none of which are binary
Integer optimization begins...
+     2: mip =     not found yet >=              -inf        (1; 0)
Solution found by heuristic: 0
+     2: mip =  0.000000000e+000 >=     tree is empty   0.0% (0; 3)
INTEGER OPTIMAL SOLUTION FOUND
x = 41, y = -4, a*x + b*y = 14
Trying 14
GLPK Simplex Optimizer, v4.55
1 row, 2 columns, 2 non-zeros
*     2: obj =  0.000000000e+000  infeas = 0.000e+000 (0)
OPTIMAL LP SOLUTION FOUND
GLPK Integer Optimizer, v4.55
1 row, 2 columns, 2 non-zeros
2 integer variables, none of which are binary
Integer optimization begins...
+     2: mip =     not found yet >=              -inf        (1; 0)
Solution found by heuristic: 0
+     3: mip =  0.000000000e+000 >=     tree is empty   0.0% (0; 5)
INTEGER OPTIMAL SOLUTION FOUND
x = -51, y = 5, a*x + b*y = 7
Trying 7
Solution is 7
Goodbye Nigel

All this output from glpk shows its working but is distracting so:
 
1. define GLP_OFF. In C# 5 these constants would better in an enum say GPL so we could then use GLP.OFF but this is the example written in 2008 that we have for now.
 
    readonly int GLP_OFF = 0;                 //***
 
2. add the link into glpk.dll for glp_term_out:
 
    [DllImport(glpkLibrary, SetLastError = true)]  //***
    static extern int glp_term_out(int flag);          //***
 
3. use it to turn glpk's terminal output off:
 
        glp_term_out(GLP_OFF);                //***
 
compiling and running this version "t1.exe 98 1001" produces:
 
a = 98, b = 1001
Hello Nigel
Trying 98
x = -10, y = 1, a*x + b*y = 21
Trying 21
x = 41, y = -4, a*x + b*y = 14
Trying 14
x = -51, y = 5, a*x + b*y = 7
Trying 7
Solution is 7
Goodbye Nigel
 
which I hope is close to what you want.
 
I have attached the modified t1.cs with the changes marked by //***
--
Nigel Galloway
address@hidden
 
 
 
On Sat, Apr 11, 2015, at 07:04 AM, usa usa wrote:
Also,
 
How to indicate algorithms in GLPK to solve LP or IP from API ?
 
GLPK has simplex, primal-dual and branch-bound algorithms, are there others?
 
thanks
 
On Sat, Apr 11, 2015 at 8:39 AM, Nigel Galloway <address@hidden> wrote:

If you are using the API then the output is controlled with GLP_ON and GLP_OFF. If you are using mathprog & glpsol then -y filename will send the output to a file rather than your terminal. If using Linux and you absolutely don't want the output then -y /dev/nul should do you.
 
--
Nigel Galloway
 
 
 
On Fri, Apr 10, 2015, at 08:24 PM, usa usa wrote:
Hi,
 
I am using GLPK to solve some linear programming models.
 
The model size is 200k variables and has one constraint.
 
It took GLPK 13 minutes to load data and build the LP model.
 
But, it took GLPK 17 minutes to solve it.
 
Is it normal ? Why building a model took so long time ?
 
Also, when GLPK is solving the model, it print out the detailed process of solving model on the command line terminal.
 
How to make GLPK to solve the model silently without printing anything on terminal ?
 
Thanks
 
 
 
_______________________________________________
Help-glpk mailing list
 
 
 
-- 
http://www.fastmail.com - Or how I learned to stop worrying and
                          love email again

 
 
_______________________________________________
Help-glpk mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/help-glpk
 
 
 
-- 
http://www.fastmail.com - Faster than the air-speed velocity of an
                          unladen european swallow

Attachment: t1.cs
Description: Binary data


reply via email to

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