help-glpk
[Top][All Lists]
Advanced

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

Re: [Help-glpk] If-then expression: invalid use of reserved keyword if


From: glpk xypron
Subject: Re: [Help-glpk] If-then expression: invalid use of reserved keyword if
Date: Wed, 02 Nov 2011 19:21:27 +0100

Hello Nilo,

set A := {1..4};
param x{A};

solve;

printf if exists{a in A} x[a] != 0 then '' else '*\n';
printf {a in A: x[a] != 0} "%s\n", a;

data;

param x :=
  1  0
  2  1
  3  0
  4  1;
end;

Best regards

Xypron
-------- Original-Nachricht --------
> Datum: Tue, 1 Nov 2011 23:30:23 -0200
> Betreff: Re: [Help-glpk] If-then expression: invalid use of reserved keyword 
> if

> In this example, suppose that I want to print '*' a single time if x[a] is
> 0 for everyone, and a if x[a] is 1.
> 
> (supposing that A is an elemental set, and a is symbolic, and x[a] = 1 for
> at most one a).
> 
> Ideas ? Simple formatting but I miss it.
> 
> Thank you.
> 
> 2011/11/1 glpk xypron <address@hidden>
> 
> > 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
> > address@hidden
> > https://lists.gnu.org/mailman/listinfo/help-glpk
> >
> 
> 
> 
> -- 
> *Nilo Cesar Teixeira*
> address@hidden

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

NEU: FreePhone - 0ct/min Handyspartarif mit Geld-zurück-Garantie!               
Jetzt informieren: http://www.gmx.net/de/go/freephone



reply via email to

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