1

The at-most-k constraint, given a number of tasks and users, where a given number of tasks must be completed by at most k number of users, each task is only assigned to one user, a user can have multiple tasks. the goal is to find which tasks are assigned to which users.

an example instance would be, given 4 users and 4 tasks, encode the constraint at most 2 users, task1, task2, task3.

I am coding this using the OrTools python library but any explanation would be helpful

x12
  • 11
  • 2

1 Answers1

2

Just create a boolvar for each (user, taskgroup_id) pair and restrict it like:

for t in taskgroup:
    # t1 v t2 v t3 => user_in_group
    model.AddImplication(assigment[u, t], user_in_taskgroup[u, taskgroup_id])

# user_in_group => t1 v t2 v t3
model.AddBoolOr([user_in_taskgroup[u, taskgroup_id].Not()] + [assigment[u, t] for t in tasks])

model.Add(sum(user_in_taskgroup[u, taskgroup_id] for u in users) <= k)
Stradivari
  • 2,626
  • 1
  • 9
  • 21
  • This sets the amount of tasks each user can have to be <= k, what I am looking for is that the group of tasks are only allowed to be completed by a set number of users, the current solution I am thinking is model.Add(sum(max(assignment[(u, t)] for t in tasks) for u in range(users)) <= k) however this does not seem to do what I am hoping it does. – x12 Dec 29 '20 at 15:08
  • Is user_in_taskgroup a new set of boolvar's that has to be defined? – x12 Dec 29 '20 at 16:50
  • yeah, 1 per (user, taskgroup) pair – Stradivari Dec 29 '20 at 16:54
  • Thank you for the help, unfortunately I don't think this solution is viable for what I am trying to achieve, ultimately steps are still getting assigned to more than k users. My overall SAT problem is larger than just this constraint which may prevent this solution. – x12 Dec 29 '20 at 17:08
  • Then fix your model. If you write sum() <= k, you will get that. If this is not true, then your model is wrong. – Laurent Perron Dec 29 '20 at 18:00
  • Is there a reason why the model.Add(sum(max(assignment[(u, t)] for t in tasks) for u in range(users)) <= k) does not work? Can you not use max inside a constraint? – x12 Dec 29 '20 at 18:45
  • You cannot use min() or max() from python. Use AddMinEquality and AddMaxEquality. – Laurent Perron Dec 29 '20 at 22:57
  • Min and max are expanded by python,and it interferes with the operator overloading on linear expressions. – Laurent Perron Dec 29 '20 at 22:58