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).

107 lines (106 loc) 4.69 kB
/// <reference types="node" /> import { EventEmitter } from 'events'; import { ProblemInfo, TimedVariableValue, VariableValue, DomainInfo, Happening } from 'pddl-workspace'; export declare class ValStepError extends Error { readonly message: string; readonly domain: DomainInfo; readonly problem: ProblemInfo; readonly valStepInput: string; constructor(message: string, domain: DomainInfo, problem: ProblemInfo, valStepInput: string); } export declare class ValStepExitCode extends Error { constructor(message: string); } /** Valstep utility execution options. */ export interface ValStepOptions { /** Valstep executable path, if undefined 'ValStep' command will be used when spawning the process. */ valStepPath?: string; /** Current directory. If undefined, the current process `cwd` will be used. */ cwd?: string; /** Verbose mode (more logging to the console). Default is `false`. */ verbose?: boolean; } export interface ValStepInteractiveOptions extends ValStepOptions { /** Timeout to wait for a state evaluation after happening burst was posted. Default: 500ms. */ timeout?: number; } /** * Wraps the Valstep executable. * @see https://github.com/KCL-Planning/VAL/blob/master/applications/README.md#valstep */ export declare class ValStep extends EventEmitter { private domainInfo; private problemInfo; private childProcess; private variableValues; private initialValues; private valStepInput; private outputBuffer; private happeningsConvertor; private static readonly QUIT_INSTRUCTION; static HAPPENING_EFFECTS_EVALUATED: symbol; static NEW_HAPPENING_EFFECTS: symbol; /** Default file name */ private readonly VALSTEP_EXE; constructor(domainInfo: DomainInfo, problemInfo: ProblemInfo); /** * Subscribe to the state update event. * @param callback state update callback * @returns `this` */ onStateUpdated(callback: (happenings: Happening[], values: VariableValue[]) => void): ValStep; /** * Subscribe to the state update event (once). * @param callback state update callback * @returns `this` */ onceStateUpdated(callback: (happenings: Happening[], values: VariableValue[]) => void): ValStep; /** * Executes series of plan happenings in one batch without waiting for incremental effect evaluation. * @param happenings plan happenings to play * @param options ValStep execution options * @returns final variable values, or undefined in case the ValStep fails */ executeBatch(happenings: Happening[], options?: ValStepOptions): Promise<TimedVariableValue[] | undefined>; createValCommand(options?: ValStepOptions): string; logValStepCommand(options: ValStepOptions | undefined, args: string[]): void; private convertHappeningsToValStepInput; /** * Executes series of plan happenings capturing the PDDL problem that VAL outputs at the end. * @param happenings plan happenings to play * @param options ValStep execution options * @returns final variable values, or null/undefined in case the tool fails */ execute(happenings: Happening[], options?: ValStepOptions): Promise<TimedVariableValue[] | undefined>; /** * Parses the problem file and extracts the initial state. * @param problemText problem file content output by ValStep * @returns variable values array, or null if the tool failed */ private extractInitialState; private startValStep; /** * Executes series of plan happenings, while waiting for each burst of happenings (scheduled at the same time) to evaluate effects. * @param happenings plan happenings to play * @param options ValStep execution options * @returns final variable values */ executeIncrementally(happenings: Happening[], options?: ValStepOptions): Promise<TimedVariableValue[]>; private createValStepArgs; /** * Posts happening interactively. * @param happenings happenings group (typically sharing the same timestamp) * @param options execution options */ postHappenings(happenings: Happening[], options?: ValStepInteractiveOptions): Promise<boolean>; private applyIfNew; private throwValStepExitCode; private throwValStepError; private readonly valStepOutputPattern; private readonly valStepLiteralsPattern; private isOutputComplete; private parseEffects; getUpdatedValues(): TimedVariableValue[]; changedFromInitial(value1: TimedVariableValue): boolean; static storeError(err: ValStepError, targetDirectoryFsPath: string, valStepPath: string): Promise<string>; }