13,514,056 members
alternative version

#### Stats

66.7K views
36 bookmarked
Posted 10 Dec 2003

# Fuzzy Logic Dot Net Fuzzy Decisions

, 10 Dec 2003
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();

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" );

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

A list of licenses authors might use can be found here

## Share

 United Kingdom
No Biography provided

## You may also be interested in...

 First Prev Next
 A suggestion LimeyRedneck24-Nov-04 11:20 LimeyRedneck 24-Nov-04 11:20
 Re: A suggestion pseudonym6724-Nov-04 14:55 pseudonym67 24-Nov-04 14:55
 Re: A suggestion LimeyRedneck25-Nov-04 6:47 LimeyRedneck 25-Nov-04 6:47
 Re: A suggestion pseudonym6725-Nov-04 7:19 pseudonym67 25-Nov-04 7:19
 Re: A suggestion LimeyRedneck25-Nov-04 9:01 LimeyRedneck 25-Nov-04 9:01
 Re: A suggestion pseudonym6725-Nov-04 10:12 pseudonym67 25-Nov-04 10:12
 A question Anthony_Yio14-Dec-03 15:54 Anthony_Yio 14-Dec-03 15:54
 Re: A question pseudonym6714-Dec-03 23:21 pseudonym67 14-Dec-03 23:21
 Re: A question Anthony_Yio15-Dec-03 16:05 Anthony_Yio 15-Dec-03 16:05
 Re: A question pseudonym6715-Dec-03 23:21 pseudonym67 15-Dec-03 23:21
 Re: A question Anthony_Yio16-Dec-03 1:32 Anthony_Yio 16-Dec-03 1:32
 Re: A question pseudonym6716-Dec-03 6:45 pseudonym67 16-Dec-03 6:45
 Thanks meisi12-Dec-03 17:49 meisi 12-Dec-03 17:49
 Last Visit: 31-Dec-99 18:00     Last Update: 26-Apr-18 19:31 Refresh 1