help-glpk
[Top][All Lists]
Advanced

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

Re: [Help-glpk] A couple of simply MathProg questions


From: Andrew Makhorin
Subject: Re: [Help-glpk] A couple of simply MathProg questions
Date: Thu, 26 Jan 2006 11:57:26 +0259

> 1. Is there an operator to tell me the number of symbols in the set. The
> only solution I have come up with is "sum {sb in SB} 1", but I think there
> may be a better way.
>

There should be the operator card(S) which determines the cardinality of
set S; unfortunately, it is not implemented yet.

> 2. How do I write an iteration statement to sum all of the elements except
> the last one. Again the only solution I have come up with is: "sum {sb in
> SB: sb != 'SP50'}" but this ties the model to a specific value "SP50" in the
> model and I want to vary the number of elements in SB so the terminal value
> "SP50" will change and the change is required in the model section not the
> data section. Is there a way of writing this without having to change the
> model for different numbers of elements in SB?

This is a more fundamental question, because "the last element"
assumes some linear ordering of the set elements. In your case "the
last element" is also a specific element, isn't it? It is understood
that the set might be thought as an array that defines some natural
ordering (like "ordered" sets in AMPL), however, I find such approach
very artificial. Let SB = A union B, where A = { SP1, SP2, SP3 } and
B = {SP3, SP4, SP1 }; then which element is "the last element" of SB?
I think a better way is to use a symbolic parameter defining a
specific set element, e.g.

set SB;
param the_last_element, symbolic, in SB;
... sum {sb in SB: sb != the_last_element } ...


Andrew Makhorin





reply via email to

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