pddl-workspace
Version:
71 lines • 2.8 kB
JavaScript
;
/* --------------------------------------------------------------------------------------------
* 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.Plan = void 0;
const ProblemInfo_1 = require("./ProblemInfo");
const PlanStep_1 = require("./PlanStep");
const DomainInfo_1 = require("./DomainInfo");
class Plan {
constructor(steps, domain, problem, now, helpfulActions) {
this.steps = steps;
this.domain = domain;
this.problem = problem;
this.now = now;
this.helpfulActions = helpfulActions;
this._makespan = steps.length ? Math.max(...steps.map(step => step.getEndTime())) : 0;
}
/**
* Copy constructor for re-constructing the plan from a serialized form.
* @param plan serialized plan
*/
static clone(plan) {
var _a, _b;
const clonedDomain = plan.domain && DomainInfo_1.DomainInfo.clone(plan.domain);
const clonedProblem = plan.problem && ProblemInfo_1.ProblemInfo.clone(plan.problem, (_b = (_a = plan.domain) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : 'unknown-domain');
const clonedPlan = new Plan(plan.steps.map(s => PlanStep_1.PlanStep.clone(s)), clonedDomain, clonedProblem, plan.now, plan.helpfulActions);
plan._metric !== undefined && (clonedPlan.metric = plan._metric);
clonedPlan.statesEvaluated = plan.statesEvaluated;
return clonedPlan;
}
/** @deprecated use `metric` */
get cost() {
return this.metric;
}
/** @deprecated use `metric` */
set cost(metric) {
this.metric = metric;
}
get metric() {
var _a;
// if cost was not output by the planning engine, use the plan makespan
return (_a = this._metric) !== null && _a !== void 0 ? _a : this._makespan;
}
set metric(metric) {
this._metric = metric;
}
get makespan() {
return this._makespan;
}
isMetricDefined() {
return this._metric !== undefined;
}
/** @deprecated use isMetricDefined */
isCostDefined() {
return this.isMetricDefined();
}
/**
* Returns true if any helpful actions were specified.
*/
hasHelpfulActions() {
var _a, _b;
return ((_b = (_a = this.helpfulActions) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) > 0;
}
getText() {
return this.steps.map(step => step.toPddl()).join("\n");
}
}
exports.Plan = Plan;
//# sourceMappingURL=Plan.js.map