Amr Qamar
Amr Qamar

Reputation: 109

Optaplanner IllegalArgumentException: The valueRangeProviderRef does not appear in valueRangeProvideIds

Using Boolean planning variable defined in the planning entity as:

@PlanningVariable(nullable = true, valueRangeProviderRefs = {"selectedRange"})
public Boolean getSelected() {
    return selected;
}

public void setSelected(Boolean selected) {
    this.selected = selected;
}

and in the planning solution I define the value range provider as:

@ValueRangeProvider(id = "selectedRange")
List<Boolean> getValueRange() {
     return Arrays.asList(Boolean.FALSE, Boolean.TRUE);
}
public List<Boolean> getBooleanList() {
    return selectedList;
}

public void setBooleanList(List<Boolean> selectedList) {
    this.selectedList = selectedList;
}

I received the following error:

Exception in thread "AWT-EventQueue-0"
java.lang.IllegalArgumentException:

The entityClass has a PlanningVariable annotated property (selected) with a valueRangeProviderRef (selectedRange) that does not exist on a registered PlanningSolution or PlanningEntity.

The valueRangeProviderRef (selectedRange) does not appear in valueRangeProvideIds ([]).

I can't recognize the problem cause.

Upvotes: 3

Views: 255

Answers (1)

Geoffrey De Smet
Geoffrey De Smet

Reputation: 27312

Normally I would say: You're missing a @ValueRangeProvider on a property of your solution class. But it looks like you have it. For some reason it's just not picking up it when it reflects over your planning solution class.

A) If you're using a 6.3.0.Final or later, your code should work. If you're using an older version, it's probably because the getValueRange() method isn't public (6.3 fixes that IIRC).

B) If the getValueRange() method is defined on a superclass instead of on the actual planning solution class, then it will only work if that superclass is known as a proper planning solution class too IIRC.

Upvotes: 4

Related Questions