prob(a <= b) is the share of the scenarios in which a <= b holds: an
estimate of its probability. It is a single number, so it can be used in a
constraint. A requirement on a probability is called a chance
constraint:
Details
reads as "demand is met in at least 90% of the scenarios". The line holds
two comparisons, which do different jobs: the inner one, demand <= stock,
is the event checked in each scenario, and the outer one, >= 0.9, is the
requirement on how often it happens. The margin argument of add()
allows for the sampling error of the estimate.
The comparison is written with <= or >=, and at least one side must
contain a random variable. == is not accepted, since the probability
that a quantity which can take any value equals one particular value is 0.
< and > are not accepted either, since for such a quantity they mean
the same as <= and >=. For vector expressions, each element gets its
own probability.
holds() turns the same comparison into a 0/1 value in each scenario, and
expectation(holds(a <= b)) is the same number as prob(a <= b).