[Top][All Lists]
[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.
- Re: [Help-glpk] Time conversion functions, (continued)
- Re: [Help-glpk] Time conversion functions, xypron, 2008/11/21
- RE: [Help-glpk] Time conversion functions, xypron, 2008/11/21
- RE: [Help-glpk] Time conversion functions, Meketon, Marc, 2008/11/21
- Re: [Help-glpk] Time conversion functions, Maurice Diamantini, 2008/11/21
- Re: [Help-glpk] Time conversion functions, xypron, 2008/11/21
- Re: [Help-glpk] Time conversion functions, Andrew Makhorin, 2008/11/21
- Re: [Help-glpk] Time conversion functions, xypron, 2008/11/21
- Re: [Help-glpk] Time conversion functions, Andrew Makhorin, 2008/11/21
- Re: [Help-glpk] Time conversion functions, xypron, 2008/11/21
- Re: [Help-glpk] Time conversion functions, xypron, 2008/11/21
- Re: [Help-glpk] Time conversion functions,
Andrew Makhorin <=
- Re: [Help-glpk] Time conversion functions, Xypron, 2008/11/22
- Re: [Help-glpk] Time conversion functions, Andrew Makhorin, 2008/11/22
- Re: [Help-glpk] Time conversion functions, Xypron, 2008/11/22
- Re: [Help-glpk] Time conversion functions, Andrew Makhorin, 2008/11/23
- Message not available
- Message not available
- Message not available
- Message not available
- Re: [Help-glpk] Time conversion functions, Xypron, 2008/11/24
- Re: [Help-glpk] Time conversion functions, Andrew Makhorin, 2008/11/25
- Re: [Help-glpk] Time conversion functions, glpk xypron, 2008/11/25
- Re: [Help-glpk] Time conversion functions, Andrew Makhorin, 2008/11/18
- Re: [Help-glpk] Time conversion functions, Harley Mackenzie, 2008/11/18
- Re: [Help-glpk] Time conversion functions, Nigel Galloway, 2008/11/19