Search code examples
optaplanner

For task assigning project, the same type task has limit in the sametime


My company produces sports shoes. There are some resources limited, such as molds used to produce shoes. So, in the same time, the number of the same task type task has a limit, see the picture.

How can I do this constraint in the task assigning? I think this constraint is very difficult, so I don't try to solve it.

Please help!


Solution

  • With 2 constraints? For example in this model:

    class Task {
       String name;
       Mold mold;
       TaskType taskType;
       ...
    }
    
    
    Constraint moldLimit(...) {
         return f.forEach(Task.class)
             .groupBy(Task::getMold, count())
             .filter((mold, taskCount) -> taskCount > mold.getMaxTaskCount())
             .penalize("mold limit", ONE_HARD,
                  (mold, taskCount) -> taskCount - mold.getMaxTaskCount());
    }
    
    
    
    Constraint taskTypeLimit(...) {
         return f.forEach(Task.class)
             .groupBy(Task::getTaskType, count())
             .filter((taskType, taskCount) -> taskCount > taskType.getMaxTaskCount())
             .penalize("taskType limit", ONE_HARD,
                  (taskType, taskCount) -> taskCount - taskType.getMaxTaskCount());
    }