Category: 

What Is Constraint Programming?

Article Details
  • Written By: Alex Tree
  • Edited By: Heather Bailey
  • Last Modified Date: 30 October 2016
  • Copyright Protected:
    2003-2016
    Conjecture Corporation
  • Print this Article
Free Widgets for your Site/Blog
Although they mainly functioned as downspouts, gargoyles were also intended to scare people into attending church.  more...

December 3 ,  1989 :  The Cold War officially ended.  more...

Constraint programming is a form of declarative programming that uses mathematical constraints to define how variables within the program relate to each other. These types of programming techniques typically interact with other types of programming techniques, such as logical and imperative techniques. These logical and imperative techniques do precisely what constraint programming avoids, logically progressing through computational statements and executing changes. Constraint programming is often combined with logic programming to form constraint logic programming, which is an extended version of logic programming. Logic programming includes literal requirements and comparisons of variables, and constraint logic programming extends this to include constraints.

A constraint is an advanced mathematical term, but it is essentially a condition that must be satisfied when making a decision. This is a simplistic definition, and the programming paradigm is best understood when a user has a solid grasp of mathematics. When looking at constraints as they relate to constraint programming, constraints map out how variables in the program must relate to each other.

Declarative programming is a programming paradigm that does not involve dictating how each individual step of a program is carried out, or executed. Instead of focusing on the steps, these types of languages specify or declare computational relationships. Constraint programming is a type of declarative programming because logic is expressed and explained, instead of systematically executed one step at a time.

Ad

In computer programming, variables have a definition that can be a bit different from their mathematical definition. A variable can mean anything unless a computer program has defined its meaning. At first glance, when it is said that constraint programming uses constraints to define how variables must relate to each other, it may sound like this is not enough to write an entire computer program with. In reality, because computer programming variables can encompass an unlimited amount of data, defining specifics of how they must relate to each other has a very high level of programming power.

Constraint programming is a programming paradigm, which means it states fundamental ideas about what basic things mean that can be radically different compared to other programming paradigms. Different paradigms can do virtually anything in a different way than another language. One language may use sequential logic, while another one may not. Different paradigms often use different basic blocks of information and relationships to represent instructions. Many things that are fundamental to other programming paradigms, such as logically executing many lines in succession, are not used in constraint programming.

Ad

You might also Like

Recommended

Discuss this Article

Charred
Post 2

@SkyWhisperer - I’ve played with constraint based programming in the form of declarative programming, which the article talks about.

One such example is Windows Presentation Foundation, where a lot of the constraints are defined in the form of properties. In other words, properties replace code – not entirely of course, but in a lot of cases.

You do find yourself wanting to write procedures to accomplish the same results, but if you can get the hand of properties, you will, as you said, end up writing less code.

The other obvious benefit, at least in Windows Presentation Foundation, is that the code is easier to understand. You can study the properties and see what the programming is trying to do, rather than wading through miles and miles of “spaghetti code.”

SkyWhisperer
Post 1

Constraint programming is definitely a change in the way you think as a programmer. I took a constraint programming tutorial once and I found it to be tough sledding.

I understand what it’s supposed to do, but it’s totally unrelated to the way I typically program, which is procedural, step by step. When I come upon something that different, it’s a bit more challenging.

If I were learning a new procedural programming language however, it would be easier, because once you learn one procedural language you can learn another one.

Constraint programming requires a lot more thinking and preparation in advance, and forces you to state the problem in a minimum of words or “constraints.” In that sense, I suppose it’s more concise, but I think the learning curve is steep, for me anyway.

Post your comments

Post Anonymously

Login

username
password
forgot password?

Register

username
password
confirm
email