title: Task scheduling gets stuck
body: <p>I am currently trying to get my grip on OptaPlanner as it seems to be the perfect solution for <a href="https://softwareengineering.stackexchange.com/questions/237431/algorithm-to-calculate-scheduling-of-task-list-check-feasability">a problem I have</a>.</p>
  <p>Basically the <a href="https://www.optaplanner.org/docs/optaplanner/latest/use-cases-and-examples/project-job-scheduling/project-job-scheduling.html#projectJobScheduling" rel="nofollow noreferrer">Project job scheduling</a> example is what I am going for, but as I only know my Java basics this is way to complex to start with. So I am trying to start with a very limited example and work my way up from there:</p>
  <p>I have tasks with a duration and one defined predecessor.
  The planning entity is the time each task starts.</p>
  <p>I have a hard score that punishes tasks starting before starttime+duration of its predecessor. I also have a soft score that tries to reduce gaps, keeping the overall process as short as possible.</p>
  <pre><code>public HardSoftScore calculateScore(Schedule schedule) {
      int hardScore = 0;
      int softScore = 0;
  
      for (Task task : schedule.getTaskList()) {
          int endTime = task.getAllocation().getStartTime() + task.getDuration();
          softScore = -endTime;
  
          for (Task task2 : schedule.getTaskList()) {
              if(task.getId()!=task2.getId()){
                  if( task2.getPredecessorId()==task.getId()) {
                      if (endTime &gt; task2.getAllocation().getStartTime()) {
                          hardScore += task2.getAllocation().getStartTime() - endTime;
                      }
                  }
              }
          }
      }
  
      return HardSoftScore.valueOf(hardScore, softScore);
  
  }
  </code></pre>
  <p>This is the solver config:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;solver&gt;
      &lt;!--&lt;environmentMode&gt;FAST_ASSERT&lt;/environmentMode&gt;--&gt;
  
      &lt;!-- Domain model configuration --&gt;
      &lt;solutionClass&gt;com.foo.scheduler.domain.Schedule&lt;/solutionClass&gt;
      &lt;planningEntityClass&gt;com.foo.scheduler.domain.Task&lt;/planningEntityClass&gt;
  
      &lt;!-- Score configuration --&gt;
      &lt;scoreDirectorFactory&gt;
          &lt;scoreDefinitionType&gt;HARD_SOFT&lt;/scoreDefinitionType&gt;
          &lt;simpleScoreCalculatorClass&gt;com.foo.scheduler.solver.score.SchedulingSimpleScoreCalculator&lt;/simpleScoreCalculatorClass&gt;
      &lt;/scoreDirectorFactory&gt;
  
      &lt;!-- Optimization algorithms configuration --&gt;
      &lt;termination&gt;
          &lt;maximumSecondsSpend&gt;100&lt;/maximumSecondsSpend&gt;
      &lt;/termination&gt;
      &lt;constructionHeuristic&gt;
          &lt;constructionHeuristicType&gt;FIRST_FIT&lt;/constructionHeuristicType&gt;
      &lt;/constructionHeuristic&gt;
      &lt;localSearch&gt;
          &lt;acceptor&gt;
              &lt;entityTabuSize&gt;7&lt;/entityTabuSize&gt;
          &lt;/acceptor&gt;
          &lt;forager&gt;
              &lt;acceptedCountLimit&gt;1000&lt;/acceptedCountLimit&gt;
          &lt;/forager&gt;
      &lt;/localSearch&gt;
  &lt;/solver&gt;
  </code></pre>
  <p><strong>The problem is that this works great as long as I only have the hard score. But of course it has gaps. As soon as I add the soft score everything gets stuck after about 10 steps. Why?</strong></p>
  <pre><code>[...]
  2014-05-03 20:01:31,966 [main] DEBUG     Step index (10), time spend (495), score (-35hard/-66soft),     best score (-34hard/-68soft), accepted/selected move count (1000/19884) for picked step (com.foo.scheduler.domain.Task@35480096 =&gt; com.foo.scheduler.domain.Allocation@f9a4520).
  2014-05-03 20:03:11,471 [main] DEBUG     Step index (11), time spend (100000), score (-35hard/-65soft),     best score (-34hard/-68soft), accepted/selected move count (0/105934687) for picked step (com.foo.scheduler.domain.Task@7050c91f =&gt; com.foo.scheduler.domain.Allocation@47c44bd4).
  </code></pre>