Upgrade Procedure For an OptaPlanner Project

Posted By : Mansi Malik | 17-Mar-2023

Optaplanner ERP

Loading...

How Can We Migrate AnOptaPlanner ProjectFrom Old To New Versions?

Several features of OptaPlanner are currently deprecated, hence an upgrade to the project is required. In order to update our project, I'm identifying what modifications are necessary and how we may implement them.

Let's start with the pom.xml file.What dependencies are necessary for Spring Boot's OptaPlanner?

<dependency>
   <groupId>org.optaplanner</groupId>
   <artifactId>optaplanner-bom</artifactId>
   <version>${version.org.optaplanner}</version>
   <type>pom</type>
   <scope>import</scope>
</dependency>

Include this dependency inside of <dependencyManagement>.

<dependency>
   <groupId>org.optaplanner</groupId>
   <artifactId>optaplanner-spring-boot-starter</artifactId>
</dependency>

Add this one inside <dependencies>. Only these two dependencies are required for OptaPlanner.

Solver configuration :

Most likely, Spring users won't need to worry about solver configuration. Simply remove the score DRL and implement a constraint provider. Moreover, you can define a constraint-provider class path in SolverConfig.xml rather than a drl path.

If you want to remove the SolverConfig.xml file, you can do that, and the updated OptaPlanner project will automatically read the entityClass, solutionClass, and constraint provider classes, so there is no need to do any configuration for this; if you added more than one constraint provider, you will need to add the SolverConfig.xml file.

Define the localSearch configuration in a Java class if solverConfig.xml is not being used.

LocalSearchPhaseConfig localSearchPhaseConfig = new LocalSearchPhaseConfig()
        .withAcceptorConfig(new LocalSearchAcceptorConfig().withEntityTabuSize(5));
localSearchPhaseConfig.setLocalSearchType(LocalSearchType.TABU_SEARCH);

There are numerous search options available in LocalSearchType, likeHILL_CLIMBING,GREAT_DELUGE,LATE_ACCEPTANCE etc.

You can refer to the following documentation for further details on the LocalSearchPhaseConfig method:https://docs.optaplanner.org/latest/optaplanner-javadoc/org/optaplanner/core/config/localsearch/LocalSearchPhaseConfig.html

Use SolverManager to solve the problem; it offers the solve or solve and listen methods. Autowire the SolverManager and initialize it inside the constructor.

@Autowired
private SolverManager<SolutionClass, Long> solverManager;

Score Configuration :

For updating the score, you can use SolutionManager and initialize it inside constructor.

@Autowired
SolutionManager<SolutionClass, HardMediumSoftLongScore> solutionManager;

Set the initial score using theupdate or explain methods. Inside both methods, call the "callScoreDirector" method.

solutionManager.update(solutionClassObject);

or

solutionManager.explain(solutionClassObject).getSummary();

Conclusion :

You can update your OptaPlanner project by implementing these modifications. Additional improvements are detailed in the OptaPlanner documentation, which is available via the URL provided below.

https://www.optaplanner.org/download/upgradeRecipe/upgradeRecipe8.html

We are a seasoned ERP development company that provides end-to-end OptaPlanner development services to cater to the diverse industry-specific needs of our clients. To learn more about OptaPlanner development and implementation in your business project, write to us at [email protected].