/// <summary>
        /// compute the similarity of case base's cases and problem case
        ///
        /// </summary>
        /// <param name="cases"></param>
        /// <param name="problem"></param>
        /// <returns></returns>
        public ArrayList ComputeSimilarity(ArrayList cases, Case problem)
        {
            if (_env == null)
            {
                throw new ContextException("environment variable is not set");
            }

            ICBRContext ctx = CBRContextManager.GetCBRContext(_env);

            if (ctx == null)
            {
                throw new ContextException("not set context");
            }

            ISimilarity sim = (ISimilarity)ctx.GetSimilarity();

            if (sim == null)
            {
                throw new ContextException("similarity method is not set");
            }

            ArrayList stats = new ArrayList();
            double    similarityThrehold = ctx.GetSimilarityThrehold();

            for (int i = 0; i < cases.Count; i++)
            {
                Case   solution   = (Case)cases[i];
                double similarity = sim.Compare(problem, solution);
                //continue if the similarity by comparing is lower than the
                //similarity threhold in context setting
                if (similarity < similarityThrehold)
                {
                    continue;
                }
                IStat s = StatFactory.newInstance();
                s.SetCBRCase(solution);
                s.SetCaseSimilarity(similarity);
                //bi-sort similarity
                if (stats.Count <= 0)
                {
                    stats.Add(s);
                    continue;
                }
                SortSimilarity(stats, s);
            }

            return(stats);
        }
Esempio n. 2
0
        [SetUp] public void Init()
        {
            if (list.Count > 0)
            {
                list.Clear();
            }
            c1.AddFeature("speed", FeatureType.TYPE_FEATURE_FLOAT,
                          2.0, 0.5, false, false);
            c2.AddFeature("speed", FeatureType.TYPE_FEATURE_FLOAT,
                          3.8, 0.5, false, false);
            c3.AddFeature("speed", FeatureType.TYPE_FEATURE_FLOAT,
                          7.0, 0.5, false, false);
            c4.AddFeature("speed", FeatureType.TYPE_FEATURE_FLOAT,
                          9.0, 0.5, false, false);
            c5.AddFeature("speed", FeatureType.TYPE_FEATURE_FLOAT,
                          5.0, 0.5, false, false);


            c1.AddFeature("temperature", FeatureType.TYPE_FEATURE_FLOAT,
                          3.0, 0.3, false, false);
            c2.AddFeature("temperature", FeatureType.TYPE_FEATURE_FLOAT,
                          4.0, 0.3, false, false);
            c3.AddFeature("temperature", FeatureType.TYPE_FEATURE_FLOAT,
                          2.0, 0.3, false, false);
            c4.AddFeature("temperature", FeatureType.TYPE_FEATURE_FLOAT,
                          7.0, 0.3, false, false);
            c5.AddFeature("temperature", FeatureType.TYPE_FEATURE_FLOAT,
                          1.0, 0.3, false, false);

            c1.AddFeature("quality", FeatureType.TYPE_FEATURE_FLOAT,
                          1.0, 0.2, false, false);
            c2.AddFeature("quality", FeatureType.TYPE_FEATURE_FLOAT,
                          2.0, 0.2, false, false);
            c3.AddFeature("quality", FeatureType.TYPE_FEATURE_FLOAT,
                          5.0, 0.2, false, false);
            c4.AddFeature("quality", FeatureType.TYPE_FEATURE_FLOAT,
                          7.0, 0.2, false, false);
            c5.AddFeature("quality", FeatureType.TYPE_FEATURE_FLOAT,
                          3.0, 0.2, false, false);

            c1.AddFeature("result", FeatureType.TYPE_FEATURE_FLOAT,
                          1.0, 0, true, false);
            c2.AddFeature("result", FeatureType.TYPE_FEATURE_FLOAT,
                          2.0, 0, true, false);
            c3.AddFeature("result", FeatureType.TYPE_FEATURE_FLOAT,
                          6.0, 0, true, false);
            c4.AddFeature("result", FeatureType.TYPE_FEATURE_FLOAT,
                          8.0, 0, true, false);
            c5.AddFeature("result", FeatureType.TYPE_FEATURE_FLOAT,
                          11.0, 0, true, false);


            IStat s1 = StatFactory.newInstance();

            s1.SetCBRCase(c1);
            s1.SetCaseSimilarity(400.03);
            list.Add(s1);

            IStat s2 = StatFactory.newInstance();

            s2.SetCBRCase(c2);
            s2.SetCaseSimilarity(300.3);
            list.Add(s2);

            IStat s3 = StatFactory.newInstance();

            s3.SetCBRCase(c3);
            s3.SetCaseSimilarity(200.4);
            list.Add(s3);

            IStat s4 = StatFactory.newInstance();

            s4.SetCBRCase(c4);
            s4.SetCaseSimilarity(100.45);
            list.Add(s4);

            IStat s5 = StatFactory.newInstance();

            s5.SetCBRCase(c5);
            s5.SetCaseSimilarity(80.23);
            list.Add(s5);


            //test case 1
            stat1 = StatFactory.newInstance();
            stat1.SetCBRCase(c1);
            stat1.SetCaseSimilarity(111.098);
            //test case 2 for upper bound
            stat2 = StatFactory.newInstance();
            stat2.SetCBRCase(c1);
            stat2.SetCaseSimilarity(50.098);
            //test case 3 for under bound
            stat3 = StatFactory.newInstance();
            stat3.SetCBRCase(c1);
            stat3.SetCaseSimilarity(1110.098);
        }