Exemple #1
0
        public static ElementalArray CompareMembership(ElementalArray array)
        {
            ElementalArray firstResult  = (ElementalArray)array.Elements[0].Value;
            ElementalArray secondResult = (ElementalArray)array.Elements[1].Value;

            ElementalArray membershipLess    = StaticConstants.False;
            ElementalArray membershipEqual   = StaticConstants.False;
            ElementalArray membershipGreater = StaticConstants.False;

            if (firstResult == StaticConstants.True)
            {
                if (secondResult == StaticConstants.True)
                {
                    membershipEqual = StaticConstants.True;
                }
                else
                {
                    membershipGreater = StaticConstants.True;
                }
            }
            else
            {
                if (secondResult == StaticConstants.True)
                {
                    membershipLess = StaticConstants.True;
                }
                else
                {
                    membershipEqual = StaticConstants.True;
                }
            }
            return(new ElementalArray(new[] { membershipLess, membershipEqual, membershipGreater }));
        }
Exemple #2
0
 private static void ElementalUnitArrayAddToList <T>(List <T> instance, ElementalArray array)
 {
     foreach (var item in array.Elements)
     {
         T value = ElementalUnitArrayTo <T>(item.Value);
         instance.Add(value);
     }
 }
        public FuzzyElementWiseUnitCompareLoop(ElementalArray lhs, ElementalArray rhs)
        {
            // if GetLoopControlMembership(ElementWiseUnitComparer)
            //      => Comparer.MovedNext And ComparisonResult = Membership.Equal
            //  ComparisonResult = UnitEnumeratorCompare(lhs.Enumerator, rhs.Enumerator)
            //      => {lhs.Current ^ rhs.Current} ? Membership.Equal : (lhs.Current ? Membership.Greater: Membership.Less);

            /* Fuzzy Rules:
             * if LoopStateNone Then Init
             * if LoopStateInit Then Loop
             * if LoopStateLoop Then Evaluate
             * if LoopStateEvaluate and Evaluate() Then LoopAction
             * if LoopStateLoopBody Then LoopAction();
             * if LoopStateDone Then LoopExit();
             */
            /*
             * If NotLoopInitialized then Initialize
             * If InLoopBody Then ExecuteLoop()
             * --- or  --
             * If Not LoopFinished Then ExecuteLoop()
             * --- Generic rule
             * If Not ReachedTarget Then Move()
             *
             */

            dynamic LoopState = null;



            dynamic LoopStateNone       = null;
            dynamic LoopStateInit       = null;
            dynamic LoopStateLoop       = null;
            dynamic LoopStateEvaluate   = null;
            dynamic LoopStateLoopAction = null;

            dynamic LoopInit    = null;
            dynamic Loop        = null;
            dynamic Evaluate    = null;
            dynamic LoopAction  = null;
            var     loopActions = new Dictionary <dynamic, dynamic>
            {
                { LoopStateNone, LoopInit },
                { LoopStateInit, Loop },
                { LoopStateLoop, Evaluate },
                { LoopStateEvaluate, LoopAction },
                { LoopStateLoopAction, Loop },
            };

            Func <dynamic, dynamic> GetMembership = (state) =>
            {
                return(loopActions[state]);
            };
            var loopMembership = GetMembership(LoopState);
        }
Exemple #4
0
        public static T ElementalUnitArrayTo <T>(ElementalArray array)
        {
            dynamic incremental = default(T);
            var     type        = typeof(T);

            if (!type.IsValueType)// Hmmm!!! Require UserDefined Conversion operators?
            {
                incremental = Activator.CreateInstance <T>();
            }
            if (type == typeof(bool))
            {
                incremental = array.Elements.Count > 0;
            }
            else if (type.IsArray)
            {
                var     listType     = typeof(List <>);
                var     genericType  = listType.MakeGenericType(type.GetElementType());
                dynamic listInstance = Activator.CreateInstance(genericType);
                ElementalUnitArrayAddToList(listInstance, array);
                return(listInstance.ToArray());
            }
            else if (type == typeof(string))
            {
                StringBuilder sb = new System.Text.StringBuilder();
                foreach (var item in array.Elements)
                {
                    char c = ElementalUnitArrayTo <char>(item.Value);
                    sb.Append(c);
                }
                incremental = sb.ToString();
            }
            else
            {
                var enumerator = array.Elements.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    incremental++;
                }
            }
            return(incremental);
        }
Exemple #5
0
 public ElementArraySiblingEnumerator(ElementalArray elementalArray)
 {
     this.elementalArray = elementalArray;
 }
Exemple #6
0
 public ElementalUnitCompareEnumerator(ElementalArray a, ElementalArray b)
 {
     this.elementalArrayA = a;
     this.elementalArrayB = b;
 }
Exemple #7
0
 public static ElementalArray IsGreaterOrEqual(ElementalArray comparisonMembership) => (ElementalArray)comparisonMembership.Elements[1].Value == StaticConstants.True ? StaticConstants.False : StaticConstants.True;
Exemple #8
0
 public static ElementalArray IsGreater(ElementalArray comparisonMembership) => (ElementalArray)comparisonMembership.Elements[2].Value;
Exemple #9
0
 public static ElementalArray IsEqual(ElementalArray comparisonMembership) => (ElementalArray)comparisonMembership.Elements[1].Value;
Exemple #10
0
 // built in operators: Implement as Linguistic variables.
 public static ElementalArray IsLessThan(ElementalArray comparisonMembership) => (ElementalArray)comparisonMembership.Elements[0].Value;