# Coverage and comfort rules

You will know what the rules that do not come from the Labour Code read and what they cost: all-rounders, quotas per game category, travel time, carpooling, quality thresholds, stability of an already published plan, and how all of them treat a past that has already been lived.

## All-rounder game category and all-rounder reserve

At most one game category carries the `polyvalent` flag (partial unique index). A staff member who has it among their skills is an **all-rounder**:

- `hasCompetenceFor(stand)` returns true for any stand: they are never penalised by `appreciationIncompatible`;
- they are excluded from `limiterTypologiesDistinctesParAnimateur`, because spreading them around is their reason for being;
- `preserverBufferPolyvalents` penalises every timeslot where no all-rounder is left free.

This last rule is **deliberately in tension** with `equilibrerCharge`: a polyvalent kept in reserve mechanically unbalances the load. The trade-off is carried by the levels: soft against medium, balancing wins except on a tie. While no game category is polyvalent, the rule costs nothing. The polyvalent is a reinforcement, not a specialist ([ADR 0017](repo:docs/decisions/0017-fragilite-le-ninja-est-un-renfort-pas-un-specialiste.md)).

## A quota per game category

A game category may carry a ceiling, `maxCreneauxParAnimateur`, entered on its record; empty, "no ceiling". The hard rule `plafondCreneauxParTypologie` enforces it ([ADR 0042](repo:docs/decisions/0042-quota-par-typologie-sur-la-typologie.md)). Two choices to know:

- **The unit is the timeslot**, not the hour: four one-hour timeslots and four six-hour timeslots weigh the same.
- **A seat counts for every game category its stand offers**, not for those its staff member masters. You hold the game you sit at, whether the record mentions it or not. This is the opposite choice from `limiterTypologiesDistinctesParAnimateur`, which reads the intersection: that one is about what a person must learn, this one about what a game consumes.

The scope is the **whole edition**, never the day or week. The rule being hard, a ceiling set too low makes the edition infeasible rather than exceeded: the diagnostic then names who, which category, how many timeslots for which ceiling. The Game categories page carries the matching reading (staff members actually assigned, seats, hours, gap with those the referential appreciates).

## Travel time between two seats

`eviterChangementEmplacementEloigne` looks only at two touching seats and judges 300 m as the crow flies with no notion of time; `limiterEmplacementsParJour` counts a day's zones with neither order nor distance. `trajetInsuffisantEntrePostes` fills this gap. Walking time between two geolocated locations is **crow-fly distance × detour factor ÷ walking speed**, rounded up to the minute: 1,000 m at 4 km/h with a factor of 1.3 make 20 min. For two consecutive seats of the same animateur the same day, on two different locations, separated by a **strictly positive** gap, each minute missing from the gap beyond the tolerance costs one medium point: a 10-minute gap for 20 minutes of travel and 5 minutes of tolerance cost 5, a slope to descend.

- **No double counting**: a pair with zero gap stays the business of `eviterChangementEmplacementEloigne`, a pair is judged by one or the other; only two consecutive shifts form a pair.
- **No routing service** (neither OSRM nor Google): no network dependency, no data sent to a third party, a deterministic computation. The detour factor is the lever for a site where one goes around.
- **Medium and adjustable, not hard**: a tight trip is a discomfort, the speed an estimate, no legal basis.
- A stand without a location, or a location without coordinates, makes the rule inert: an unknown trip is neither short nor long.

The connection check (`GET /api/planning/enchainements`, `consulter_repas_pauses`, `enchainements` section) reads the persisted plan with the same computation but a wider net: all consecutive pairs, zero gap and past included; it also flags a gap that is the legal break when the trip eats part of it ("trip taken from the break").

## Grouped arrival (carpooling)

Volunteers come several to a car and leave together. `affiniteAdHoc` cannot say it: too strict for a car (which does not need the same stand) and too weak (nothing aligns the hours). `arriveeGroupee` reads, for each `ARRIVEE_GROUPEE` adjustment (2 to 4 members), each pair of the group and each day:

- if one member works and the other does not: **flat penalty of 120 minutes**, because "the same days" weighs as much as "the same hours";
- if both work: the minutes of gap between their **first starts** beyond the tolerance (30 min by default, adjustable on the rule's row), plus those between their **last ends**. These are the effective windows, read on the same (staff member, day) folding as `eviterFermeturePuisOuverture`: a break or a meal break in the middle of the day changes nothing.

A member arriving 45 min after the other costs 15: per pair and per day, in minutes, a slope not a wall. The rule is **soft and not medium**: a comfort that must yield to `equilibrerCharge`, wishes and all legal rules; a fully past day is no longer billed.

Different declared unavailabilities make some days inevitably misaligned: the Availability tab's Carpooling count them before validation, writing the adjustment warns (by id) and the consistency list recalls it. The Problems page lists misaligned days per group, and the space tells each person, day by day, whether their carpool holds, without detailing others' seats.

## Quality thresholds

The "Organisation quality" rules read their thresholds in `ParametresQualite`, **persisted per edition**, set in Settings, Organisation tab (the line of the rule reading them points there). The `planning.contraintes.*` block gives the values of an edition that never set them, and a scenario carries them in `parametres.organisation:`. The list of thresholds and their defaults is in [shifts, legal parameters, meals and quality](parametres-legaux-et-qualite.md#les-paramètres-de-qualité). None has a public-order floor: they are comforts the organiser arbitrates; leaving both service hours empty is a legitimate answer ([ADR 0031](repo:docs/decisions/0031-signaler-le-plancher-sans-le-decider.md)). The reasoning on 22:00 and 10:00 is in [Rest and consecutive days](repos-et-jours-d-affilee.md).

## Stability of the published plan

`stabiliteDuPlanPublie` (medium, "Organisation quality", adjustable) answers an observation: a solve relaunched after publication moved dozens of already notified people for a marginal fairness gain ([ADR 0025](repo:docs/decisions/0025-stabilite-du-plan-publie.md)). **What it counts**: one medium point per seat whose holder is not the one the published plan had on that stand and timeslot, one point per person to whom the publication would say "your schedule changed". The facts are the seats of the last published snapshot (`AffectationPubliee`), loaded by `SolveRunner.prepareProblem` before each solve and diagnostic, never sent by a client. A published seat left empty costs as much as a replacement: it is what stops the solver from freely drawing a holder to a new line while leaving a hole behind.

**What it deliberately does not count**: anything while nothing has been published (the rule is silent); a stand or timeslot created after publication (nobody was notified of anything there); a seat added on a published line counts its new occupant, a person to notify. **What it cannot do**: it is medium, a hard rule or an unavailability always wins (`PlanningHardConstraintsTest.publishedSeatsNeverOutweighAHardRule`), and it freezes nothing (to freeze, there are locks and incremental replanning). **Its default weight is the strong importance (25)** (`planning.constraint-weights.stabiliteDuPlanPublie`): `equilibrerCharge` produces thousands of points, so at equal weight stability would weigh little; it is dosed per edition and switched off by the switch.

### Keeping feasibility despite stability

When a change adds seats (a new stand open all day), filling a new seat at peak hours requires a chain of moves that every stability point makes impassable step by step. Three mechanisms answer this:

- the feasibility phase carries a *ruin and recreate* selector restricted to the seats of a hole's hour (`HoleNeighbourPosteFilter`, `solverConfig.xml`), which evaluates the chain as a single move;
- as soon as a plan is published and the rule is active, the solve runs **in two stages within the same job**: feasibility first, stability weighted at zero in memory, at most two thirds of the budget; then polishing, stability restored, which gives their published seats back to as many people as possible. The Calculate tab's summary says so, with the number of seats returned ([ADR 0067](repo:docs/decisions/0067-la-faisabilite-avant-la-stabilite-apres-publication.md));
- another hole resists *ruin and recreate* because its chain goes through another day of the week: `WeekRelocationMoveIteratorFactory` plays the whole chain as a single move, with colleagues eligible in the sense of `EligibleAnimateurMoveFilter`; when the edition holds consecutive days hard, the returned day may be in the other week.

**A changing grid takes the rule's grip away**: a derivation or a template calendar replacing the grid (the saved plan goes with it) reshuffles all stand × timeslot lines; an added stand does not move the others. **The count beside the score**: each solve returns `impactPublication.personnes`, the number of people the publication would notify, computed as the publication computes it (a person changing two seats counts two points and one person): the screen shows this count.

## Counted, not blamed: the past

During the event, a solve receives the seats of timeslots already started **taken from the saved plan and pinned**: the past is frozen ([ADR 0044](repo:docs/decisions/0044-le-passe-est-fige.md), mechanics in [plan, locks and publication](plan-verrous-et-publication.md)). These seats carry a `passe` flag that every rule reads by a single logic:

- a past seat **counts**: it stays in every stream, group and join (what someone worked yesterday conditions the rest due tonight, the hours left in the week, the consecutive days);
- a past seat is **never blamed**: a match whose seats are all past (a hole from yesterday, a minor at night yesterday, a meal break missed yesterday) is history the solver cannot repair, and billing it would stop a feasible future from reaching zero hard. A match is billed only if at least one of the seats it involves is not past.

**A medium floor during the event, accepted.** `equilibrerCharge` and `equilibrerCreneauxPenibles` measure the whole edition, past seats included, and are billed only while a seat is to come; but the solve can move only the future: a gap dug before today cannot be made up, and the medium score keeps a floor no relaunch brings back to zero. It is neither flagged like the [per-rule floors](doser-et-desactiver-les-regles.md) nor subtracted: a solve's score during the event is compared to the previous one, not to zero. Measuring balance only on the future would invert the rule: the animateur already loaded yesterday would become "to load" again tomorrow.
