Interface SolveProgress

Thenable controller for a solve request.

Used to listen to events during solving, and can be awaited to retrieve the final solution/statistics/status.

interface SolveProgress {
    cancel(): void;
    isRunning(): boolean;
    off<T>(event: string, callback: (e: T) => void): void;
    on(event: "solution", callback: (e: SolutionMessage) => void): void;
    on(event: "checker", callback: (e: CheckerMessage) => void): void;
    on(event: "status", callback: (e: StatusMessage) => void): void;
    on(event: "statistics", callback: (e: StatisticsMessage) => void): void;
    on(event: "timestamp", callback: (e: TimestampMessage) => void): void;
    on(event: "trace", callback: (e: TraceMessage) => void): void;
    on(event: "error", callback: (e: ErrorMessage) => void): void;
    on(event: "warning", callback: (e: WarningMessage) => void): void;
    on(event: "exit", callback: (e: ExitMessage) => void): void;
    on(event: string, callback: (e: object) => void): void;
}

Hierarchy

Methods

  • Cancel solving.

    Returns void

    const solve = model.solve({
    solver: 'gecode'
    });
    setTimeout(() => {
    if (solve.isRunning()) {
    solve.cancel();
    }
    }, 10000);
  • Return whether or not solving is still in progress.

    Returns boolean

    const solve = model.solve({
    solver: 'gecode'
    });
    setInterval(() => {
    if (solve.isRunning()) {
    console.log('Still running');
    }
    }, 1000)
  • Stop listening for an event.

    Type Parameters

    • T

    Parameters

    • event: string
    • callback: (e: T) => void

    Returns void

    const solve = model.solve({
    solver: 'gecode'
    });
    const onSolution = e => {
    console.log(e.output);
    };
    // Start listening
    solve.on('solution', onSolution);
    setTimeout(() => {
    // Stop listening
    solve.off('solution', onSolution);
    }, 1000);