Makes the given string contents available to MiniZinc using the given filename.
/// 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.
The file name to use
The contents of the file
Optional use: booleanWhether to add this file as an argument to the MiniZinc command
Adds the given file to the model.
model.addFile("./path/to/model.mzn");
Only available using the native version of MiniZinc in NodeJS.
The file name to use
Adds data to the model in JSON format.
Note that each snippet is used as a complete JSON data file.
model.addJson({
  y: 1.5
});
The data as an object in MiniZinc JSON data input format
The filename of the snippet (may be useful to identify sources of errors)
Add a snippet of code to the model.
Note that each snippet is used as a complete model file.
model.addString("var 1..3: x;");
model.addString("float: y;");
MiniZinc code as a string
The filename of the snippet (may be useful to identify sources of errors)
Check for errors in the model using --model-check-only.
const errors = model.check({
  options: {
    solver: 'gecode'
  }
});
for (const error of errors) {
  console.log(error.what, error.message);
}
Configuration options
Optional options?: ParamConfigOptions to pass to MiniZinc in parameter configuration file format
The errors in the model
Compile this model to FlatZinc.
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);
Configuration options
Optional options?: ParamConfigOptions to pass to MiniZinc in parameter configuration file format
Get the model interface using --model-interface-only.
model.interface({
  options: {
    solver: 'gecode'
  }
}).then(console.log);
Configuration options
Optional options?: ParamConfigOptions to pass to MiniZinc in parameter configuration file format
The model interface
Solve this model and retrieve the result.
// 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);
});
Configuration options
Optional jsonWhether to use --output-mode json (true by default)
Options to pass to MiniZinc in parameter configuration file format
Generated using TypeDoc
Main class for solving MiniZinc instances.
This API allows you to add
.mzn,.dzn,.jsonand.mpcfiles 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