Loading solver…
CP-SAT - Model Playground
Problem: load a user-provided CP-SAT model, validate it, and solve it with editable search parameters.
Show code
import { CpSat, type SatParameters } from 'or-tools-wasm/cp-sat';
const modelJson = JSON.parse(textarea.value);
const workers = 4;
const params: SatParameters = {
...JSON.parse(paramsTextarea.value),
numWorkers: workers,
};
const model = await CpSat.createModel(modelJson);
const validation = await CpSat.validate(model, { executor: 'worker' });
if (!validation.ok) throw new Error(validation.message);
const controller = new AbortController();
const result = await CpSat.solveProto(model, {
...params,
executor: 'worker',
eventMask: { solution: true, bestBound: true, log: true },
onEvent: (event) => console.log(event),
signal: controller.signal,
});
console.log(result.response);
Paste a JSON-shaped CpModelProto, optionally edit SAT parameters, then validate or solve it in the browser.
Model
- The model input is raw JSON shaped like a CP-SAT
CpModelProto. - The parameter input is JSON shaped like
SatParameters. - Validate checks whether the protobuf model is structurally acceptable before solving.
- Solve sends the same encoded request through the selected executor.