Live data from Hacker News

How can one manage thousands of IF…THEN…ELSE rules?

programmers.stackexchange.com

11–20 of 86 posts

Re: How can one manage thousands of IF…THEN…ELSE rules?

#11
Mildly unrelated, but I wanted to point out the awesomeness of the K-map[1] for handling simple minimization problems like these.

Unfortunately, once your dimensions get large it becomes difficult for humans to visualize the optimizations, which is where Espresso[2][3] comes in handy.

[1] http://en.wikipedia.org/wiki/Karnaugh_map

[2] http://embedded.eecs.berkeley.edu/pubs/downloads/espresso/in...

[3] ftp://ftp.cs.man.ac.uk/pub/amulet/balsa/other-software/espresso-ab-1.0.tar.gz

Re: How can one manage thousands of IF…THEN…ELSE rules?

#12
post #3

If only these questions appeared on one's résumé...

What, are you insinuating that asking about great big if-then-else trees means you'd never hire that person? Because, what, you've never been a complete novice programmer before? Considering the question-asker has a specific problem to solve, I would even hazard they probably aren't a programmer by trade.

Considering the question-asker has a specific problem to solve, I would even hazard they probably aren't a programmer by trade.

So why would someone hire them to be a programmer? And yet, unlike other skilled professions, rank amateurs often present themselves as competent programmers. It would be valuable to include evidence to the contrary with résumés.

you've never been a complete novice programmer before?

I certainly wasn't hired when I was. What kind of ridiculous statement is this?

The poster is asking the wrong question. They are asking about how to manage incidental complexity, when they should be asking how to avoid inherent complexity. Incidentally complex code is the worst possible code to maintain, and you'll thank yourself for not letting contributors commit it.

Re: How can one manage thousands of IF…THEN…ELSE rules?

#13
post #4

Such a great question. Want to predict cow movement while taking into consideration sudden events, food and sun, using thousands of if then rules? Sounds like the perfect problem for one of the following tree learners that not only manage themselves but build the model for you, in order of suitability to the problem* : Genetic Programming ADTree Random Forest Decision Tree Most of the work would be in figuring out th…

All machine learning techniques build models for you.

ADTrees, Random Forests, and Decision trees are all classifiers, so they serve this guy's needs. Genetic Programming is not a machine learning technique: it is an optimization method for a very specific task and is quite unsuited for his purposes.

Re: How can one manage thousands of IF…THEN…ELSE rules?

#15
post #3

If only these questions appeared on one's résumé...

What, are you insinuating that asking about great big if-then-else trees means you'd never hire that person? Because, what, you've never been a complete novice programmer before? Considering the question-asker has a specific problem to solve, I would even hazard they probably aren't a programmer by trade.

The idea of things on resumes shouldn't be to make hire/no-hire decisions (well, unless your job is to bin all the incoming resumes written in crayon..). Talking about this situation during an interview may provide insight though.

Re: How can one manage thousands of IF…THEN…ELSE rules?

#18
Even with the clue that he wants to "predict how cows move around in any landscape", his description seems like it wouldn't be enough any definite design advice.

What do the states of the cows and the landscape look like? What is changed by the if-then-else results. Does he already have his rules? Is this for a biology project or a video game, etc.

You could use a finite automaton system, an array of cow-states, a cow DSL or something else depending on the answers to these and other questions.

[insert joke about "till the cows come home"]

Re: How can one manage thousands of IF…THEN…ELSE rules?

#19
post #4

Such a great question. Want to predict cow movement while taking into consideration sudden events, food and sun, using thousands of if then rules? Sounds like the perfect problem for one of the following tree learners that not only manage themselves but build the model for you, in order of suitability to the problem* : Genetic Programming ADTree Random Forest Decision Tree Most of the work would be in figuring out th…

Solution is great and there are very nice algorithm suggestions given here as well. Now the question is how easily one can apply growing number of rules to production without taking down the application.

Re: How can one manage thousands of IF…THEN…ELSE rules?

#20
post #6

You really don't want to think of this in terms of IF ... THEN ... ELSE but as individual binary or multi-path choices. These are most efficiently handled with hash tables that choose a route through a logic diagram in a way that is more intuitive than If ... THEN ... ELSE as well as more efficient. You start by writing a logic flowchart that you understand, then you reduce the logic flowchart to code, usually automa…

Maybe I'm off the mark, but whenever I see a long runon procedure full of if-then-else, I think "This is a job for a state machine!" With that approach, you can exhaustively provide actions for every combination of states and events. You can also immediately identify the code responsible for handling any state+event. You can also track which state+event transitions have been tested automatically.

You're not, imho. The problem is : how do we manage the data associated with the structure of this gigantic state-machine. It is likely to change overtime, so it cannot be hard coded (although if it were, one could perhaps use a tool which compiles the state machine to hard code).

Basically, many of the solutions proposed are more or less specialized state machines (decision trees, markov chains, rete algorithm).

Post reply on HN