Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ A [feature-rich](https://livecodes.io/docs/features/), open-source, **client-sid
[![LiveCodes: npm version](https://img.shields.io/npm/v/livecodes)](https://www.npmjs.com/package/livecodes)
[![LiveCodes: npm downloads](https://img.shields.io/npm/dm/livecodes)](https://www.npmjs.com/package/livecodes)
[![LiveCodes: jsdelivr downloads](https://data.jsdelivr.com/v1/package/npm/livecodes/badge?style=rounded)](https://www.jsdelivr.com/package/npm/livecodes)
[![LiveCodes: languages](https://img.shields.io/badge/languages-97-blue)](https://livecodes.io/docs/languages/)
[![LiveCodes: languages](https://img.shields.io/badge/languages-98-blue)](https://livecodes.io/docs/languages/)
[![LiveCodes: docs](https://img.shields.io/badge/Documentation-575757?logo=gitbook&logoColor=white)](https://livecodes.io/docs/)
[![LiveCodes: llms.txt](https://img.shields.io/badge/llms.txt-575757?logo=googledocs&logoColor=white)](https://livecodes.io/docs/llms.txt)
[![LiveCodes: llms-full.txt](https://img.shields.io/badge/llms--full.txt-575757?logo=googledocs&logoColor=white)](https://livecodes.io/docs/llms-full.txt)
Expand Down
145 changes: 145 additions & 0 deletions docs/docs/languages/minizinc.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# MiniZinc

[MiniZinc](https://www.minizinc.org/) 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

import LiveCodes from '../../src/components/LiveCodes.tsx';

export const params = {
'minizinc': `% Soduku

include "globals.mzn";

any: board = [|
5, 3, <>, <>, 7, <>, <>, <>, <> |
6, <>, <>, 1, 9, 5, <>, <>, <> |
<>, 9, 8, <>, <>, <>, <>, 6, <> |

8, <>, <>, <>, 6, <>, <>, <>, 3 |
4, <>, <>, 8, <>, 3, <>, <>, 1 |
7, <>, <>, <>, 2, <>, <>, <>, 6 |

<>, 6, <>, <>, <>, <>, 2, 8, <> |
<>, <>, <>, 4, 1, 9, <>, <>, 5 |
<>, <>, <>, <>, 8, <>, <>, 7, 9
|];

array [1..9, 1..9] of var 1..9: solution;

% Given numbers are fixed
constraint forall (i, j in 1..9) (solution[i, j] ~= board[i, j]);

% Rows are all different
constraint forall (i in 1..9) (all_different(solution[i, ..]));
% Columns are all different
constraint forall (j in 1..9) (all_different(solution[.., j]));

% Subgrids are all different
constraint forall (i, j in 1..3) (
all_different(solution[
3 * (i - 1) + 1 .. 3 * i,
3 * (j - 1) + 1 .. 3 * j
])
);

solve satisfy;
`,
console: 'full',
};

<LiveCodes params={params}></LiveCodes>

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](https://js.minizinc.dev/).

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 calling `livecodes.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 after `livecodes.minizinc.init()` resolves. It returns a [solve progress object](https://js.minizinc.dev/docs/stable/interfaces/SolveProgress.html), 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:

```ts
interface MiniZincData {
dzn?: string;
json?: string;
config?: {
jsonOutput?: boolean;
options?: {
solver?: string;
"time-limit"?: number;
statistics?: boolean;
"all-solutions"?: boolean;
// ... other MiniZinc options
};
};
}
```

#### Example

<LiveCodes template='minizinc' height="80vh"></LiveCodes>

## Language Info

### Name

`minizinc`

### Extension

`mzn`

### Editor

`script`

## Compiler

The official [JavaScript port](https://js.minizinc.dev/) for MiniZinc which uses WebAssembly.

### Version

`minizinc` v4.4.4

## Code Formatting

Using a [MiniZinc plugin](https://github.com/live-codes/prettier-plugin-minizinc) for the [Prettier](https://prettier.io/) formatter.


## Limitations

Currently, [visualisations](https://docs.minizinc.dev/en/stable/visualisation.html) are not supported out-of-the-box.
However, using the [helper methods](#usage-from-javascript), and based on [official implementations](https://github.com/MiniZinc/libminizinc/tree/master/share/minizinc/std/ide), it should be possible to create custom visualisations.

Example:

<LiveCodes import='id/xj98m7cfpnv' height="80vh"></LiveCodes>

## Starter Template

https://livecodes.io/?template=minizinc

## Links

- [MiniZinc](https://www.minizinc.org/)
- [MiniZinc documentation](https://docs.minizinc.dev/en/stable/)
- [MiniZinc JavaScript port](https://js.minizinc.dev/)
- [MiniZinc tutorial](https://docs.minizinc.dev/en/stable/part_2_tutorial.html)
1 change: 1 addition & 0 deletions docs/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ const config: Config = {
plugin: ['typedoc-plugin-missing-exports'],
excludeExternals: true,
internalModule: '_internal',
skipErrorChecking: true,
},
],
[
Expand Down
1 change: 1 addition & 0 deletions docs/src/components/LanguageSliders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export default function Sliders() {
{ name: 'sql', title: 'SQL' },
{ name: 'postgresql', title: 'PostgreSQL' },
{ name: 'prolog', title: 'Prolog' },
{ name: 'minizinc', title: 'MiniZinc' },
{ name: 'blockly', title: 'Blockly' },
],
};
Expand Down
1 change: 1 addition & 0 deletions docs/src/components/TemplateList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ const templates = [
{ name: 'sql', title: 'SQL Starter', thumbnail: 'sqlite.svg' },
{ name: 'postgresql', title: 'PostgreSQL Starter', thumbnail: 'postgresql.svg' },
{ name: 'prolog', title: 'Prolog Starter', thumbnail: 'tau-prolog.svg' },
{ name: 'minizinc', title: 'MiniZinc Starter', thumbnail: 'minizinc.png' },
{ name: 'blockly', title: 'Blockly Starter', thumbnail: 'blockly.svg' },
{ name: 'diagrams', title: 'Diagrams Starter', thumbnail: 'diagrams.svg' },
];
Expand Down
3 changes: 3 additions & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ const esmBuild = () =>
'editor/monaco/languages/monaco-lang-astro.ts',
'editor/monaco/languages/monaco-lang-clio.ts',
'editor/monaco/languages/monaco-lang-imba.ts',
'editor/monaco/languages/monaco-lang-minizinc.ts',
'editor/monaco/languages/monaco-lang-prolog.ts',
// 'editor/monaco/languages/monaco-lang-sql.ts',
'editor/monaco/languages/monaco-lang-wat.ts',
'editor/codemirror/codemirror.ts',
Expand Down Expand Up @@ -228,6 +230,7 @@ const iifeBuild = () =>
'languages/liquid/lang-liquid-compiler.ts',
'languages/lua-wasm/lang-lua-wasm-script.ts',
'languages/malina/lang-malina-compiler.ts',
'languages/minizinc/lang-minizinc-script.ts',
'languages/mustache/lang-mustache-compiler.ts',
'languages/nunjucks/lang-nunjucks-compiler.ts',
'languages/perl/lang-perl-script.ts',
Expand Down
1 change: 1 addition & 0 deletions src/livecodes/UI/command-menu-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ export const getCommandMenuActions = ({
'sql',
'postgresql',
'prolog',
'minizinc',
'blockly',
'diagrams',
).map((template) => ({
Expand Down
Binary file added src/livecodes/assets/templates/minizinc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/livecodes/editor/codemirror/editor-languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const moduleUrls = {
sql: getPath('codemirror-lang-sql.js'),
wast: getPath('codemirror-lang-wast.js'),
scss: getPath('codemirror-lang-scss.js'),
minizinc: getPath('codemirror-lang-minizinc.js'),
prolog: getPath('codemirror-lang-prolog.js'),
coffeescript: getPath('codemirror-lang-coffeescript.js'),
livescript: getPath('codemirror-lang-livescript.js'),
ruby: getPath('codemirror-lang-ruby.js'),
Expand Down Expand Up @@ -72,6 +74,8 @@ export const editorLanguages: Partial<{ [key in Language]: () => Promise<Languag
wat: async () => (await import(moduleUrls.wast)).wast(),
scss: async () => (await import(moduleUrls.scss)).sass(),
sass: async () => (await import(moduleUrls.scss)).sass({ indented: true }),
minizinc: async () => (await import(moduleUrls.minizinc)).MiniZinc(),
prolog: async () => (await import(moduleUrls.prolog)).prolog(),
Comment thread
hatemhosny marked this conversation as resolved.
coffeescript: async () => legacy((await import(moduleUrls.coffeescript)).coffeeScript),
livescript: async () => legacy((await import(moduleUrls.livescript)).liveScript),
ruby: async () => legacy((await import(moduleUrls.ruby)).ruby),
Expand Down
Loading