0

Is there a way to access planning variable's assignment during planning?

In my use case, I want to assign a planning variable with certain status only one time only during planning. After that I don't want to use that planning variable.

I know that in optaplanner, a planning variable/problem fact can not change, so i can not change its status.

Is there a way to get list of planning variable assignment during planning so that in java code or drools file, i can avoid re-assignment if it has been used once?

Thanks!

mluser
  • 53
  • 1
  • 6

1 Answers1

0

Use a hard constraint to enforce that.

Yes, you could use MoveFilters too, but that's not a good idea because sometimes you need to break hard constraints to escape local optima.

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
  • thanks for replying. I'd also like to implement it as a hard constraint in drools file but how do I access this information in drools file. Let's say i have following scenario: **Planning entity** : F1, F2 **Planning variable**: v1, v2. I want to use v1 only once. Now if planner randomly assigns v1 to F1, how do i access this information to write a hard constraint so that v1 is not assigned to F2 ? – mluser Oct 16 '18 at 13:56
  • See the score rule "2 talks in same room at the same time" in conference scheduling example – Geoffrey De Smet Oct 16 '18 at 14:54
  • thanks a lot for help @Geoffrey! I end up implementing it as an accumulate function in drools file. I check if sum of usage of a planning variable is more than one then a hard constraint is violated. – mluser Oct 16 '18 at 21:24
  • thats sub-efficient to check conflicts. Accumulates are much slower score calculation speed wise than doing `when Talk($f: foo, $id : id) Talk(foo == $f, id > $id) then -1hard end` – Geoffrey De Smet Oct 17 '18 at 06:52
  • That's helpful information, I have changed it as you suggested. Using accumulate I was getting hard constraint violation even though i have enough resources but it wasn't using all of them (I am not sure why). After changing it as per your suggestion, it works perfectly. Thank you!! – mluser Oct 17 '18 at 17:41