[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-glpk] [Fwd: Exception raised in GLPK-Java when deleting a probl
From: |
Heinrich Schuchardt |
Subject: |
Re: [Bug-glpk] [Fwd: Exception raised in GLPK-Java when deleting a problem] |
Date: |
Tue, 7 Nov 2017 14:52:04 +0100 |
Hello Sergio,
I would replace ‘== 1’ by ‘> 0.5’ due to the use of tolerances inside GLPK.
Best regards
Heinrich Schuchardt
http://www.xypron.de
Am 07.11.17 um 14:32 schrieb Sergio Torassa
> Thanks Heinrich for the explanation.
> The usage of indixes in the library is not straightforward. May I ask you
> whether I used them correctly (apart from the mistake in the array init)?
>
> Thanks again
> Sergio
>
> On Tue, Nov 7, 2017 at 12:40 PM, Heinrich Schuchardt <address@hidden>
> wrote:
>
> > Dear Sergio,
> >
> > you are creating arrays ind and val with size data.size() and indexes 0
> > to data.size()-1.
> >
> > Then you set elements with index data.size() which is out of bounds.
> >
> > Best regards
> >
> > Heinrich Schuchardt
> >
> > http://www.xypron.de
> >
> > Am 07.11.17 um 10:37 schrieb Andrew Makhorin
> >
> > > -------- Forwarded Message --------
> > > To: address@hidden
> > > Subject: Exception raised in GLPK-Java when deleting a problem
> > > Date: Tue, 7 Nov 2017 10:00:52 +0100
> > >
> > > In case of problems more complex than a given threshold, an
> > > EXCEPTION_ACCESS_VIOLATION is raised by the Java Virtual Machine during
> > > the deletion of a solved problem.
> > >
> > >
> > > Code in the following.
> > > data is a table of <ArrayList<ArrayList<String>> and data.get(i).get(0)
> > > gives the value to add to the value array.
> > > The crash is raised when data.size() is higher than 6
> > >
> > >
> > > SO: Windows 7 64bit SP1
> > > Processor: Intel(R) Core(TM) i5 CPU, M540 @ 2.53GHz
> > > RAM: 6 GB
> > >
> > >
> > >
> > >
> > >
> > >
> > > glp_prob lp;
> > > SWIGTYPE_p_int ind;
> > > SWIGTYPE_p_double val;
> > > int ret;
> > >
> > >
> > > try {
> > > // Create problem
> > > lp = GLPK.glp_create_prob();
> > > System.out.println(" Problem created ");
> > > GLPK.glp_set_prob_name(lp, " myProblem ");
> > >
> > >
> > > // Define columns
> > > GLPK.glp_add_cols(lp, data.size());
> > >
> > >
> > > for (int i = 0; i < data.size(); i++) {
> > > GLPK.glp_set_col_name(lp, i + 1, "x" + (i + 1));
> > > GLPK.glp_set_col_kind(lp, i + 1, GLPKConstants.GLP_IV);
> > > GLPK.glp_set_col_bnds(lp, i + 1, GLPKConstants.GLP_DB, 0, 1);
> > > }
> > >
> > >
> > > // Create constraints
> > > GLPK.glp_add_rows(lp, 1);
> > > GLPK.glp_set_row_name(lp, 1, "power");
> > > GLPK.glp_set_row_bnds(lp, 1, GLPKConstants.GLP_LO, power, 0);
> > >
> > >
> > > // Create and fill in index and value arrays
> > > ind = GLPK.new_intArray(data.size());
> > > val = GLPK.new_doubleArray(data.size());
> > > for (int i = 0; i < data.size(); i++) {
> > > GLPK.intArray_setitem(ind, i + 1, i + 1);
> > > GLPK.doubleArray_setitem(val, i + 1,
> > > Double.parseDouble(data.get(i).get(0)));
> > > }
> > >
> > >
> > > // set the row and delete the index and value arrays
> > > GLPK.glp_set_mat_row(lp, 1, data.size(), ind, val);
> > > GLPK.delete_intArray(ind);
> > > GLPK.delete_doubleArray(val);
> > >
> > >
> > > // Define objective
> > > GLPK.glp_set_obj_name(lp, "z");
> > > GLPK.glp_set_obj_dir(lp, GLPKConstants.GLP_MIN);
> > > GLPK.glp_set_obj_coef(lp, 0, 0);
> > > for (int i = 0; i < data.size(); i++) {
> > > GLPK.glp_set_obj_coef(lp, i + 1,
> > > Double.parseDouble(data.get(i).get(0)));
> > > }
> > >
> > >
> > > // Solve model
> > > glp_smcp smcpParm = new glp_smcp();
> > > GLPK.glp_init_smcp(smcpParm);
> > > GLPK.glp_simplex(lp, smcpParm);
> > >
> > >
> > > glp_iocp iocpParm = new glp_iocp();
> > > iocpParm.setPresolve(GLPK.GLP_ON);
> > > GLPK.glp_init_iocp(iocpParm);
> > > ret = GLPK.glp_intopt(lp, iocpParm);
> > >
> > > // Retrieve solution
> > > if (ret == 0) {
> > > // write_lp_solution(lp);
> > > for (int i = 0; i < data.size(); i++) {
> > > data.get(i).set(3, GLPK.glp_mip_col_val(lp, i + 1) == 1.0 ? "true" :
> > > "false");
> > > reducedPower = (int)GLPK.glp_mip_obj_val(lp);
> > > }
> > > } else {
> > > System.out.println("The problem could not be solved ");
> > > }
> > >
> > > // Free memory
> > > GLPK.glp_delete_prob(lp);
> > >
> > > } catch (GlpkException ex) {
> > > ex.printStackTrace();
> > > }
> > >
> > >
> > > void write_lp_solution(glp_prob lp) {
> > > int i, n;
> > > String name;
> > > double val;
> > >
> > >
> > > name = GLPK.glp_get_obj_name(lp);
> > > val = GLPK.glp_get_obj_val(lp);
> > >
> > >
> > > System.out.print(name);
> > > System.out.print(" = ");
> > > System.out.println(val);
> > >
> > >
> > > n = GLPK.glp_get_num_cols(lp);
> > >
> > >
> > > for (i = 1; i <= n; i++) {
> > >
> > >
> > > name = GLPK.glp_get_col_name(lp, i);
> > > val = GLPK.glp_mip_col_val(lp, i);
> > >
> > >
> > > System.out.print(name);
> > > System.out.print(" = ");
> > > System.out.println(val);
> > > }
> > > }
> > >
> > >
> > > In the following the text output by the application
> > >
> > >
> > > Problem created
> > > GLPK Simplex Optimizer, v4.63
> > > 1 row, 7 columns, 7 non-zeros
> > > 0: obj = 0.000000000e+00 inf = 1.212e+03 (1)
> > > 2: obj = 1.212000000e+03 inf = 0.000e+00 (0)
> > > OPTIMAL LP SOLUTION FOUND
> > > GLPK Integer Optimizer, v4.63
> > > 1 row, 7 columns, 7 non-zeros
> > > 7 integer variables, all of which are binary
> > > Integer optimization begins...
> > > + 2: mip = not found yet >= -inf (1; 0)
> > > Solution found by heuristic: 1220
> > > + 9: mip = 1.220000000e+03 >= tree is empty 0.0% (0; 9)
> > > INTEGER OPTIMAL SOLUTION FOUND
> > > #
> > > # A fatal error has been detected by the Java Runtime Environment:
> > > #
> > > # EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000077aef23c,
> > > pid=4140, tid=0x00000000000009bc
> > > #
> > > # JRE version: Java(TM) SE Runtime Environment (8.0_151-b12) (build
> > > 1.8.0_151-b12)
> > > # Java VM: Java HotSpot(TM) 64-Bit Server VM (25.151-b12 mixed mode
> > > windows-amd64 compressed oops)
> > > # Problematic frame:
> > > # C [ntdll.dll+0x4f23c]
> > > #
> > > # Failed to write core dump. Minidumps are not enabled by default on
> > > client versions of Windows
> > > #
> > > # An error report file with more information is saved as:
> > > # C:\Users\sergio.torassa\workspace\DispatchSim\hs_err_pid4140.log
> > > #
> > > # If you would like to submit a bug report, please visit:
> > > # http://bugreport.java.com/bugreport/crash.jsp
> > > # The crash happened outside the Java Virtual Machine in native code.
> > > # See problematic frame for where to report the bug.
> > > #
> > >
> > >
> > >
> > >
> > > Attached the log of the crash
> > >
> > >
> > >
> > >
> > >
> > > _______________________________________________
> > > Bug-glpk mailing list
> > > address@hidden
> > > https://lists.gnu.org/mailman/listinfo/bug-glpk
> >