Sunder
Sunder

Reputation: 503

Having a PlanningEntity inside another class

I'm looking to solve a problem very similar to the Project Job Scheduling example provided by optaplanner here (I didn't find any code related to that example - if it exists it would help me a lot).

I have designed the solution using 3 classes.

My PlanningSolution is defined as such :

@PlanningSolution
public class TimeTable {

    @ValueRangeProvider(id = "resourceRange")
    @ProblemFactCollectionProperty
    private List<Resource> resourceList;

    @ValueRangeProvider(id = "startRange")
    @ProblemFactCollectionProperty
    private List<LocalDate> dates;

    @ValueRangeProvider(id = "projectRange")
    @ProblemFactCollectionProperty
    private List<Project> projectList;

    @PlanningEntityCollectionProperty
    private List<Task> taskList;

    @PlanningScore
    private HardSoftScore score;

    // ...
}

This design allowed me to write my constraints easily (a task can't start before its previous ones are finished ; a task is assigned the correct resource ; a resource can't be assigned to different tasks on the same day ; minimize the time between two tasks), but the tasks contained in my Project class have not changed after solving.
Only the tasks in the global taskList will have their PlanningVariables set correctly.

How can I remedy that ?

I have thought about making the project a PlanningEntity as well, but it really doesn't have any variable to plan inside. I also looked at shadow variables but as I understood it this is not what they are used for.

Upvotes: 0

Views: 69

Answers (1)

Radovan Synek
Radovan Synek

Reputation: 1029

If I understand your domain model correctly, each project contains a subset of all the tasks. This assignment of tasks to projects is fixed. If you are saying these project.taskLists don't show any changes after solving, while the taskList located in the TimeTable does, I would check what instances of Tasks the project.taskLists contain. All these project.taskLists should point to the Task instances from the TimeTable.taskList.

Upvotes: 1

Related Questions