public override RepairActionsSet ComputePossibleAcions(SystemState state)
        {
            int k = K;

            if (state == null || state.Diagnoses == null || state.Diagnoses.Count == 0)
            {
                return(null);
            }
            RepairActionsSet ans;

            if (RATrie)
            {
                ans = new RepairActionsTrie();
            }
            else
            {
                ans = new RepairActionsHashSet();
            }

            List <Diagnosis> diagnoses     = state.Diagnoses.Diagnoses.ToList();
            double           diagProb      = 0;
            bool             cropDiagnoses = false;

            if (diagnoses.Count > 2000)
            {
                cropDiagnoses = true;
            }
            if (diagnoses.Count < k) //need to correct this!!
            {
                k = diagnoses.Count;
            }

            int             maxIndex        = diagnoses.Count - 1;
            SortedSet <int> currPermutation = new SortedSet <int>();

            for (int size = 1; size <= k; size++)
            {
                if (cropDiagnoses && diagProb > 0.999)
                {
                    break;
                }
                if (currPermutation == null)
                {
                    currPermutation = new SortedSet <int>();
                }
                for (int i = 0; i < size; i++)  //computing first permutation
                {
                    currPermutation.Add(i);
                }

                while (currPermutation != null && currPermutation.Count != 0)
                {
                    if (cropDiagnoses && diagProb > 0.999)
                    {
                        break;
                    }
                    SortedSet <Comp> newAction = new SortedSet <Comp>(new Comp.CompComparer());
                    foreach (int index in currPermutation)
                    {
                        Diagnosis diag = diagnoses[index];
                        diagProb += diag.Probability / state.Diagnoses.SetProbability;
                        foreach (Comp c in diag.Comps)
                        {
                            if (!newAction.Contains(c))
                            {
                                newAction.Add(c);
                            }
                        }
                    }
                    ans.AddAction(newAction);
                    currPermutation = nextPermutation(currPermutation, maxIndex);
                }
            }
            return(ans);
        }
Beispiel #2
0
        public override RepairActionsSet ComputePossibleAcions(SystemState state)
        {
            int k = K;

            if (state == null || state.Diagnoses == null || state.Diagnoses.Count == 0)
            {
                return(null);
            }
            List <List <Comp> > ans   = new List <List <Comp> >();
            List <Comp>         comps = new List <Comp>(); // hash set?

            foreach (Diagnosis diag in state.Diagnoses.Diagnoses)
            {
                foreach (Comp c in diag.Comps)
                {
                    if (!comps.Contains(c))
                    {
                        comps.Add(c);
                        List <Comp> list = new List <Comp>();
                        list.Add(c);
                        ans.Add(list);
                    }
                }
            }
            while (k > 1)
            {
                List <List <Comp> > temp = new List <List <Comp> >();
                foreach (List <Comp> list in ans)
                {
                    foreach (Comp c in comps)
                    {
                        if (!list.Contains(c))
                        {
                            List <Comp> newList = new List <Comp>(list);
                            newList.Add(c);
                            temp.Add(newList);
                        }
                    }
                }
                ans.AddRange(temp);
                k--;
            }
            RepairActionsSet actions;

            if (k == 1)
            {
                actions = new RepairActionsHashSet();
            }
            else
            {
                actions = new RepairActionsTrie();
            }
            foreach (List <Comp> list in ans)
            {
                SortedSet <Comp> action = new SortedSet <Comp>(new Comp.CompComparer());
                foreach (Comp c in list)
                {
                    action.Add(c);
                }
                actions.AddAction(action);
            }
            return(actions);
        }