bug-glpk
[Top][All Lists]
Advanced

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

Re: Bad expression parsing/evaluation


From: Domingo Alvarez Duarte
Subject: Re: Bad expression parsing/evaluation
Date: Fri, 17 Dec 2021 11:56:50 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0

Hello again !

I just found a fix that solves the endless recursion and segfault mentioned on the previous message (see bellow) the commit containing it is here https://github.com/mingodad/GLPK/commit/fbcc066a6e336cd4cfefbac15a69c908d08a7f92 , basically it delays the insertion of the parameter into the symbol table for parameters with zero dimension, this way models like "examples/bpp.mod" continue to work as before.

I also managed to set a github workflow to build binaries and do some tests for Linux, Windows and OSX see the result here https://github.com/mingodad/GLPK/actions/runs/1591816602 .

Probably there is other corner cases where we'll enter in an endless recursion but I'll stop here for now.

Any feedback/suggestion is welcome !

Cheers !

On 16/12/21 11:30, Domingo Alvarez Duarte wrote:
My proposed fix for the segfault that happens with a model like the one bellow is not a good one because it prevents other useful expressions like the one in "examples/bpp.mod", the problem is that GMPL enter an endless loop.

====

param a := 3;
param b := a * b;
display a,b;

====

b := a * b; => b := a * (a*b); => b := a * (a*(a*b)); => ...

====


On 15/8/21 18:07, Domingo Alvarez Duarte wrote:
The segfault problem seems to be due to inserting the "param" in the symbol table before it's fully parsed, moving the insertion to the end seems to fix this problem and GMPL/GLPSOL gives an error message instead of segfault (see diff bellow):

Output after applying the patch shown bellow:

====

GLPSOL: GLPK LP/MIP Solver, v4.65-ex, glp_double size 8
Parameter(s) specified in the command line:
 -m test.ampl
Reading model section from test.ampl...
test.ampl:7: a2 not defined
Context: ...) ) ) + ( 8871 ) ; printf '...' , a1 ; param a2 := a1 * a2 ;
MathProg model processing error

====

Patch to fix the segfault (Probably the same should be done for "set/var/..."):

====

-------------------------------- src/mpl/mpl1.c --------------------------------
index 9327c52..aa0c7e2 100644
@@ -3578,12 +3578,6 @@ PARAMETER *parameter_statement(MPL *mpl)
       {  par->domain = indexing_expression(mpl);
          par->dim = domain_arity(mpl, par->domain);
       }
-      /* include the parameter name in the symbolic names table */
-      {  AVLNODE *node;
-         node = avl_insert_node(mpl->tree, par->name);
-         avl_set_node_type(node, A_PARAMETER);
-         avl_set_node_link(node, (void *)par);
-      }
       /* parse the list of optional attributes */
       for (;;)
       {  if (mpl->scan_input->token == T_COMMA)
@@ -3765,6 +3759,12 @@ err:           error(mpl, "at most one := or default allowed");
          else
             error(mpl, "syntax error in parameter statement");
       }
+      /* include the parameter name in the symbolic names table */
+      {  AVLNODE *node;
+         node = avl_insert_node(mpl->tree, par->name);
+         avl_set_node_type(node, A_PARAMETER);
+         avl_set_node_link(node, (void *)par);
+      }
       /* close the domain scope */
       if (par->domain != NULL) close_scope(mpl, par->domain);
       /* the parameter statement has been completely parsed */

====

On 15/8/21 16:50, Heinrich Schuchardt wrote:
On 8/15/21 4:06 PM, Domingo Alvarez Duarte wrote:
Comparing how AMPL and GMPL calculate random expressions I found some of then where they differ or GMPL can't manage see bellow, also one of then
that references itself makes glpsol segfault but ampl gives an error

I can't see a segfault with GLPK 5.0.

Please, use gdb to identify in which line of code it occurs:

    gdb --args glpk -m test.od

message explaining the problem:

====

param a0 := (((((((788)*(8.46))))+8342*1.803-1))*4186.4*(15));
printf "%f\n", a0;

param a1 := (((22 mod 284/((7530/((2)*(((((25))-421))))))*597 mod
2663)+7283.8-9.60+167 mod ((3))))+(8871);
printf "%f\n", a1;

#param a2 := a1 * a2; #glpsol segfault
param a2 := a0 * a1;
printf "%f\n", a2;

param a = (((((((788)*(8.46))))+8342*1.803-1))*4186.4*(15))*(((22 mod

Your syntax is wrong. This should be:

param a :=

With correct syntax:

glpsol -m /tmp/test.mod
GLPSOL: GLPK LP/MIP Solver, v4.65
Parameter(s) specified in the command line:
 -m /tmp/test.mod
Reading model section from /tmp/test.mod...
28 lines were read
1363056632.376000
17428.775299
23756407765226.851562
11664732388290.359375
11665910614443.386719
8259816920615.111328
8259816920615.111328
Model has been successfully generated

Best regards

Heinrich

284/((7530/((2)*(((((25))-421))))))*597 mod 2663)+7283.8-9.60+167 mod
((3))))+(8871);
#param a := 3+2;
printf "%f\n", a;

param b = (((((((788)*(8.46))))+8342*1.803-1))*4186.4*(15))*(((22 mod
284/((7530/((2)*(((((25))-421))))))*597 mod 2663)+7283.8-9.60+167.8644
mod ((3))))+(8871);
#param a := 3+2;
printf "%f\n", b;

param c =
(((((((788)*(8.46))))+8342*1.803-1))*4186.4*(15))*(((22/((7530/((2)*(((((25))-421))))))*597)+7283.8-9.60+167))+(8871);

#param a := 3+2;
printf "%f\n", c;

param d =
(((((((788.0)*(8.46))))+8342.0*1.803-1.0))*4186.4*(15.0))*(((22.0/((7530.0/((2.0)*(((((25.0))-421))))))*597.0)+7283.8-9.60+167.0))+(8871.0);

#param a := 3+2;
printf "%f\n", d;

====

AMPL output:

====

ampl test.ampl
1363056632.376000
14765.775299
20126587953209.562500
8034912576273.071289
8036090802426.097656
8259816920615.111328
8259816920615.111328

====

GLPSOL output:

====

glpsol -m test.ampl
GLPSOL: GLPK LP/MIP Solver, v4.65
Parameter(s) specified in the command line:
  -m test.ampl
Reading model section from test.ampl...
test.ampl:25: warning: unexpected end of file; missing end statement
inserted
25 lines were read
1363056632.376000
17428.775299
23756407765226.851562
test.ampl:13: no value for a
MathProg model processing error

====

With a incorrect expression:

====

param a2 := a1 * a2; #glpsol segfault
#param a2 := a0 * a1;

====

AMPL output:

====

ampl test.ampl
1363056632.376000
14765.775299

test.ampl, line 7 (offset 228):
     a2 is not defined
context:  param a2 := a1 *  >>> a2; <<< #glpsol segfault

====

GLPSOL output:

====

glpsol -m test.ampl
GLPSOL: GLPK LP/MIP Solver, v4.65
Parameter(s) specified in the command line:
  -m test.ampl
Reading model section from test.ampl...
test.ampl:25: warning: unexpected end of file; missing end statement
inserted
25 lines were read
1363056632.376000
17428.775299
Segmentation fault (core dumped)

====

Cheers !






reply via email to

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