/// <summary> /// Constructs the constant manager. /// </summary> /// <param name="inputData">Input data.</param> /// <param name="idManager">ID manager.</param> public ConstantsManager(InputData.PDDLInputData inputData, IdManager idManager) { IdManager = idManager; TypeHierarchy = new TypeHierarchy(inputData, idManager); ConstantDefinitionTypes = new Dictionary <int, ICollection <int> >(); foreach (var type in TypeHierarchy) { TypeId typeId = type.Key; Add(typeId, new ConstantIdCollection()); } System.Action <string, List <string> > processConstantItem = (constantName, typeNames) => { HashSet <TypeId> typeIDs = new HashSet <int>(); ConstantId constantId = idManager.Constants.GetId(constantName); foreach (string type in typeNames) { TypeId typeId = idManager.Types.GetId(type); this[typeId].Add(constantId); typeIDs.Add(typeId); } ConstantDefinitionTypes.Add(constantId, typeIDs); }; foreach (var constant in inputData.Domain.Constants) { processConstantItem(constant.ConstantName, constant.TypeNames); } foreach (var obj in inputData.Problem.Objects) { processConstantItem(obj.ObjectName, obj.TypeNames); } System.Action <TypeId, TypeId> fillConstantsFromChildType = null; fillConstantsFromChildType = (typeId, outputTypeId) => { this[outputTypeId].UnionWith(this[typeId]); TypeIdCollection childrenTypes = TypeHierarchy[typeId]; foreach (TypeId childTypeId in childrenTypes) { fillConstantsFromChildType(childTypeId, outputTypeId); } }; foreach (TypeId typeId in Keys) { fillConstantsFromChildType(typeId, typeId); } }
/// <summary> /// Gets the collection of direct children types for the specified type. /// </summary> /// <param name="typeId">Type ID.</param> /// <returns>Direct children types of the given type.</returns> public IEnumerable <TypeId> GetChildrenTypes(TypeId typeId) { return(TypeHierarchy.GetChildrenTypes(typeId)); }