[[cloudBalancingSolverConfiguration]]
= Solver configuration
:imagesdir: ../../..

The solver configuration file determines how the solving process works; it is considered a part of the code.
The file is named `cloudBalancingSolverConfig.xml`.

.cloudBalancingSolverConfig.xml
====
[source,xml,options="nowrap"]
----
<?xml version="1.0" encoding="UTF-8"?>
<solver xmlns="https://www.optaplanner.org/xsd/solver" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="https://www.optaplanner.org/xsd/solver https://www.optaplanner.org/xsd/solver/solver.xsd">
  <!-- Domain model configuration -->
  <solutionClass>org.optaplanner.examples.cloudbalancing.domain.CloudBalance</solutionClass>
  <entityClass>org.optaplanner.examples.cloudbalancing.domain.CloudProcess</entityClass>

  <!-- Score configuration -->
  <scoreDirectorFactory>
    <easyScoreCalculatorClass>org.optaplanner.examples.cloudbalancing.optional.score.CloudBalancingEasyScoreCalculator</easyScoreCalculatorClass>
    <!--<constraintProviderClass>org.optaplanner.examples.cloudbalancing.score.CloudBalancingConstraintProvider</constraintProviderClass>-->
  </scoreDirectorFactory>

  <!-- Optimization algorithms configuration -->
  <termination>
    <secondsSpentLimit>30</secondsSpentLimit>
  </termination>
</solver>
----
====

This solver configuration consists of three parts:

. *Domain model configuration*: _What can OptaPlanner change?_
+
We need to make OptaPlanner aware of our domain classes, annotated with `@PlanningEntity` and `@PlanningSolution` annotations:
+
[source,xml,options="nowrap"]
----
  <solutionClass>org.optaplanner.examples.cloudbalancing.domain.CloudBalance</solutionClass>
  <entityClass>org.optaplanner.examples.cloudbalancing.domain.CloudProcess</entityClass>
----

. *Score configuration*: _How should OptaPlanner optimize the planning variables?
What is our goal?_
+
Since we have hard and soft constraints, we use a ``HardSoftScore``.
But we need to tell OptaPlanner how to calculate the score, depending on our business requirements.
Further down, we will look into two alternatives to calculate the score, such as using an easy Java implementation, or Constraint Streams.
+
[source,xml,options="nowrap"]
----
  <scoreDirectorFactory>
    <easyScoreCalculatorClass>org.optaplanner.examples.cloudbalancing.optional.score.CloudBalancingEasyScoreCalculator</easyScoreCalculatorClass>
    <!--<constraintProviderClass>org.optaplanner.examples.cloudbalancing.score.CloudBalancingConstraintProvider</constraintProviderClass>-->
  </scoreDirectorFactory>
----

. *Optimization algorithms configuration*: _How should OptaPlanner optimize it?_
+
In this case, we use the default <<optimizationAlgorithms,optimization algorithms>> (because no explicit optimization algorithms are configured) for 30 seconds:
+
[source,xml,options="nowrap"]
----
  <termination>
    <secondsSpentLimit>30</secondsSpentLimit>
  </termination>
----
+
OptaPlanner should get a good result in seconds (and even in less than 15 milliseconds with
<<realTimePlanning,real-time planning>>), but the more time it has, the better the results.
Advanced use cases might use different <<termination,termination criteria>> than a hard time limit.
+
The default algorithms already easily surpass human planners and most in-house implementations.
Use the <<benchmarker,Benchmarker>> to <<powerTweaking,power tweak>> to get even better results.
