inter

OPL keyword for intersections of sets.

Purpose

OPL keyword to construct set expressions.

context
Model files (.mod)

Syntax

BinaryExpression: Expression "==" Expression
                | Expression "!=" Expression
                | Expression "<=" Expression
                | Expression "<" Expression
                | Expression ">=" Expression
                | Expression ">" Expression
                | Expression "+" Expression
                | Expression "-" Expression
                | Expression "*" Expression
                | Expression "/" Expression
                | Expression "div" Expression
                | Expression "%" Expression
                | Expression "mod" Expression
                | Expression "in" Expression
                | Expression "not in" Expression
                | Expression "inter" Expression
                | Expression "union" Expression
                | Expression "diff" Expression
                | Expression "symdiff" Expression
                | Expression "^" Expression
                | Expression "&&" Expression
                | Expression "||" Expression
                | Expression "=>" Expression


AggregateExpression: "sum" '(' Qualifiers ')' Expression
                   | "min" '(' Qualifiers ')' Expression
                   | "max" '(' Qualifiers ')' Expression
                   | "prod" '(' Qualifiers ')' Expression
                   | "or" '(' Qualifiers ')' Expression
                   | "and" '(' Qualifiers ')' Expression
                   | "union" '(' Qualifiers ')' Expression
                   | "inter" '(' Qualifiers ')' Expression
                   | AllExpression

Description

Set data can be initialized by set expressions. These expressions are constructed from previously defined sets and the set operations union, inter, diff, and symdiff.

Two forms:

  • In the BinaryExpression form, the keyword inter goes through the first set and checks for each element whether that element is in the second set and, if it is, keeps it.

  • In the AggregateExpression form, the keyword inter allows you to express an intersection using an aggregate expression.

Examples

Binary

These code lines initialize i to {1}, u to {1,2,3,4,5}, d to {2,3}, and sd to {2,3,4,5}.


{int} s1 = {1,2,3}; 
{int} s2 = {1,4,5}; 
{int} i = s1 inter s2; 
{int} u = s1 union s2; 
{int} d = s1 diff s2; 
{int} sd = s1 symdiff s2;

Aggregate

This code line initializes rInter to {2}.


{int} i[1..3] = [ {1, 2}, {2, 3}, {2, 5} ]; 
{int} rInter = inter( x in 1..3 ) i[x];

This is true if the result is an ordered set. If you apply the property sorted or reversed to the resulting set, the result is affected accordingly.