示例#1
0
        public void TestComapreSimpleDateStructureAndCompSetTree()
        {
            const int numOfSets   = 10000;
            var       rand        = new Random();
            var       diagnosises = new List <Diagnosis>();
            var       id          = 1;

            for (var j = 0; j < numOfSets; j++)
            {
                var numOfGates = rand.Next(1, 100);
                var diagnosis  = new Diagnosis();
                for (var i = 0; i < numOfGates; i++)
                {
                    Gate gate = new MultipleInputComponent(id, Gate.Type.and);
                    diagnosis.AddCompToDiagnosis(gate);
                    id++;
                }
                diagnosises.Add(diagnosis);
            }

            var diagnosiSetsDataStructure = new SetsDataStructure("Diagnosis");
            var diagnosisesTree           = new CompSetTree.CompSetTree();

            var sw = new Stopwatch();

            sw.Start();
            foreach (var diagnosise in diagnosises)
            {
                diagnosiSetsDataStructure.AddSet(diagnosise.TheDiagnosis);
            }
            sw.Stop();
            var timeSpan1 = sw.Elapsed; sw.Start();

            sw.Reset();
            sw.Start();
            foreach (var diagnosise in diagnosises)
            {
                diagnosisesTree.AddSet(diagnosise.TheDiagnosis);
            }
            sw.Stop();
            var timeSpan2 = sw.Elapsed; sw.Start();

            sw.Reset();
            var count1 = diagnosiSetsDataStructure.GetCompSets().Count;
            var count2 = diagnosisesTree.GetAllCompsSets().Count;

            Debug.WriteLine("Simple Data Structure Time: " + timeSpan1 + ", Comp Tree Time: " + timeSpan2);
            Assert.AreEqual(count1, count2);
            Assert.IsTrue(timeSpan2 < timeSpan1);
        }
示例#2
0
        public PhysioCaseInstance ParseCase(string fileName)
        {
            char[] delrow = new char[1];
            delrow[0] = ',';
            int progress = 0;

            PhysioCaseInstance ans = new PhysioCaseInstance();

            //extract case number from fileName
            string caseNumber = fileName.Substring(fileName.LastIndexOf('_') + 1);

            caseNumber = caseNumber.Substring(0, caseNumber.IndexOf(".txt"));
            int num;

            if (Int32.TryParse(caseNumber, out num))
            {
                ans.Id = num;
            }

            FileStream   fs     = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            StreamReader reader = new StreamReader(fs);



            while (!reader.EndOfStream && progress < 3)
            {
                string line = reader.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                //read real
                if (progress == 0)
                {
                    ans.RealDiagnosis = new Diagnosis();
                    List <string> realDiagComps = line.Split(delrow, StringSplitOptions.RemoveEmptyEntries).ToList();
                    foreach (string c in realDiagComps)
                    {
                        PhysioComp comp = new PhysioComp(c);
                        ans.RealDiagnosis.AddCompToDiagnosis(comp);
                    }
                    progress++;
                    ans.RealDiagCardinality = ans.RealDiagnosis.Diag.Count;
                }
                //read obs
                else if (progress == 1)
                {
                    ans.Observation = new List <PhysioComp>();
                    List <string> obs = line.Split(delrow, StringSplitOptions.RemoveEmptyEntries).ToList();
                    foreach (string c in obs)
                    {
                        PhysioComp comp = new PhysioComp(c);
                        ans.Observation.Add(comp);
                    }
                    progress++;
                }
                //read diagnoses
                else if (progress == 2)
                {
                    ans.Diagnoses = new DiagnosisSet();
                    do
                    {
                        Diagnosis     diag      = new Diagnosis();
                        List <string> diagComps = line.Split(delrow, StringSplitOptions.RemoveEmptyEntries).ToList();
                        foreach (string c in diagComps)
                        {
                            PhysioComp comp = new PhysioComp(c);
                            diag.AddCompToDiagnosis(comp);
                        }
                        if (diag.Diag.Count > 0)
                        {
                            ans.Diagnoses.AddDiagnosis(diag);
                        }
                        if (reader.EndOfStream)
                        {
                            break;
                        }
                        line = reader.ReadLine();
                    }while (!string.IsNullOrEmpty(line));
                    progress++;
                }
            }

            if (progress > 2 && ans.ValidCaseInstance())
            {
                int maxCard = ans.RealDiagCardinality;
                int minCard = ans.RealDiagCardinality;
                foreach (Diagnosis diag in ans.Diagnoses.Diagnoses)
                {
                    int card = diag.Diag.Count;
                    if (card > maxCard)
                    {
                        maxCard = card;
                    }
                    if (card < minCard)
                    {
                        minCard = card;
                    }
                }
                ans.MaxCardinality = maxCard;
                ans.MinCardinality = minCard;
                return(ans);
            }
            return(null);
        }