These kind of use cases aren't out-of-the-box examples and well studied, but it is possible with some custom code:
- OptaPlanner can optimize on top of any score calculation function. The only real requirement is that it returns a
Score
, which is essentially a Comparable
.
- You can define a custom
Score
(see docs), but in the example below, I 'll use a standard HardSoftScore
and that will do. A HardSoftScore
is basically 2 int
variables.
For example, presume the probability of rain is: 50% on Monday, 10% on Tuesday, 20% on Wednesday. Now presume we have vehicle routing problem and need to deliver 100 packages during that week, with 2 trucks: truck A that can carry 20 packages and is unaffected by rain and truck B that can carry 40 packages but is affected by rain: rain inflicts a maintenance cost on it and too much rain in 1 week breaks it.
Now we can write a score calculation function to take those things into account in our score rules:
- when the "sum" of the probability accumulated rain on B is too high, reduce the hard score with how much too much (so the solution is not feasible)
- the probability of rain when B is used inflicts a soft cost (=> reduces the soft score)
- the use of A or B inflicts a soft cost per distance driven
That being said, OptaPlanner does not provide any methods for probability arithmetic, such a doing a sum of probabilities (which is non-trivial). However, you can plug in any Java framework that provides that, call those functions for the drools DRL. Furthermore, drools-chance was suppose to provide that, but that project is currently inactive (but sooner or later we 'll reboot it).