public override bool ConsistentWith(Predicate p)
        {
            if (Name != p.Name)
            {
                return(true); //irrelvant predicate - no contradiction
            }
            if (p is ParametrizedPredicate)
            {
                //TODO
                throw new NotImplementedException();
            }
            GroundedPredicate gp = (GroundedPredicate)p;

            if (((List <Constant>)Constants).Count != ((List <Constant>)gp.Constants).Count)
            {
                return(true);
            }
            for (int i = 0; i < Constants.Count; i++)
            {
                if (!gp.Constants[i].Equals(Constants[i]))
                {
                    return(true);//irrelvant predicate - no contradiction
                }
            }
            return(Negation == p.Negation);
        }
Exemple #2
0
        /**
         * TODO: Not clear what this does. It looks like there's a bug here.
         **/
        private static void ShareGoals(List <Agent> agents)
        {
            bool stop = false;

            while (!stop)
            {
                stop = true;
                string            name        = "";
                GroundedPredicate currentGoal = null;
                foreach (Agent agent in agents)
                {
                    currentGoal = agent.GetGoal();
                    if (currentGoal != null)
                    {
                        stop = false;
                        name = agent.name;
                        break;
                    }
                }
                if (!stop)
                {
                    foreach (Agent agent in agents)
                    {
                        if (!agent.name.Equals(name))
                        {
                            agent.ReceiveGoal(currentGoal);
                        }
                    }
                }
            }
        }
        public override Predicate GenerateKnowGiven(string sTag, bool bKnowWhether)
        {
            GroundedPredicate pKGiven = null;

            if (bKnowWhether)
            {
                pKGiven = new GroundedPredicate("KWGiven" + Name);
            }
            else
            {
                pKGiven = new GroundedPredicate("KGiven" + Name);
            }
            foreach (Constant c in Constants)
            {
                pKGiven.AddConstant(c);
            }
            pKGiven.AddConstant(new Constant(Domain.TAG, sTag));
            if (!bKnowWhether)
            {
                if (Negation)
                {
                    pKGiven.AddConstant(new Constant(Domain.VALUE, Domain.FALSE_VALUE));
                }
                else
                {
                    pKGiven.AddConstant(new Constant(Domain.VALUE, Domain.TRUE_VALUE));
                }
            }
            return(pKGiven);
        }
 public override int Similarity(Predicate p)
 {
     if (Negation != p.Negation)
     {
         //if (Name != p.Name || Negation != p.Negation)
         return(0);
     }
     if (p is GroundedPredicate)
     {
         GroundedPredicate gpGrounded = (GroundedPredicate)p;
         int iSimilarity = 0;
         if (Name == p.Name)
         {
             for (int i = 0; i < Constants.Count; i++)
             {
                 if (Constants[i].Equals(gpGrounded.Constants[i]))
                 {
                     iSimilarity++;
                 }
             }
         }
         else
         {
             foreach (Constant c in Constants)
             {
                 if (gpGrounded.Constants.Contains(c))
                 {
                     iSimilarity++;
                 }
             }
         }
         return(iSimilarity);
     }
     return(0);
 }
        public GroundedPredicate Ground(Dictionary <string, Constant> dBindings)
        {
            GroundedPredicate gp = new GroundedPredicate("K" + Knowledge.Name);

            if (Knowledge is ParametrizedPredicate)
            {
                foreach (Argument a in ((ParametrizedPredicate)Knowledge).Parameters)
                {
                    if (a is Parameter)
                    {
                        if (dBindings.ContainsKey(a.Name))
                        {
                            gp.AddConstant(dBindings[a.Name]);
                        }
                        else
                        {
                            throw new NotImplementedException();
                        }
                    }
                    else
                    {
                        gp.AddConstant((Constant)a);
                    }
                }
            }
            else
            {
                foreach (Constant c in ((GroundedPredicate)Knowledge).Constants)
                {
                    gp.AddConstant(c);
                }
            }
            return(gp);
        }
 public GroundedPredicate(string sName)
     : base(sName)
 {
     //if (sName == Domain.FALSE_PREDICATE)
     //    Debug.WriteLine("Initialized  a false predicate");
     m_gpNegation = null;
     Constants    = new List <Constant>();
 }
 public Block(Block b)
 {
     observePredicate = b.observePredicate;
     effect           = b.effect;
     canGet           = new List <Formula>();
     canGet.AddRange(b.canGet);
     grade = b.grade;
 }
 public Block(GroundedPredicate observePredicate)
 {
     grade  = 0;
     canGet = new List <Formula>();
     this.observePredicate = observePredicate;
     //canGet = new CompoundFormula();
     effect = new List <Action>();
 }
 public override Predicate Negate()
 {
     if (m_gpNegation == null)
     {
         m_gpNegation              = new GroundedPredicate(this);
         m_gpNegation.Negation     = !Negation;
         m_gpNegation.m_gpNegation = this;
     }
     return(m_gpNegation);
 }
Exemple #10
0
 public RegressedPredicate(GroundedPredicate pCurrent, Predicate pNext, int iChoice)
     : base(pCurrent)
 {
     Choice = iChoice;
     if (pNext is RegressedPredicate)
     {
         Next = (RegressedPredicate)pNext;
     }
     else
     {
         Next = null;
     }
 }
Exemple #11
0
        public Predicate PartiallyGround(Dictionary <string, Constant> dBindings)
        {
            GroundedPredicate     gpred = new GroundedPredicate(Name);
            ParametrizedPredicate ppred = new ParametrizedPredicate(Name);

            gpred.Negation = Negation;
            ppred.Negation = Negation;
            bool bAllGrounded = true;

            foreach (Argument a in Parameters)
            {
                if (a is Parameter)
                {
                    if (!dBindings.ContainsKey(a.Name))
                    {
                        ppred.AddParameter(a);
                        bAllGrounded = false;
                    }
                    else
                    {
                        ppred.AddParameter(dBindings[a.Name]);
                        gpred.AddConstant(dBindings[a.Name]);
                    }
                }
                else
                {
                    gpred.AddConstant((Constant)a);
                    ppred.AddParameter(a);
                }
            }
            if (bAllGrounded)
            {
                if (gpred.Name == "=")
                {
                    bool bSame = gpred.Constants[0].Equals(gpred.Constants[1]);
                    if (bSame && !Negation || !bSame && Negation)
                    {
                        return(new GroundedPredicate(Domain.TRUE_PREDICATE));
                    }
                    else
                    {
                        return(new GroundedPredicate(Domain.FALSE_PREDICATE));
                    }
                }
                return(gpred);
            }
            else
            {
                return(ppred);
            }
        }
        public override bool IsTrue(IEnumerable <Predicate> lKnown, bool bContainsNegations)
        {
            if (Predicate.Name == Domain.TRUE_PREDICATE)
            {
                return(true);
            }
            if (Predicate.Name == Domain.FALSE_PREDICATE)
            {
                return(false);
            }
            if (Predicate.Name == "=" && Predicate is GroundedPredicate)
            {
                GroundedPredicate gp = (GroundedPredicate)Predicate;
                bool bIsSame         = gp.Constants[0].Equals(gp.Constants[1]);
                if (gp.Negation)
                {
                    return(!bIsSame);
                }
                return(bIsSame);
            }
            if (lKnown != null)
            {
                if (bContainsNegations)
                {
                    return(lKnown.Contains(Predicate));
                }
                else
                {
                    Predicate pCheck = Predicate;
                    if (Predicate.Negation)
                    {
                        pCheck = Predicate.Negate();
                    }

                    bool bContained = lKnown.Contains(pCheck);
                    if (!bContained && Predicate.Negation)
                    {
                        return(true);
                    }

                    if (bContained && !Predicate.Negation)
                    {
                        return(true);
                    }

                    return(false);
                }
            }
            return(false);
        }
        public override Formula Reduce(IEnumerable <Predicate> lKnown)
        {
            Predicate pReduced = Predicate;

            if (lKnown.Contains(Predicate))
            {
                pReduced = new GroundedPredicate(Domain.TRUE_PREDICATE);
            }
            if (lKnown.Contains(Predicate.Negate()))
            {
                pReduced = new GroundedPredicate(Domain.FALSE_PREDICATE);
            }
            return(new PredicateFormula(pReduced));
        }
        public override Predicate GenerateGiven(string sTag)
        {
            GroundedPredicate pGiven = new GroundedPredicate("Given" + Name);

            foreach (Constant c in Constants)
            {
                pGiven.AddConstant(c);
            }
            pGiven.AddConstant(new Constant(Domain.TAG, sTag));
            if (Negation)
            {
                return(pGiven.Negate());
            }
            return(pGiven);
        }
        private GroundedPredicate ReadGroundedPredicate(CompoundExpression exp, Domain d)
        {
            GroundedPredicate gp = new GroundedPredicate(exp.Type);
            int      iExpression = 0;
            Constant c           = null;
            string   sName       = "";

            for (iExpression = 0; iExpression < exp.SubExpressions.Count; iExpression++)
            {
                sName = exp.SubExpressions[iExpression].ToString();
                c     = d.GetConstant(sName);
                gp.AddConstant(c);
            }
            return(gp);
        }
        private Formula ReadPredicate(CompoundExpression exp, Dictionary <string, string> dParameterNameToType, bool bParametrized, Domain d)
        {
            Predicate p           = null;
            int       iExpression = 0;
            string    sName       = "";

            if (bParametrized)
            {
                p = new ParametrizedPredicate(exp.Type);
            }
            else
            {
                p = new GroundedPredicate(exp.Type);
            }
            for (iExpression = 0; iExpression < exp.SubExpressions.Count; iExpression++)
            {
                sName = exp.SubExpressions[iExpression].ToString();
                if (bParametrized)
                {
                    Argument a = null;
                    if (sName.StartsWith("?"))
                    {
                        a = new Parameter(dParameterNameToType[sName], sName);
                    }
                    else
                    {
                        a = new Constant(d.ConstantNameToType[sName], sName);
                    }
                    ((ParametrizedPredicate)p).AddParameter(a);
                }
                else
                {
                    Constant c = new Constant(d.ConstantNameToType[sName], sName);
                    ((GroundedPredicate)p).AddConstant(c);
                }
            }
            if (bParametrized)
            {
                if (!MatchParametersToPredicateDeclaration((ParametrizedPredicate)p, d))
                {
                    throw new NotImplementedException();
                }
            }

            PredicateFormula vf = new PredicateFormula(p);

            return(vf);
        }
        public override Predicate ToTag()
        {
            GroundedPredicate gpNew = new GroundedPredicate(this);

            if (Negation)
            {
                gpNew.Name = gpNew.Name + "-Remove";
            }
            else
            {
                gpNew.Name = gpNew.Name + "-Add";
            }
            gpNew.Negation = false;

            return(gpNew);
        }
Exemple #18
0
 public void AddPrivatePredicate(GroundedPredicate gp, string name)
 {
     isPublic = false;
     if (EncryptedLandmark[name] == null)
     {
         EncryptedLandmark[name] = new Landmark("Disjunctive", false);
         EncryptedLandmark[name].AddFact(gp, "first_round");
         EncryptedLandmark[name].index = index;
     }
     else
     {
         if (!EncryptedLandmark[name].facts.ContainsKey(gp))
         {
             EncryptedLandmark[name].AddFact(gp, "first_round");
         }
     }
 }
        //for MPSR
        public static Predicate GenerateKNot(Constant cTag1, Constant cTag2)
        {
            GroundedPredicate gp = new GroundedPredicate("KNot");
            int iTag1            = int.Parse(cTag1.Name.Substring(3));
            int iTag2            = int.Parse(cTag2.Name.Substring(3));

            if (iTag1 < iTag2)
            {
                gp.AddConstant(cTag1);
                gp.AddConstant(cTag2);
            }
            else
            {
                gp.AddConstant(cTag2);
                gp.AddConstant(cTag1);
            }
            return(gp);
        }
        private Predicate DisplayPredicate(Predicate p, Agent agent)
        {
            bool negation          = false;
            GroundedPredicate curr = (GroundedPredicate)p;

            if (p.Negation)
            {
                negation = true;
                curr     = (GroundedPredicate)p.Negate();
            }
            Predicate display = agent.ArtificialToPrivate[curr];

            if (negation)
            {
                display = display.Negate();
            }
            return(display);
        }
Exemple #21
0
        public Dictionary <string, Constant> Match(GroundedPredicate pOther, Dictionary <string, Constant> dBindings)
        {
            if (pOther.Name != Name)
            {
                return(null);
            }
            if (pOther.Negation != Negation)
            {
                return(null);
            }
            if (pOther.Constants.Count != m_lParameters.Count)
            {
                return(null);
            }
            int i = 0;
            Dictionary <string, Constant> dNewBindings = new Dictionary <string, Constant>();

            for (i = 0; i < pOther.Constants.Count; i++)
            {
                Argument a = m_lParameters[i];
                if (a is Constant)
                {
                    if (pOther.Constants[i].Name != a.Name)
                    {
                        return(null);
                    }
                }
                else if (a is Parameter)
                {
                    if (dBindings.ContainsKey(a.Name))
                    {
                        if (!pOther.Constants[i].Equals(dBindings[a.Name]))
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        dNewBindings[a.Name] = pOther.Constants[i];
                    }
                }
            }
            return(dNewBindings);
        }
Exemple #22
0
 public void AddPublicPredicate(GroundedPredicate gp)
 {
     foreach (string ag in m_agents)
     {
         if (EncryptedLandmark[ag] == null)
         {
             EncryptedLandmark[ag] = new Landmark("Disjunctive", false);
             EncryptedLandmark[ag].AddFact(gp, "first_round");
             EncryptedLandmark[ag].index = index;
         }
         else
         {
             if (!EncryptedLandmark[ag].facts.ContainsKey(gp))
             {
                 EncryptedLandmark[ag].AddFact(gp, "first_round");
             }
         }
     }
 }
        public void AddPublicFact(GroundedPredicate gp, string s)
        {
            if (facts.Count == 0)
            {
                isPublic = true;
                mix      = false;
            }
            else
            {
                if (!isPublic)
                {
                    mix = true;
                }
            }

            if (!facts.ContainsKey(gp))
            {
                facts.Add(gp, s);
            }
        }
 public override Formula Ground(Dictionary <string, Constant> dBindings)
 {
     if (Predicate is ParametrizedPredicate)
     {
         ParametrizedPredicate ppred = (ParametrizedPredicate)Predicate;
         GroundedPredicate     gpred = ppred.Ground(dBindings);
         return(new PredicateFormula(gpred));
     }
     if (Predicate is KnowPredicate)
     {
         KnowPredicate     kp    = (KnowPredicate)Predicate;
         GroundedPredicate gpred = kp.Ground(dBindings);
         return(new PredicateFormula(gpred));
     }
     if (Predicate is KnowGivenPredicate)
     {
         throw new NotImplementedException();
     }
     return(this);
 }
Exemple #25
0
 public KnowGivenPredicate(GroundedPredicate p, bool bValue, string sTag, bool bKnowWhether)
     : base((bKnowWhether ? "KWGiven" : "KGiven") + p.Name)
 {
     KnowWhether = bKnowWhether;
     Predicate   = p;
     Tag         = sTag;
     Value       = bValue;
     Constants   = new List <Constant>(p.Constants);
     Constants.Add(new Constant(Domain.TAG, Tag));
     if (!bKnowWhether)
     {
         if (Value)
         {
             Constants.Add(new Constant(Domain.VALUE, Domain.TRUE_VALUE));
         }
         else
         {
             Constants.Add(new Constant(Domain.VALUE, Domain.FALSE_VALUE));
         }
     }
 }
 public override bool SameInvariant(Predicate p, Argument aInvariant)
 {
     if (Name != p.Name)
     {
         return(false);
     }
     if (p is GroundedPredicate)
     {
         GroundedPredicate gpGrounded = (GroundedPredicate)p;
         for (int i = 0; i < Constants.Count; i++)
         {
             if (Constants[i].Equals(aInvariant) &&
                 !gpGrounded.Constants[i].Equals(aInvariant))
             {
                 return(false);
             }
         }
         return(true);
     }
     return(false);
 }
        private string GenerateKnowGivenLine(GroundedPredicate gp, string sTag, bool bKnowWhether)
        {
            string sKP = "";

            if (bKnowWhether)
            {
                sKP = "(KWGiven" + gp.Name;
            }
            else
            {
                if (SDRPlanner.Translation == SDRPlanner.Translations.SDR)
                {
                    sKP = "(KGiven" + gp.Name;
                }
                else
                {
                    sKP = "(Given" + gp.Name;
                }
            }
            foreach (Constant c in gp.Constants)
            {
                sKP += " " + c.Name;
            }

            sKP += " " + sTag;

            if (SDRPlanner.Translation == SDRPlanner.Translations.SDR)
            {
                if (gp.Negation)
                {
                    sKP += " " + Domain.FALSE_VALUE;
                }
                else
                {
                    sKP += " " + Domain.TRUE_VALUE;
                }
            }

            return(sKP + ")");
        }
Exemple #28
0
        public virtual GroundedPredicate Ground(Dictionary <string, Constant> dBindings)
        {
            GroundedPredicate gpred = new GroundedPredicate(Name);

            gpred.Negation = Negation;
            foreach (Argument a in Parameters)
            {
                if (a is Parameter)
                {
                    if (!dBindings.ContainsKey(a.Name))
                    {
                        return(null);
                    }
                    gpred.AddConstant(dBindings[a.Name]);
                }
                else
                {
                    gpred.AddConstant((Constant)a);
                }
            }
            return(gpred);
        }
Exemple #29
0
        public static List <string> SolveFactored(List <Domain> lDomains, List <Problem> lProblems, ref List <Agent> m_agents, Domain joinDomain)
        {
            if (Program.highLevelPlanerType != Program.HighLevelPlanerType.ProjectionMafs)
            {
                Program.projectionVersion = Program.ProjectionVersion.NULL;
            }
            Program.Start   = DateTime.Now;
            pdbCreationTime = 0;
            var lGroundedProblems = GroundProblems(lDomains, lProblems);

            Program.internalPlaner = Program.PlanerType.ff_toActions;
            BuildAgents_II buildAgents = new BuildAgents_II(lDomains, lGroundedProblems, lProblems);
            List <Agent>   agents      = buildAgents.ReturnAgents();

            GetPublicPredicates(agents);
            List <string> lPlan = null;

            if (Program.highLevelPlanerType == Program.HighLevelPlanerType.Projection)
            {
                Console.WriteLine("Planning");
                ShareGoals(agents);
                AdvancedLandmarkProjectionPlaner planner = new AdvancedLandmarkProjectionPlaner();
                lPlan = planner.Plan(agents, lDomains, lProblems, joinDomain);
            }
            else
            {
                try
                {
                    Program.StartHighLevelPlanning = DateTime.Now;
                    if (Program.highLevelPlanerType == Program.HighLevelPlanerType.Landmark)
                    {
                        Console.WriteLine("Identifying landmarks");
                        bool stop = false;
                        while (!stop)
                        {
                            stop = true;
                            string            name        = "";
                            GroundedPredicate currentGoal = null;
                            foreach (Agent agent in agents)
                            {
                                currentGoal = agent.GetGoal();
                                if (currentGoal != null)
                                {
                                    stop = false;
                                    name = agent.name;
                                    break;
                                }
                            }
                            if (!stop)
                            {
                                foreach (Agent agent in agents)
                                {
                                    if (!agent.name.Equals(name))
                                    {
                                        agent.ReceiveGoal(currentGoal);
                                    }
                                }
                            }
                        }
                        foreach (Agent agent in agents)
                        {
                            agent.InitMutex();
                        }

                        agents = Distributed_Landmarks_Detection.Landmarks_Detection(agents, false);
                        Planer_I Planner = new Planer_I(agents);
                        Console.WriteLine("Planning");
                        lPlan = Planner.Plan();
                    }
                    else
                    {
                        if (Program.highLevelPlanerType == Program.HighLevelPlanerType.PDB)
                        {
                            DateTime startPdbCreation = DateTime.Now;
                            PdbPlaner.pdb   = new PatternDatabase(lDomains, lProblems, agents, pdbPath);
                            pdbCreationTime = DateTime.Now.Subtract(startPdbCreation).TotalSeconds;
                            foreach (Agent agent in agents)
                            {
                                agent.InitMutex();
                            }
                            Distributed_Landmarks_Detection.Reset(agents);
                            List <Landmark> PublicAndArtificialGoals = FindPublicAndArtificialGoals(agents);

                            PdbPlaner Planner = new PdbPlaner(agents, PublicAndArtificialGoals, PdbPlaner.pdb);
                            Console.WriteLine("Planning");

                            lPlan = Planner.Plan();
                        }
                        else
                        {
                            if (Program.highLevelPlanerType == Program.HighLevelPlanerType.ForwardHsp)
                            {
                                bool stop = false;
                                while (!stop)
                                {
                                    stop = true;
                                    string            name        = "";
                                    GroundedPredicate currentGoal = null;
                                    foreach (Agent agent in agents)
                                    {
                                        currentGoal = agent.GetGoal();
                                        if (currentGoal != null)
                                        {
                                            stop = false;
                                            name = agent.name;
                                            break;
                                        }
                                    }
                                    if (!stop)
                                    {
                                        foreach (Agent agent in agents)
                                        {
                                            if (!agent.name.Equals(name))
                                            {
                                                agent.ReceiveGoal(currentGoal);
                                            }
                                        }
                                    }
                                }
                                foreach (Agent agent in agents)
                                {
                                    agent.InitMutex();
                                }
                                Distributed_Landmarks_Detection.Reset(agents);
                                PlanerHsp Planner = new PlanerHsp(agents);
                                Console.WriteLine("Planning");
                                lPlan = Planner.Plan();
                            }
                            else
                            {
                                if (Program.highLevelPlanerType == Program.HighLevelPlanerType.BackwardHsp)
                                {
                                    bool stop = false;
                                    List <GroundedPredicate> publishPublic     = new List <GroundedPredicate>();
                                    List <GroundedPredicate> nextPublishPublic = new List <GroundedPredicate>();
                                    foreach (Agent a in agents)
                                    {
                                        publishPublic.AddRange(a.InitBackwardHspGraph());
                                    }
                                    bool outFlag = false;
                                    while (!stop)
                                    {
                                        stop    = true;
                                        outFlag = false;
                                        foreach (Agent agent in agents)
                                        {
                                            nextPublishPublic.AddRange(agent.UpdateBackwardHspGraph(publishPublic, out outFlag));
                                            if (outFlag)
                                            {
                                                stop = false;
                                            }
                                        }
                                        publishPublic = nextPublishPublic;
                                    }

                                    foreach (Agent agent in agents)
                                    {
                                        agent.InitMutex();
                                    }
                                    Distributed_Landmarks_Detection.Reset(agents);
                                    // agents = Distributed_Landmarks_Detection.Landmarks_Detection(agents);
                                    PlanerHspII Planner = new PlanerHspII(agents);
                                    Console.WriteLine("Planning");
                                    lPlan = Planner.Plan();
                                }
                                else
                                {
                                    if (Program.highLevelPlanerType == Program.HighLevelPlanerType.LandmarkAndHsp)
                                    {
                                        bool stop = false;
                                        while (!stop)
                                        {
                                            stop = true;
                                            string            name        = "";
                                            GroundedPredicate currentGoal = null;
                                            foreach (Agent agent in agents)
                                            {
                                                currentGoal = agent.GetGoal();
                                                if (currentGoal != null)
                                                {
                                                    stop = false;
                                                    name = agent.name;
                                                    break;
                                                }
                                            }
                                            if (!stop)
                                            {
                                                foreach (Agent agent in agents)
                                                {
                                                    if (!agent.name.Equals(name))
                                                    {
                                                        agent.ReceiveGoal(currentGoal);
                                                    }
                                                }
                                            }
                                        }
                                        foreach (Agent agent in agents)
                                        {
                                            agent.InitMutex();
                                        }

                                        agents = Distributed_Landmarks_Detection.Landmarks_Detection(agents, false);

                                        PlanerHspAndLandmarks Planner = new PlanerHspAndLandmarks(agents);

                                        Console.WriteLine("Planning..");

                                        lPlan = Planner.Plan();
                                    }
                                    else
                                    {
                                        if (Program.highLevelPlanerType == Program.HighLevelPlanerType.WeightedLandmarkAndHsp)
                                        {
                                            bool stop = false;
                                            while (!stop)
                                            {
                                                stop = true;
                                                string            name        = "";
                                                GroundedPredicate currentGoal = null;
                                                foreach (Agent agent in agents)
                                                {
                                                    currentGoal = agent.GetGoal();
                                                    if (currentGoal != null)
                                                    {
                                                        stop = false;
                                                        name = agent.name;
                                                        break;
                                                    }
                                                }
                                                if (!stop)
                                                {
                                                    foreach (Agent agent in agents)
                                                    {
                                                        if (!agent.name.Equals(name))
                                                        {
                                                            agent.ReceiveGoal(currentGoal);
                                                        }
                                                    }
                                                }
                                            }
                                            foreach (Agent agent in agents)
                                            {
                                                agent.InitMutex();
                                            }
                                            agents = Distributed_Landmarks_Detection.Landmarks_Detection(agents, false);
                                            PlanerWeightedLandmarkAndHsp Planner = new PlanerWeightedLandmarkAndHsp(agents);
                                            Console.WriteLine("Planning");
                                            lPlan = Planner.Plan();
                                        }
                                        else
                                        {
                                            if (Program.highLevelPlanerType == Program.HighLevelPlanerType.SophisticatedProjection)
                                            {
                                                bool stop = false;
                                                while (!stop)
                                                {
                                                    stop = true;
                                                    string            name        = "";
                                                    GroundedPredicate currentGoal = null;
                                                    foreach (Agent agent in agents)
                                                    {
                                                        currentGoal = agent.GetGoal();
                                                        if (currentGoal != null)
                                                        {
                                                            stop = false;
                                                            name = agent.name;
                                                            break;
                                                        }
                                                    }
                                                    if (!stop)
                                                    {
                                                        foreach (Agent agent in agents)
                                                        {
                                                            if (!agent.name.Equals(name))
                                                            {
                                                                agent.ReceiveGoal(currentGoal);
                                                            }
                                                        }
                                                    }
                                                }
                                                foreach (Agent agent in agents)
                                                {
                                                    agent.InitMutex();
                                                }
                                                //  agents = AdvancedLandmarkProjectionAgents.CreateProjAgents(agents, lDomains, lProblems);

                                                agents = Distributed_Landmarks_Detection.Landmarks_Detection(agents, false);
                                                PlanerHspAndLandmarks Planner = new PlanerHspAndLandmarks(agents);
                                                Console.WriteLine("Planning");
                                                lPlan = Planner.Plan();
                                            }
                                            else
                                            {
                                                if (Program.highLevelPlanerType == Program.HighLevelPlanerType.PDBMafs)
                                                {
                                                    MapsVertex.pdb = new PatternDatabase(lDomains, lProblems, agents, pdbPath);
                                                    bool stop = false;
                                                    while (!stop)
                                                    {
                                                        stop = true;
                                                        string            name        = "";
                                                        GroundedPredicate currentGoal = null;
                                                        foreach (Agent agent in agents)
                                                        {
                                                            currentGoal = agent.GetGoal();
                                                            if (currentGoal != null)
                                                            {
                                                                stop = false;
                                                                name = agent.name;
                                                                break;
                                                            }
                                                        }
                                                        if (!stop)
                                                        {
                                                            foreach (Agent agent in agents)
                                                            {
                                                                if (!agent.name.Equals(name))
                                                                {
                                                                    agent.ReceiveGoal(currentGoal);
                                                                }
                                                            }
                                                        }
                                                    }
                                                    foreach (Agent agent in agents)
                                                    {
                                                        agent.InitMutex();
                                                    }


                                                    Console.WriteLine("Planning");

                                                    MapsPlanner Planner = new MapsPlanner(agents, lDomains, lProblems);

                                                    Program.StartGrounding = DateTime.Now;
                                                    lPlan = Planner.Plan();
                                                }
                                                else
                                                if (Program.highLevelPlanerType == Program.HighLevelPlanerType.MafsLandmark)
                                                {
                                                    bool stop = false;
                                                    while (!stop)
                                                    {
                                                        stop = true;
                                                        string            name        = "";
                                                        GroundedPredicate currentGoal = null;
                                                        foreach (Agent agent in agents)
                                                        {
                                                            currentGoal = agent.GetGoal();
                                                            if (currentGoal != null)
                                                            {
                                                                stop = false;
                                                                name = agent.name;
                                                                break;
                                                            }
                                                        }
                                                        if (!stop)
                                                        {
                                                            foreach (Agent agent in agents)
                                                            {
                                                                if (!agent.name.Equals(name))
                                                                {
                                                                    agent.ReceiveGoal(currentGoal);
                                                                }
                                                            }
                                                        }
                                                    }
                                                    foreach (Agent agent in agents)
                                                    {
                                                        agent.InitMutex();
                                                    }

                                                    agents = Distributed_Landmarks_Detection.Landmarks_Detection(agents, true);

                                                    Console.WriteLine("Planning");

                                                    MapsPlanner Planner = new MapsPlanner(agents, lDomains, lProblems);

                                                    Program.StartGrounding = DateTime.Now;
                                                    lPlan = Planner.Plan();
                                                }
                                                else
                                                if (Program.highLevelPlanerType == Program.HighLevelPlanerType.Mafsff)
                                                {
                                                    bool stop = false;
                                                    while (!stop)
                                                    {
                                                        stop = true;
                                                        string            name        = "";
                                                        GroundedPredicate currentGoal = null;
                                                        foreach (Agent agent in agents)
                                                        {
                                                            currentGoal = agent.GetGoal();
                                                            if (currentGoal != null)
                                                            {
                                                                stop = false;
                                                                name = agent.name;
                                                                break;
                                                            }
                                                        }
                                                        if (!stop)
                                                        {
                                                            foreach (Agent agent in agents)
                                                            {
                                                                if (!agent.name.Equals(name))
                                                                {
                                                                    agent.ReceiveGoal(currentGoal);
                                                                }
                                                            }
                                                        }
                                                    }
                                                    foreach (Agent agent in agents)
                                                    {
                                                        agent.InitMutex();
                                                    }

                                                    agents = Distributed_Landmarks_Detection.Landmarks_Detection(agents, true);

                                                    Console.WriteLine("Planning");

                                                    MapsPlanner Planner = new MapsPlanner(agents, lDomains, lProblems);

                                                    Program.StartGrounding = DateTime.Now;
                                                    lPlan = Planner.PreferableFFPlan();
                                                }
                                                else
                                                {
                                                    if (Program.highLevelPlanerType == Program.HighLevelPlanerType.ProjectionMafs)
                                                    {
                                                        bool stop = false;
                                                        while (!stop)
                                                        {
                                                            stop = true;
                                                            string            name        = "";
                                                            GroundedPredicate currentGoal = null;
                                                            foreach (Agent agent in agents)
                                                            {
                                                                currentGoal = agent.GetGoal();
                                                                if (currentGoal != null)
                                                                {
                                                                    stop = false;
                                                                    name = agent.name;
                                                                    break;
                                                                }
                                                            }
                                                            if (!stop)
                                                            {
                                                                foreach (Agent agent in agents)
                                                                {
                                                                    if (!agent.name.Equals(name))
                                                                    {
                                                                        agent.ReceiveGoal(currentGoal);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        foreach (Agent agent in agents)
                                                        {
                                                            agent.InitMutex();
                                                        }

                                                        agents = Distributed_Landmarks_Detection.Landmarks_Detection(agents, true);

                                                        Console.WriteLine("Planning");

                                                        MapsPlanner Planner = new MapsPlanner(agents, lDomains, lProblems);

                                                        Program.StartGrounding = DateTime.Now;

                                                        lPlan = Planner.PreferablePlan();
                                                    }
                                                    else
                                                    if (Program.highLevelPlanerType == Program.HighLevelPlanerType.DistrebutedProjectionMafs)
                                                    {
                                                        bool stop = false;
                                                        while (!stop)
                                                        {
                                                            stop = true;
                                                            string            name        = "";
                                                            GroundedPredicate currentGoal = null;
                                                            foreach (Agent agent in agents)
                                                            {
                                                                currentGoal = agent.GetGoal();
                                                                if (currentGoal != null)
                                                                {
                                                                    stop = false;
                                                                    name = agent.name;
                                                                    break;
                                                                }
                                                            }
                                                            if (!stop)
                                                            {
                                                                foreach (Agent agent in agents)
                                                                {
                                                                    if (!agent.name.Equals(name))
                                                                    {
                                                                        agent.ReceiveGoal(currentGoal);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                        foreach (Agent agent in agents)
                                                        {
                                                            agent.InitMutex();
                                                        }

                                                        agents = Distributed_Landmarks_Detection.Landmarks_Detection(agents, true);

                                                        Console.WriteLine("Planning");

                                                        MapsPlanner Planner = new MapsPlanner(agents, lDomains, lProblems);

                                                        Program.StartGrounding = DateTime.Now;
                                                        lPlan = Planner.DistrebutedPreferablePlan();
                                                    }
                                                    else
                                                    {
                                                        Console.WriteLine("highLevelPlanerType did not selected");
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    RunUtils.KillPlanners();
                    return(null);
                }
            }
            Program.End = DateTime.Now;
            RunUtils.KillPlanners();
            m_agents = agents;
            return(lPlan);
        }
 public void AddFact(GroundedPredicate gp, string s)
 {
     facts[gp] = s;
 }