[Top][All Lists]

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

Re: [Help-glpk] Sorting Vars?

From: Michael Hennebry
Subject: Re: [Help-glpk] Sorting Vars?
Date: Sat, 9 Feb 2008 16:56:17 -0600 (CST)

 On Sat, 9 Feb 2008, Andrew Makhorin wrote:

> > after specifying a 3-dimensional array of vars [1] in my model file I am
> > surprised to see that this array appears to be unsorted [2]. That is
> > very annoying as in the C API vars are always referenced by index [3].
> > So, to calculate a valid index from a given l, p and b [4] the array has
> > to be sorted!
> Not necessary. It depends on implementation. Besides, arrays can be
> sparse, in which case sorting is useless.
> >  Is there any way to do that? Alternatively is there a
> > function which returns the var's index for a given name?
> Yes. It is glp_find_col.

That works, but it's fragile and might be too slow to use repeatedly.
A more efficient and more robust mechanism might
be to read and parse the names in index order,
building a 3D table as you go.
You could convert all the non-alphanumeric characters
into blanks and look at the resulting tokens.
It wouldn't matter whether the indices were
introduced with square brackets or parenthises.
It wouldn't matter whether the indices were separated
with commas, blanks, something else, or all three.

If you wanted, armed with this data,
you could rewrite the problem, sorted as you like.

> >  4 x[1,1,2]
> >  4 x[1,1,3]
> > 10 x[2,1,0]
> >  2 x[2,1,1]
> >  2 x[2,1,2]
> >  2 x[2,1,3]
> >  3 x[1,1,4]
> > ...

Michael   address@hidden
"Those parts of the system that you can hit with a hammer (not advised)
are called Hardware;  those program instructions that you can only
curse at are called Software."

reply via email to

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