Skip to main content
Log in

MiniCP: a lightweight solver for constraint programming

  • Full Length Paper
  • Published:
Mathematical Programming Computation Aims and scope Submit manuscript

Abstract

This paper introduces MiniCP, a lightweight, open-source solver for constraint programming. MiniCP is motivated by educational purposes and the desire to provide the core implementation of a constraint-programming solver for students in computer science and industrial engineering. The design of MiniCP provides a one-to-one mapping between the theoretical and implementation concepts and its compositional abstractions favor extensibility and flexibility. MiniCP obviously does not support all available constraint-programming features and implementation techniques, but these could be implemented as future extensions or exploratory projects. MiniCP also comes with a full set of exercises, unit tests, and development projects.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Fig. 1
Fig. 2
Fig. 3
Fig. 4
Fig. 5
Fig. 6

Similar content being viewed by others

Notes

  1. When all the filtering algorithms are domain-consistent, Algorithm 2 is equivalent to the AC-3 algorithm in [17].

  2. The actual code has additional instructions to gather statistics, but its essence is identical.

  3. Expressions are a fourth, more general, alternative which was implemented in CHIP, Ilog Solver, and many subsequent solvers; They require a heavier machinery.

  4. For more discussion on each combinators, readers can consult [32,33,34].

References

  1. Colmerauer, A.: An introduction to Prolog III. Commun. ACM 28(4), 412–418 (1990)

    Google Scholar 

  2. Jaffar, J., Lassez, J.L.: Constraint logic programming. In: POPL-87, Munich, Germany (1987)

  3. Van Hentenryck, P.: Constraint Satisfaction in Logic Programming. The MIT Press, Cambridge (1989)

    Google Scholar 

  4. Laborie, P., Rogerie, J., Shaw, P., Vilím, P.: IBM ILOG CP optimizer for scheduling. Constraints, pp. 1–41 (2018)

  5. Van Hentenryck, P., Saraswat, V., Deville, Y.: Design, implementation, and evaluation of the constraint language cc (FD). J. Log. Program. 37(1), 139–164 (1998)

    Article  Google Scholar 

  6. Dynadec, Van Hentenryck, P., Michel, L., Schaus, P.: Comet v2. 1 user manual (2009)

  7. Hentenryck, P.V., Michel, L.: Constraint-Based Local Search. The MIT Press, Cambridge (2009)

    MATH  Google Scholar 

  8. Van Hentenryck, P., Michel, L.: The objective-cp optimization system. In: International Conference on Principles and Practice of Constraint Programming, pp. 8–29. Springer, Berlin (2013)

  9. OscaR Team: OscaR: Scala in OR (2012). https://bitbucket.org/oscarlib/oscar

  10. Michel, L., Van Hentenryck, P.: A microkernel architecture for constraint programming. Constraints, pp. 1–45 (2014)

  11. van Omme, N., Perron, L., Furnon, V.: Or-tools user’s manual. Technical report, Google (2014)

  12. Kuchcinski, K., Szymanek, R.: Jacop-java constraint programming solver. In: Proceedings of CP Solvers: Modeling, Applications, Integration, and Standardization (2013)

  13. Hebrard, E.: Mistral, a constraint satisfaction library. In: Proceedings of the Third International CSP Solver Competition, vol. 3, p. 3 (2008)

  14. Prud’homme, C., Fages, J.G., Lorca, X.: Choco4 documentation. In: TASC, INRIA Rennes, LINA CNRS UMR, vol. 6241 (2014)

  15. Aggoun, A., Beldiceanu, N.: An overview of the CHIP compiler. In: the 8th International Conference on Logic Programming (ICLP-91). The MIT Press, Paris, France (1991)

  16. Schulte, C., Carlsson, M.: Finite domain constraint programming systems. In: Handbook of Constraint Programming, p. 493 (2006)

  17. Mackworth, A.: Consistency in networks of relations. Artif. Intell. 8(1), 99–118 (1977)

    Article  MathSciNet  Google Scholar 

  18. Gamma, E., Helm, R., Johnson, R., Vlissides, J.: Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley Longman Publishing Co., Inc., Boston (1995)

    MATH  Google Scholar 

  19. Van Hentenryck, P., Carillon, J.P.: Generality versus specificity: an experience with AI and OR techniques. In: AAAI, pp. 660–664 (1988)

  20. Van Hentenryck, P., Michel, L.: Domain views for constraint programming. In: International Conference on Principles and Practice of Constraint Programming, pp. 705–720. Springer, Berlin (2014)

  21. de Saint-Marcq, V.l.C., Schaus, P., Solnon, C., Lecoutre, C.: Sparse-sets for domain implementation. In: CP Workshop on Techniques for Implementing Constraint Programming Systems (TRICS), pp. 1–10 (2013)

  22. Knuth, D.E.: The Art of Computer Programming: Volume 4B, Combinatorial Algorithms: Part 2, Backtrack Programming, vol. 4B. Addison-Wesley, Boston (2016)

  23. Floyd, R.W.: Nondeterministic algorithms. J. ACM (JACM) 14(4), 636–644 (1967)

    Article  Google Scholar 

  24. Schulte, C., Tack, G.: Views and iterators for generic constraint implementations. In: Recent Advances in Constraints (2005), Lecture Notes in Artificial Intelligence, vol. 3978, pp. 118–132. Springer, Berlin (2006)

  25. Van Hentenryck, P., Deville, Y.: The cardinality operator: a new logical connective and its application to constraint logic programming. In: ICLP-91, pp. 745–759 (1991)

  26. Beldiceanu, N., Carlsson, M., Rampon, J.X.: Global constraint catalog, (revision a) (2012)

  27. van Hoeve, W.J., Katriel, I.: Global constraints. In: Foundations of Artificial Intelligence, vol. 2, pp. 169–208. Elsevier, New York (2006)

  28. Hooker, J.N.: Integrated Methods for Optimization, vol. 170. Springer, Berlin (2012)

    Book  Google Scholar 

  29. Van Hentenryck, P., Carillon, J.P.: Generality versus specificity: an experience with AI and OR techniques. In: Proceedings of the American Association for Artificial Intelligence (AAAI-88). AAAI, Menlo Park, Calif., (St. Paul, MN) (1988)

  30. Régin, J.C.: A filtering algorithm for constraints of difference in csps. In: AAAI, vol. 94, pp. 362–367 (1994)

  31. van Hoeve, W.J.: The alldifferent constraint: A survey. arXiv preprint arXiv:cs/0105015 (2001)

  32. Michel, L., Van Hentenryck, P.: A microkernel architecture for constraint programming. Constraints 22(2), 107–151 (2017). https://doi.org/10.1007/s10601-016-9242-1

    Article  MathSciNet  MATH  Google Scholar 

  33. Van Hentenryck, P., Michel, L.: The Objective-CP optimization system. In: Proceedings of the 19th International Conference on Principles and Practice of Constraint Programming (2013)

  34. Schrijvers, T., Tack, G., Wuille, P., Samulowitz, H., Stuckey, P.: Search Combinators. Constraints 18(2), 269–305 (2013). https://doi.org/10.1007/s10601-012-9137-8

    Article  MathSciNet  MATH  Google Scholar 

  35. Harvey, W.D., Ginsberg, M.L.: Limited discrepancy search. In: IJCAI (1995)

  36. Shaw, P.: Using constraint programming and local search methods to solve vehicle routing problems. In: International Conference on Principles and Practice of Constraint Programming, pp. 417–431. Springer, Berlin (1998)

  37. Boussemart, F., Lecoutre, C., Piette, C.: Xcsp3: An integrated format for benchmarking combinatorial constrained problems. arXiv preprint arXiv:1611.03398 (2016)

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to P. Van Hentenryck.

Additional information

Publisher's Note

Springer Nature remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

Appendices

Java closures

Java 1.8 supports the concept of closures (aka first-order functions) which is at the core of functional programming. The MiniCP solver makes extensive use of closures for more readibility and conciseness. Consider the identity function \(\lambda x.x\) expressed in lambda-calculus. It can be written in Java 1.8 as

figure az

The code indicates that Java provides a generic type \({\texttt {Function<A,B>}}\) to represent a function of type \(A \rightarrow B\). and r is used to refer to the identity function. The next two lines show how to apply closure r for various values. Since this example is somewhat verbose, Java 1.8 offers syntactic sugar to simplify the notation, dropping the argument type, the block syntax, and the return keyword to obtain

figure ba

This brings the definition of r close to a lambda calculus definition. Java 1.8 also makes it possible to define arbitrary closure types through the concept of functional interface. For instance, the snippet

figure bb

defines the type of a closure that takes no input and return no outputs. It just executes a block of code. MiniCP also makes extensive use of functional interfaces defined in the JDK 1.8. For instance, a branching (closure returning an array of Procedure) is none other than \({\texttt {Supplier<Procedure[]>}}\). Boolean predicates over some type T (i.e., first-order functions of type \(T \rightarrow \mathbb {B}\) use \({\texttt {Predicate<T>}}\) while first-order functions of type \(T \rightarrow N\) use \({\texttt {Function<T,N>}}\).

Performance evaluation

The objective of those experiments is to measure the raw performances of the basic funtionalities offered by a solver: backtracking and propagation mechanisms, domains, search, etc. Our goal is to measure if, despite its simplicity, MiniCP achieve reasonable performance when compared to carefully engineered and optimized solvers, including Choco [14] (version 4.0.2) implemented in Java and OscaR [9] (version 4.0.0) implemented in Scala. Both [14] and [9] have more than 50K lines of code. The MiniCP version used in the test is 1.0.1. Table 3 was obtained on a MacBook Pro with a 2.6Ghz 6-Core i7 running macOS Catalina 10.15.1. The Java version used is

figure bc

Runtime were obtained by using the time command of the operating system as in, for instance:

figure bd

and reporting the wall clock time.

Table 3 Performance comparison with Choco [14] and OscaR [9]

In state-of-the-art solvers, great care is dedicated to the efficient implementation of global constraints. Since comparing implementations of global constraints is not the purpose of this evaluation, the models used in the experiments and available here https://zenodo.org/record/3557449 are quite simple and composed of sum, elements, reification and binary constraints. The experimental evaluation ensures that the same search trees is explored by all the solvers. The evaluation also forces a sparse-representation of the domains as this is the only available option in MiniCP in the base implementation.

Table 3 presents the results and running times are given in seconds. The performance of MiniCP is reasonably good despite its simplicity, flexibility and the fact that we explicitly refrain from optimizing the implementation. For instance, the code uses Java collections which induce a significant overhead due to object and iterator creations; An optimized solver such as OscaR or Choco often uses its own array-based collections. Boolean variables in MiniCP are simply 0/1 integer variables, while OscaR uses a dedicated implementation. OscaR statically pre-allocates frequently used objects to avoid the dynamic creation of StateEntries. Aside from this lack of optimization in memory management, the performance difference can be explained by the fact that OscaR and Choco have a priority system to schedule light constraints before more complex ones. While the default implementation of MiniCP has no constraint priorities, adding the necessary support is straightforward and un-intrusive. First, one must add a constant attribute (and an accessor) to each constraint instance to hold onto a priority level (a value from a discrete subset of integers, e.g., 0 through k where k is the highest priority). Second, the state of MiniCP solver class (Listing 15) must be upgraded to hold onto a vector of \({\texttt {Queue<Constraint>}}\), one for each discrete priority. Third, when a constraint c is scheduled, it gets added to the propagation queue matching c’s priority (changes to method schedule of MiniCP. Finally, the fixpoint algorithm (method fixPoint of MiniCP) must, at each iteration, determine the highest non-empty priority queue and pull the next constraint from there. Once all queues become empty, the fixpoint is reached and one can break out of the loop.

Rights and permissions

Reprints and permissions

About this article

Check for updates. Verify currency and authenticity via CrossMark

Cite this article

Michel, L., Schaus, P. & Van Hentenryck, P. MiniCP: a lightweight solver for constraint programming. Math. Prog. Comp. 13, 133–184 (2021). https://doi.org/10.1007/s12532-020-00190-7

Download citation

  • Received:

  • Accepted:

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s12532-020-00190-7

Navigation