[Top][All Lists]

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

Re: [Help-glpk] [Fwd: Help in if Statement]

From: Andrew Makhorin
Subject: Re: [Help-glpk] [Fwd: Help in if Statement]
Date: Thu, 12 May 2011 21:28:53 +0400

On Thu, 2011-05-12 at 09:42 -0700, sina hamedheidari wrote:
> Hi Andrew,
> Thanks for your attention and your answer.
> Actually I want to make a little change in Knapsack model, I have the
> model itself from the GLPK distribution package.
> Surely you know the knapsack problem better than me.
> As you know "Selected" is the variable that restore selected items in
> binary mode (it's actually an array).
> I can see the value of "Selected" by 'display' keyword, but the
> problem is that I want to show the index of the first
> selected item in "Selected" array.
> for example if the sequence in "Selected" is like this:0 0 1 0 1 0 0 1
> The desire output would be 3.
> (3 is the index of the first selected item)
> Regards.
> Sina Hamedheidari

Assuming that Items is a set of integers from 1 to n, the first in your
case means the least. So you can use the following statement:

printf "First item is %d\n", (min{i in Items: selected[i] = 1} i);

reply via email to

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