Wednesday, February 6, 2008

Fluent Problem Solving by Elimination

Many problems lend themselves to a solution through a process of elimination. These include the selection of scientific hypothesis, technical troubleshooting, medical diagnosis, etc. I have written a small framework to help solve this class of problems. Additionally, I made a fluent interface to create constraint rules. You can download it from the code samples section.

I am planning on creating a few examples in the near future to show it off, but for this post I just want to give a sneak peek at a couple of lines of Java code that uses it. This comes from a test that categorizes an animal based on observable qualities. This is the definition of one constraint rule that allows the system to know that no mammals have scales or feathers.

constraint = when(skin).is(scaley).or(skin).is(feathery).then(animalType).isNot(mammal);

Here is another that tells the system that only bats have both fur and wings:

constraint = when(skin).is(furry).and(phalanx).is(wings).then(animal).is(bat);

2 comments:

Ray Myers said...

Can it solve the Zebra puzzle?

Steve Asher said...

Evidently not :( What a great test though. In the process I found a bug. That Zebra puzzle has a lot of assumptions built in, and I think that the current reason that it isn't working has to do with not fully capturing those assumptions.

I assure you, though, that the fluent api makes it read very nicely. I will try a bit more to get it to work, but if I don't figure it out soon I would probably be better off to wrap some known working constraint engine with a fluent api rather than using mine that was really designed just for a few toy examples.