An Introduction To Reasoning In OptaPlanner

ERP Solutions oodles
2 min readAug 16, 2023

--

Introduction

We will discover “What reasoning in OptaPlanner is and how to implement the reasoning in any optaplanning project” in this blog article. But let’s first go over the goal of optaplanning before moving on to the justification section. “Optaplanner is a constraint solution algorithm that uses constraints to help solve complicated problems. The limitation only indicates to Optaplanner which solution is superior than others.

Returning to the reasoning section, the goal of reasoning in OptaPlanner is to identify all constraints that are broken as a result of constraint resolution.

Example:

Imagine there is one strict rule listed in the drools file regarding the employee/shift rostering issue. The logic can be used to determine the precise cause of any shifts that remain unscheduled at the conclusion of the plan because of that one hard rule.

NOTICE: In addition to harsh rules, we can also identify when a medium or soft rule is being broken.

Types of constraints:

  • Hard limitations: Hard limitations are ones that cannot be broken under any circumstances. An employee cannot work two different shifts at the same time, for instance.
  • Medium constraints: If a planning issue prevents proper planning, then a medium restriction is one that can be broken. For instance: No employee may put in more than eight hours each day.
  • Soft constraints: These restrictions are ones that can be avoided and serve to enhance the planning solution. As an illustration, a worker doesn’t want to work on Friday afternoon.

Below is the code snippet of reasoning:

SolverFactory<OptSolution> solverFactory = SolverFactory.createFromXmlResource(“optaplanner/SolverConfig.xml”);

org.optaplanner.core.api.solver.Solver<OptSolution> solver = solverFactory.buildSolver();

OptSolution optSolution1 = solver.solve(optSolution);

ScoreManager<OptSolution> manager= ScoreManager.create(solverFactory);

log.info(manager.explainScore(driverTripAssignationSolution));

ScoreDirector scoreDirector = solver.getScoreDirectorFactory().buildScoreDirector();

scoreDirector.setWorkingSolution(solver);

To get the entity wise reasoning use below code:

Map map = scoreDirector.getIndictmentMap();

scoreDirector.getConstraintMatchTotals();

OptSolution: OptSolution is the planning entity class.

ScoreManager: A stateless service which help to calculate Score, ConstraintMatchTotal, Indictment, etc.

ScoreDirector: The ScoreDirector holds the working solution and calculates the Score for it.

Conclusion

In this blog, we have learned how to utilise reasoning in optaplanning to identify all the constraints that are being violated while they are being resolved.

At Oodles, we specialise in optimising intricate corporate procedures with custom ERP development services. Contact us at erp@oodles.io for more information about our custom ERP software development services.

--

--

ERP Solutions oodles
ERP Solutions oodles

Written by ERP Solutions oodles

We are a leading ERP development company in India offers a wide range of ERP software development services to help you grow your business exponentially.

No responses yet