和顺 / 势衡 返回所属 Agent
SH-03.03

约束冲突

原能力

找出压缩时间、增加任务或切换方案时可能出现的资源冲突。(细化版 p.8–9)

首选项目

OR-Tools(Apache-2.0)。 OR-Tools

匹配范围

CP-SAT 按容量与时间限制检测不可行的安排。

源码

OR-Tools · def solve(

ortools/sat/python/cp_model.py · 1785–1798 行。 在 GitHub 查看源码 · 许可证与声明

源码片段
    def solve(
        self,
        model: CpModel,
        solution_callback: Optional["CpSolverSolutionCallback"] = None,
    ) -> cmh.CpSolverStatus:
        """Solves a problem and passes each solution to the callback if not null."""
        with self.__lock:
            self.__solve_wrapper = cmh.SolveWrapper()

        self.__solve_wrapper.set_parameters(self.parameters)
        if solution_callback is not None:
            self.__solve_wrapper.add_solution_callback(solution_callback)

        if self.log_callback is not None:
  • # Copyright 2010-2025 Google LLC

OR-Tools · def add_cumulative(

ortools/sat/python/cp_model.py · 1476–1489 行。 在 GitHub 查看源码 · 许可证与声明

源码片段
    def add_cumulative(
        self,
        intervals: Iterable[IntervalVar],
        demands: Iterable[LinearExprT],
        capacity: LinearExprT,
    ) -> Constraint:
        """Adds Cumulative(intervals, demands, capacity).

        This constraint enforces that:

            for all t:
              sum(demands[i]
                if (start(intervals[i]) <= t < end(intervals[i])) and
                (intervals[i] is present)) <= capacity
  • # Copyright 2010-2025 Google LLC
接口用法示意
model.add_cumulative(intervals, demands, capacity)

实现与验收要点

识别冲突的责任主体、约束强弱及可调整范围。