473,396 Members | 1,918 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Avoiding endless conditional statements

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
9 1695
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
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
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
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
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
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
<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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: neblackcat | last post by:
Would anyone like to comment on the following idea? I was just going to offer it as a new PEP until it was suggested that I post it here for comment & consideration against PEP 308. I'm far...
10
by: clueless_google | last post by:
hello. i've been beating my head against a wall over this for too long. setting the variables 'z' or 'y' to differing numbers, the following 'if/else' code snippet works fine; however, the ...
3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
1
by: chris han | last post by:
Hi, all, I'm trying to use Conditional Compilation Statements in my code. using System; #define DEBUG public class MyClass { public static void Main() {
92
by: Raghavendra R A V, CSS India | last post by:
hie.. Do any one knows how to write a C program without using the conditional statements if, for, while, do, switch, goto and even condotional statements ? It would be a great help for me if...
10
by: nimmi_srivastav | last post by:
Below you will see an example of a nested conditional expression that this colleague of mine loves. He claims that it is more efficient that a multi-level if-else-if structure. Moreover, our...
10
by: Dave | last post by:
I'm a C++ programmer of many years, trying to get my feet wet in C#. I have a question about conditional compilation. In C++, I would sometimes define a constant in an include file, and then...
43
by: dev_cool | last post by:
Hello friends, I'm a beginner in C programming. One of my friends asked me to write a program in C.The purpose of the program is print 1 to n without any conditional statement, loop or jump. ...
5
by: alex21 | last post by:
For my program i need a great deal of completely random, unique, 12 character id's. So i wrote these three functions public static string GiveUniqueID(IEnumerator id_key, int count) {...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.