Click here to Skip to main content
15,867,686 members
Articles / Programming Languages / C#
Article

Fuzzy Logic Dot Net Fuzzy Decisions

Rate me:
Please Sign up or sign in to vote.
3.14/5 (11 votes)
10 Dec 20034 min read 74.4K   1.4K   37   13
Classes to help make decisions.

Introduction

This article looks at the idea of Fuzzy Decisions, that is the idea that we have a decision to make within the code and that there are certain factors that are going to influence the decision. I am working from the assumption that whatever the decision is, it is not a simple decision that relies on a true or false variable or the return value from a function, but a decision that has to take a number of specific things within the code into account. In the strictest sense, these things that influence the decision need not be related, and in fact to use the Fuzzy Decision classes properly, it would probably be better if they weren't.

The Fuzzy Decision classes are designed as a way to help make decisions without requiring specific knowledge of the decision process or code details. The reason for this being that all of us make decisions all the time within our code yet we always make them based on the results of a function or a true or false variable. The Fuzzy Decision classes enable us to make decisions that have a number of different influences to the decision making process and provide a flexible reusable framework for making decisions.

For example, say that we are in a situation where we are trying to decide if we are to move a character to the left or the right in a game. We will assume that both paths are open and there is nothing to prevent the character from moving in either direction, but then there are going to be things within the code or the game that influence the way that we wish to move. One thing could be if we have found some item previously then we should be more inclined to move to the left.

In theory, the code for this would go something like:

C#
if( Itemfound == true )
{
    MoveLeft();
}
else
    MoveRight();

However things aren't always as straight forward as this. What if we don't want to automatically move right if the item isn't found because we also know that there is food on the left and our health is a bit low. The code then looks like:

C#
if( ItemFound == true )
{
    MoveLeft();
}
else
{
    if( HealthLow == true )
        MoveLeft();
    else
        MoveRight();
}

Then we suddenly remember that there is a big gun on the right and there's also a bad guy on the left whom we need the gun to shoot if we are going to get the health. At this point, anyone with more than a few weeks coding experience can see where this is going. The code is getting more and more complex, the nested conditions are getting longer and longer and we are heading towards a maintenance nightmare. This is where the idea for the Fuzzy Decisions comes in. With the Fuzzy Decision classes, we would start out creating a couple of Fuzzy Decision objects, one for the move to the left and one for the move to the right, and then compare them to wee which was the winner. The code would look something like this:

C#
FuzzyDecision left = new FuzzyDecision( "Left" );
FuzzyDecision right = new FuzzyDecision( "Right" );

if( ItemFound == true )
    left.IncrementDecision();

if( HealthLow == true )
    left.IncrementDecision();
else
    right.IncrementDecision();
    
if( GunToRight == true )
    right.IncrementDecision();
    
if( BadGuyToLeft == true )
    right.IncrementDecision();
    
FuzzyDecision decision = left.Compare( right );

if( decision.Name == "Left" )
    MoveLeft();
else
    MoveRight();

The FuzzyDecision class is basically nothing more than a counter class that can be added to or negated from, in order to obtain a final value which is then compared to the other decision objects that are used for different options for the decision.

FuzzyDecisionSet Class

The FuzzyDecisionSet class is a simple mechanism for grouping the decisions available within sets, so that if the decision was to decide which way to move and the options were left, right, up and down, the setting up of the set would be:

C#
FuzzyDecisionSet set = new FuzzyDecisionSet( "WayToMove" );
set.Add( "Left", true );
set.Add( "Right", true );
set.Add( "Up", true );
set.Add( "Down", true );

The Fuzzy Decision Set is created first and given the name WayToMove and then the components of the decision are added. These are created as Fuzzy Decisions by the Add function and are specified with a name and the "is valid" parameter, to label them as valid decisions when the final decision is decided by the compare function.

The FuzzyDecisionSet Class has functions to access the individual decisions based on either the name or the location within the array that stores the decisions, contained within the class. So in order to update the decisions, you would use code like:

C#
set.IncrementByName( "Left" );
set.DecrementByName( "Left" );

or

C#
set.IncrementAt( 0 );
set.DecrementAt( 0 );

Both of which will increment and decrement the Left decision within the set.

Finally

The supplied example contains code that more fully demonstrates the functions of the classes mentioned here and includes printouts of everything that is happening within the code.

History

  • 11 December 2003 :- Initial release.

References

  • Tom Archer ( 2001 ) Inside C#, Microsoft Press
  • Jeffery Richter ( 2002 ) Applied Microsoft .NET Framework Programming, Microsoft Press
  • Charles Peltzold ( 2002 ) Programming Microsoft Windows With C#, Microsoft Press
  • Robinson et al ( 2001 ) Professional C#, Wrox
  • Bart Kosko ( 1994 ) Fuzzy Thinking, Flamingo
  • Buckley & Eslami ( 2002 ) An Introduction To Fuzzy Logic And Fuzzy Sets, Physica-Verlag
  • Earl Cox ( 1999 ) The Fuzzy Systems Handbook, AP Professional

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralA suggestion Pin
LimeyRedneck24-Nov-04 11:20
professionalLimeyRedneck24-Nov-04 11:20 
GeneralRe: A suggestion Pin
pseudonym6724-Nov-04 14:55
pseudonym6724-Nov-04 14:55 
GeneralRe: A suggestion Pin
LimeyRedneck25-Nov-04 6:47
professionalLimeyRedneck25-Nov-04 6:47 
GeneralRe: A suggestion Pin
pseudonym6725-Nov-04 7:19
pseudonym6725-Nov-04 7:19 
GeneralRe: A suggestion Pin
LimeyRedneck25-Nov-04 9:01
professionalLimeyRedneck25-Nov-04 9:01 
GeneralRe: A suggestion Pin
pseudonym6725-Nov-04 10:12
pseudonym6725-Nov-04 10:12 
GeneralA question Pin
Anthony_Yio14-Dec-03 15:54
Anthony_Yio14-Dec-03 15:54 
GeneralRe: A question Pin
pseudonym6714-Dec-03 23:21
pseudonym6714-Dec-03 23:21 
GeneralRe: A question Pin
Anthony_Yio15-Dec-03 16:05
Anthony_Yio15-Dec-03 16:05 
GeneralRe: A question Pin
pseudonym6715-Dec-03 23:21
pseudonym6715-Dec-03 23:21 
GeneralRe: A question Pin
Anthony_Yio16-Dec-03 1:32
Anthony_Yio16-Dec-03 1:32 
My point is, having using prolog doesn't mean you are refraining yourself from using any other programming languages like the one you are using now, .NET. It is however, more productive as an option as the language, Prolog itself has already done excellent work of designing the data structure and abrastraction needed to capture information logically in a shorter form.

You can also port prolog to C++ or to some other programming languages if you want to.

In short, if you feel comfortable with what you are doing now with .NET, no one stopping you. At least you are not expert of all trades, master of none.

Just that, in my personal opinion is true inteligence need more diversities, in term of tools or programming languages which design it.




Sonork 100.41263:Anthony_Yio
GeneralRe: A question Pin
pseudonym6716-Dec-03 6:45
pseudonym6716-Dec-03 6:45 
GeneralThanks Pin
Meysam Mahfouzi12-Dec-03 17:49
Meysam Mahfouzi12-Dec-03 17:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.