Skip to content

Commit

Permalink
Fix start earliesr objective
Browse files Browse the repository at this point in the history
  • Loading branch information
tpaviot committed Dec 14, 2023
1 parent 41850e3 commit 7d7268e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
22 changes: 22 additions & 0 deletions processscheduler/objective.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,28 @@ def __init__(self, **data) -> None:


class ObjectiveTasksStartEarliest(Objective):
"""This is the dual of the completion weighted times
but for task starts."""

def __init__(self, **data) -> None:
all_priorities = []
for task in processscheduler.base.active_problem.tasks.values():
if task.optional:
all_priorities.append(task._start * task.priority * task._scheduled)
else:
all_priorities.append(task._start * task.priority)
priority_sum = z3.Sum(all_priorities)
priority_indicator = IndicatorFromMathExpression(
name="WeightedStartTimes", expression=priority_sum
)
super().__init__(
name="MinimizeWeightedStartTimes",
target=priority_indicator,
kind="minimize",
)


class ObjectiveMinimizeGreatestStartTime(Objective):
"""minimize the greatest start time, i.e. tasks are schedules
as early as possible"""

Expand Down
8 changes: 4 additions & 4 deletions test/test_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,13 @@ def test_start_earliest_2():
ps.TaskStartAt(task=task_1, value=8)
ps.TaskPrecedence(task_before=task_1, task_after=task_2)

ps.ObjectiveTasksStartEarliest(list_of_tasks=[task_2, task_3])
ob = ps.ObjectiveTasksStartEarliest(list_of_tasks=[task_2, task_3])

solution = solve_problem(problem)
assert solution
assert solution.tasks["task1"].start == 8
assert solution.tasks["task2"].start == 13
assert solution.tasks["task3"].start == 0
# the weighted start time should be:
# 0 * 1 + 8 * 1 + 13 * 1
assert solution.indicators[ob.target.name] == 21


def test_start_latest_1():
Expand Down

0 comments on commit 7d7268e

Please sign in to comment.