473,799 Members | 3,033 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1717
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 multidimensiona l
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 multidimensiona l 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.84 6</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.ph p , pk , ph**********@gm ail.com>
<11************ **********@z14g 2000cwz.googleg roups.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
2292
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 from being a "language internist" (on Python or anything else) so go easy on me if this is stupid - it just seemed quite elegant to me as a relative newbie in town :-) I also havent got a clue whether this would be easy or even possible
10
9589
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 'case' code snippet does not. (the code's function is illustrative.) ////////////////////////////////////////// //////// working 'if/else' switch //////// //////////////////////////////////////////
3
5939
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 terminated by pressing ++ and then terminate the process. I searched the entire internet and found out that there could be two things wrong (both of them are mentioned in the bug list on the access
1
16563
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
9911
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 someone helps me... Urgent - Please reply soon ! Thanks, Raghu
10
3247
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 complexity analyzer tool supposedly does not pick it up. Is it really more efficient? Personally I find this coding style extremely cryptic, misleading and error-prone. I believe that I have removed all traces of proprietary-ness from this coding...
10
3098
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 have blocks of code in different source files that were conditionally compiled based on that constant. Now that C# has done away with include files, is there any way of doing the same thing, short of defining the constant multiple times at the head...
43
7587
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. How is it possible? Please help me. Thanks in advance.
5
1913
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) { string id = ""; bool done = false; while (!done)
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9544
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10490
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10238
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4145
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.