Approximate the cost function
In some cases, it may be best to approximate the cost function.
The client for your application may supply, as part of the specification, a cost function that takes into account various complex measures of solution quality from a business point of view. Since it is familiar and business-like, your client may expect to see results in terms of this cost function, as he or she already understands this measure.
However, cost functions coming from clients may not necessarily be the best way to get good solutions to an optimization problem. In such situations, a proxy for the cost function supplied by the client may be a better way to proceed.
The idea behind this advice is that the proxy approximates the cost function supplied by the client. The proxy should correspond closely to the client-supplied cost function, but it should be significantly more amenable to optimization with constraint programming. CP Optimizer will optimize the proxy to produce a good solution. However, the client need never see this proxy, as you can write code in your application to calculate his or her preferred cost function from the solution produced by the proxy.
As an example of a good place to use a proxy instead of a client-supplied cost function, consider the nursing roster again. In order to limit the number of times that a given nurse must work at night, it is conventional in some rostering applications to use a Big-M formulation, where a counting variable with a very large maximal value is introduced as part of the cost function. A better approach is to add a constraint that limits the maximum value of this counting variable, instead of adding this parameter in the cost function.