예제 #1
0
        private void BuildTypeDict(PlanningParser.TypeDefineContext context)
        {
            _typeDict = new Dictionary <string, PlanningType>();

            if (context != null)
            {
                _typeDict.Add(PlanningType.ObjectType.Name, PlanningType.ObjectType);
                _typeDict.Add(PlanningType.AgentType.Name, PlanningType.AgentType);

                foreach (var typeContext in context.typeDeclaration())
                {
                    PlanningType type;
                    string       name = typeContext.NAME().GetText();
                    if (typeContext.LB() == null)
                    {
                        type = new PlanningType {
                            Name = name
                        };
                    }
                    else
                    {
                        int min = GetValue(typeContext.constTerm(0));
                        int max = GetValue(typeContext.constTerm(1));
                        type = new PlanningNumericType {
                            Name = name, Min = min, Max = max
                        };
                    }

                    _typeDict.Add(name, type);
                }
            }
        }
예제 #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);
            }
        }