pddl-workspace
Version:
101 lines • 4.19 kB
JavaScript
"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.PlanStepCommitment = exports.PlanStep = void 0;
const HappeningsInfo_1 = require("./HappeningsInfo");
class PlanStep {
constructor(time, fullActionName, isDurative, duration, lineIndex, commitment, iterations) {
this.time = time;
this.fullActionName = fullActionName;
this.isDurative = isDurative;
this.duration = duration;
this.lineIndex = lineIndex;
this.commitment = commitment;
this.iterations = iterations;
const nameFragments = fullActionName.split(' ');
this.actionName = nameFragments[0];
this.objects = nameFragments.slice(1);
}
static clone(planStep) {
return new PlanStep(planStep.time, planStep.fullActionName, planStep.isDurative, planStep.duration, planStep.lineIndex, planStep.commitment, planStep.iterations);
}
getActionName() {
return this.actionName;
}
getFullActionName() {
return this.fullActionName;
}
getObjects() {
return this.objects;
}
getStartTime() {
return this.time;
}
getEndTime() {
var _a;
return this.isDurative ? this.time + ((_a = this.duration) !== null && _a !== void 0 ? _a : Number.NaN) : this.time;
}
/**
* @returns end time that makes this plan step effectively durative
*/
getEffectiveEndTime() {
var _a;
return this.time + ((_a = this.duration) !== null && _a !== void 0 ? _a : Number.NaN);
}
getDuration() {
return this.duration;
}
getIterations() {
var _a;
return (_a = this.iterations) !== null && _a !== void 0 ? _a : 1;
}
equals(other, epsilon) {
if (this.isDurative) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
if (!other.isDurative || !PlanStep.equalsWithin(this.duration, other.duration, epsilon)) {
return false;
}
}
return PlanStep.equalsWithin(this.time, other.time, epsilon)
&& this.fullActionName.toLowerCase() === other.fullActionName.toLowerCase();
}
static equalsWithin(a, b, epsilon) {
return Math.abs(a - b) <= 1.1 * epsilon;
}
toPddl() {
var _a;
let output = "";
if (this.time !== null && this.time !== undefined) {
output += `${this.time.toFixed(5)}: `;
}
output += `(${this.fullActionName})`;
if (this.isDurative) {
output += ` [${(_a = this.duration) === null || _a === void 0 ? void 0 : _a.toFixed(5)}]`;
}
return output;
}
getHappenings(priorSteps) {
const count = priorSteps.filter(step => step.fullActionName === this.fullActionName).length;
const line = priorSteps.length;
if (this.isDurative) {
const start = new HappeningsInfo_1.Happening(this.getStartTime(), HappeningsInfo_1.HappeningType.START, this.fullActionName, count, line);
const end = new HappeningsInfo_1.Happening(this.getEndTime(), HappeningsInfo_1.HappeningType.END, this.fullActionName, count, line);
return [start, end];
}
else {
const instant = new HappeningsInfo_1.Happening(this.getStartTime(), HappeningsInfo_1.HappeningType.INSTANTANEOUS, this.fullActionName, count, line);
return [instant];
}
}
}
exports.PlanStep = PlanStep;
var PlanStepCommitment;
(function (PlanStepCommitment) {
PlanStepCommitment["Committed"] = "COMMITTED";
PlanStepCommitment["EndsInRelaxedPlan"] = "ENDS_IN_RELAXED_PLAN";
PlanStepCommitment["StartsInRelaxedPlan"] = "STARTS_IN_RELAXED_PLAN";
})(PlanStepCommitment || (exports.PlanStepCommitment = PlanStepCommitment = {}));
//# sourceMappingURL=PlanStep.js.map