[Top][All Lists]

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

Re: next question - find some element of a set

From: Mate Hegyhati
Subject: Re: next question - find some element of a set
Date: Thu, 12 Dec 2019 19:45:20 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.1

Yes, sorry, forgot to mention that limitation.

I may be wrong, but getting a Singleton set is doable. Getting its only element is the thing for which I don't see a way now.

So it is possible to generate such a set, Selected, and include {s in Selected} everywhere where needed.

One way to generate it with the mentioned index solution:

set S;
set Indices := 1..card(S);
param position{s in S}:=sum{ss in S: ss<s}1;
set Selected := setof{s in S:position[s]=0} s;

Irand can be put on the top of it, if you need it to be more random.

On 12/12/19 7:12 PM, Meketon, Marc wrote:
Thank you.  That works in the case that the array cost is numeric (and would 
work for me in this case!).

The  max  function will not work if the array is symbolic.  Out of sheer 
curiosity, I wonder if there is a general solution for getting an element from 
a set and putting that into a (symbolic) parameter.

-----Original Message-----
From: Mate Hegyhati <address@hidden>
Sent: Thursday, December 12, 2019 12:35 PM
To: Meketon, Marc <address@hidden>; address@hidden
Subject: Re: next question - find some element of a set


Thanks for the clarification. If I understand correctly, and ANY proper cost 
value is ok, and you don't need the element itself, just the cost value, then 
min/max could also  work.

param some_valid_cost := max{s in S} cost[s];

Another more "random" solution (more like a workaround):

param selector{s in S} := Irand224();
param some_valid_cost := sum{s in S: selector[s] == max {ss in S} selector[ss]} 

(but it fails, if the max value is generated twice)

I hope this helps.

All the best!


On 12/12/19 4:19 PM, Meketon, Marc wrote:
Here is more clarification.  I have a set  S  and an array  cost[].
I wanted to get a cost -- any cost -- that is found in the array cost.
I didn't want to have to specify in the data section a sample element
of  S, I just wanted to use GMPL to find one.  In the example below, I
want to find  SOME_ELEMENT_IN_S  as an index to the array cost[].

set S; param cost{S};

param some_valid_cost := cost[SOME_ELEMENT_IN_S];

data; param : S : cost := A 100 B 105 C 198 ;

-----Original Message----- From: Help-glpk
<help-glpk-bounces+marc.meketon=address@hidden> On Behalf Of
Mate Hegyhati Sent: Thursday, December 12, 2019 2:29 AM To:
address@hidden Subject: Re: next question - find some element of a


I'm not exactly sure, what you would like to do, but you could just
say, but maybe this answers your question:

set sports; param  favorite symbolic in sports;

var train{sports} >=0;

s.t. foobar: train[favorite] >=2;

minimize work: sum{f in sports} train[f];


set sports := running cycling swimming; param favorite := 'running';


So put ' around the name for a symbolic parameter, and also don't put
comma between set elements.

I hope this helped. If not, please clarify your situation.

All the best,


set := A, B, C;

param some_element_in_set, symbolic := ?????;

The closest I saw was in this old help-glpk email:

Which says:

set S;

param ref{i in 1..card(S)}, symbolic, in S;

# ref[i] refers to i-th element of S;

param a{S};

... a[ref[i]]   ...  # means a[i-th element of S]

But I cannot get this to work.  If I could get it to work, then I
would do something like: param some_element_in_set := ref[1];

BTW, I’m still hoping that someone will help solve how to work the
sudoku_excel.mod example in the ‘examples\sql’ directory of the GLPK
directory under Windows 10 64bit.  I still cannot get that to work.


reply via email to

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