Domain Modeling

Model your planning problem with entities, variables, and solutions.

Domain modeling is the foundation of any SolverForge application. You define your problem structure using Python dataclasses and type annotations.

Core Concepts

Model Structure

A typical SolverForge model consists of:

Planning Solution
├── Problem Facts (immutable data)
│   ├── Timeslots, Rooms, Employees, etc.
│   └── Value Range Providers
├── Planning Entities (mutable)
│   └── Planning Variables (assigned by solver)
└── Score (calculated from constraints)

Example

@planning_entity
@dataclass
class Lesson:
    id: Annotated[str, PlanningId]
    subject: str
    teacher: str
    # Planning variables - assigned by the solver
    timeslot: Annotated[Timeslot | None, PlanningVariable] = field(default=None)
    room: Annotated[Room | None, PlanningVariable] = field(default=None)

@planning_solution
@dataclass
class Timetable:
    # Problem facts - immutable
    timeslots: Annotated[list[Timeslot], ProblemFactCollectionProperty, ValueRangeProvider]
    rooms: Annotated[list[Room], ProblemFactCollectionProperty, ValueRangeProvider]
    # Planning entities - contain variables to optimize
    lessons: Annotated[list[Lesson], PlanningEntityCollectionProperty]
    # Score - calculated by constraints
    score: Annotated[HardSoftScore, PlanningScore] = field(default=None)

Planning Entities

Define planning entities that the solver will optimize.

Planning Variables

Define what the solver assigns: simple variables and list variables.

Planning Solutions

Define the container for problem data and solution score.

Shadow Variables

Define calculated variables that update automatically.

Pinning

Lock specific assignments to prevent the solver from changing them.