UNPKG

pddl-workspace

Version:
65 lines 2.76 kB
"use strict"; /* -------------------------------------------------------------------------------------------- * Copyright (c) Jan Dolejsi. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. * ------------------------------------------------------------------------------------------ */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Grounder = void 0; const language_1 = require("./language"); const typeInheritance_1 = require("./typeInheritance"); class Grounder { constructor(domain, problem) { this.domain = domain; this.problem = problem; this.typeObjects = this.domain.getConstants().merge(this.problem.getObjectsTypeMap()); } getObjectsForType(typeName) { return (0, typeInheritance_1.getObjectsInheritingFrom)(this.typeObjects, typeName, this.domain.getTypeInheritance()); } getObjects(typeNames) { return typeNames.map(typeName => this.getObjectsForType(typeName)); } getObjectPermutations(typeNames) { const objects = this.getObjects(typeNames); if (typeNames.length === 0) { return []; } else if (typeNames.length === 1) { return objects[0].map(name => [name]); } else if (typeNames.length === 2) { const objectPermutations = []; for (let index0 = 0; index0 < objects[0].length; index0++) { for (let index1 = 0; index1 < objects[1].length; index1++) { objectPermutations.push([objects[0][index0], objects[1][index1]]); } } return objectPermutations; } else { throw new Error("Not implemented for 3-ary+ relationships."); } } ground(variable) { if (variable.parameters.length === 0) { return [variable]; } else if (variable.parameters.length <= 2) { const types = variable.parameters.map(p => p.type); const objectPermutations = this.getObjectPermutations(types); return objectPermutations.map(objectVector => new language_1.Variable(variable.declaredName, this.createObjectInstances(types, objectVector))); } else { //todo: handle variables with multiple parameters return []; } } createObjectInstances(types, objectVector) { if (types.length !== objectVector.length) { throw new Error('List of types and list objects have different sizes.'); } return types.map((type, index) => new language_1.ObjectInstance(objectVector[index], type)); } } exports.Grounder = Grounder; //# sourceMappingURL=Grounder.js.map