Makes the given string contents available to MiniZinc using the given filename.
The file name to use
The contents of the file
Optional
use: booleanWhether to add this file as an argument to the MiniZinc command
/// Add this file to the MiniZinc command
model.addFile("model.mzn", `
include "foo.mzn";
var 1..3: x;
`);
// Make this file available, but don't add it to the MiniZinc command
model.addFile("foo.mzn", "var 1..3: y;", false);
This method is generally only used from the browser.
Adds the given file to the model.
The file name to use
model.addFile("./path/to/model.mzn");
Only available using the native version of MiniZinc in NodeJS.
Adds data to the model in JSON format.
Note that each snippet is used as a complete JSON data file.
The data as an object in MiniZinc JSON data input format
The filename of the snippet (may be useful to identify sources of errors)
model.addJson({
y: 1.5
});
Add a snippet of code to the model.
Note that each snippet is used as a complete model file.
MiniZinc code as a string
The filename of the snippet (may be useful to identify sources of errors)
model.addString("var 1..3: x;");
model.addString("float: y;");
Check for errors in the model using --model-check-only
.
Configuration options
Optional
options?: ParamConfigOptions to pass to MiniZinc in parameter configuration file format
The errors in the model
const errors = model.check({
options: {
solver: 'gecode'
}
});
for (const error of errors) {
console.log(error.what, error.message);
}
Compile this model to FlatZinc.
Configuration options
Optional
options?: ParamConfigOptions to pass to MiniZinc in parameter configuration file format
const compile = model.compile({
options: {
solver: 'gecode',
statistics: true
}
});
// Print compilation statistics when received
compile.on('statistics', e => console.log(e.statistics));
// Wait for completion
compile.then(console.log);
Get the model interface using --model-interface-only
.
Configuration options
Optional
options?: ParamConfigOptions to pass to MiniZinc in parameter configuration file format
The model interface
model.interface({
options: {
solver: 'gecode'
}
}).then(console.log);
Solve this model and retrieve the result.
Configuration options
Optional
jsonWhether to use --output-mode json
(true
by default)
Options to pass to MiniZinc in parameter configuration file format
// Begin solving
const solve = model.solve({
options: {
solver: 'gecode',
'all-solutions': true
}
});
// Print each solution as it is produced
solve.on('solution', e => console.log(e.output));
// Wait for completion
solve.then(result => {
console.log(result.status);
});
Generated using TypeDoc
Main class for solving MiniZinc instances.
This API allows you to add
.mzn
,.dzn
,.json
and.mpc
files using theaddFile()
method, and then run MiniZinc on the files using thesolve()
method.Code can also be added programmatically using the
addString()
(and similar) methods.Example