MiniZinc
MiniZinc is a high-level constraint modelling language that allows you to easily express and solve discrete optimisation problems.
LiveCodes runs MiniZinc in the browser using WebAssembly.
Basic Demo
See below for more advanced examples.
Usage
By default the output is logged to the integrated console. In addition, helper methods are available to access solve progress and solution from JavaScript.
Usage from JavaScript
Helper methods are available in the browser global livecodes.minizinc object.
They allow interacting with the JavaScript interface for MiniZinc.
The following methods are available:
livecodes.minizinc.init: A method that returns a promise that resolves when the MiniZinc environment is loaded. This should be used before callinglivecodes.minizinc.solve.livecodes.minizinc.getSolvers: A method that returns a promise that resolves to an array of available MiniZinc solvers.livecodes.minizinc.run: A method that returns a promise that resolves to the final solution/statistics/status. It optionally accepts a data object (see below) as an argument.livecodes.minizinc.solve: This method should only be run afterlivecodes.minizinc.init()resolves. It returns a solve progress object, which can be used to listen to events during solving, and can be awaited to retrieve the final solution/statistics/status. This method also optionally accepts a data object (see below) as an argument.
Data Object
The data object can be used to pass data to the MiniZinc environment, such as dzn or json. It can also pass configuration object. It has the following type definition:
interface MiniZincData {
dzn?: string;
json?: string;
config?: {
jsonOutput?: boolean;
options?: {
solver?: string;
"time-limit"?: number;
statistics?: boolean;
"all-solutions"?: boolean;
// ... other MiniZinc options
};
};
}
Example
Language Info
Name
minizinc
Extension
mzn
Editor
script
Compiler
The official JavaScript port for MiniZinc which uses WebAssembly.
Version
minizinc v4.4.4
Code Formatting
Using a MiniZinc plugin for the Prettier formatter.
Limitations
Currently, visualisations are not supported out-of-the-box. However, using the helper methods, and based on official implementations, it should be possible to create custom visualisations.
Example:
Starter Template
https://livecodes.io/?template=minizinc