Code Monkey home page Code Monkey logo

timefoldai / timefold-solver-python Goto Github PK

View Code? Open in Web Editor NEW
36.0 6.0 3.0 14.72 MB

Timefold Solver is an AI constraint solver for Python to optimize the Vehicle Routing Problem, Employee Rostering, Maintenance Scheduling, Task Assignment, School Timetabling, Cloud Optimization, Conference Scheduling, Job Shop Scheduling, Bin Packing and many more planning problems.

Home Page: https://timefold.ai

License: Apache License 2.0

employee employee-scheduling maintenance-scheduling metaheuristic-optimisation operational-ai planning-algorithms python resource-allocation-algorithm solver vehicle-routing

timefold-solver-python's Introduction

PROJECT MOVED

This project has been merged into the Timefold Solver repo. All future development will be done there.

timefold-solver-python's People

Contributors

christopher-chianelli avatar dependabot[bot] avatar ge0ffrey avatar jdmbs avatar leon0824 avatar triceo avatar zepfred avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

timefold-solver-python's Issues

README uses value_range_provider_refs

Are value range provider refs still needed? In Java, by default they are not if there is no ambiguity.

From the readme:
@planning_variable(Timeslot, value_range_provider_refs=["timeslotRange"])

python: hello-world / JavaException when using DEBUG log level

Describe the bug

Turning on DEBUG logging causes exceptions with the hello-world example.

Expected behavior
More detailed log messages.

Actual behavior

The following error is shown (only first few lines):

Traceback (most recent call last):
File "DefaultSolver.java", line 200, in ai.timefold.solver.core.impl.solver.DefaultSolver.solve
Exception: Java Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/***/.virtualenvs/timefold/lib/python3.11/site-packages/timefold/solver/_solver.py", line 109, in solve
java_solution = self._delegate.solve(java_problem)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ai.timefold.jpyinterpreter.types.errors.ai.timefold.jpyinterpreter.types.errors.AttributeError: ai.timefold.jpyinterpreter.types.errors.AttributeError: object '08:30' does not have attribute 'strftime'

To Reproduce

diff --git a/python/hello-world/src/hello_world/main.py b/python/hello-world/src/hello_world/main.py
index 660f7430..4b60fade 100644
--- a/python/hello-world/src/hello_world/main.py
+++ b/python/hello-world/src/hello_world/main.py
@@ -10,7 +10,7 @@ from .domain import *
from .constraints import define_constraints

-logging.basicConfig(level=logging.INFO)
+logging.basicConfig(level=logging.DEBUG)
LOGGER = logging.getLogger('app')

Environment

Timefold Solver Version or Git ref:
1.11.0b0

Output of java -version:
openjdk version "17.0.11" 2024-04-16
OpenJDK Runtime Environment (build 17.0.11+9-suse-150400.3.42.1-x8664)
OpenJDK 64-Bit Server VM (build 17.0.11+9-suse-150400.3.42.1-x8664, mixed mode, sharing)

Output of uname -a or ver:
Linux think14 5.14.21-150500.55.65-default TimefoldAI/timefold-solver#1 SMP PREEMPT_DYNAMIC Thu May 23 04:57:11 UTC 2024 (a46829d) x86_64 x86_64 x86_64 GNU/Linux

Getter throws error about name format

Describe the bug
Getter methods for accessing planning entities are not usable. I am unsure if this is an intended behavior of Timefold or not, but this was the recommended method for OptaPy. If not a bug then increased documentation would be helpful.

Expected behavior
I expect to be able to annotate either atttributes or methods in a class and still construct a valid PlanningSolution.

Actual behavior
Error is thrown

To Reproduce
I was able to reproduce by modifying tests/test_solver_factory.py. The Solution class now reads:

@planning_solution
@dataclass
class Solution:
    entities: List[Entity]
    value_range: Annotated[List[int], ValueRangeProvider]
    score: Annotated[SimpleScore, PlanningScore] = field(default=None)

    def get_entities(self) -> Annotated[List[Entity], PlanningEntityCollectionProperty]:
        return self.entities
    
    def __str__(self) -> str:
        return str(self.entities)

Note the approach here of Annotating the method similar to the original Annotated attribute.

I received:

java.lang.java.lang.IllegalStateException: java.lang.IllegalStateException: The getterMethod (public ai.timefold.jpyinterpreter.types.collections.PythonLikeList org.jpyinterpreter.user.__main__.Solution.$method$get_entities()) with a PlanningEntityCollectionProperty annotation has a methodName ($method$get_entities) that does not start with a valid prefix ([get, is]).

Environment

Timefold Solver Version or Git ref:
1.11.0b0

Python version used:
3.12.4

Output of uname -a or ver:
Darwin MacBook-Pro-4.local 23.5.0 Darwin Kernel Version 23.5.0: Wed May 1 20:14:38 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6020 arm64

Additional information

Occurred during migration from OptaPy.

Discussion: Package Layout

Determine how we should layout the classes, functions and packages.

Some options:

  • Everything accessible from timefold.solver
  • Everything accessible from a package at most 1 level deep to timefold.solver
  • Copy Java's package layout

jpyinterpreter - Java annotation support

Currently, timefold.solver is doing a lot of extra work just to add annotations (see https://github.com/TimefoldAI/timefold-solver-python/blob/main/timefold-solver-python-core/src/main/java/ai/timefold/solver/python/PythonWrapperGenerator.java). Ideally, the entire class can be removed if jpyinterpreter allows adding annotations to fields and methods.

Python supports annotations via Annotated: https://docs.python.org/3/library/typing.html#typing.Annotated ,
so

class Entity:
    value: V | None
    
    def __init__(self):
        self.value = None
    
    @planning_variable(V)
    def get_value(self):
        return self.value

    def set_value(self, value):
        self.value = value

can be replaced with

class Entity:
    value: PlanningVariable(V | None)
    
    def __init__(self):
        self.value = None

(where PlanningVariable = lambda x: Annotated[x, JavaAnnotation(annotation_class=PlanningVariable.class)])

print(ScoreAnalysis): make it easy to analyze a score during POC

print() is great during POC
ScoreAnalysis and ConstraintAnalysis should work will it wel

Blocked by TimefoldAI/timefold-solver#883
This should work well in Java too.

Current status:

print(score_analysis)
<timefold.solver.score._score_analysis.ScoreAnalysis object at 0x1049ff350>

    print(score_analysis.constraint_map)
    
{ConstraintRef(package_name='org.jpyinterpreter.user.employee_scheduling.domain', constraint_name='Desired day for employee'): <timefold.solver.score._score_analysis.ConstraintAnalysis object at 0x1049b6fc0>, ConstraintRef(package_name='org.jpyinterpreter.user.employee_scheduling.domain', constraint_name='Undesired day for employee'): <timefold.solver.score._score_analysis.ConstraintAnalysis object at 0x17eddc440>, ConstraintRef(package_name='org.jpyinterpreter.user.employee_scheduling.domain', constraint_name='At least 10 hours between 2 shifts'): <timefold.solver.score._score_analysis.ConstraintAnalysis object at 0x17eddc110>, ConstraintRef(package_name='org.jpyinterpreter.user.employee_scheduling.domain', constraint_name='Max one shift per day'): <timefold.solver.score._score_analysis.ConstraintAnalysis object at 0x17eddc200>, ConstraintRef(package_name='org.jpyinterpreter.user.employee_scheduling.domain', constraint_name='Missing required skill'): <timefold.solver.score._score_analysis.ConstraintAnalysis object at 0x17eddc350>, ConstraintRef(package_name='org.jpyinterpreter.user.employee_scheduling.domain', constraint_name='Overlapping shift'): <timefold.solver.score._score_analysis.ConstraintAnalysis object at 0x17eddc380>, ConstraintRef(package_name='org.jpyinterpreter.user.employee_scheduling.domain', constraint_name='Unavailable employee'): <timefold.solver.score._score_analysis.ConstraintAnalysis object at 0x17eddc2f0>}

Desired: I want to know how many overlapping shifts there are, at which impact weight. Pretty printed (see ScoreExplanation docs)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.