optimaru.conference_scheduling¶
Generated from the sources of optimaru/conference_scheduling/ and the stubs of its compiled
extension. The guide explains the model and the constraints in prose.
optimaru.conference_scheduling ¶
Conference scheduling — Python wrapper of the C++ solver on the optimaru engine.
Timeslot/Room/Speaker/Talk/ConferenceSchedule/Score/Solver/
SolverConfig/calculate_score/constraint_costs/constraint_info come from the
compiled C++ core (_core). Talk.slot_room is the decision variable
(-1 == unassigned; the value is the composite encoding timeslot_index * room_count + room_index),
and solve changes it and score in place::
import optimaru.conference_scheduling as cs
schedule = cs.generate_demo_data()
cs.solve(schedule, time_limit_seconds=10.0, random_seed=42)
print(schedule.score, schedule.assignment())
Score: the 37 constraints at their default weights,
17 hard and 20 soft; three of the soft ones (*_diversity_cost) are
rewards. constraint_costs(schedule) gives every constraint's raw cost (the only
per-constraint surface), and
constraint_info() lists every constraint with its default level and weight. Pick or
re-weight constraints with solve(..., constraints=...) (see
optimaru.conference_scheduling.constraints).
The pydantic mirror (for serialization) is in optimaru.conference_scheduling.models.
optimaru.conference_scheduling.models ¶
Pydantic v2 mirror of the engine domain — for JSON serialization/deserialization.
Mirrors _core's Timeslot/Room/Speaker/Talk/ConferenceSchedule and SolverConfig
1:1. Use it to store or transfer the engine shape as-is (debug dumps, regression
snapshots, ...)::
from optimaru.conference_scheduling.models import ConferenceScheduleModel
model = ConferenceScheduleModel.from_core(schedule) # engine -> pydantic
clone = ConferenceScheduleModel.model_validate_json(model.model_dump_json())
schedule2 = clone.to_core() # pydantic -> engine
TimeslotModel ¶
Bases: StrictModel
A time slot. In minutes (shared origin; midnight boundaries are multiples of 1440).
RoomModel ¶
Bases: StrictModel
A room. unavailable_timeslots are timeslot indices.
TalkModel ¶
Bases: StrictModel
Slot_room is the composite timeslot*room variable (-1 = unassigned).
ConferenceScheduleModel ¶
Bases: StrictModel
Solution mirror. score is a read-only result, kept as a separate field.
SolveConfig ¶
Bases: StrictModel
Serializable mirror of _core.SolverConfig.
ConferenceScheduleRequest ¶
Bases: SolveRequest
The conference schedule with the settings of one solve (see SolveRequest for those).
parameter_uses ¶
parameter_uses(schedule: ConferenceScheduleModel) -> list[ParameterUse]
The parameters schedule sets away from their defaults that act only through a cost.
solve refuses a model whose selection holds none of a parameter's costs
(optimaru._constraint.require_costs); the table is "Parameters and their costs" in
docs/use-cases/README.md. The timeslots' talk_types, their times and a talk's
talk_type describe the problem itself and are not checked; neither are pins.
with_initial_solution ¶
with_initial_solution(problem, solution)
Return a copy of problem whose search starts from solution.
solution is what a solve returns (ConferenceScheduleModel.from_core), or a plain
dict of that shape (the JSON the API returned). Talks are matched by code. A talk
left out becomes unassigned and the construction heuristic places it, and only
it, so a complete solution starts the search exactly from it. problem is not
mutated. Pinned talks keep their value on problem, whatever solution says.
slot_room is the composite timeslot_index * room_count + room_index, so it is
only valid for the same timeslots and rooms in the same order: ValueError if
solution lists different ones.
Raises ValueError naming the talk for an unknown or repeated code and for a
slot_room outside -1..slot_room_count - 1 (the engine does not range-check).
solve_request ¶
solve_request(request: ConferenceScheduleRequest, *, constraints=None) -> ConferenceScheduleModel
Solve a pydantic request and return the solved problem model.
This is solve(request.model_input, ...) with the request's settings as the keywords
of the same names (see SolveRequest), and constraints the selection solve
takes. The request is not changed.
optimaru.conference_scheduling.constraints ¶
Constraint assembly specs — an API for picking the cost function declaratively.
The default path (cs.solve(schedule)) enables all thirty-seven constraints at their
default weights. This module is the alternative path next to it:
pick constraints, change weights, change levels, shape the cost, and pass the list to
solve(schedule, constraints=...).
A constraint list reads one way: one class call per constraint::
import optimaru.conference_scheduling as cs
from optimaru.conference_scheduling.constraints import (
ContentConflictCost, RoomConflictCost, get_constraints,
)
cs.solve(schedule, constraints=get_constraints()) # the defaults as-is
cs.solve(schedule, constraints=[ # picked
RoomConflictCost(), ContentConflictCost(weight=500),
])
Only listed constraints are scored — leave one out and its term disappears from the
score. (The module also carries ready-made default instances: room_conflict_cost
is RoomConflictCost(), and so on.)
Every spec takes five knobs:
weightlinear multiplier on the constraint cost.None= the component default (cs.constraint_info()reports every default level and weight).levelNone= the default level, otherwiseLevel.HARDorLevel.SOFT(or the names"hard"and"soft"). This use case has no medium level:level="medium"raises ValueError.exponentsign-preserving power shaping:weight * sign(c) * |c| ** exponent. Every constraint here is global, so it shapes the one total. 2.0 = squared, so concentrated violations grow much costlier.offset(keyword) shifts that shaping of the total; 0.0 = none.clip(keyword)True(the default) counts only what lies beyond the offset,sign(c) * max(0, |c| - offset) ** exponent;Falseshapesc - offsetas it is, so a total below the offset (a 0 included) lowers the penalty. With an offset it is refused on hard (RoomConflictCostby default), because hard 0 must mean no violation.
The same constraint may be picked several times; each pick is scored on its own with its own knobs (its level included) and the picks add up. The content-conflict minutes plus their square beyond one hour::
cs.solve(schedule, constraints=[
RoomConflictCost(),
ContentConflictCost(),
ContentConflictCost(weight=1, exponent=2, offset=60),
])
cs.constraint_costs(schedule, picks) keys the second pick
"content_conflict_cost#2".
Three terms (audience_type_diversity_cost, audience_level_diversity_cost,
language_diversity_cost) are rewards: their raw cost is <= 0, so raising their
weight raises the score. A reward is never hard: level="hard" raises ValueError (here,
in score() and in the C++ core). Everything else is a penalty that flips both ways.
Names (name) are the C++ component names in snake_case
(RoomConflictCost -> room_conflict_cost). The core derives them mechanically,
so there is no hand-maintained alias table — check them with cs.list_constraints().
Module-level instance names use the same snake_case, so they match the strings
list_constraints() prints.
Constraint
dataclass
¶
Spec selecting one constraint: weight / level / shaping.
Subclasses set the ClassVars: name (the snake_case registry name the
core reports in list_constraints(); required), label_en /
label_ko (a short title) and description_en / description_ko
(one or two sentences on what one unit of raw cost means). An
intermediate base that should not need a name passes abstract=True::
class _RouteLimit(Constraint, abstract=True): ...
offset and clip are keyword-only, so the positional order stays
weight, level, exponent followed by a subclass's domain parameters.
A name must not contain #, which constraint_costs() keys
repeated picks with ("<name>#<k>").
params ¶
params() -> dict[str, Any]
The domain parameters: every dataclass field but the five knobs.
Level ¶
Bases: StrEnum
The score level a constraint is charged on. Hard dominates medium, medium dominates soft.
Score ¶
Bases: NamedTuple
Engine-level (hard, soft) from score(). Penalties, so <= 0 without rewards.
A domain with a medium level folds it the way its C++ Score adapter does (into soft, or below hard), so this compares directly with the engine.
TalkTypeIncompatibilityCost
dataclass
¶
Bases: Constraint
Talks placed in a timeslot or room that does not accept their talk type. Every (timeslot, room) cell is open to every talk in the search, so the prohibition is expressed as a cost. Default: hard, weight 100'000.
RoomUnavailabilityCost
dataclass
¶
Bases: Constraint
Talks placed in a room that is unavailable in that timeslot. Default: hard, weight 100'000.
RoomConflictCost
dataclass
¶
Bases: Constraint
Two talks in overlapping timeslots sharing a room. Valued by overlapping minutes. Default: hard, weight 1'000.
SpeakerUnavailabilityCost
dataclass
¶
Bases: Constraint
Talks placed in a timeslot where one of their speakers is unavailable. Valued per unavailable speaker. Default: hard, weight 100.
SpeakerConflictCost
dataclass
¶
Bases: Constraint
Two overlapping talks sharing a speaker. Valued by overlapping minutes per shared speaker — one person cannot be in two places at once. Default: hard, weight 10.
TalkPrerequisiteTalksCost
dataclass
¶
Bases: Constraint
A talk scheduled before (or overlapping) a talk marked as its prerequisite. Valued by the sum of both talks' durations. Default: hard, weight 10.
TalkMutuallyExclusiveTalksTagsCost
dataclass
¶
Bases: Constraint
Two overlapping talks with the same mutually exclusive tag. Valued by shared tags × overlap. Default: hard, weight 1.
ConsecutiveTalksPauseCost
dataclass
¶
Bases: Constraint
Two talks of one speaker back to back without the minimum pause. Valued by the sum of both durations. Default: hard, weight 1.
CrowdControlRiskCost
dataclass
¶
Bases: Constraint
A crowd-risk talk in a timeslot that holds two or more other risky talks — the hallway overflows. Default: hard, weight 1.
SpeakerRequiredTimeslotTagsCost
dataclass
¶
Bases: Constraint
Tags a speaker requires that the assigned timeslot lacks. Valued by tags × duration. Default: hard, weight 1.
SpeakerProhibitedTimeslotTagsCost
dataclass
¶
Bases: Constraint
Tags a speaker prohibits that the assigned timeslot carries. Valued by tags × duration. Default: hard, weight 1.
TalkRequiredTimeslotTagsCost
dataclass
¶
Bases: Constraint
Tags a talk requires that the assigned timeslot lacks. Valued by tags × duration. Default: hard, weight 1.
TalkProhibitedTimeslotTagsCost
dataclass
¶
Bases: Constraint
Tags a talk prohibits that the assigned timeslot carries. Valued by tags × duration. Default: hard, weight 1.
SpeakerRequiredRoomTagsCost
dataclass
¶
Bases: Constraint
Tags a speaker requires that the assigned room lacks. Valued by tags × duration. Default: hard, weight 1.
SpeakerProhibitedRoomTagsCost
dataclass
¶
Bases: Constraint
Tags a speaker prohibits that the assigned room carries. Valued by tags × duration. Default: hard, weight 1.
TalkRequiredRoomTagsCost
dataclass
¶
Bases: Constraint
Tags a talk requires that the assigned room lacks. Valued by tags × duration. Default: hard, weight 1.
TalkProhibitedRoomTagsCost
dataclass
¶
Bases: Constraint
Tags a talk prohibits that the assigned room carries. Valued by tags × duration. Default: hard, weight 1.
ThemeTrackConflictCost
dataclass
¶
Bases: Constraint
Two overlapping talks of the same theme track. Valued by shared themes × overlap — attendees following that track must give one up. Default: soft, weight 10.
ThemeTrackRoomChangeCost
dataclass
¶
Bases: Constraint
Two talks of one theme track on the same day in different rooms. The audience following that track has to pack up and move. Default: soft, weight 10.
SectorConflictCost
dataclass
¶
Bases: Constraint
Two overlapping talks targeting the same sector. Valued by shared sectors × overlap. Default: soft, weight 10.
AudienceTypeThemeTrackConflictCost
dataclass
¶
Bases: Constraint
Two overlapping talks sharing both a theme track and an audience type. Default: soft, weight 1.
ContentAudienceLevelFlowViolationCost
dataclass
¶
Bases: Constraint
An introductory talk scheduled after (or overlapping) an advanced talk of the same content — the audience cannot follow from easy to hard. Default: soft, weight 10.
ContentConflictCost
dataclass
¶
Bases: Constraint
Two overlapping talks of the same content. The most expensive soft constraint — the same audience wants both. Default: soft, weight 100.
DifferentDayTalksCost
dataclass
¶
Bases: Constraint
Two talks sharing content or a theme track placed on different days. Attendees have to come twice. Default: soft, weight 10.
PopularTalksRoomSizeCost
dataclass
¶
Bases: Constraint
A less popular talk getting a bigger room than a more popular one. Valued by the sum of both durations. Default: soft, weight 10.
SpeakerPreferredTimeslotTagsCost
dataclass
¶
Bases: Constraint
Tags a speaker prefers that the assigned timeslot lacks. Valued by tags × duration. Default: soft, weight 20.
SpeakerUndesiredTimeslotTagsCost
dataclass
¶
Bases: Constraint
Tags a speaker would rather avoid that the assigned timeslot carries. Valued by tags × duration. Default: soft, weight 20.
TalkPreferredTimeslotTagsCost
dataclass
¶
Bases: Constraint
Tags a talk prefers that the assigned timeslot lacks. Valued by tags × duration. Default: soft, weight 20.
TalkUndesiredTimeslotTagsCost
dataclass
¶
Bases: Constraint
Tags a talk would rather avoid that the assigned timeslot carries. Valued by tags × duration. Default: soft, weight 20.
SpeakerPreferredRoomTagsCost
dataclass
¶
Bases: Constraint
Tags a speaker prefers that the assigned room lacks. Valued by tags × duration. Default: soft, weight 20.
SpeakerUndesiredRoomTagsCost
dataclass
¶
Bases: Constraint
Tags a speaker would rather avoid that the assigned room carries. Valued by tags × duration. Default: soft, weight 20.
TalkPreferredRoomTagsCost
dataclass
¶
Bases: Constraint
Tags a talk prefers that the assigned room lacks. Valued by tags × duration. Default: soft, weight 20.
TalkUndesiredRoomTagsCost
dataclass
¶
Bases: Constraint
Tags a talk would rather avoid that the assigned room carries. Valued by tags × duration. Default: soft, weight 20.
SpeakerMakespanCost
dataclass
¶
Bases: Constraint
Speakers whose talks spread over more than two days. Valued by extra days × a working day (480 minutes) — keeps speakers from being held for the whole conference. Default: soft, weight 20.
AudienceTypeDiversityCost
dataclass
¶
Bases: Constraint
Reward: talks in one timeslot that share an audience type. Valued by shared audience types × slot duration (a negative cost, so it raises the score). Despite the name it rewards SHARED audience types. Default: soft, weight 1; a reward, so never hard.
AudienceLevelDiversityCost
dataclass
¶
Bases: Constraint
Reward: a timeslot mixing audience levels — beginners and experts both have somewhere to go. Default: soft, weight 1; a reward, so never hard.
LanguageDiversityCost
dataclass
¶
Bases: Constraint
Reward: a timeslot running talks in different languages together. Default: soft, weight 10; a reward, so never hard.
get_constraints ¶
get_constraints(constraints: list[Constraint] | None = None) -> list[Constraint]
Return the cost function. Without arguments, all thirty-seven default constraints.
When constraints is given, that list is used as-is — only the listed
constraints are scored::
get_constraints([RoomConflictCost(), ContentConflictCost(weight=500)])
Same contract as the C++ applyConstraints: an empty list (most likely a filter that came out empty) raises ValueError; a constraint named several times is scored once per pick, each with its own knobs.
score ¶
score(costs: dict, constraints: list[Constraint] | None = None) -> Score
Apply specs to raw constraint costs and produce a score — pure Python.
costs is what cs.constraint_costs(schedule) returns: per constraint, the
raw cost (one global total each; the three rewards are <= 0), before weight,
exponent, offset and level rounding. Fetch it once and rescore with different
weights without re-solving::
raw = cs.constraint_costs(schedule)
score(raw) # default set
score(raw, [RoomConflictCost(), ContentConflictCost(weight=500)])
score(raw, [ContentConflictCost(), ContentConflictCost(exponent=2, offset=60)])
No solver and no search are involved. The arithmetic matches the engine —
each total contributes weight * shape(cost, exponent, offset, clip) and hard
contributions are rounded before summing (the same order as the engine). A
second pick of a constraint reads the same raw cost with its own knobs.
When constraints is given, only those constraints are scored — the same
semantics as get_constraints. Unknown names raise ValueError, and so does
level="hard" on a reward.
optimaru.conference_scheduling._core ¶
Type stubs for the compiled optimaru.conference_scheduling._core extension.
Solver ¶
solve_with_constraints ¶
solve_with_constraints(schedule: ConferenceSchedule, constraints: Iterable[Any] | None = ...) -> None
Score the same solve with a caller-chosen constraint set (see optimaru.conference_scheduling.constraints). The given list replaces the default set; None keeps the default set. A name may be picked several times: each pick is its own instance with its own knobs, and the instances add up.
ConstraintInfo ¶
Bases: NamedTuple
One constraint-catalog row, read off the C++ default assembly.
list_constraints ¶
list_constraints() -> list[str]
Constraint names scored by this domain (default assembly order, snake_case): talk_type_incompatibility_cost, room_unavailability_cost, room_conflict_cost, ..., language_diversity_cost (37). The same names optimaru.conference_scheduling.constraints uses.
constraint_costs ¶
constraint_costs(schedule: ConferenceSchedule, constraints: Iterable[Any] | None = ...) -> dict[str, dict[str, Any]]
Raw cost of every constraint, before weight/exponent/offset/level: every
constraint is global, so "costs" holds one total. {key: {"costs": [total],
"weight": float, "exponent": float, "offset": float, "clip": bool,
"global": True, "level": "hard" | "soft", "reward": bool, "level_flippable": bool,
"name": str, "label": str, "default_weight": float, "default_level": str}}.
None = the default constraints; a pick list (as for solve) scores exactly those
picks, each entry carrying its pick's knobs, the k-th pick of a name keyed
"
constraint_info ¶
constraint_info() -> list[ConstraintInfo]
The constraint catalog, in list_constraints() order: 17 hard and 20 soft constraints at their default weights (talk_type_incompatibility_cost hard 100000, ..., language_diversity_cost soft 10). Every one is scored by default (default_enabled); the three *_diversity_cost rewards have reward=True and level_flippable=False, every other constraint flips both ways.