boolean decisions

Paul Hankin paul.hankin at gmail.com
Tue Feb 5 06:55:34 EST 2008


On Feb 5, 10:52 am, Robin Becker <ro... at reportlab.com> wrote:
> I have a couple of business decisions to make that essentially use 6 binary
> input variables. After the business users have gone back and forth for two weeks
> trying to build special case rules I asked them to make up a table containing
> all of the input possibilities and specify what should happen in each case.
> There are only 64 rows and some of the decisions are obviously explainable in
> simple ways ie
>
> if a and not b do action 1
>
> is there a way to derive simplified rules for each binary outcome? I'm sure this
> is a standard sort of problem and probably some python code is out there. It
> seems to me I need to solve an overdetermined binary equation system and then
> choose the solution with the shortest number of terms or something, but perhaps
> I am daft.

Why bother? Build a hash table mapping the 64 cases to a function or
method-name. That way you can keep the business rules intact in your
code, it'll be just as fast (or faster), and your code will be much
easier to fix when one of the lines of that table changes (not that
business logic EVER changes ;). I'd be tempted to include the business
rule table as a text file or string, and parse it at program startup
to build the hashtable. That way anyone can look at or modify the
table, even if they know nothing about python or coding.

--
Paul Hankin



More information about the Python-list mailing list