help-glpk
[Top][All Lists]
Advanced

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

Re: [Help-glpk] Time conversion functions


From: Andrew Makhorin
Subject: Re: [Help-glpk] Time conversion functions
Date: Sat, 22 Nov 2008 16:40:14 +0300

>>> Probably it would be reasonable to add two functions atoi and atod to
>>> convert symbolic values to numeric ones.
> 
> GLPK executes automatic conversion to symbol in:
> 
> param i := 2008;
> param s symbolic := i;
> display i;

No, there is no conversion in your example.

The point is that each symbolic value can be character string as well
as floating-point number, i.e. each symbolic value has a flag indicating
whether it is a number or string (see struct SYMBOL in glpmpl.h).

> 
> What I missed is that GLPK has no automatic conversion to numeric.
> 
> The following code fails:
> param y := '2008';
> display y;
> 
> The error given is:
> "cannot convert '2008' to floating-point number"
> 
> A function atoi/atof is not necessary. Automatic conversion to numeric
> could be an alternative.

Sometimes it is desirable to distinguish between integer and floating
point values.

Moreover, probably it would be reasonable to have a function, say,
sprintf, to convert one or several values to a character string to be
assigned to a symbolic parameter or used in symbolic computations.

> The following patch in glpmpl03.c might be sufficient:

>          case O_CVTNUM:
>             /* conversion to numeric */
>             {  SYMBOL *sym;
>                sym = eval_symbolic(mpl, code->arg.arg.x);
>                if (sym->str != NULL)
>                {
> //                error(mpl, "cannot convert %s to floating-point numbe"
> //                   "r", format_symbol(mpl, sym));
>                   value = atof(sym->str);
>                }
>                else
>                {
>                   value = sym->num;
>                }
>                delete_symbol(mpl, sym);
>             }
>             break;

It is not sufficient, because there should be a check that the
character string to be converted is correct. In glpk there are two
routines str2int and str2num intended to perform such conversion.





reply via email to

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