Exemplo n.º 1
0
 public void InitView(Boolean isFuzzy, Double ranking, Double value, String fuzzyString, String text, String shortText)
 {
     if (isFuzzy)
     {
         TriangularFuzzyNumber fValue = null;
         if (String.IsNullOrWhiteSpace(fuzzyString))
         {
             fValue      = value.ToFuzzy();
             fuzzyString = fValue.ToString();
         }
         else
         {
             try
             {
                 TriangularFuzzyNumber.TryParse(fuzzyString, out fValue);
             }
             catch (Exception ex)
             {
                 fValue = value.ToFuzzy();
             }
         }
         View.RenderRankingFuzzyNumber(text, shortText, ranking.ToString(), fuzzyString, (fValue == null ? "0" : fValue.CenterOfGravity.Round()));
     }
     else
     {
         if (Math.Floor(value) == Math.Round(value, 3))
         {
             View.RenderNumber(text, Math.Floor(value).ToString());
         }
         else
         {
             View.RenderNumber(text, value.Round());
         }
     }
 }
Exemplo n.º 2
0
 public void InitView(Boolean isFuzzy, Double ranking, Double value)
 {
     if (isFuzzy)
     {
         TriangularFuzzyNumber fValue = value.ToFuzzy();
         View.RenderRankingFuzzyNumber(value.ToString(), ranking.ToString(), ranking.ToString(), fValue.ToString(), fValue.CenterOfGravity.Round());
     }
     else
     {
         InitView(false, value);
     }
 }
Exemplo n.º 3
0
        private NormalizationStatus CheckWeights(List <dtoItemWeight> weights, Boolean isFuzzy, Boolean autoUpdateWeights)
        {
            NormalizationStatus nStatus = NormalizationStatus.none;

            if (weights.Any(i => !String.IsNullOrWhiteSpace(i.Value)))
            {
                LM.MathLibrary.Extensions.FuzzyExtension.Normalization status;
                TriangularFuzzyNumber[] w = null;
                try
                {
                    if (isFuzzy)
                    {
                        w = weights.Select(i => TriangularFuzzyNumber.Parse(i.Value)).ToArray();
                    }
                    else
                    {
                        w = weights.Select(i => new TriangularFuzzyNumber(long.Parse(i.Value))).ToArray();
                    }
                    w = w.NormalizeWeights(out status).ToArray();
                    if (status == FuzzyExtension.Normalization.normalizable)
                    {
                        Int32 index = 0;
                        foreach (TriangularFuzzyNumber i in w)
                        {
                            if (w[index] != null)
                            {
                                weights[index].Value = (isFuzzy ? w[index].ToString() : w[index].ToCrispy().ToString());
                            }
                            else
                            {
                                weights[index].Value = "";
                            }
                            index++;
                        }
                        if (autoUpdateWeights)
                        {
                            View.UpdateWeights(weights);
                        }
                    }
                }
                catch (Exception ex)
                {
                    status = FuzzyExtension.Normalization.none;
                }
                nStatus = TranslateStatus(status);
            }

            View.CurrentNormalization = nStatus;
            return(nStatus);
        }
Exemplo n.º 4
0
 public void InitView(Boolean isFuzzy, Double value)
 {
     if (isFuzzy)
     {
         TriangularFuzzyNumber fValue = value.ToFuzzy();
         View.RenderFuzzyNumber(value.ToString(), value.ToString(), fValue.ToString(), fValue.CenterOfGravity.Round());
     }
     else
     {
         if (Math.Floor(value) == Math.Round(value, 3))
         {
             View.RenderNumber(Math.Floor(value).ToString(), Math.Floor(value).ToString());
         }
         else
         {
             View.RenderNumber(value.Round().ToString(), value.Round());
         }
     }
 }
Exemplo n.º 5
0
        public dtoItemRating VerifySettings(dtoItemRating settings)
        {
            if (settings.Error == DssError.None)
            {
                switch (settings.RatingType)
                {
                case RatingType.simple:
                    TemplateRatingValue item = Service.RatingValueGet(settings.IdRatingValue);
                    if (item != null)
                    {
                        if (item.IsFuzzy)
                        {
                            TriangularFuzzyNumber fValue = null;
                            if (TriangularFuzzyNumber.TryParse(item.FuzzyValue, out fValue))
                            {
                                settings.Value      = fValue.CenterOfGravity;
                                settings.ValueFuzzy = item.FuzzyValue;
                            }
                            else
                            {
                                settings.Error = DssError.InvalidWeight;
                            }
                        }
                        else
                        {
                            settings.Value = item.Value;
                        }
                    }
                    else
                    {
                        settings.Error = DssError.InvalidWeight;
                    }
                    break;

                case RatingType.intermediateValues:
                    TemplateRatingValue fromValue = Service.RatingValueGet(settings.IdRatingValue);
                    TemplateRatingValue toValue   = Service.RatingValueGet(settings.IdRatingValueEnd);
                    if (fromValue != null && toValue != null)
                    {
                        if (fromValue.IsFuzzy)
                        {
                            try{
                                TriangularFuzzyNumber fValue = TriangularFuzzyNumber.Intermediate(TriangularFuzzyNumber.Parse(fromValue.FuzzyValue), TriangularFuzzyNumber.Parse(toValue.FuzzyValue));
                                settings.Value      = fValue.CenterOfGravity;
                                settings.ValueFuzzy = fValue.ToString();
                            }
                            catch (Exception ex)
                            {
                                settings.Error = DssError.InvalidWeight;
                            }
                        }
                        else
                        {
                            settings.Value = ((fromValue.Value + toValue.Value) / 2);
                        }
                    }
                    else
                    {
                        settings.Error = DssError.InvalidWeight;
                    }
                    break;
                }
            }
            return(settings);
        }
Exemplo n.º 6
0
 public virtual void AddValue(TriangularFuzzyNumber value)
 {
     Values.Add(value);
 }