[rules-users] Optaplanner: Shadow Variables vs insertLogical

jonathan.labin jonathan.labin at gmail.com
Wed Jul 10 10:30:34 EDT 2013


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.


More information about the rules-users mailing list