Misleading error: invalid planning entity

5 views
Skip to first unread message

holger brandl

unread,
Jan 19, 2023, 2:29:33 AM1/19/23
to OptaPlanner development
Hi there, 

just wanted to share some feedback. When building a solver, I got confused when it reported:
Exception in thread "main" java.lang.IllegalArgumentException: The entityClass (class com.Foo) has an @InverseRelationShadowVariable annotated property (nap) with a sourceClass (class com.Bar) which is not a valid planning entity.

I reviewed my implementation for quite a while without spotting any contract violation. The root cause turned out to be solver config builder, which I had translated too literally from an xml config as
    SolverConfig()
        .withSolutionClass(Something::class.java)
        .withEntityClasses(Foo::class.java)
        .withEntityClasses(Bar::class.java)

There are 2 ways to potentially improve this.
a) the builder could at least warn that withEntityClasses is not additative
b) the message (which is unfortunately implemented several times in different ShadowVariableDescriptor classes) could be slightly extended to guide the user better. ie. "...which is not a valid planning entity or the planning entity is not correctly registered in the solver configuration".

What do you think?

Best
Holger

Radovan Synek

unread,
Jan 19, 2023, 4:09:43 AM1/19/23
to optapla...@googlegroups.com
Hello Holger,

thanks for sharing your experience.

The method accepts multiple classes, so the typical usage looks as follows:
  SolverConfig()
        .withEntityClasses(Foo.class, Bar.class)

As far as I know, this behavior is consistent across the with* methods of the SolverConfig and the underlying *Config classes. Personally, I would expect additive behavior if the method was called addEntityClass().

As for your second suggestion, I think it's a good proposal. The more guidance the fail-fast message gives, the better:

Regards,
Radek

--
You received this message because you are subscribed to the Google Groups "OptaPlanner development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to optaplanner-d...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/optaplanner-dev/4d6b69e3-0999-4ead-bd58-e3780b283d78n%40googlegroups.com.


--

Radovan Synek

Principal Software Engineer, Business Automation

Red Hat EMEA

Brno, Czech Republic

Holger Brandl

unread,
Jan 19, 2023, 5:17:36 AM1/19/23
to optapla...@googlegroups.com
Thanks Radek,

indeed the API makes sense from a naming perspective. I had figured my misconception about withEntityClasses eventually, but with the improvement now tracked in  PLANNER-2888 it would have been a much faster process.

Thanks for your kind support.

Kind regards,
Holger



Reply all
Reply to author
Forward
0 new messages