Adding The Solver.config File Configuration To The Java Class

Posted By : Mansi Malik | 22-May-2023

Optaplanner Java

Loading...

Introduction

In this blog article, we will discuss how to configure the solver.config file in the Java class. We'll also look at how to dynamically pass some necessary data, such as the termination limit. In Optaplanner's latest version, Solution Manager and Solver Factory don't provide any method for dynamically setting the termination-related data, so for this, we will use another class, TerminationConfig. TerminationConfig provides many methods, such as setBestScoreLimit, setDaysSpentLimit, setHoursSpentLimit, setMinutesSpentLimit, setMillisecondsSpentLimit, etc.

Please see the link provided below for further details about the Termination Config class.

https://docs.optaplanner.org/latestFinal/optaplanner-javadoc/org/optaplanner/core/config/solver/termination/TerminationConfig.html

Also, ReadGraphhopper Map Setup In Vehicle Routing Problem Using OptaPlanner

Let's see the solver.config file configuration in the Java class.

To do this, we first need to create an object of the SolverConfig class, then the data isadded in this object. We used to provide constructionHeuristic, scoreDirectorFactory, and localSearch-related information in the Solver.config file. Therefore, an object will be created for all of these fields. For constructionHeuristic configuration, we will create the ConstructionHeuristicPhaseConfig class object; for scoreDirectorFactory configuration, we will create the ScoreDirectorFactoryConfig class object; and for localSearch configuration, we will create the LocalSearchPhaseConfig class object, then set the data in all of these objects.

I only set the construction heuristic type during the construction phase, and I am using FIRST_FIT as that type. Numerous more algorithms, including WEAKEST_FIT, WEAKEST_FIT_DECREASING, STRONGEST_FIT, STRONGEST_FIT_DECREASING, and others, were supported by the construction heuristic.

Also, ReadUpgrade Procedure For an OptaPlanner Project

After setting all the data in the solverConfig object, we pass it to the solverFactary create function. We use the createFromXmlResource function whenever we are using the solverConfig.xml file.

You can configure the solver.config file using these screenshots; you can add additional configuration or remove it based on your requirements.