Sets of tuples

Sets of tuples can be used to model data that is related.

In many constraint applications, it is necessary to process a huge quantity of data. For instance, the features of some products can be described as a relation in a database or in text files. In this case, a useful data modeling object is a tupleset, or a set of tuples.

A tuple is an ordered set of values represented by an array. Tuples are useful for representing allowed combinations of data in a model. A set of integer tuples in a model is represented by an instance of a tupleset.

The elements of a tupleset are tuples of integer values, represented by arrays. The number of values in a tuple is known as the arity of the tuple, and the arity of the tuples in a set is called the arity of the set. (In contrast, the number of tuples in the set is known as the cardinality of the set.)

In the C++ API of CP Optimizer, the class IloTupleSet represents tuplesets.

In the Java™ API of CP Optimizer, the interface IloTupleset represents tuplesets.

In the C# API of CP Optimizer, the interface ITupleSet represents tuplesets.

Note:

Set of tuples

An integer tuple is an ordered set of values represented by an array. A set of integer tuples in a model is represented by a tupleset.

The number of values in a tuple is known as the arity of the tuple.

Consider as an example a bicycle factory that can produce thousands of different models. For each model of bicycle, a relation associates the features of that bicycle such as size, weight, color and price. This information can be used in a constraint programming application that allows a customer to find the bicycle that most closely fits a specification.

Then the tupleset bicycleSet defines the set of possible combinations of features. In the C++ API, the tupleset is created and built as follows:


    IloIntTupleSet bicycleSet(env, 5);
    bicycleSet.add(IloIntArray(env, 5, 1, 57, 12, 3, 1490));
    bicycleSet.add(IloIntArray(env, 5, 2, 57, 13, 5, 1340));
    bicycleSet.add(IloIntArray(env, 5, 3, 60, 14, 3, 1790));
    bicycleSet.add(IloIntArray(env, 5, 4, 65, 14, 7, 1550));
    bicycleSet.add(IloIntArray(env, 5, 5, 67, 15, 2, 2070));
    bicycleSet.add(IloIntArray(env, 5, 6, 70, 15, 2, 1990));

In the Java API, the tupleset is created using the method IloCP.intTable and built as follows:


      IloIntTupleSet bicycleSet = cp.intTable(5);
      int[][] tuples = {{1, 57, 12, 3, 1490},
                        {2, 57, 13, 5, 1340},
                        {3, 60, 14, 3, 1790},
                        {4, 65, 14, 7, 1550},
                        {5, 67, 15, 2, 2070},
                        {6, 70, 15, 2, 1990}};
      cp.addTuple(bicycleSet, tuples[0]);
      cp.addTuple(bicycleSet, tuples[1]);
      cp.addTuple(bicycleSet, tuples[2]);
      cp.addTuple(bicycleSet, tuples[3]);
      cp.addTuple(bicycleSet, tuples[4]);
      cp.addTuple(bicycleSet, tuples[5]);

In the C# API, the tupleset is created using the method CP.IntTable and built as follows:


      IIntTupleSet bicycleSet = cp.IntTable(5);
      int[][] tuples = { new int [] {1, 57, 12, 3, 1490},
                         new int [] {2, 57, 13, 5, 1340},
                         new int [] {3, 60, 14, 3, 1790},
                         new int [] {4, 65, 14, 7, 1550},
                         new int [] {5, 67, 15, 2, 2070},
                         new int [] {6, 70, 15, 2, 1990}};
      cp.AddTuple(bicycleSet, tuples[0]);
      cp.AddTuple(bicycleSet, tuples[1]);
      cp.AddTuple(bicycleSet, tuples[2]);
      cp.AddTuple(bicycleSet, tuples[3]);
      cp.AddTuple(bicycleSet, tuples[4]);
      cp.AddTuple(bicycleSet, tuples[5]);

A tupleset can be used as an argument to a compatibility constraint in order to enforce the possible combinations allowed for a solution.