Beispiel #1
0
        public override void EnterObjectDeclaration(PlanningParser.ObjectDeclarationContext context)
        {
            var listNameContext = context.listName();

            Problem.BuildConstantTypeMap(listNameContext);
            Problem.BuildGroundPredicate();
            Problem.BuildGroundAction();
        }
Beispiel #2
0
        private void BuildConstTypeMap(PlanningParser.ObjectDeclarationContext context)
        {
            _constTypeDict     = new StringDictionary();
            _typeConstListDict = new Dictionary <string, IList <string> >();

            _constTypeDict.Add(Agent1Id, PlanningType.AgentType.Name);
            _constTypeDict.Add(Agent2Id, PlanningType.AgentType.Name);
            _typeConstListDict.Add(PlanningType.AgentType.Name, new List <string> {
                Agent1Id, Agent2Id
            });

            foreach (var pair in _typeDict)
            {
                if (pair.Value is PlanningNumericType)
                {
                    PlanningNumericType type      = pair.Value as PlanningNumericType;
                    List <string>       constList = new List <string>(type.Max - type.Min + 1);
                    for (int i = type.Min; i <= type.Max; i++)
                    {
                        constList.Add(i.ToString());
                    }
                    _typeConstListDict.Add(type.Name, constList);
                }
            }

            if (context != null)
            {
                var listNameContext = context.listName();
                do
                {
                    string type = listNameContext.type() != null
                        ? listNameContext.type().GetText()
                        : PlanningType.ObjectType.Name;

                    IList <string> constList;

                    if (_typeConstListDict.ContainsKey(type))
                    {
                        constList = _typeConstListDict[type];
                    }
                    else
                    {
                        constList = new List <string>(listNameContext.NAME().Count);
                        _typeConstListDict.Add(type, constList);
                    }

                    foreach (var nameNode in listNameContext.NAME())
                    {
                        _constTypeDict.Add(nameNode.GetText(), type);
                        constList.Add(nameNode.GetText());
                    }

                    listNameContext = listNameContext.listName();
                } while (listNameContext != null);
            }
        }