UNPKG

pddl-workspace

Version:
125 lines 4.04 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.Happening = exports.HappeningsInfo = exports.HappeningType = void 0; const FileInfo_1 = require("./FileInfo"); const PddlSyntaxTree_1 = require("./parser/PddlSyntaxTree"); const language_1 = require("./language"); var HappeningType; (function (HappeningType) { /** Action start. */ HappeningType[HappeningType["START"] = 0] = "START"; /** Action end */ HappeningType[HappeningType["END"] = 1] = "END"; /** Instantaneous (non-durative) action */ HappeningType[HappeningType["INSTANTANEOUS"] = 2] = "INSTANTANEOUS"; /** Timed-action e.g. time-initial literal/fluent. */ HappeningType[HappeningType["TIMED"] = 3] = "TIMED"; })(HappeningType || (exports.HappeningType = HappeningType = {})); /** * Plan happenings file. */ class HappeningsInfo extends FileInfo_1.FileInfo { constructor(fileUri, version, problemName, domainName, text, positionResolver) { super(fileUri, version, problemName, PddlSyntaxTree_1.PddlSyntaxTree.EMPTY, positionResolver); this.problemName = problemName; this.domainName = domainName; this.happenings = []; this.setText(text); } getLanguage() { return language_1.PddlLanguage.HAPPENINGS; } setHappenings(happenings) { this.happenings = happenings; } getHappenings() { return this.happenings; } isHappenings() { return true; } } exports.HappeningsInfo = HappeningsInfo; /** * Single plan happening e.g. a thing that happens at a given time. */ class Happening { /** * Constructs happening instance. * @param time happening time * @param type happening type * @param fullActionName action name including parameter names * @param counter same happening counter * @param lineIndex line index in the file */ constructor(time, type, fullActionName, counter, lineIndex) { this.time = time; this.type = type; this.fullActionName = fullActionName; this.counter = counter; this.lineIndex = lineIndex; const nameFragments = fullActionName.split(' '); this.actionName = nameFragments[0]; this.objects = nameFragments.slice(1); } /** * Happening time. */ getTime() { return this.time; } /** * Happening type: start/end/instantaneous/til/tif */ getType() { return this.type; } /** * Action name without parameters. */ getAction() { return this.actionName; } /** * Action name with parameters. */ getFullActionName() { return this.fullActionName; } /** * Counter for the equivalent actions within the same plan. */ getCounter() { return this.counter; } /** * Returns true if this happening belongs to the other happening. * It is decided by comparing the full action name and the counter. */ belongsTo(other) { if (other === null || other === undefined) { return false; } return this.fullActionName === other.fullActionName && this.counter === other.counter; } toString() { return `${this.time}: ${this.toHappeningType(this.type)} (${this.fullActionName}) #${this.counter}`; } toHappeningType(type) { switch (type) { case HappeningType.START: return 'start '; case HappeningType.END: return 'end '; default: return ''; } } } exports.Happening = Happening; //# sourceMappingURL=HappeningsInfo.js.map