[Help-glpk] [Fwd: C# API Exception]
Forwarded Message From: Passorelli, Curtis To: 'help-glpk@gnu.org' Subject: C# API Exception Date: Mon, 12 Jun 2017 22:51:50 + Good afternoon, I wanted to know if I could ask for help when working with the GLPK API. I imported the libglpk-cli.dll from the source code into Visual Studio 2015 as part of my references. Following the example in the source code, I included the code listed below. When I compiled, I had the exception thrown. Any help would be greatly appreciated. Thanks for all of the hard work that you do, Curtis Passorelli Exception: An unhandled exception of type 'System.TypeInitializationException' occurred in libglpk-cli.dll Additional information: The type initializer for 'org.gnu.glpk.GLPKPINVOKE' threw an exception. Code: using System; using System.Collections.Generic; using System.Linq; using System.Text; using org.gnu.glpk; namespace api { classProgram { staticvoid Main(string[] args) { Console.WriteLine("GLPK " + GLPK.glp_version()); } } } THE INFORMATION CONTAINED IN THIS E-MAIL MESSAGE AND ANY ATTACHMENTS SENT FROM GENTEX CORPORATION IS GENTEX CONFIDENTIAL INFORMATION INTENDED ONLY FOR THE PERSONAL USE OF THE INDIVIDUAL OR ENTITY NAMED ABOVE. If you are not the intended recipient, you are hereby notified that any review, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender by return e-mail, and delete this e-mail message and any attachments from your computer. ___ Help-glpk mailing list Help-glpk@gnu.org https://lists.gnu.org/mailman/listinfo/help-glpk
Re: [Help-glpk] glp_intopt runs forever (related to Dusan Plavak's issue)
> For my setup, the instability appears with pre-release 4.59.2, if this > is any help. > Thanks. The error appears on solving problem.lp with glpsol, which performs scaling by default; however, it doesn't appear in main.cpp where scaling is not used. Specifying tiny constraint coefficients (which normally should be zeros) is a common error that makes the instance badly conditioned and leads to numerical difficulties. ___ Help-glpk mailing list Help-glpk@gnu.org https://lists.gnu.org/mailman/listinfo/help-glpk
Re: [Help-glpk] glp_intopt runs forever (related to Dusan Plavak's issue)
Hi Andrew, > Thank you. I could reproduce the error using glpk 4.62; it appears due > to numerical instability in the dual simplex routine. For my setup, the instability appears with pre-release 4.59.2, if this is any help. Best Regards, Chris Matrakidis ___ Help-glpk mailing list Help-glpk@gnu.org https://lists.gnu.org/mailman/listinfo/help-glpk
Re: [Help-glpk] glp_intopt runs forever (related to Dusan Plavak's issue)
> the test code is the same as Rafael posted. I am including it in > attachment. > > > You should be able to compile it with: > > > g++ main.cpp -std=gnu++11 -lglpk > Thank you. I could reproduce the error using glpk 4.62; it appears due to numerical instability in the dual simplex routine. Please note that replacing four tiny coefficients 4e-12 at x5 by exact zeros in problem.lp allows to solve the instance successfully. Andrew Makhorin ___ Help-glpk mailing list Help-glpk@gnu.org https://lists.gnu.org/mailman/listinfo/help-glpk
Re: [Help-glpk] glp_intopt runs forever (related to Dusan Plavak's issue)
Hi, the test code is the same as Rafael posted. I am including it in attachment. You should be able to compile it with: g++ main.cpp -std=gnu++11 -lglpk On Mon, Jun 12, 2017 at 12:05 PM, Chris Matrakidis wrote: > Hi Dusan, > > > we found out that the looping forever on this example manifests on the > > version 4.59 onward i.e. with 4.58 it still ran successfully. > > This seems more reasonable, but am still curious. Can you share the > test code? I have here several intermediate versions between 4.58 and > 4.59 and I would like to isolate the change responsible for this. > > Best Regards, > > Chris Matrakidis > -- S pozdravom Dušan Plavák #include #include #include using namespace std; vector solveSimplex() { vector mins; vector maxs; vector i_mins; vector i_maxs; vector signs; vector objectives; vector > left_parts; // here is hardcoded the problem definition left_parts = { {1.04902,5.077312556,0.179050001,2.54804,9.300799965,0,0,0,0}, {0.06509,0.680062490,0.02325,0.74411,9.30071,0,0,0,0}, {0.00820,3.528562505,0.10291,0.36899,0.00040,0,0,0,0}, {0.97580,0.868687506,0.05289,1.43483,0.00040,0,0,0,0}, {1,18.75000,1,10,1,0,0,0,0},{1.04902,5.077312556,0.179050001,2.54804,9.300799965,1,0,0,0}, {1.04902,5.077312556,0.179050001,2.54804,9.300799965,-1,0,0,0}, {0.06509,0.680062490,0.02325,0.74411,9.30071,0,1,0,0}, {0.06509,0.680062490,0.02325,0.74411,9.30071,0,-1,0,0}, {0.00820,3.528562505,0.10291,0.36899,0.00040,0,0,1,0}, {0.00820,3.528562505,0.10291,0.36899,0.00040,0,0,-1,0}, {0.97580,0.868687506,0.05289,1.43483,0.00040,0,0,0,1}, {0.97580,0.868687506,0.05289,1.43483,0.00040,0,0,0,-1} }; mins = {-8,-32000,-16000,-32000,0,400,400,160,160,80,80,160,160}; maxs = {8,32000,16000,32000,800,400,400,160,160,80,80,160,160}; i_mins = {100,8,2,4,4}; i_maxs = {400,16,400,20,30}; signs = {0,0,0,0,1,-1,1,-1,1,-1,1,-1,1}; objectives = {0,0,0,0,0,6,6,6,6}; glp_prob *lp; int *ia = NULL; int *ja = NULL; double *ar = NULL; vector results; lp = glp_create_prob(); glp_set_prob_name(lp, "amounts"); glp_set_obj_dir(lp, GLP_MIN); glp_add_rows(lp, left_parts.size()); for (unsigned int i = 0; i < left_parts.size(); i++) { if (signs[i] == 0) { glp_set_row_bnds(lp, i + 1, GLP_DB, mins[i], maxs[i]); } if (signs[i] == -1) { glp_set_row_bnds(lp, i + 1, GLP_LO, mins[i], mins[i]); } if (signs[i] == 1) { glp_set_row_bnds(lp, i + 1, GLP_UP, maxs[i], maxs[i]); } } glp_add_cols(lp, objectives.size()); for (unsigned int i = 0; i < objectives.size(); i++) { if (i < objectives.size() - 4) { glp_set_obj_coef(lp, i + 1, 0.0); if (i_mins[i] != i_maxs[i]) { glp_set_col_bnds(lp, i + 1, GLP_DB, i_mins[i], i_maxs[i]); } else { glp_set_col_bnds(lp, i + 1, GLP_FX, i_mins[i], i_mins[i]); } glp_set_col_kind(lp, i + 1, GLP_IV); } else { int tot = maxs.size() - 1; glp_set_obj_coef(lp, i + 1, 2/maxs[tot-6] * objectives[i]); glp_set_obj_coef(lp, i + 2, 1/maxs[tot-4] * objectives[i + 1]); glp_set_obj_coef(lp, i + 3, 1/maxs[tot-2] * objectives[i + 2]); glp_set_obj_coef(lp, i + 4, 1/maxs[tot] * objectives[i + 3]); glp_set_col_bnds(lp, i + 1, GLP_LO, 0.0, 0.0); glp_set_col_bnds(lp, i + 2, GLP_LO, 0.0, 0.0); glp_set_col_bnds(lp, i + 3, GLP_LO, 0.0, 0.0); glp_set_col_bnds(lp, i + 4, GLP_LO, 0.0, 0.0); break; } } long long fields_c; fields_c = left_parts.size() * objectives.size(); ia = (int *) malloc((fields_c + 1) * sizeof(int)); ja = (int *) malloc((fields_c + 1) * sizeof(int)); ar = (double *) malloc((fields_c + 1) * sizeof(double)); if (ia == NULL || ja == NULL || ar == NULL) { free(ia); free(ja); free(ar); } long long counter = 1; for (unsigned int i = 0; i < left_parts.size(); i++) { for (unsigned int j = 0; j < objectives.size(); j++) { if (left_parts[i][j] != 0) { ia[counter] = i+1; ja[counter] = j+1; ar[counter] = left_parts[i][j]; counter++; } } } glp_load_matrix(lp, counter-1, ia, ja, ar); glp_write_lp(lp, 0, "problem.lp"); glp_iocp parm; glp_init_iocp(&parm); parm.msg_lev = GLP_MSG_OFF; parm.presolve = GLP_ON; // upon calling glp_intopt here, the program loops forever if (glp_intopt(lp, &parm) == 0) { for (unsigned int i = 0; i < objectives.size() -
Re: [Help-glpk] glp_intopt runs forever (related to Dusan Plavak's issue)
Hi Dusan, > we found out that the looping forever on this example manifests on the > version 4.59 onward i.e. with 4.58 it still ran successfully. This seems more reasonable, but am still curious. Can you share the test code? I have here several intermediate versions between 4.58 and 4.59 and I would like to isolate the change responsible for this. Best Regards, Chris Matrakidis ___ Help-glpk mailing list Help-glpk@gnu.org https://lists.gnu.org/mailman/listinfo/help-glpk
Re: [Help-glpk] glp_intopt runs forever (related to Dusan Plavak's issue)
Hi Chris, we found out that the looping forever on this example manifests on the version 4.59 onward i.e. with 4.58 it still ran successfully. We tested all the versions from 4.58 to 4.61 on the same environment. Best regards On Mon, Jun 12, 2017 at 11:09 AM, Chris Matrakidis wrote: > Dear Rafael, > > > even after scaling your model the ratio between minimum and maximum > > coefficient in the matrix is very big. See below. > > I agree that Heinrich's explanation is the most likely one. However I > am curious why this change of behaviour happened with version 4.61. > There are no changes in this version that should affect the simplex > method execution. Did you change anything else in your environment > (like C compiler or compilation flags)? Or are you comparing against > an older version of GLPK (and if so which one)? > > Best Regards, > > Chris Matrakidis > > ___ > Help-glpk mailing list > Help-glpk@gnu.org > https://lists.gnu.org/mailman/listinfo/help-glpk > -- S pozdravom Dušan Plavák ___ Help-glpk mailing list Help-glpk@gnu.org https://lists.gnu.org/mailman/listinfo/help-glpk
Re: [Help-glpk] glp_intopt runs forever (related to Dusan Plavak's issue)
Dear Rafael, > even after scaling your model the ratio between minimum and maximum > coefficient in the matrix is very big. See below. I agree that Heinrich's explanation is the most likely one. However I am curious why this change of behaviour happened with version 4.61. There are no changes in this version that should affect the simplex method execution. Did you change anything else in your environment (like C compiler or compilation flags)? Or are you comparing against an older version of GLPK (and if so which one)? Best Regards, Chris Matrakidis ___ Help-glpk mailing list Help-glpk@gnu.org https://lists.gnu.org/mailman/listinfo/help-glpk