Reputation: 55
I'm using OptaPlanner to solve a variant of a Vehicle routing problem in which the requirements of the customers to be served by vehicles vary significantly. I have a few most common customer types and want to model them using different entity classes. As it's possible for a single driver to attend different types, they should be able to form heterogeneous chains with instances of all classes on them.
I tried to do a proof of concept by modifying the VRP example. I extracted ICustomer
, an interface for all my customers and changed the Standstill
so that getNextCustomer
returns an ICustomer
.
When I try to run it with Customer and Customer2 (a copy of the customer class), both implementing ICustomer, I get this error:
Exception in thread "main" java.lang.IllegalArgumentException: The entityClass
(interface org.optaplanner.examples.vehiclerouting.domain.Standstill) has a
InverseRelationShadowVariable annotated property (nextCustomer) with a masterClass
(interface org.optaplanner.examples.vehiclerouting.domain.ICustomer) which is not a
valid planning entity.
In the worst case, I'll just model different customer types with enums and "ifs" in a single planning entity to get the same behaviour. Still, would be great to know if I encountered an API limitation or someone knows a better way to achieve this. Thanks :)
Upvotes: 1
Views: 700
Reputation: 27357
OptaPlanner fully supports polymorfism, class hierarchies, etc. We have tests for it (and have regularly found bugs for it which have been solved - as recently as for 7.3.final IIRC). See also TestDataSolution.java and the like. New reproducers are welcome as PR's of course.
The exception tells a different story. Check where you use @InverseRelationShadowVariable
, the return type of that field/method - I suspect your refactor might not have impacted that code correctly.
Upvotes: 3