private List <string> ComputeJointPrefix(List <List <string> > lPlans, Domain d)
        {
            List <string>         lJointPrefix = new List <string>();
            List <List <string> > lPlansSuffix = new List <List <string> >();

            foreach (List <string> lPlan in lPlans)
            {
                lPlansSuffix.Add(FilterReasoningActions(lPlan));
            }
            string sCurrentAction = "";

            while (lPlansSuffix[0].Count > 0)
            {
                sCurrentAction = lPlansSuffix[0][0];
                bool bAllAgree = true;
                for (int i = 1; i < lPlansSuffix.Count; i++)
                {
                    if (lPlansSuffix[i][0] != sCurrentAction)
                    {
                        bAllAgree = false;
                    }
                }
                if (bAllAgree)
                {
                    lJointPrefix.Add(sCurrentAction);
                    foreach (List <string> lPlan in lPlansSuffix)
                    {
                        lPlan.RemoveAt(0);
                    }
                }
                else
                {
                    break;
                }
            }
            //now add all immediate sensing actions
            foreach (List <string> lPlan in lPlansSuffix)
            {
                int iCurrent = 0;
                while (d.IsObservationAction(lPlan[iCurrent]))
                {
                    if (!lJointPrefix.Contains(lPlan[iCurrent]))
                    {
                        lJointPrefix.Add(lPlan[iCurrent]);
                    }
                    iCurrent++;
                }
            }

            return(lJointPrefix);
        }
        private List <string> ComputeVotingPrefix(List <List <string> > lPlans, Domain d)
        {
            List <string>         lJointPrefix = new List <string>();
            List <List <string> > lPlansSuffix = new List <List <string> >();

            foreach (List <string> lPlan in lPlans)
            {
                lPlansSuffix.Add(FilterReasoningActions(lPlan));
            }
            string     sCurrentAction = "";
            SameAction sa             = new SameAction();

            while (lPlansSuffix.Count >= lPlans.Count / 2 && lPlansSuffix[0].Count > 0)
            {
                bool bFoundObservationAction    = false;
                Dictionary <string, int> dVotes = new Dictionary <string, int>(sa);
                foreach (List <string> lPlan in lPlansSuffix)
                {
                    if (lPlan.Count > 0)
                    {
                        while (d.IsObservationAction(lPlan[0]))
                        {
                            if (!lJointPrefix.Contains(lPlan[0]))
                            {
                                lJointPrefix.Add(lPlan[0]);
                            }
                            bFoundObservationAction = true;
                            lPlan.RemoveAt(0);
                        }
                        sCurrentAction = lPlan[0];
                        if (!dVotes.ContainsKey(sCurrentAction))
                        {
                            dVotes[sCurrentAction] = 0;
                        }
                        dVotes[sCurrentAction]++;
                    }
                }
                if (bFoundObservationAction)
                {
                    break;
                }
                string sMaxAction = dVotes.Keys.First();
                foreach (KeyValuePair <string, int> p in dVotes)
                {
                    if (p.Value > dVotes[sMaxAction])
                    {
                        sMaxAction = p.Key;
                    }
                }
                lJointPrefix.Add(sMaxAction);
                List <List <string> > lNewSuffixes = new List <List <string> >();
                foreach (List <string> lPlan in lPlansSuffix)
                {
                    if (lPlan.Count > 0 && sa.Equals(lPlan[0], sMaxAction))
                    {
                        lPlan.RemoveAt(0);
                        lNewSuffixes.Add(lPlan);
                    }
                }
                lPlansSuffix = lNewSuffixes;
            }
            return(lJointPrefix);
        }
        private List <string> ComputeSensingPrefix(List <List <string> > lPlans, Domain d)
        {
            List <string>         lJointPrefix = new List <string>();
            List <List <string> > lPlansSuffix = new List <List <string> >();

            foreach (List <string> lPlan in lPlans)
            {
                lPlansSuffix.Add(FilterReasoningActions(lPlan));
            }
            SameAction sa = new SameAction();

            List <string> lFirstSensingPlan = null, lShortestPlan = null;
            int           iFirstSensingAction = -1;
            int           iAction             = 0;
            int           cPlans = lPlansSuffix.Count;

            for (iAction = 0; cPlans > 0 && lFirstSensingPlan == null; iAction++)
            {
                foreach (List <string> lPlan in lPlansSuffix)
                {
                    if (lPlan.Count == iAction)
                    {
                        if (lShortestPlan == null)
                        {
                            lShortestPlan = lPlan;
                        }
                        cPlans--;
                    }
                    if (iAction < lPlan.Count && d.IsObservationAction(lPlan[iAction]))
                    {
                        iFirstSensingAction = iAction;
                        lFirstSensingPlan   = lPlan;
                    }
                }
            }
            if (lFirstSensingPlan == null)
            {
                lFirstSensingPlan = lShortestPlan;
            }
            if (iFirstSensingAction == -1)
            {
                iFirstSensingAction = lFirstSensingPlan.Count;
            }


            for (iAction = 0; iAction < iFirstSensingAction; iAction++)
            {
                List <List <string> > lNewSuffixes = new List <List <string> >();
                foreach (List <string> lPlan in lPlansSuffix)
                {
                    if (sa.Equals(lPlan[iAction], lFirstSensingPlan[iAction]))
                    {
                        lNewSuffixes.Add(lPlan);
                    }
                }
                lJointPrefix.Add(lFirstSensingPlan[iAction]);
                lPlansSuffix = lNewSuffixes;
            }
            foreach (List <string> lPlan in lPlansSuffix)
            {
                for (iAction = iFirstSensingAction; iAction < lPlan.Count; iAction++)
                {
                    if (d.IsObservationAction(lPlan[iAction]))
                    {
                        if (!lJointPrefix.Contains(lPlan[iAction]))
                        {
                            lJointPrefix.Add(lPlan[iAction]);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(lJointPrefix);
        }