This chapter introduces the basics of the or-tools library. In particular, we show how to use the Constraint Programming Solver (CP Solver). It takes a while to get used to the logic of the library, but once you grasp the basics explained in this chapter, you’re good to go and you should be able to find your way through the numerous examples provided with the library.
Overview:
We start with a discussion on the setup of the library, then walk through a complete example to solve a cryptarithmetic puzzle. Along the way, we see how to create the CP solver and populate it with a model, how to control the search with a DecisionBuilder, collect solutions with SolutionCollectors and change the behavior of the program with parameters (through the Google gflags library). Finally, we say a few words about the other supported languages (Python, Java and C#).
The section At a glance summarizes in two Figures all the required steps to write a basic program.
Prerequisites:
Classes under scrutiny:
IntVar, AllDifferent, DecisionBuilder, SolutionCollector, Assignment, SearchMonitor.
Files:
The files used in this chapter are:
Content: