Sums and loops
- Summations
-
Sum up an array of variables in a constraint:
MaxCap := sum(p in 1..10) buy(p) <= 100 MaxCap := sum(p in 1..10) (buy(p) + sum(r in 1..5) make(p,r)) <= 100 MaxCap := sum(p in 1..NP, t in 1..NT) CAP(p)*buy(p,t) <= MAXCAP MaxCap := sum(p in 1..NP) (2*CAP(p)*buy(p)/10 + SCAP(p)*sell(p)) <= MAXCAP
- Loops
-
Use a loop to assign an array of constraints:
forall(t in 2..NT) Inven(t) := bal(t) = bal(t-1) + buy(t) - sell(t)
Use do/ end-do to group several statements into one loopforall(t in 1..NT) do MaxRef(t) := sum(i in 1..NI) use(i,t) <= MAXREF(t) Inven(t) := store(t) = store(t-1) + buy(t) - use(t) end-do
Can nest forall statements:forall(t in 1..NT) do MaxRef(t) := sum(i in 1..NI) use(i,t) <= MAXREF(t) forall(i in 1..NI) Inven(i,t) := store(i,t) = store(i,t-1) + buy(i,t) - use(i,t) end-do
Similarly for specification of bounds (a bound is just a simple unnamed constraint):forall(i in 1..NI) do forall(t in 1..NT) store(i,t) <= MAXSTORE(t) store(i,0) = STORE0 end-do
May include conditions in sums or loops:forall(c in 1..10 | CAP(c)>=100.0) MaxCap(c) := sum(i in 1..10, j in 1..10 | i<>j) TECH(i,j,c)*x(i,j,c) <= MAXTECH(c)
© 2001-2019 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.