# Fuzzy Sets

Verb: `fuzzySet`

Available from: <Enterprise>

Defines a fuzzy set based on its membership function.

## Syntax

`fuzzySet --function(FuzzyMembershipFunctions) --sets(String) --shape(Nullable<FuzzyShapes>) --edge(FuzzyEdges) --m1(Numeric) --m2(Numeric) --m3(Numeric) --m4(Numeric) --minimum(Numeric) --maximum(Numeric) (FuzzySet)=value `

## Inputs

Script Designer Required AcceptedTypes Description
--function Function Required FuzzyMembershipFunctions Function that defines the degree of membership of a given element to the set, returning actual values between 0 and 1. Options:
• Piecewise Linear
• Trapezoidal
• --sets Sets Only whenFunction is PiecewiseLinear Text Text with Piecewise Linear coordinates to form the function.
Format: (x1, y1); (x2, y2); ...; (xn, yx), where x refers to the x coordinate of the Cartesian plane and y refers to the y coordinate of the Cartesian plane
--shape Shape Only whenFunction is Trapezoidal FuzzyShapes Trapezoidal function shape used to specify the coordinates of the fuzzy set membership function. Options:
• Flat
• Flat With Range
• Number
• Number With Range
• Triangular
• Triangular With Range
• --edge Edge Only whenShape is Reserved_Edge FuzzyEdges Defines the edge format that is used in Trapezoidal. Options:
• Left
• None
• Right
• --m1 M1 Only whenShape is Reserved_M1 Number Number that defines the value of the "x" coordinate of the first point of Trapezoidal.
M1 values:
• For Number, Triangular or Flat: 0;
• For Number With Range, Triangular With Range or Flat With Range: This is the value defined in Minimum.
• --m2 M2 Only whenShape is Reserved_M2 Number Number that defines the value of the "x" coordinate of the second point of Trapezoidal.
M2 values:
• For Number, Triangular or Flat: 1;
• For Number With Range, Triangular With Range or Flat With Range: This is the value defined in Maximum.
• --m3 M3 Only whenShape is Reserved_M3 Number Number that defines the value of the "x" coordinate for the third point of Trapezoidal.
M3 values:
• For Triangular: 0;
• For Triangular With Range: The value defined in Minimum;
• For Flat: 1;
• For Flat With Range: This is the value defined in Maximum.
• --m4 M4 Only whenShape is Reserved_M4 Number Number that defines the value of the "x" coordinate for the fourth point of Trapezoidal.
M4 values:
• For Flat: 0;
• For Flat With Range: This is the value defined in Minimum.
• --minimum Minimum Only whenShape is Reserved_Min Number Defines the minimum return value of the specified fuzzy set membership function.
--maximum Maximum Only whenShape is Reserved_Max Number Defines the maximum return value of the specified fuzzy set membership function.

## Outputs

Script Designer AcceptedTypes Description
value Result Fuzzy Set Returns a variable of the "Fuzzy Set" type, which contains the fuzzy set specified in the input parameters.

## Example

First, a fuzzy logic set is started with Begin Fuzzy with Intervals = 1000. Next, fuzzy logic is created to tell the quality of service of a restaurant. Then, the End Fuzzy command is used to terminate the set.

``````defVar --name low --type FuzzySet
defVar --name medium --type FuzzySet
defVar --name good --type FuzzySet
defVar --name serviceQuality --type Fuzzy
defVar --name foodQuality --type Fuzzy
defVar --name littleTip --type FuzzySet
defVar --name reasonableTip --type FuzzySet
defVar --name generousTip --type FuzzySet
defVar --name tip --type Fuzzy
defVar --name foodGrade --type Numeric --value "7.5"
defVar --name serviceGrade --type Numeric --value 6
defVar --name tipValue --type Numeric
beginFuzzy --intervals 1000
fuzzySet --function "Trapezoidal" --shape "Number" --edge "Right" --m1 0 --m2 5 low=value
fuzzySet --function "Trapezoidal" --shape "Triangular" --m1 3 --m2 5 --m3 7 medium=value
fuzzySet --function "Trapezoidal" --shape "Number" --edge "Left" --m1 5 --m2 10 good=value
fuzzyVariable --left 0 --right 10 --labels "\${low} \${medium} \${good}" serviceQuality=value
fuzzyVariable --left 0 --right 10 --labels "\${low} \${medium} \${good}" foodQuality=value
fuzzySet --function "Trapezoidal" --shape "Number" --edge "Right" --m1 0 --m2 12.5 littleTip=value
fuzzySet --function "Trapezoidal" --shape "Triangular" --m1 6.25 --m2 12.5 --m3 18.75 reasonableTip=value
fuzzySet --function "Trapezoidal" --shape "Number" --edge "Left" --m1 12.5 --m2 25 generousTip=value
fuzzyVariable --left 0 --right 25 --labels "\${littleTip} \${reasonableTip} \${generousTip}" tip=value

//The food was rancid or the service was poor.
fuzzyRule --name "Terrible food or service" --condition "\${foodQuality} IS \${low} OR \${serviceQuality} IS \${low}" --variable \${tip} --set \${littleTip}

//The service was reasonable.
fuzzyRule --name "Average service" --condition "\${serviceQuality} IS \${medium}" --variable \${tip} --set \${reasonableTip}

//The food was delicious or the service was good.
fuzzyRule --name "Great Food or Service" --condition "\${foodQuality} IS \${good} OR \${serviceQuality} IS \${good}" --variable \${tip} --set \${generousTip}
endFuzzy
setVar --name "\${foodQuality}" --value "\${foodGrade}"
setVar --name "\${serviceQuality}" --value "\${serviceGrade}"
evaluate --expression "\${tip}" tipValue=value
logMessage --message "Tip Value: \${tipValue};\r\nFood Grade: \${foodGrade};\r\nService Grade: \${serviceGrade}" --type "Info"
``````

## See Also

• Begin Fuzzy
• End Fuzzy
• Fuzzy Rule
• Fuzzy Variable