stateFunction

Creates a new state function.

Note: this section describes the function stateFunction. There is also a type with the same name, see stateFunction. The semantics of state functions are also described elsewhere, see State functions in CP Optimizer.

Syntax


stateFunction stateFunction(transitionMatrix distanceMatrix = null)

Parameters

  • distanceMatrix: an optional transition matrix defining the transition distance between consecutive states of the state function.

Description

Informally speaking, a state function is a decision variable whose value is a set of non-overlapping intervals over which the function maintains a particular non-negative integer state. In between those intervals, the state of the function is not defined, typically because of an ongoing transition between two states.

For instance a state function could be used to describe the evolution of an oven's temperature over time. Assuming there are 3 possible temperature levels (indexed by 0, 1, and 2), a fixed value for this state function could be the following set of non-overlapping valued intervals:

  • [start=0, end=100): state=0,
  • [start=150, end=250): state=1,
  • [start=250, end=300): state=1,
  • [start=320, end=420): state=2,
  • [start=460, end=560): state=0, ...

A set of constraints is available to restrict the evolution of a state function. These constraints allow you to specify:

  • That the state of the function must be defined and should remain equal to a given state everywhere over a given fixed or variable interval (alwaysEqual).
  • That the state of the function must be defined and should remain constant (no matter its value) everywhere over a given fixed or variable interval (alwaysConstant).
  • That intervals requiring the state of the function to be defined cannot overlap a given fixed or variable interval (alwaysNoState).
  • That everywhere over a given fixed or variable interval, the state of the function, if defined, must remain within a given range of states [vmin, vmax] (alwaysIn).

Example

The value of the state function described above is a possible solution to the following problem.


a1 = intervalVar(size=100);
a2 = intervalVar(size=150);
a3 = intervalVar(size=100);
a4 = intervalVar(size=50);
a5 = intervalVar(size=100);
a6 = intervalVar(size=100);
// A transition matrix between temperature levels [0,1,2]
distanceMatrix = transitionMatrix(
           0, 50, 30, 
          30,  0, 20, 
          40, 20,  0,);
temperature = stateFunction(distanceMatrix);
alwaysEqual(temperature, a1, 0);
alwaysIn(temperature, a2, 1, 2);
alwaysEqual(temperature, a3, 1, 1, 1);
alwaysEqual(temperature, a4, 1, 1, 1);
alwaysEqual(temperature, a5, 2);
alwaysEqual(temperature, a6, 0);

Requirements

  • If a transition matrix distanceMatrix is specified, this matrix should satisfy the triangle inequality.