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 nigel_gallo...@operamail.com 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 > <nigel_gallo...@operamail.com> 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 nigel_gallo...@operamail.com >> >> >> >> 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 Help-glpk@gnu.org >>> https://lists.gnu.org/mailman/listinfo/help-glpk >>> >> >> >> -- >> http://www.fastmail.com - Or how I learned to stop worrying and love email again >> >> >> >> _______________________________________________ >> Help-glpk mailing list >> Help-glpk@gnu.org https://lists.gnu.org/mailman/listinfo/help-glpk >> > -- http://www.fastmail.com - Faster than the air-speed velocity of an unladen european swallow
t1.cs
Description: Binary data
_______________________________________________ Help-glpk mailing list Help-glpk@gnu.org https://lists.gnu.org/mailman/listinfo/help-glpk