Constraint based on assignment percentage

38 views
Skip to first unread message

Ivan Femenia

unread,
Sep 12, 2022, 5:29:57 AM9/12/22
to OptaPlanner development
Hello all,

I am implementing a small variation of task assignment that is provided in the quickstarts examples but I need to add a constraint based on percentage of task type assigned (X % of task A should be assigned, Y % of task B should be assigned, ...).

I tried to design the solution and here is my conclusion :
* The percentages must be stored in a @CustomShadowVariable
* A VariableListener should be implemented to update the percentages for the solution
* As these percentages are global, they should be stored in the @PlanningSolution class

But I struggle on some questions :
How these percentages can be computed ? how can we compute percentages in a VariableListener ?
How to retrieve these percentages during score calcultation => the @PlanningSolution class is not reachable in the ConstraintProvider class...

So could you please help me figure it out where I am wrong ?

Thank you,
Ivan

Lukáš Petrovický

unread,
Sep 12, 2022, 5:40:39 AM9/12/22
to optapla...@googlegroups.com
Ivan,

On Mon, Sep 12, 2022 at 11:30 AM Ivan Femenia <ivan.f...@gmail.com> wrote:
I am implementing a small variation of task assignment that is provided in the quickstarts examples but I need to add a constraint based on percentage of task type assigned (X % of task A should be assigned, Y % of task B should be assigned, ...).

I was thinking about this and I would do it in a constraint.
Calculating the number of assigned tasks is trivial there; the only issue is how to get the total number of tasks.

When you create your entities, can you pass the planning solution to the constructor? If so, your problem is solved - store the total number of tasks in the entities by reading it from the solution.

--

Lukáš Petrovický

Principal Software Engineer

lukas.pe...@redhat.com

My work week is Monday to Thursday.
No need to respond outside of your working hours.

Ivan Femenia

unread,
Sep 12, 2022, 6:51:13 AM9/12/22
to OptaPlanner development
Oh yes, I kept entities construction untouched from quickstarts examples so didn't thought about that.
Thank you for the tip

Ivan Femenia

unread,
Sep 13, 2022, 5:48:57 AM9/13/22
to OptaPlanner development
Hello again,

Thanks to you, I managed to add the percentages constraint but another problem comes because whenever the assigned percentage is overpassed the task does not remain unassigned.
After some reading, this is because the missing of nullable @PlanningVariable property but this is not compatible with chained graph which is the case in the task assignment with the use of @PlanningListVariable and I need it also for some constraint.
It seems to have a workaround https://stackoverflow.com/a/57521278, please do you have any link to that solution ? Is it possible to implement that in my case ?
Thank you for your help

Lukáš Petrovický

unread,
Sep 13, 2022, 5:55:41 AM9/13/22
to optapla...@googlegroups.com
On Tue, Sep 13, 2022 at 11:49 AM Ivan Femenia <ivan.f...@gmail.com> wrote:
It seems to have a workaround https://stackoverflow.com/a/57521278, please do you have any link to that solution ? Is it possible to implement that in my case ?

I don't think we have an example of that anywhere. It is relatively simple - pick a value that represents an unassigned task. We typically call that a "dummy" value. Use the dummy value everywhere where null would otherwise be used. Make sure your constraints understand that the dummy value means unassigned.
 

Ivan Femenia

unread,
Sep 13, 2022, 6:09:58 AM9/13/22
to OptaPlanner development
Wooah a dummy employee, ok got it !
Sorry for my questions, they looks awfully simple now ^^'
Thanks a lot

Reply all
Reply to author
Forward
0 new messages