pddl-workspace
Version:
90 lines • 3.47 kB
JavaScript
/* --------------------------------------------------------------------------------------------
* Copyright (c) Jan Dolejsi. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
exports.SearchState = void 0;
/** State generated in the process of the plan search. */
class SearchState {
/**
* Search state constructor.
* @param id state ID (assigned when received from the planner)
* @param origId original/external state ID (by which the planner refers to it)
* @param g generation (initial state is gen 0)
* @param earliestTime earliest time this state may be scheduled
* @param planHead plan head (list of happening starting from the initial state)
* @param landmarks number of landmarks encountered up to this state
* @param parentId parent state id
* @param actionName action applied to create this state
*/
constructor(id, origId, g, earliestTime, planHead, landmarks, parentId, actionName) {
this.id = id;
this.origId = origId;
this.g = g;
this.earliestTime = earliestTime;
this.planHead = planHead;
this.landmarks = landmarks;
this.parentId = parentId;
this.actionName = actionName;
/** This state meets the goal criteria and other applicable criteria to represent the end-state of a plan. */
this.isPlan = false;
this._isEvaluated = false;
}
/** Creates initial search state. */
static createInitial() {
return new SearchState(0, "0", 0, 0, [], 0);
}
get isEvaluated() {
return this._isEvaluated;
}
/**
* Records state evaluation.
* @param h heuristic value
* @param totalMakespan total plan makespan (plan head plus relaxed plan makespan)
* @param helpfulActions helpful action list
* @param relaxedPlan relaxed plan
*/
evaluate(h, totalMakespan, helpfulActions, relaxedPlan) {
this.h = h;
this.totalMakespan = totalMakespan;
this.helpfulActions = helpfulActions;
this.relaxedPlan = relaxedPlan;
this.isDeadEnd = false;
this._isEvaluated = true;
return this;
}
/**
* Makes this state a search dead-end.
*/
setDeadEnd() {
this.h = Number.POSITIVE_INFINITY;
this.totalMakespan = Number.POSITIVE_INFINITY;
this.helpfulActions = [];
this.relaxedPlan = [];
this.isDeadEnd = true;
this._isEvaluated = true;
return this;
}
/**
* Makes this state trimmed by state memoisation.
*/
setVisitedOrIsWorse() {
this.wasVisitedOrIsWorse = true;
return this;
}
/** Returns the plan head, and if present, the actions from the relaxed plan. */
getTotalPlan() {
if (this.relaxedPlan) {
return this.planHead.concat(this.relaxedPlan);
}
else {
return this.planHead;
}
}
toString() {
return `State={origId: ${this.origId}, G: ${this.g}, Action: ${this.actionName}, O: ${this.id}, Time: ${this.earliestTime}, parent: ${this.parentId} H: ${this.h}, Makespan: ${this.totalMakespan}}`;
}
}
exports.SearchState = SearchState;
//# sourceMappingURL=SearchState.js.map