[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-glpk] New statements (solve; printf, if, for, etc.)
From: |
Andrew Makhorin |
Subject: |
Re: [Help-glpk] New statements (solve; printf, if, for, etc.) |
Date: |
Thu, 5 Aug 2004 21:03:38 +0400 |
>I am learning and testing the new statements of the 4.6 version, and in
>my test I was not able to print i , j and k only if x[i,j,k] =1.
>
>The code used was:
>
>printf("\nFlow Assignment: ");
>for {i in I}
>{
> for {j in J}
> { for {k in K} printf "\nThe flow from %d to %d is via hub %d.",
> if x[i,j,k] then i,j,k;
> }
>}
>
>With this code, the output print all the cases.
>
>What's wrong?
You should write:
for {k in K: x[i,j,k]} printf ...
to skip executing printf when x[i,j,k] is false.
Btw, "if x[i,j,k] then i,j,k" is three separate expressions: the first
is a conditional expression (if x[i,j,k] is true, its value is current
value of i, otherwise zero), the second is j, and the third is k.
Andrew Makhorin