-
-
Notifications
You must be signed in to change notification settings - Fork 246
add minizinc language support #931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f3476d4
feat(Compilers): add minizinc language support
hatemhosny aaf030a
fix
hatemhosny 39457af
fix
hatemhosny a38b42c
fix
hatemhosny 759df11
update minizinc monaco support
hatemhosny 2f7cd1c
improve minizinc prettier plugin
hatemhosny 393238e
minizinc solvers
hatemhosny 03dbe02
pass config during run
hatemhosny a244abe
add `solve` helper function for minizinc
hatemhosny 06d0ab2
log minizinc solutions
hatemhosny b1eab5a
add minizinc docs
hatemhosny cf098a4
minor fixes
hatemhosny 2b8a82f
Merge branch 'develop' into minizinc
hatemhosny ed3ef73
Merge branch 'develop' into minizinc
hatemhosny 0d35428
Merge branch 'develop' into minizinc
hatemhosny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.