Пример #1
0
 private static CoreLogic.Classes.Class ConvertModelToClass(Models.Class classModel)
 {
     if (classModel.type == MF_TRIANGULAR)
     {
         return new CoreLogic.Classes.ClassWithTriangularMF(
             classModel.name,
             classModel.@params[MF_TRIANGULAR_A],
             classModel.@params[MF_TRIANGULAR_B],
             classModel.@params[MF_TRIANGULAR_C]
         );
     }
     else if (classModel.type == MF_TRAPEZOIDAL)
     {
         return new CoreLogic.Classes.ClassWithTrapezoidalMF(
             classModel.name,
             classModel.@params[MF_TRAPEZOIDAL_A],
             classModel.@params[MF_TRAPEZOIDAL_B],
             classModel.@params[MF_TRAPEZOIDAL_C],
             classModel.@params[MF_TRAPEZOIDAL_D]
         );
     }
     else if (classModel.type == MF_GAUSSIAN)
     {
         return new CoreLogic.Classes.ClassWithGaussianMF(
             classModel.name,
             classModel.@params[MF_GAUSSIAN_C],
             classModel.@params[MF_GAUSSIAN_SIGMA]
         );
     }
     else if (classModel.type == MF_GENERALISED_BELL)
     {
         return new CoreLogic.Classes.ClassWithGeneralisedBellMF(
             classModel.name,
             classModel.@params[MF_GENERALISED_BELL_A],
             classModel.@params[MF_GENERALISED_BELL_B],
             classModel.@params[MF_GENERALISED_BELL_C]
         );
     }
     else if (classModel.type == MF_SIGMOID_DIFF)
     {
         return new CoreLogic.Classes.ClassWithSigmoidDifferenceMF(
             classModel.name,
             classModel.@params[MF_SIGMOID_DIFF_A1],
             classModel.@params[MF_SIGMOID_DIFF_A2],
             classModel.@params[MF_SIGMOID_DIFF_C1],
             classModel.@params[MF_SIGMOID_DIFF_C2]
         );
     }
     else
     {
         throw new ArgumentException($"Attemt to parse an unknown type of classes: {classModel.type}");
     }
 }
Пример #2
0
        private static Models.Class ConvertClassToModel(CoreLogic.Classes.Class clazz)
        {
            var classModel = new Models.Class { name = clazz.Name, @params = new Dictionary<string, double>() };

            if (clazz is CoreLogic.Classes.ClassWithTriangularMF)
            {
                classModel.type = MF_TRIANGULAR;
                var classWithTriangularMF = clazz as CoreLogic.Classes.ClassWithTriangularMF;
                classModel.@params[MF_TRIANGULAR_A] = classWithTriangularMF.A;
                classModel.@params[MF_TRIANGULAR_B] = classWithTriangularMF.B;
                classModel.@params[MF_TRIANGULAR_C] = classWithTriangularMF.C;
            }
            else if (clazz is CoreLogic.Classes.ClassWithTrapezoidalMF)
            {
                classModel.type = MF_TRAPEZOIDAL;
                var classWithTrapezoidalMF = clazz as CoreLogic.Classes.ClassWithTrapezoidalMF;
                classModel.@params[MF_TRAPEZOIDAL_A] = classWithTrapezoidalMF.A;
                classModel.@params[MF_TRAPEZOIDAL_B] = classWithTrapezoidalMF.B;
                classModel.@params[MF_TRAPEZOIDAL_C] = classWithTrapezoidalMF.C;
                classModel.@params[MF_TRAPEZOIDAL_D] = classWithTrapezoidalMF.D;
            }
            else if (clazz is CoreLogic.Classes.ClassWithGaussianMF)
            {
                classModel.type = MF_GAUSSIAN;
                var classWithGaussianMF = clazz as CoreLogic.Classes.ClassWithGaussianMF;
                classModel.@params[MF_GAUSSIAN_C] = classWithGaussianMF.C;
                classModel.@params[MF_GAUSSIAN_SIGMA] = classWithGaussianMF.Sigma;
            }
            else if (clazz is CoreLogic.Classes.ClassWithGeneralisedBellMF)
            {
                classModel.type = MF_GENERALISED_BELL;
                var classWithGeneralisedBellMF = clazz as CoreLogic.Classes.ClassWithGeneralisedBellMF;
                classModel.@params[MF_GENERALISED_BELL_A] = classWithGeneralisedBellMF.A;
                classModel.@params[MF_GENERALISED_BELL_B] = classWithGeneralisedBellMF.B;
                classModel.@params[MF_GENERALISED_BELL_C] = classWithGeneralisedBellMF.C;
            }
            else if (clazz is CoreLogic.Classes.ClassWithSigmoidDifferenceMF)
            {
                classModel.type = MF_SIGMOID_DIFF;
                var classWithSigmoidDifferenceMF = clazz as CoreLogic.Classes.ClassWithSigmoidDifferenceMF;
                classModel.@params[MF_SIGMOID_DIFF_A1] = classWithSigmoidDifferenceMF.A1;
                classModel.@params[MF_SIGMOID_DIFF_A2] = classWithSigmoidDifferenceMF.A2;
                classModel.@params[MF_SIGMOID_DIFF_C1] = classWithSigmoidDifferenceMF.C1;
                classModel.@params[MF_SIGMOID_DIFF_C2] = classWithSigmoidDifferenceMF.C2;
            }
            else
            {
                throw new ArgumentException($"Attempt to handle an unknown type: {clazz.GetType().FullName}.");
            }

            return classModel;
        }