Click here to Skip to main content
Click here to Skip to main content

Fuzzy Logic Dot Net Fuzzy Decisions

, 10 Dec 2003
Rate this:
Please Sign up or sign in to vote.
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:

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:

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:

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:

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:

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

or

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

Share

About the Author

pseudonym67

United Kingdom United Kingdom
No Biography provided

Comments and Discussions

 
GeneralA suggestion PinmemberLimeyRedneck24-Nov-04 11:20 
GeneralRe: A suggestion Pinmemberpseudonym6724-Nov-04 14:55 
GeneralRe: A suggestion PinmemberLimeyRedneck25-Nov-04 6:47 
GeneralRe: A suggestion Pinmemberpseudonym6725-Nov-04 7:19 
GeneralRe: A suggestion PinmemberLimeyRedneck25-Nov-04 9:01 
GeneralRe: A suggestion Pinmemberpseudonym6725-Nov-04 10:12 
GeneralA question PinmemberAnthony_Yio14-Dec-03 15:54 
GeneralRe: A question Pinmemberpseudonym6714-Dec-03 23:21 
GeneralRe: A question PinmemberAnthony_Yio15-Dec-03 16:05 
GeneralRe: A question Pinmemberpseudonym6715-Dec-03 23:21 
GeneralRe: A question PinmemberAnthony_Yio16-Dec-03 1:32 
GeneralRe: A question Pinmemberpseudonym6716-Dec-03 6:45 
GeneralThanks Pinmembermeisi12-Dec-03 17:49 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 11 Dec 2003
Article Copyright 2003 by pseudonym67
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid