0:05

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

Â some people prefer to use the 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 want to be able to use IDE in your tool chain.

Â So basically this is information about how to use MiniZinc in the command line.

Â So before we go into how to use it, let's look inside the MiniZinc tool chain,

Â a little bit to see what actually goes on inside MiniZinc.

Â 0:35

So we start with our model and some data.

Â And there's also some global definitions,

Â which How your solver handles the global.

Â 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 model that basically reflects the output statement,

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

Â 1:14

Little executable solutions throughout, which just processes the solution and

Â prints out the output in format, and that's what goes to standard out.

Â But the way we typically use these things from the command line is basically you

Â have a single executable which encapsulates all of this, and

Â it's going to attach to a particular solver.

Â 1:37

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

Â And there's plenty of other ways of running MiniZinc files without a solver.

Â But these are the most obvious ones, and in particular we use within the course.

Â So mzn-gecode is basically minizinc bundled with the Gecode solver, and

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

Â Because indeed, all 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.

Â This mzn-cbc which minizinc with COIN OR CBC solver, that's a free MIP solver.

Â And there's also mzn-gurobi, which is minizinc that attached to Gurobi.

Â This is a commercial MIP solver, but

Â of course we can't give you a license for Gurobi,

Â what you need to do use this is to install the dynamically vibrate of Gurobi result.

Â And get an appropriate license to use it, but

Â there are free academic licenses available for Gurobi.

Â And there's other solvers, these are the older solvers, mzn-g12fd,

Â this with a constraint or rather old one.

Â Minizinc, the executable called minizinc is the same as this runs

Â minizinc with g12fd, which is the original solver attached to minizinc.

Â Then there's mzn-gl12lazy, which is minizinc with lazyfd,

Â another learning CP solver, but older, not as good as chaff.

Â And g12mip, which is with an older MIP solver.

Â 3:08

So these are the sort of the eight executables that you can use a command

Â line to run minizinc models.

Â So the usage is basically mzn-gecode, or use that for the examples, you can

Â do some options, a model file, a single model file and one or more data files.

Â 3:27

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

Â a satisfaction problem, it'll search for a single solution.

Â It'll stop and print out the first solution found.

Â Otherwise it will print UNSATISFIABLE.

Â For an optimization problem, it will search for the optimal solution,

Â if it can prove optimally, it'll print out the authorization.

Â If it finds no solution, it will 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 going to print anything if it proves that the solution is optimal.

Â 4:09

So one of the important flags that we want to use is the all-solutions flag,

Â --all-solutions or -a.

Â And this changes the behavior or MiniZinc.

Â For satisfaction problems it does work as you'd expect.

Â It prints out all of the solutions that are found,

Â one after the other and puts this separator of ten dashes in between them.

Â Otherwise, if there's no solution, it prints out UNSATISFIABLE as before, for

Â optimization 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, it prints UNSATISFIABLE.

Â And but the important difference about using the -a flag is that

Â in an optimization problem,

Â 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 the last solution you've found, and

Â that's the best solution we've found so far.

Â So often for optimization problems, we want to use MiniZinc with a -a flag,

Â because often they'll not be able to prove optimality,

Â in which case they'll just sit there and do nothing.

Â Note that it's really only CP solvers that tend to support the all solution flag and

Â the MIP solvers such as cdc, gurobi and

Â g12mip basically only ever return one solution.

Â 5:31

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 which solver you are 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 solver and

Â particularly, you could compare two different variations that are in model

Â using the same solver to see differences.

Â So things like runtime 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 are what's printed out by the statistics option.

Â So another important option is 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 vary one of the two

Â critical parameters.

Â So if you've got some size parameter, and

Â you want to run the different versions of the model in some script by changing

Â the size parameter from 10 to 50 by a factor of 10 every time.

Â Then that's very easy for you using this -D.

Â 6:52

You can change the output of MiniZinc, so

Â if you put -o then the output's sent to the file.

Â You can also change the strings that MiniZinc uses to print out things.

Â So the solution separated 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 also you can change the completion message.

Â So normally when MiniZinc says I've found all solutions or

Â I've proved optimality, it prints out the search completion string,

Â which is the ten equality sign, you can change that [INAUDIBLE].

Â Some other interesting options are the keep files or

Â -k option that allow 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.

Â Another interesting thing is if you want to pass an information

Â to an underlying solver, you can use a minus minus epsilon end flags.

Â Option, give those flags.

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

Â to which is the actual decode solver.

Â Requiring it to run with a 1,000 millisecond timeout.

Â And you just stop and that [INAUDIBLE] do anything.

Â So you can see with probably one of the minus a as well.

Â So you see the answer [INAUDIBLE].

Â Although I think it'll print out the best answer it finds at the end of the time.

Â So in summary, MiniZinc has a lot of command line options.

Â Command line can be very useful for using MiniZinc within some other cool chains.

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

Â you can look at this by basically going into minus.

Â That'll give you a list of all of the [INAUDIBLE] options available.

Â