-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Removed `__all__` because it's unneeded (quickstarts should be as simple as possible but still demoable) - standarized constraint method on define_constraints, like in Java - **Users only need to grok domain.py and, constraint.py**. Maybe solver.py and score_analysis.py later on. Everything else is stuff for the UI/REST/JSON so moved that stuff into seperate files (json_serialization.py, ...). - Used star imports for domain and constraints. --------- Co-authored-by: Christopher Chianelli <[email protected]>
- Loading branch information
1 parent
77ca693
commit 1da69b9
Showing
34 changed files
with
311 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import uvicorn | ||
|
||
from .routes import app | ||
from .rest_api import app | ||
|
||
|
||
def main(): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
python/employee-scheduling/src/employee_scheduling/json_serialization.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from timefold.solver.score import HardSoftScore | ||
from typing import Annotated, Any | ||
from pydantic import BaseModel, ConfigDict, Field, PlainSerializer, BeforeValidator, ValidationInfo | ||
from pydantic.alias_generators import to_camel | ||
|
||
ScoreSerializer = PlainSerializer(lambda score: str(score) if score is not None else None, | ||
return_type=str | None) | ||
|
||
|
||
def validate_score(v: Any, info: ValidationInfo) -> Any: | ||
if isinstance(v, HardSoftScore) or v is None: | ||
return v | ||
if isinstance(v, str): | ||
return HardSoftScore.parse(v) | ||
raise ValueError('"score" should be a string') | ||
|
||
|
||
ScoreValidator = BeforeValidator(validate_score) | ||
|
||
|
||
class JsonDomainBase(BaseModel): | ||
model_config = ConfigDict( | ||
alias_generator=to_camel, | ||
populate_by_name=True, | ||
from_attributes=True, | ||
) |
22 changes: 2 additions & 20 deletions
22
...eduling/src/employee_scheduling/routes.py → ...uling/src/employee_scheduling/rest_api.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
python/employee-scheduling/src/employee_scheduling/solver.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from timefold.solver import SolverManager, SolverFactory, SolutionManager | ||
from timefold.solver.config import (SolverConfig, ScoreDirectorFactoryConfig, | ||
TerminationConfig, Duration) | ||
|
||
from .domain import * | ||
from .constraints import define_constraints | ||
|
||
|
||
solver_config = SolverConfig( | ||
solution_class=EmployeeSchedule, | ||
entity_class_list=[Shift], | ||
score_director_factory_config=ScoreDirectorFactoryConfig( | ||
constraint_provider_function=define_constraints | ||
), | ||
termination_config=TerminationConfig( | ||
spent_limit=Duration(seconds=30) | ||
) | ||
) | ||
|
||
solver_manager = SolverManager.create(SolverFactory.create(solver_config)) | ||
solution_manager = SolutionManager.create(solver_manager) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import uvicorn | ||
|
||
from .routes import app | ||
from .rest_api import app | ||
|
||
|
||
def main(): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.