the.wizard
the.wizard

Reputation: 1109

Priority Based Project Job Scheduling using Optaplanner

I want to enhance the project job scheduling example from Optaplanner with adding priority to each project. Let's say, each project has it's own priority (1: High, 2: Medium, 3: Low), and project with higher priority will be executed first, if projects have same priority, it will be executed based on it's order (first come first serve). If we take this example: enter image description here Let's say project Book1 has medium priority and Book2 project has High priority, which mean project Book2 should be executed first before project Book1, and of course the result will be different from the picture above. I need suggestion on how to implement this additional requirement. One solution that already in my mind was to sort all projects data list before give it to Optaplanner to solve it, but that solution seems to be a little strange. Any suggestions and comments will be appreciated. Thanks & Regards.

Upvotes: 1

Views: 945

Answers (2)

Tech Savvy
Tech Savvy

Reputation: 1

Per the Optaplanner documentation, we should not be using difficultyComparatorClass to implement business logic. The above approach violates that principle. Maybe a constraint using time should be implemented?

Upvotes: 0

the.wizard
the.wizard

Reputation: 1109

After some trials-errors and pull hair activities, I finally succeeded to enhance the example with priority base project feature. So I thought, I will share it here because maybe in future time, this might be help someone who has the same need with me. First of all, we need to add a simple property (I am using int) in Project class :

private int priority;

Remember to create the getter and setter method for this property. After that create a comparator class and give it a name AllocationDifficultyComparator, set it to implements Comparator, Serializable. Put these codes inside the compare method :

return new CompareToBuilder().append(a.getProject.getPriority(), b.getProject().getPriority()).append(b.getId(), a.getId()).toComparison();

Open Allocation class then add a difficultyComparatorClass variable inside @PlanningEntity annotation, set the value to AllocationDifficultyComparator.class. Last step, open the projectJobSchedulingSolverConfig.xml file, change the constructionHeuristicType to FIRST_FIT_DECREASING and we are done, yay! :-D

To test it, we can add priority property to sampleData xml file, for example we can use the value :

High = 3 | Medium = 2 | Low = 1

Note : if 2 project have the same priority, it will be executed based on the smaller id (it means the project come first than the other one).

That's it, I hope this share could help someone in the future to finished their job and prevent them from pulling their hair :-D

Upvotes: 3

Related Questions