UNPKG

ai-planning-val

Version:

Javascript/typescript wrapper for VAL (AI Planning plan validation and evaluation tools from KCL Planning department and the planning community around the ICAPS conference).

71 lines 3.2 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.HappeningsToValStep = void 0; const pddl_workspace_1 = require("pddl-workspace"); const pddl_workspace_2 = require("pddl-workspace"); class HappeningsToValStep { constructor() { this.durativeActionCounter = 0; this.durativeActionIndex = new Map(); this.valStepText = []; this.makespan = -1; } convertAllHappenings(happenings) { this.convert(happenings.getHappenings()); } convert(happenings, batchId) { const header = []; const footer = []; if (batchId !== undefined) { const minTime = Math.min(...happenings.map(h => h.getTime())); const maxTime = Math.max(...happenings.map(h => h.getTime())); const message = `batch [${batchId}]: ${happenings.length} happening(s) from time ${minTime} up to time ${maxTime}.`; header.push('e Posting ' + message); footer.push('e Executed ' + message); } const newSteps = happenings.map(h => this.happeningToValStep(h)); const newStepsFlatten = pddl_workspace_2.utils.Util.flatMap(newSteps); newStepsFlatten.push('x'); const valStepInstructions = pddl_workspace_2.utils.Util.flatMap([header, newStepsFlatten, footer]); this.valStepText = this.valStepText.concat(valStepInstructions); return valStepInstructions.join('\n') + '\n'; } getExportedText(andQuit) { if (andQuit) { this.valStepText.push('q'); } return this.valStepText.join('\n') + '\n'; } happeningToValStep(h) { const newValStepText = []; switch (h.getType()) { case pddl_workspace_1.HappeningType.START: case pddl_workspace_1.HappeningType.INSTANTANEOUS: this.durativeActionCounter += 1; this.durativeActionIndex.set(this.toOrderedActionName(h), this.durativeActionCounter); // ? start action-name argument1 argument2 @ 0 newValStepText.push(`start ${h.getFullActionName()} @ ${h.getTime()}`); break; case pddl_workspace_1.HappeningType.END: const index = this.durativeActionIndex.get(this.toOrderedActionName(h)); // ? end 3 @ 4.001 newValStepText.push(`end ${index} @ ${h.getTime()}`); break; default: newValStepText.push('; error exporting: ' + h.toString()); break; } // update the plan makespan this.makespan = h.getTime(); return newValStepText; } toOrderedActionName(h) { return h.getFullActionName() + '#' + h.getCounter(); } } exports.HappeningsToValStep = HappeningsToValStep; //# sourceMappingURL=HappeningsToValStep.js.map