Optaplanner
Today we are discussing a few major changes that will require updating and how we can do those changes.
Let's first understand the need for upgradation to a higher version, the older version had some methods that were deprecated one of them including "DRL File" which was arguably the most important file ofall the rules were written to it, in the newer version there are changes with the library in place of DRS File. The newer version is faster and better for developers to develop new software using this technology.
In the properties section of the pom.xml file, we define the version of OptaPlannar that we need to implement. I'm using OptaPlanner 8.35.0.Final, the most recent version. The updated versions now require Java 11 or above.
Creating a brenchmarkConfig.xml file and adding optaplanner-benchmark dependencies to pom.xml is no longer required.
We have replaced the drl file with a Java class that implements a ConstraintProvider and has a defineConstraints method where we can define our rules.
Thus, this is how we can define our rules. Many methods provided by ConstraintFactory can be used to write rules.
In the solverConfig.xml file, almost everything is the same; however, we define the constraintProvideClass location rather than the DRLFile location.
@CustomShadowVariable : The@CustomShadowVariable
has been deprecated. So in place of@CustomShadowVariable we can use
@ShadowVariable annotation and@PiggybackShadowVariable.
Before
After
@ValueRangeProviderRefs: In most cases, links between planning variables and value ranges can now be automatically detected. Therefore,
@ValueRangeProvider
no longer needs to provide anID
property. Likewise, planning variables no longer need to reference value range providers via thevalueRangeProviderRefs
property.
Some new annotations are also provided by OptaPlanner'slatest version like @PlanningListVariable,@PreviousElementShadowVariable,
@NextElementShadowVariable.
5.) Solver Changes
SolutionManager is used in place of ScoreManager, and the updateScore() method of ScoreManager has been replaced with the update() method of SolutionManager. When we are using ScoreManager, we can get the summary from ScoreManager using ScoreManager.getSummary() method, we now get the summary using solutionManager.explain(solution).getSummary() method.
This ends the blog with the mention of all the features of the newer version of OptaPlanner and all the facts about the previously used files and their replacements with details and hands-on experience.
We are a seasoned ERP application development company that specializes in building custom planning solutions using OptaPlanner, an open-source AI constraint solver. To learn more about our OptaPlanner development and integration services, write to us at [email protected].