0

I have something like that:

   scoreHolder.addSoftConstraintMatch(kcontext, (System.currentTimeMillis()-$time.getTime()));

I want to use the current time at the beginning of firing the rule only, and not to be updated during running the rule. just to catch the current time at the first moment the rule is fired and does not change till the end of solving.

I'm using optaplanner 6.1.

thanks in advance.

Amr Qamar
  • 99
  • 6

1 Answers1

0

That would break OptaPlanner, as the Score of the same Solution would change over time (which also implies that comparing 2 different Solutions can not be done fairly - so if a new working score is compared to the best score (which was calculated x seconds ago) it breaks).

Instead, before the solver starts, set the current time millis in a singleton:

 myParametrization.setStartingMillis(System.currentMillis());
 ... = solver.solve(...);

and add that as a problem fact and use it in the score rules (see examination example's InstitutionParameterization).

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120