0:05

So the course is designed again to be undertaken using the IDE but,

some people prefer to use Command Line Interface.

And indeed if you're going to solve real world problems

using MiniZinc you don't want to do that through the IDE,

you'll only be able to you use IDE in a tool chain.

So basically this is information about how you use MiniZinc from the command line.

So before we go into how you use it,

let's look inside the MiniZinc Tool Chain a little bit.

Just see what actually goes on inside the MiniZinc.

0:46

All those are taken by the translator, which translates from MiniZinc to FlatZinc.

And outputs two things, a FlatZinc model, which is going to be sent to the solver.

And a little more that basically reflects the output statement which

is going to be used to process the output later on.

But FlatZinc model goes to the solver and it returns a solution, and

then that solution together with these hosted info file goes to another.

Little executables solutions which just processed the solution and

prints out the output in your graphic format.

And that's what goes to stdout.

But the way we typically use these things from the command line is,

basically of a single executable which encapsulates all of this,

and is attached to a particular solver.

1:37

So let's look at what executables come bundled with the MiniZincIDE.

There's plenty of other ways of running MiniZinc files with other solvers,

but these are the most obvious ones and particularly used within the course.

So mzn-gecode is specifically MiniZinc bundled with the Gecode solver, and

this is default for the course and this is what we recommend you use.

Because indeed, all of the assessment of the assignments and

model assessment will be done using Gecode.

There is mzn-chuffed which is minizinc connected with chuffed which is a learning

CP solver.

There's mzn-cbc, which is MiniZinc with the COIN OR CBC solver.

It's a free MIP solver, and

there's also mzn-gurobi, which is MiniZinc attached to Gurobi.

This is a commercial MIP solver,

but of course we can't give you a license for Gurobi.

What we need to do to use this is to install the dynamic-link library for

Gurobi yourself.

And get an appropriate license to use it, but

there are free academic licenses for Gurobi.

There's other solvers, these are the other solvers, msn-g12fd,

this is a constraint programming solver, a rather old one.

Minizinc, the executable called Minizinc is the same as this.

Runs Minizinc with G12 FD, which is the original solver attached to MiniZinc.

Then there's mzn-g12lazy which is MiniZinc with lazyfd, another learning CP solver

but older and not as good as Chuff, and g12mip, which is with an older MIP solver.

3:27

So, by default if you run a command line of this, then for

a satisfaction problem it'll search for a single solution, it'll stop and

print out the first solution found.

Otherwise, it'll print UNSATISFIABLE.

For an optimization problem, it'll search for the optimal solution,

if it can prove optimality, it'll print out the optimal solution.

If it finds no solution, it'll print out UNSATISFIABLE.

But we have to be careful because many problems that we'll see in the course, and

in the real world, it's very hard to prove optimality of a solution.

So, this can take a long time and do nothing because remember,

it's only got to print anything if it proves that the solution is optimal.

4:09

So, while the important flags that we are to use is the all solutions flag.

Minus, minus all solutions or minus, and this changes the behavior of MiniZinc.

So for satisfaction problems it does what you'd expect it.

Prints out all solutions that are found, one after the other, and

puts this separator of ten dashes in between them.

Otherwise, if there's no solutions, prints UNSATISFIABLE as before.

For optimisation problems, it works slightly differently.

What it does is prints all the solutions found on the way to the optimal solution.

So the optimal solution basically, will be the last one printed.

4:45

Otherwise, if it finds no solutions, you print UNSATISFIABLE.

And, but the important difference about using the minus a flag,

is that in optimisation problems, you may well be finding solutions.

You'll see them printed out.

If you give up and can't afford enough time to prove optimality

you can just stop computation, and look at that last solution you found and

that's the best solution you found so far.

So often for optimization problems we're going to use MiniZinc with the minus

a flag because often they'll not be able to prove optimality in which case.

They'll just sit there and do nothing.

5:20

And note that it's really only CP solvers that tend to support the all solution

flag and the MIP solvers such as cbc,

gurobi, and g12mip basically only ever return one solution.

So another important option is the statistics option,

"--statistics" or "-s".

And that means the solver will print statistics about the solving process,

typically at the end.

And the statistics that are printed depend on what solver you're using.

And so different solvers will print out different statistics, but

at least you can get some idea about what's going on with the solvent.

Particularly you can compare two different variations of your model

using the same solver to see differences.

5:59

So things like run time or solving time, the number of solutions found,

the size of the problem and statistics about search like the number of nodes or

failures or restarts.

What's printed out by these statistics option.

So another important option we use this -D flag.

So we put -D, and then in a string, some content, and basically,

that's just treated as part of the model.

So we can basically add data from the command line, and this can be very useful

if you want to run a model while you're vary one or two critical parameters.

So if you've got some size parameter and

you want to run them different versions of the model.

In some script are changing the size parameter from 10 to 15 by

effective 10 every time, and that's very easier for you using this -D.

Now you can change the output of MiniZinc, so if you put minus o,

then the output is sent to the file tather than stdout].

You can also change the strings that we use just to print out things.

So the solution separator string, which is normally ten dashes,

you could make it empty and

that means that you can print out all your solutions without a line between them.

And there's also a way you can change the completion message.

So normally when MiniZinc says, I've found all solutions or I've proved optimality,

print out the search completion stream which is the ten quality signs.

We can change that to be different for printing.

Some other interesting options are the keep files or

minus k option that keeps the temporary files constructed.

So this is useful for examining what flattening or debugging is doing,

and looking at some error messages.

You can run -p or --parallel with a number of threads.

And that's supported by at least Geocode and Gurobi.

7:53

Another interesting thing is, if you want to pass now information to an underlying

solver, you can use the -fzn-flags option in the first flags.

An example of that is given here where we're passing in the time option to fzn

in gecode which is the actual gecode solver requiring

it to a 1000ms timeout and it'll stop, doing things.

So you can see we'd probably want our -a as well, so we see the.

And I think you'll print out the best answer it finds

at the end of the timer.

So In summary, MiniZinc has a lot of command line options, command line can be

very useful for using MiniZinc within some other tool chain.

We've covered the most important here, but there are plenty more.

And if we look at this by going mzn-gecode --help

That will give you a list of all of the command line options available.