Search in sources :

Example 6 with TaskAssignment

use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.

the class ProblemFactChangeUtil method unlinkTaskAssignment.

/**
 * Unlinks a task assignment from the elements chain and relinks the remaining part of the chain to the specified
 * previous chain element.
 *
 * @param taskAssignment a task assigning element to unlink from the chain.
 * @param previousElement a ChainElement to relink the chain remainder to.
 */
public static void unlinkTaskAssignment(TaskAssignment taskAssignment, ChainElement previousElement, ScoreDirector<TaskAssigningSolution> scoreDirector) {
    TaskAssignment nextTaskAssignment = taskAssignment.getNextElement();
    if (nextTaskAssignment != null) {
        scoreDirector.beforeVariableChanged(nextTaskAssignment, PREVIOUS_ELEMENT);
        nextTaskAssignment.setPreviousElement(previousElement);
        scoreDirector.afterVariableChanged(nextTaskAssignment, PREVIOUS_ELEMENT);
    }
}
Also used : TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Example 7 with TaskAssignment

use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.

the class ReleaseTaskProblemFactChange method doChange.

@Override
public void doChange(ScoreDirector<TaskAssigningSolution> scoreDirector) {
    TaskAssignment workingTaskAssignment = scoreDirector.lookUpWorkingObjectOrReturnNull(taskAssignment);
    if (workingTaskAssignment == null || workingTaskAssignment.getPreviousElement() == null) {
        // or it's simply not yet assigned.
        return;
    }
    // unlink the workingTaskAssignment from the chain.
    ChainElement previousElement = workingTaskAssignment.getPreviousElement();
    unlinkTaskAssignment(workingTaskAssignment, previousElement, scoreDirector);
    scoreDirector.beforeVariableChanged(workingTaskAssignment, PREVIOUS_ELEMENT);
    workingTaskAssignment.setPreviousElement(null);
    scoreDirector.afterVariableChanged(workingTaskAssignment, PREVIOUS_ELEMENT);
    if (workingTaskAssignment.isPinned()) {
        scoreDirector.beforeProblemPropertyChanged(workingTaskAssignment);
        workingTaskAssignment.setPinned(false);
        scoreDirector.afterProblemPropertyChanged(workingTaskAssignment);
    }
    scoreDirector.triggerVariableListeners();
}
Also used : ChainElement(org.kie.kogito.taskassigning.core.model.ChainElement) ProblemFactChangeUtil.unlinkTaskAssignment(org.kie.kogito.taskassigning.core.model.solver.realtime.ProblemFactChangeUtil.unlinkTaskAssignment) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Example 8 with TaskAssignment

use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.

the class RemoveTaskProblemFactChange method doChange.

@Override
public void doChange(ScoreDirector<TaskAssigningSolution> scoreDirector) {
    TaskAssigningSolution solution = scoreDirector.getWorkingSolution();
    TaskAssignment workingTaskAssignment = scoreDirector.lookUpWorkingObjectOrReturnNull(taskAssignment);
    if (workingTaskAssignment != null) {
        ChainElement previousElement = workingTaskAssignment.getPreviousElement();
        unlinkTaskAssignment(workingTaskAssignment, previousElement, scoreDirector);
        scoreDirector.beforeEntityRemoved(workingTaskAssignment);
        // Planning entity lists are already cloned by the SolutionCloner, no need to clone.
        solution.getTaskAssignmentList().remove(workingTaskAssignment);
        scoreDirector.afterEntityRemoved(workingTaskAssignment);
        scoreDirector.triggerVariableListeners();
    }
}
Also used : ChainElement(org.kie.kogito.taskassigning.core.model.ChainElement) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) ProblemFactChangeUtil.unlinkTaskAssignment(org.kie.kogito.taskassigning.core.model.solver.realtime.ProblemFactChangeUtil.unlinkTaskAssignment) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Example 9 with TaskAssignment

use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.

the class AbstractTaskAssigningCoreTest method printSolution.

public static void printSolution(TaskAssigningSolution solution, StringBuilder builder) {
    solution.getUserList().forEach(user -> {
        appendln(builder, "------------------------------------------");
        appendln(builder, printUser(user));
        appendln(builder, "------------------------------------------");
        appendln(builder);
        TaskAssignment taskAssignment = user.getNextElement();
        while (taskAssignment != null) {
            builder.append(" -> ");
            appendln(builder, printTask(taskAssignment));
            taskAssignment = taskAssignment.getNextElement();
            if (taskAssignment != null) {
                appendln(builder);
            }
        }
        appendln(builder);
    });
}
Also used : TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Example 10 with TaskAssignment

use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.

the class TaskAssigningGenerator method createTaskAssigningSolution.

private TaskAssigningSolution createTaskAssigningSolution(String fileName, int taskListSize, int groupListSize, int userListSize) {
    List<Group> groupList = createGroupList(groupListSize);
    List<User> userList = createUserList(userListSize, groupList);
    List<TaskAssignment> taskAssignmentList = createTaskAssignmentList(taskListSize, userList, groupList);
    TaskAssigningSolution solution = new TaskAssigningSolution("0", userList, taskAssignmentList);
    BigInteger totalFacts = AbstractSolutionImporter.factorial(taskListSize + userListSize - 1);
    BigInteger fixedFacts = AbstractSolutionImporter.factorial(userListSize - 1);
    BigInteger possibleSolutionSize = (totalFacts == null || fixedFacts == null) ? null : totalFacts.divide(fixedFacts);
    LOGGER.info("TaskAssigningSolution {} has {} tasks, {} groups, and {} users with a search space of {}.", fileName, taskListSize, groupListSize, userListSize, AbstractSolutionImporter.getFlooredPossibleSolutionSize(possibleSolutionSize));
    return solution;
}
Also used : Group(org.kie.kogito.taskassigning.core.model.Group) User(org.kie.kogito.taskassigning.core.model.User) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) BigInteger(java.math.BigInteger) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Aggregations

TaskAssignment (org.kie.kogito.taskassigning.core.model.TaskAssignment)72 User (org.kie.kogito.taskassigning.core.model.User)39 Test (org.junit.jupiter.api.Test)27 TaskAssigningSolution (org.kie.kogito.taskassigning.core.model.TaskAssigningSolution)23 ChainElement (org.kie.kogito.taskassigning.core.model.ChainElement)14 ArrayList (java.util.ArrayList)12 TestUtil.mockTaskAssignment (org.kie.kogito.taskassigning.core.model.TestUtil.mockTaskAssignment)12 TestUtil.mockUser (org.kie.kogito.taskassigning.core.model.TestUtil.mockUser)11 TaskUtil.fromTaskData (org.kie.kogito.taskassigning.service.util.TaskUtil.fromTaskData)10 Task (org.kie.kogito.taskassigning.core.model.Task)8 AddTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange)8 AssignTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)8 TestUtil.mockTaskData (org.kie.kogito.taskassigning.service.TestUtil.mockTaskData)8 RemoveTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange)6 List (java.util.List)5 AddUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AddUserProblemFactChange)5 ProblemFactChange (org.optaplanner.core.api.solver.ProblemFactChange)5 DisableUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange)4 ProblemFactChangeUtil.unlinkTaskAssignment (org.kie.kogito.taskassigning.core.model.solver.realtime.ProblemFactChangeUtil.unlinkTaskAssignment)4 ReleaseTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange)4