Hello Kasper,

in GMPL "if" is not a statement but an expression. The following
is a valid use of if:

set A := {1..4};
param x{A};
printf {a in A} ( if x[a] then "x[%s] = %d\n" else "" ), a, x[a];
data;
param x :=
  1 0
  2 2
  3 0
  4 1;
end;

Best regards

Xypron


-------- Original-Nachricht --------
> Datum: Tue, 1 Nov 2011 15:11:33 +0100
> Betreff: [Help-glpk] If-then expression: invalid use of reserved keyword if

> Hi guys
> 
> I was trying to make a simple if-then statement as below, but failed with
> the error: "invalid use of reserved keyword if".
> I then tried searching the archive but the closest I got to an answer, was
> that it is not allowed to use if-then like this.
> Anyone know a workaround for that?
> I got a lot of 0-entries in 'x' and i simply just want to print the ones
> that is set to 1
> 
> for {r in R} {
>  for {s in S} {
>   for {i in 1..fr[r]} {
>    if x[s,r,i] = 1 then printf "x[%s,%s,%i] = %i\n", s,r,i,x[s,r,i]
>   }
>  }
> }
> 
> Best regards,
> Kasper

-- 
Follow me at http://twitter.com/#!/xypron

Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir
belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.de

_______________________________________________
Help-glpk mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/help-glpk

Reply via email to