0

Is there a more detailed example of a Shadow Variable being used with non-chained entities? The upgrade recipe for OptaPlanner 6.2 -> 6.3 briefly mentions @InverseRelationShadowVariable using the Cloud Balancing example, but I was unable to get it to work (shadow var doesn't update)

http://www.optaplanner.org/download/upgradeRecipe/upgradeRecipe6.3.html

Laurent
  • 656
  • 5
  • 9
  • Detailed documentation in the optaplanner docs chapter 3. Several examples use shadow vars. 2 examples specifically use that `@InverseRelationShadowVariable` (vehicle routing and coach shuttle gathering). – Geoffrey De Smet Mar 01 '16 at 09:36

1 Answers1

2

Shadow variables need to be defined on a planning entity, so you probably forgot to define that class with that @InverseRelationShadowVariable annotated member as a entity in your solver configuration (and an @PlanningEntity annotation on the class itself).

A genuine entity has at least one genuine planning variable. A shadow entity has no genuine planning variables and at least one shadow planning variable.

Geoffrey De Smet
  • 26,223
  • 11
  • 73
  • 120
  • I had added the @PlanningEntity annotation, but did not add it to the solver configuration... Thanks! – Laurent Mar 01 '16 at 17:59
  • So I ran into this issue again, but this time the issue is that I have a ValueRangeProvider set on the Entity class instead of the Solution in order to implement a built-in hard constraint (this one can never be broken). The InverseShadowVariable works if I move the ValueRangeProvider back to the Solution class. The error message is "java.lang.IllegalArgumentException: The entity () was never added to this ScoreDirector. Usually the cause is that that specific instance was not in your Solution's entities." – Laurent Mar 21 '17 at 17:16
  • Sounds like an issue, please create a jira with a reproducer if it reproduces on master. – Geoffrey De Smet Mar 22 '17 at 12:49