# Soft constraints and hard constraints

The terms "soft constraints" and "hard constraints" are used in the context of optimization modeling.

Is there any standard way to figure out which is which in some of the complicated models?

• Are you asking how to decide which is which when you are building a model (in which case, see dxb's answer) or how to tell which is which when reading a model someone else wrote?
– prubin
Jul 21, 2019 at 15:23
• Thanks, @prubin. In many cases in some of the practical modelling or academic papers. Jul 22, 2019 at 4:08

In an optimization model, a hard constraint is a constraint that must be satisfied by any feasible solution to the model. On the other hand, a soft constraint can be violated, but violating the constraint incurs a penalty in the objective function (often, the greater the amount by which the constraint is violated, the greater the penalty). So, a good way to start looking for soft constraints in models is to find constraints that have associated penalty terms in the objective function.

For example, suppose you are a manager, and you are planning one of your salaried employee’s schedule for the next week. Suppose that $$x \geq 0$$ is the total number of hours the employee is to work Monday through Friday, and $$y \geq 0$$ is the total number of hours the employee is to work on Saturday and Sunday.

A hard constraint in this scenario might be - “by her contract, this salaried employee is allowed to work no more than 40 hours per week”: $$x+y \leq 40$$. A similar soft constraint might be - “this employee should work no more than 40 hours per week, but must be paid £150 per hour for every hour she works over 40”: $$x + y - z \leq 40$$, where $$z \geq 0$$ is the number of hours over 40 the employee is scheduled to work. Then, in the model’s objective function, you would include a term “$$+150z$$” (assuming some type of cost minimization objective).

Note that a particular function of the decision variables can appear in both hard and soft constraints in the same model. For instance, the total hours worked by an individual worker in a week might have a hard upper limit of 60, with a goal of at most (or exactly) 40 and objective penalties for exceeding 40.

Out of many implementations of these terms in the literature, an example of categorization of the constraint into soft and hard constraints can be found in the paper by Ilham Berrada et al., where they categorized their constraints in a nurse scheduling problem as either soft or hard. They stated that:

"Some hard constraints must be satisfied by all feasible solutions. They are related to administrative and union contract specifications. Other constraints (so-called soft constraints) are concerned with days off, the number of consecutive working days, and other specific nurses' wishes".

These soft constraints are treated as goals to be reached, where the overall objective is to get as close as possible to these goals.

Paper: Berrada, Ilham, Jacques A. Ferland, and Philippe Michelon. "A multi-objective approach to nurse scheduling with both hard and soft constraints." Socio-economic planning sciences 30.3 (1996): 183-193.

• Note that the cited paper is not the first occurrence of the terms hard and soft constraints, which predate the reference by at least a couple of decades. Jul 22, 2019 at 9:34
• @KevinDalmeijer that’s right, thanks for comment. I should have said, “one of the many applications of these terms in the field...”. As the question has already been answered, should I edit my own answer? Jul 22, 2019 at 12:52
• That sounds like a good addition. I think editing your answer is a good idea. Jul 22, 2019 at 13:13
• If the law says there must always be 3 nurces on duty, it is still better having 2 nurces then letting all the clients die! Hence a system should be able to find the best solution even when it has to break hard constraints. Jul 22, 2019 at 15:35
• In nurce rostering I think of hard constraints as being things that require a report to the medical director, and soft constraints as being "would like if not too costly". Jul 22, 2019 at 15:40