(!*******************************************************
Mosel Example Problems
======================
file loop.mos
`````````````
Demonstrate effect of `exists'
(c) 2008 Fair Isaac Corporation
author: S. Heipcke, 2002, rev. Sep. 2018
*******************************************************!)
model "loop"
uses "mmsystem"
public declarations
R1,R2,R3,R4,R5: range
Cost: dynamic array(R1,R2,R3,R4,R5) of real
x: dynamic array(R1,R2,R3,R4,R5) of mpvar
end-declarations
! This would normally be read in from a file
Cost(1,1,1,1,1) := 1.1
Cost(1,30,1,3,3) := 2.2
Cost(1,1,30,1,4) := 3.3
Cost(1,1,1,30,1) := 4.4
Cost(1,6,1,1,30) := 5.5
Cost(30,1,1,1,3) := 6.6
forall(i1 in R1, i2 in R2, i3 in R3, i4 in R4, i5 in R5 |
exists(Cost(i1,i2,i3,i4,i5)) ) create(x(i1,i2,i3,i4,i5))
starttime:=gettime
! 'exists' is not required here from a logical point of view, since the
! sum will only contain the variables that have been created, but it
! helps speeding up things. Compare the running times with and without it:
sum(i1 in R1, i2 in R2, i3 in R3, i4 in R4, i5 in R5 |
exists(Cost(i1,i2,i3,i4,i5)) )
Cost(i1,i2,i3,i4,i5) * x(i1,i2,i3,i4,i5) = 1
writeln("Time using `exists': ", gettime-starttime)
sum(i1 in R1, i2 in R2, i3 in R3, i4 in R4, i5 in R5 )
Cost(i1,i2,i3,i4,i5) * x(i1,i2,i3,i4,i5) = 1
writeln("Time without `exists': ", gettime-starttime)
! Display the resulting constraint definitions
exportprob(0,"",0)
end-model