[rules-users] Optaplanner: Shadow Variables vs insertLogical

Geoffrey De Smet ge0ffrey.spam at gmail.com
Wed Jul 10 15:08:50 EDT 2013


I am not sure yet where the recommendation line between insertLogical 
and shadow variables are yet.
Shadow variables are new - but very powerful.

A) insertLogical()'s are good for things that are only needed in the 
score function.
For example: nurse rostering

B) Shadow variables are interesting when
1) you want to store the state of those variables in your database (even 
though in that state can be calculated based on the state of the other 
variables)
For example: arrivalTime in VRP timewindows. Based on the other 
information, an arrival time can be calculated, but it's so 
fundamentally needed on the javabean for the user,
that you want to have it on the javabean (which makes writing the 
constraints a lot easier too).
or 2) using insertLogicals would make it too complex (or in some cases 
too slow)

Shadow variables have 1 big pitfall: they can only be used on classes 
that are a @PlanningEntity.


But the first question is why you're getting score corruption the first 
place.


On 10-07-13 16:30, jonathan.labin wrote:
> I noticed the recent introduction of the concept of Shadow Variables in the
> Optaplanner.  I'm wondering if someone could help me understand the
> difference between Shadow Variables and inserting facts with
> insertLogical()?
>
> Each are described a little bit in the manual and it seems that there is a
> similar use case but I'm not sure I understand the implications of using one
> over the other?  I see that some of the examples still use insertLogical so
> I'm assuming that shadow variables are not a replacement in every case.
>
> To help frame the answer, consider the following toy problem which maps to
> my domain fairly well:
>
> Say my problem is creating purchase orders of raw materials for my factory
> from various vendors.  The input states how many of each raw material I
> need.  Obviously I would want to minimize cost but I also have no capacity
> to store extra raw materials so any extra that I buy will be waste.
> Therefore, I'll want to create a list of orders that obtains exactly the
> required number of each if possible.
> Each vendor offers package deals that include different combinations of raw
> materials in different amounts.
> There would clearly be other optimizations such as reducing the number of
> vendors used but those would likely be secondary to the cost and waste
> optimizations.
>
> The domain model for this problem would include a Planning Value for each
> individual raw material item as well as one for each package combo offered
> by a vendor (essentially anything with a price).
>
> So, for a problem space like this, I'll want rules which count the number of
> each raw material type across all of the different packages purchased from
> different vendors and make sure it meets the needs of the particular
> provided problem.
>
> Currently I am using a rule that fires for each raw material type and counts
> the number of units ordered for that type using an accumulator over Planning
> Entities. I am currently experiencing score corruption which I believe may
> be due to this approach so I am looking to redesign.
>
> Would Shadow Variables or calls to insertLogical() be more
> appropriate/efficient for this use?
>
> Thanks in advance,
>
> Jon
>
>
>
> --
> View this message in context: http://drools.46999.n3.nabble.com/Optaplanner-Shadow-Variables-vs-insertLogical-tp4024863.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



More information about the rules-users mailing list