示例#1
0
        public void testGetCBRContext()
        {
            CBRContextManager.Load("engine1", path);
            ICBRContext ctx = CBRContextManager.GetCBRContext("engine1");               //path);

            System.Console.WriteLine(ctx.GetCaseBase().ToString());
            System.Console.WriteLine(ctx.GetCaseBase().GetEnv());

            System.Console.WriteLine(ctx.GetCaseBaseInput().ToString());

            System.Console.WriteLine(ctx.GetCaseBaseInputType().ToString());

            System.Console.WriteLine(ctx.GetCaseRestoreMethod().ToString());
            System.Console.WriteLine(ctx.GetCaseRestoreMethod().GetEnv());

            System.Console.WriteLine(ctx.GetCaseRetrievalMethod().ToString());
            System.Console.WriteLine(ctx.GetCaseRetrievalMethod().GetEnv());

            System.Console.WriteLine(ctx.GetCaseReuseMethod().ToString());
            System.Console.WriteLine(ctx.GetCaseReuseMethod().GetEnv());

            System.Console.WriteLine(ctx.GetCaseReuseStrategy().ToString());
            System.Console.WriteLine(ctx.GetCaseReuseStrategy().GetEnv());

            System.Console.WriteLine(ctx.GetSimilarity().ToString());
            System.Console.WriteLine(ctx.GetSimilarity().GetEnv());

            System.Console.WriteLine(ctx.GetSimilarityThrehold().ToString());
        }
        /// <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);
        }
示例#3
0
        public bool Startup()
        {
            if (_env == null ||
                CBRContextManager.GetCBRContext(_name) == null)
            {
                System.Console.WriteLine("environment is not set or context is null");
                return(false);
            }

            _ctx = CBRContextManager.GetCBRContext(_name);
            if (_problem == null)
            {
                System.Console.WriteLine("problem is not set");
                return(false);
            }
            _ctx.SetCurrentCase(_problem);
            #region only for test
            if (Version.DEBUG)
            {
                System.Console.WriteLine("=====context detail=====");
                System.Console.WriteLine("Reasoning Engine startup successfully!");
                System.Console.WriteLine("problem case is:");
                for (int i = 0; i < _problem.GetFeatures().Count; i++)
                {
                    Feature f = (Feature)_problem.GetFeatures()[i];
                    System.Console.WriteLine("\t" + f.GetFeatureName() + ":" + f.GetFeatureValue());
                }
                System.Console.WriteLine("context is:");
                System.Console.WriteLine("case base\t" + _ctx.GetCaseBase().ToString());
                System.Console.WriteLine("case base input\t" + _ctx.GetCaseBaseInput().ToString());
                System.Console.WriteLine("case base input type\t" + _ctx.GetCaseBaseInputType().ToString());
                System.Console.WriteLine("case base url\t" + _ctx.GetCaseBaseURL().ToString());
                System.Console.WriteLine("case restore method\t" + _ctx.GetCaseRestoreMethod().ToString());
                System.Console.WriteLine("case retrieval method\t" + _ctx.GetCaseRetrievalMethod().ToString());
                System.Console.WriteLine("case reuse method\t" + _ctx.GetCaseReuseMethod().ToString());
                System.Console.WriteLine("case reuse strategy\t" + _ctx.GetCaseReuseStrategy().ToString());
                System.Console.WriteLine("case revise method\t" + _ctx.GetCaseReviseMethod().ToString());
                System.Console.WriteLine("current case\t" + _ctx.GetCurrentCase().ToString());
                System.Console.WriteLine("similarity\t" + _ctx.GetSimilarity().ToString());
                System.Console.WriteLine("similarity threhold\t" + _ctx.GetSimilarityThrehold().ToString());
                System.Console.WriteLine("=====end of context detail=====");
            }
            #endregion
            return(true);
        }