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.

Â