📄 fuzzydecision.cs
字号:
return true;
}
else
return false;
}
/// <summary>
/// Add the number to the Fuzzy Decision with the given name
/// </summary>
/// <param name="name">name of the decision</param>
/// <param name="number">number to be added</param>
/// <returns>true if done</returns>
public bool AddByName( string name, int number )
{
bool bDone = false;
for( int i=0; i<this.FuzzyArray.Count; i++ )
{
if( name == ( ( FuzzyDecision )this.FuzzyArray[ i ] ).Name )
{
( ( FuzzyDecision )this.FuzzyArray[ i ] ).Number += number;
bDone = true;
i=this.FuzzyArray.Count;
}
}
return bDone;
}
/// <summary>
/// Subtract the number from the Fuzzy Decision at the given index
/// </summary>
/// <param name="index">index of the decision</param>
/// <param name="number">number to be subtracted</param>
/// <returns>true if done</returns>
public bool SubtractAt( int index, int number )
{
if( index < this.FuzzyArray.Count )
{
( ( FuzzyDecision )this.FuzzyArray[ index ] ).Number -= number;
return true;
}
else
return false;
}
/// <summary>
/// Subtract the number from the Fuzzy Decision with the given name
/// </summary>
/// <param name="name">name of the decision</param>
/// <param name="number">number to be subtracted</param>
/// <returns>true if done</returns>
public bool SubtractByName( string name, int number )
{
bool bDone = false;
for( int i=0; i<this.FuzzyArray.Count; i++ )
{
if( name == ( ( FuzzyDecision )this.FuzzyArray[ i ] ).Name )
{
( ( FuzzyDecision )this.FuzzyArray[ i ] ).Number -= number;
bDone = true;
i=this.FuzzyArray.Count;
}
}
return bDone;
}
/// <summary>
/// Zero the Fuzzy Decision at the given index
/// </summary>
/// <param name="index">index of the decision</param>
/// <returns>true if done</returns>
public bool ZeroNumberAt( int index )
{
if( index < this.FuzzyArray.Count )
{
( ( FuzzyDecision )this.FuzzyArray[ index ] ).Number = 0;
return true;
}
else
return false;
}
/// <summary>
/// Zero the Fuzzy Decision with the given name
/// </summary>
/// <param name="name">name of the decision</param>
/// <returns>true if done</returns>
public bool ZeroNumberByName( string name )
{
bool bDone = false;
for( int i=0; i<this.FuzzyArray.Count; i++ )
{
if( name == ( ( FuzzyDecision )this.FuzzyArray[ i ] ).Name )
{
( ( FuzzyDecision )this.FuzzyArray[ i ] ).Number = 0;
bDone = true;
i=this.FuzzyArray.Count;
}
}
return bDone;
}
/// <summary>
/// Compare the Fuzzy Decisions in the array and return the winner
/// </summary>
/// <returns>the decision with the highest value</returns>
public FuzzyDecision Compare()
{
FuzzyDecision decision = null;
if( this.FuzzyArray.Count > 1 )
{
for( int i=1; i<this.FuzzyArray.Count; i++ )
{
if( decision == null )
{
decision = ( ( FuzzyDecision )this.FuzzyArray[ i-1 ] ).Compare( ( FuzzyDecision )this.FuzzyArray[ i ] );
}
else
{
decision = decision.Compare( ( FuzzyDecision )this.FuzzyArray[ i ] );
}
}
}
return decision;
}
/// <summary>
/// Set the Fuzzy Decision at the given index to valid or not
/// </summary>
/// <param name="index">index of the decision</param>
/// <param name="valid">set true or false</param>
/// <returns>true if done</returns>
public bool IsValidAt( int index, bool valid )
{
if( index < this.FuzzyArray.Count )
{
( ( FuzzyDecision )this.FuzzyArray[ index ] ).IsValid = valid;
return true;
}
else
return false;
}
/// <summary>
/// Set the Fuzzy Decision with the given name
/// </summary>
/// <param name="name">name of the decision</param>
/// <param name="valid">set true or false</param>
/// <returns>true if done</returns>
public bool SetIsValidByName( string name, bool valid )
{
bool bDone = false;
for( int i=0; i<this.FuzzyArray.Count; i++ )
{
if( name == ( ( FuzzyDecision )this.FuzzyArray[ i ] ).Name )
{
( ( FuzzyDecision )this.FuzzyArray[ i ] ).IsValid = valid;
bDone = true;
i=this.FuzzyArray.Count;
}
}
return bDone;
}
/// <summary>
/// get the Fuzzy Decision's valid parameter with the given name
/// </summary>
/// <param name="name">name of the decision</param>
/// <returns>true or false</returns>
public bool IsValidByName( string name )
{
for( int i=0; i<this.FuzzyArray.Count; i++ )
{
if( name == ( ( FuzzyDecision )this.FuzzyArray[ i ] ).Name )
{
return ( ( FuzzyDecision )FuzzyArray[ i ] ).IsValid;
}
}
return false;
}
/// <summary>
/// Get the valid status of the Fuzzy Decision at the given index
/// </summary>
/// <param name="index">index of the decision</param>
/// <returns>true if valid</returns>
public bool GetValidAt( int index )
{
if( index < this.FuzzyArray.Count )
{
return ( ( FuzzyDecision )this.FuzzyArray[ index ] ).IsValid;
}
else
return false;
}
/// <summary>
/// Get the valid status of the Fuzzy Decision with the given name
/// </summary>
/// <param name="name">name of the decision</param>
/// <returns>true if valid</returns>
public bool GetValidByName( string name )
{
bool bDone = false;
for( int i=0; i<this.FuzzyArray.Count; i++ )
{
if( name == ( ( FuzzyDecision )this.FuzzyArray[ i ] ).Name )
{
return ( ( FuzzyDecision )this.FuzzyArray[ i ] ).IsValid;
}
}
return bDone;
}
/// <summary>
/// Get the number of the Fuzzy Decision at the given index
/// </summary>
/// <param name="index">index of hte decision</param>
/// <returns>the number of the decision at the index</returns>
public int GetNumberAt( int index )
{
if( index < this.FuzzyArray.Count )
{
return ( int )( ( FuzzyDecision )this.FuzzyArray[ index ] ).Number;
}
else
return 0;
}
/// <summary>
/// Get the number of the Fuzzy Decision with the given name
/// </summary>
/// <param name="name">name of the decision</param>
/// <returns>the number of the decision with the given name</returns>
public int GetNumberByName( string name )
{
for( int i=0; i<this.FuzzyArray.Count; i++ )
{
if( name == ( ( FuzzyDecision )this.FuzzyArray[ i ] ).Name )
{
return ( int )( ( FuzzyDecision )this.FuzzyArray[ i ] ).Number;
}
}
return 0;
}
/// <summary>
/// Gets the Fuzzy Decision at the given index
/// </summary>
/// <param name="index">index of the decision</param>
/// <returns>decision at the given index</returns>
public FuzzyDecision GetDecisionAt( int index )
{
if( index < this.FuzzyArray.Count )
{
return ( FuzzyDecision )FuzzyArray[ index ];
}
else
return null;
}
/// <summary>
/// Gets the Fuzzy Decision with the given name
/// </summary>
/// <param name="name">name of the decision</param>
/// <returns>decision with the given name</returns>
public FuzzyDecision GetDecisionByName( string name )
{
for( int i=0; i<FuzzyArray.Count; i++ )
{
if( name == ( ( FuzzyDecision )FuzzyArray[ i ] ).Name )
{
return ( FuzzyDecision )FuzzyArray[ i ];
}
}
return null;
}
/// Saving and Loading
///
public virtual void Save( XmlWriter xmlWriter )
{
xmlWriter.WriteStartElement( "FuzzyDecisionSet" );
xmlWriter.WriteElementString( "Name", Name );
for( int i=0; i<FuzzyArray.Count; i++ )
{
( ( FuzzyDecision )FuzzyArray[ i ] ).Save( xmlWriter );
}
xmlWriter.WriteEndElement();
}
public virtual void Load( XmlReader xmlReader )
{
while( xmlReader.Name != "Name" )
{
xmlReader.Read();
if( xmlReader.EOF == true )
return;
}
xmlReader.Read();
Name = xmlReader.Value;
bool bBreak = false;
for( ;; )
{
xmlReader.Read();
if( xmlReader.EOF == true )
return;
switch( xmlReader.NodeType )
{
case XmlNodeType.Element:
{
switch( xmlReader.Name )
{
case "FuzzyDecision":
{
FuzzyDecision temp = new FuzzyDecision();
temp.Load( xmlReader );
AddDecision( temp );
break;
}
default: bBreak = true; break;
}
} break;
case XmlNodeType.EndElement:
{
switch( xmlReader.Name )
{
case "FuzzyDecisionSet" : bBreak = true; break;
}
} break;
}
if( bBreak == true )
break;
}
}
/// comparison stuff
///
public static bool operator ==( FuzzyDecisionSet setOne, FuzzyDecisionSet setTwo )
{
bool bOneIsNull = false;
bool bBothAreNull = false;
try
{
int nTemp = setOne.Count;
}
catch( NullReferenceException nullRefExp )
{
string strTemp = nullRefExp.Message;
bOneIsNull = true;
}
try
{
int nTemp = setTwo.Count;
}
catch( NullReferenceException nullRefExp )
{
string strTemp = nullRefExp.Message;
if( bOneIsNull == true )
{
bBothAreNull = true;
}
else
bOneIsNull = true;
}
if( bOneIsNull == true )
return false;
if( bBothAreNull == true )
return true;
if( setOne.Count != setTwo.Count )
return false;
bool bAllEqual = true;
for( int i=0; i<setOne.Count; i++ )
{
if( ( FuzzyDecision )setOne[ i ] != ( FuzzyDecision )setTwo[ i ] )
bAllEqual = false;
}
if( bAllEqual == true )
return true;
return false;
}
public static bool operator !=( FuzzyDecisionSet setOne, FuzzyDecisionSet setTwo )
{
bool bOneIsNull = false;
bool bBothAreNull = false;
try
{
int nTemp = setOne.Count;
}
catch( NullReferenceException nullRefExp )
{
string strTemp = nullRefExp.Message;
bOneIsNull = true;
}
try
{
int nTemp = setTwo.Count;
}
catch( NullReferenceException nullRefExp )
{
string strTemp = nullRefExp.Message;
if( bOneIsNull == true )
{
bBothAreNull = true;
}
else
bOneIsNull = true;
}
if( bOneIsNull == true )
return true;
if( bBothAreNull == true )
return false;
if( setOne.Count != setTwo.Count )
return true;
bool bAllNotEqual = true;
for( int i=0; i<setOne.Count; i++ )
{
if( ( FuzzyDecision )setOne[ i ] == ( FuzzyDecision )setTwo[ i ] )
bAllNotEqual = false;
}
if( bAllNotEqual == true )
return true;
return false;
}
/// required overrides
///
public override bool Equals(object obj)
{
if( obj == null || GetType() != obj.GetType() )
return false;
FuzzyDecisionSet temp = ( FuzzyDecisionSet )obj;
return this == temp;
}
public override int GetHashCode()
{
return this.FuzzyArray.GetHashCode() ^ this.Name.GetHashCode();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -