By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,071 Members | 1,244 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,071 IT Pros & Developers. It's quick & easy.

Avoiding endless conditional statements

P: n/a
pk
Here is my problem. I want to make a webapp that will basically take
the work out of finding what tool works for what situation. There are
5 factors that go into tool selection. 1)Material Group, 2)Insert
Radius, 3)Insert Type and Size, and 2 others that I can't remember
off-hand. There are probably about 1000 different scenarios that I
have to code for..(there are several blank table cells and it's not
setup as you might imagine, there is a lot of overlapping), and I
desperately want to avoid making a gigantic conditional statement. I'm
afraid that I really have to provide a picture of what I'm doing here,
so I will do that. Here is the link.
http://www.bigkaiser.com/temp/weirdtable.jpg You only see 3 of the 5
factors on this page, and the other 2 have to do with whether this
table or one of many other tables (not pictured) will be used.

So, now that I've confused everyone. That's my table. What's a good
way to go about programming that sucker in so that people don't have to
do all the "work" involved to figure out what tools they need. They
should just be able to choose selections from 5 dropdown boxes and get
one tool back. A tool is something like "10.655.600".

Thanks for whomever tries to come up with a solution to this poorly
explained problem. :)

-pk

Aug 26 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Hi pk,

Sounds like a schoolbook example for an expert system, typically an
application of production rules, backward chaining. But you do need an
inference engine for that, i am not sure there is one written in php. If
you can't find one, maybe you can just build a series of methods, each
reacting on one a specific question and filled with rules that return a
value if applicable. The condition of each rule may call other methods
and so on, that is how you get the backward chaining funcionality. There
may be some refactoring to avoid the same rules reproduced in several
methods. If you can't follow me, buy a book on AI or find a sponsor (a
big one) and hire a knowledge engineer (and take a lot of time to answer
his questions).

Greetings,

Henk Verhoeven,
MetaClass.

pk wrote:
Here is my problem. I want to make a webapp that will basically take
the work out of finding what tool works for what situation. There are
5 factors that go into tool selection. 1)Material Group, 2)Insert
Radius, 3)Insert Type and Size, and 2 others that I can't remember
off-hand. There are probably about 1000 different scenarios that I
have to code for..(there are several blank table cells and it's not
setup as you might imagine, there is a lot of overlapping), and I
desperately want to avoid making a gigantic conditional statement. I'm
afraid that I really have to provide a picture of what I'm doing here,
so I will do that. Here is the link.
http://www.bigkaiser.com/temp/weirdtable.jpg You only see 3 of the 5
factors on this page, and the other 2 have to do with whether this
table or one of many other tables (not pictured) will be used.

So, now that I've confused everyone. That's my table. What's a good
way to go about programming that sucker in so that people don't have to
do all the "work" involved to figure out what tools they need. They
should just be able to choose selections from 5 dropdown boxes and get
one tool back. A tool is something like "10.655.600".

Thanks for whomever tries to come up with a solution to this poorly
explained problem. :)

-pk

Aug 26 '05 #2

P: n/a
pk
Thanks a lot. It seems that expert systems are exactly what I was
looking for. Now to find one that doesn't look horrible...

Aug 26 '05 #3

P: n/a
pk wrote:
Here is my problem. I want to make a webapp that will basically take
the work out of finding what tool works for what situation. There are
5 factors that go into tool selection. 1)Material Group, 2)Insert
Radius, 3)Insert Type and Size, and 2 others that I can't remember
off-hand. There are probably about 1000 different scenarios that I
have to code for..(there are several blank table cells and it's not
setup as you might imagine, there is a lot of overlapping), and I
desperately want to avoid making a gigantic conditional statement. I'm
afraid that I really have to provide a picture of what I'm doing here,
so I will do that. Here is the link.
http://www.bigkaiser.com/temp/weirdtable.jpg You only see 3 of the 5
factors on this page, and the other 2 have to do with whether this
table or one of many other tables (not pictured) will be used.

So, now that I've confused everyone. That's my table. What's a good
way to go about programming that sucker in so that people don't have to
do all the "work" involved to figure out what tools they need. They
should just be able to choose selections from 5 dropdown boxes and get
one tool back. A tool is something like "10.655.600".

Thanks for whomever tries to come up with a solution to this poorly
explained problem. :)

-pk

If you have one handy, my solution would be to us a small database with
the 5 factors as the key attributes and the tool id as the sixth
attribute. If that is not possible, a really large multidimensional
array would do it, but performance issues need to be addressed. Perhaps
a 2 dimensional table which gives the name of the appropriate include
module which instantiates a 3 dimensional array which yields tool_id?
Aug 26 '05 #4

P: n/a
pk
:) After looking at the work involved getting one of those expert
systems off the ground, I think I'll definitely be going the database
route. I thought about a large multidimensional array, but ultimately
decided against it since it seemed to be overkill.

Aug 26 '05 #5

P: n/a
pk
(This thread is definitely in the wrong group, but I have no way to
move it so I'll just continue on.)

Why isn't there a program that does just what I want it to? I'm not
trying to whine here, and maybe it's just because I'm in the thick of
it here, but it seems to me that this could be a very useful little
tool. It seems that with a little work, one could develop a
user-friendly program could take any table and create a simple GUI with
drop-down menus that would help the end-user make an informed decision.
I know, I know..."If you want it so bad, make it!" I'd like to say
that it'd be easy for me to do it, but the simple fact is that it
wouldn't be. BUT there are many people out there who COULD do it
easily...is there really no demand for such a product? Am I the only
one with this need?

Aug 26 '05 #6

P: n/a
pk wrote:
Here is my problem. I want to make a webapp that will basically take
the work out of finding what tool works for what situation. There are
5 factors that go into tool selection. 1)Material Group, 2)Insert
Radius, 3)Insert Type and Size, and 2 others that I can't remember
off-hand. There are probably about 1000 different scenarios that I
have to code for..(there are several blank table cells and it's not
setup as you might imagine, there is a lot of overlapping), and I
desperately want to avoid making a gigantic conditional statement. I'm
afraid that I really have to provide a picture of what I'm doing here,
so I will do that. Here is the link.
http://www.bigkaiser.com/temp/weirdtable.jpg You only see 3 of the 5
factors on this page, and the other 2 have to do with whether this
table or one of many other tables (not pictured) will be used.

So, now that I've confused everyone. That's my table. What's a good
way to go about programming that sucker in so that people don't have to
do all the "work" involved to figure out what tools they need. They
should just be able to choose selections from 5 dropdown boxes and get
one tool back. A tool is something like "10.655.600".


Is there a constant in this problem? Can you find with a certain
"equation" the right tool for the input?

If not, you'll definitely have to enter the data somewhere. Each tool
depends on 5 factors. In a relational database, that would look like

[Tools] [Factor1] [Factor2] ...
..tool_id .fac1_id .fac2_id ...
..tool_name .fac1_name .fac2_name ...

[Data]
..fac1_id
..fac2_id
..tool_id

First, fill the factor and tool tables (for example, tool_id is 1 and
tool_name is 11.938.846) and then associate them in the data table.
When you search the database, you provide all the factor ids and you
get the corresponding line, fetch the tool_name and display it. That's
a really simple application of databases.

You can adapt this situation to many kind of databases. You could use
an xml file:

<tool id="1">
<fac1>fac1id</fac1>
<fac2>fac2id</fac2>
<name>11.938.846</name>
</tool>

You search all tools, check their factors and if it matches, display
the name. At worst, use an array you filled manually:

echo data["fac1id"]["fac2id"]["name"];

Anyways, it says "all cutting data without guarantee", so you may make
a few mistakes :)
Jonathan

Aug 26 '05 #7

P: n/a
<comp.lang.php , pk , ph**********@gmail.com>
<11**********************@z14g2000cwz.googlegroups .com>
<26 Aug 2005 12:30:28 -0700>
Thanks for whomever tries to come up with a solution to this poorly
explained problem. :)


If I understand it correctly - you want something that some car websites
have when buying a car on the internet .

- select model
- (another drop down box appears)
- select engine size
- (another drop down box appears)
- select colour

etc etc
--
www.phpguestbook.co.uk
Aug 26 '05 #8

P: n/a
Meaby you should try using masks. For example: you have 3 factors
1)Material Group
2)Insert Radius
3)Insert

and every factor have say 5 conditions wich would make many situations
=] situations. YOu start from giving every condition a number like 1,
3, 5, 7, 11.
Now imagine you factor 1) is 1+3+7=10 factor 2) is 1+11=12 3) is
3+7+11=21

Then you probalby will choose a 3D array[F1][F2][F3].

soulution[10][12][21]

All you need now is to fill that array with solutions.

Then again I didn'd try that myself so I myght be wrong

Aug 27 '05 #9

P: n/a
Hi pk,

pk wrote:
It seems that with a little work, one could develop a
user-friendly program could take any table and create a simple GUI with
drop-down menus
that would help the end-user make an informed decision.


Yes, is suppose a generic program could be built to show options given a
big table of solutions and some choices one has already made. However,
for most problems the number of solutions is simply too large. For
example, a game of chess: There are only 32 pieces of 6 types on 64
fields, and there is only a single starting position. But with all the
effort that has been put into chess programs, no one has ever come up
with a series of moves that is allways winning. The reason is that there
are simply so many options that, with current computing power, you do
not even get remotely close to a solution, even if you let hundreds of
computers calculate for several years. The strategy to put all solutions
into a big soluton table is simply not a viable strategy for most real
ife problems. So why would someone make a nice GUI for using this strategy?

To put it an other way: suppose you have built this program and filled
your solution table. Your customer is enthousiast and puts in in use.
Soon someone finds a situation where the outcome of the program is
clearly incorrect. You soon find out that there was another factor that
was not taken into account. So your customer asks you to add this factor
to the program. This factor has 10 possible values. Here your table
grows from, lets's say 10.000 to a 100.000 rows. If this happens only
once, it may not be a problem. But if it is repeated a few times your
database quickly runs out of control. Your customer may not want to be
held liable for not taking into account a factor he nows to be relevant
for a correct outcome. So he decides to take the entire program off line.

So in practice too many factors may render your program useless for the
problem you are solving. Your customer may not understand this, becuase
the number of factors to be taken into account only doubled, and he he
is perfectly willing to pay you twice as much (but not a thousend times
as much, of course). So if you go for the solution table, you better
tell him in advance about the limitations, if you don't want to end up
trying to explain this to a lawyer. (Building your own inference engine
will be easier, i guess ;-) )

Greetings,

Henk Verhoeven,
www.metaclass.nl.
Aug 27 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.