Constraint Satisfaction & AI Planning

Fundamental Approaches to Problem Solving in Artificial Intelligence

Dr. Dhaval Patel • 2025

index

Today we'll explore two powerful ways that computers solve complex problems and make smart decisions.

  • Constraint Satisfaction Problems (CSP) - How to solve puzzles with rules and restrictions
  • Graph Coloring - Coloring maps and graphs without breaking the rules
  • Math Puzzles - Solving letter-to-number puzzles step by step
  • AI Planning - How computers make step-by-step plans to reach goals
  • Different Planning Methods - Various ways computers can think ahead and plan
  • Real-World Uses - How these ideas help robots, delivery services, hospitals, and games
Goal: Learn how computers solve complex problems and make smart decisions automatically.

Part I: Constraint Satisfaction

Systematic Problem Solving Through Constraint Propagation

What Are Constraint Satisfaction Problems?

Think of constraint satisfaction problems like solving puzzles with rules. You have to find solutions that follow all the rules at the same time.

Simple Definition: A way to solve problems by finding answers that satisfy all the given rules and restrictions.
  • Tell the Computer What You Want: Describe the rules instead of how to solve it
  • Rule Checking: The computer automatically checks if rules are broken
  • Smart Searching: When something doesn't work, go back and try something else
  • Real Problems: Perfect for scheduling, organizing, and arranging things

Unlike finding the shortest path, constraint problems focus on finding any solution that works rather than finding the best route to get somewhere.

The Building Blocks of Constraint Problems

Things & Their Options

Variables: The things you need to assign values to

  • Like empty boxes that need to be filled
  • Each box has a clear label and purpose
  • Could be time slots, colors, or numbers

Domains: The possible choices for each thing

  • All the options available for each box
  • Options get smaller as we make choices
  • Could be colors (red, blue) or numbers (1-9)

Rules & Relationships

Constraints: The rules that limit our choices

  • Simple Rules: Rules about just one thing
  • Pair Rules: Rules about how two things relate
  • Group Rules: Complex rules involving many things
Key Idea: As we make choices, the remaining options automatically get smaller, making the problem easier to solve.

Solving these problems means finding choices that make all the rules happy at the same time.

Strategic Importance of CSP in AI Systems

Constraint satisfaction problems form the computational foundation for numerous AI applications where intelligent agents must make decisions under complex restrictions.

  • Autonomous Planning: Robot path planning with obstacle avoidance and resource constraints
  • Resource Allocation: Optimal assignment of computing resources, scheduling, and logistics
  • Configuration Management: Software deployment, network configuration, and system design
  • Knowledge Representation: Modeling complex relationships and dependencies in knowledge bases
  • Machine Learning: Constraint-based learning algorithms and neural network architecture search
Critical Understanding: CSP provides a unified framework for modeling diverse AI problems, enabling systematic solution approaches and efficient search algorithms.

The ability to model real-world problems as constraint satisfaction problems and apply systematic search with backtracking is essential for developing robust, scalable AI systems that can handle complex decision-making scenarios.

Smart Trial and Error: Backtracking

Backtracking is like smart trial and error. Instead of trying everything randomly, we learn from our mistakes and avoid making the same errors again.

Key Idea: Only change your mind when you hit a dead end - don't waste time exploring paths that can't work.
  • Spot Problems Early: Notice right away when rules are broken
  • Update Automatically: When you make a choice, automatically update what's still possible
  • Go Back When Stuck: Return to your last decision when you hit a dead end
  • Skip Useless Paths: Jump directly to the source of the problem
  • Remember Mistakes: Keep track of what doesn't work to avoid repeating errors

Understanding when to go back and try something different is crucial for solving complex puzzles efficiently.

Important Skill: Learn to spot all the hidden rules in a problem before you start solving it.

CSP vs Traditional Search Paradigms

Traditional Search

  • Focus on finding paths from initial to goal states
  • Explores state transitions sequentially
  • Goal: Discover sequence of actions
  • Example: A* pathfinding, game tree search
Emphasis on navigation through state space

Constraint Satisfaction

  • Focus on finding consistent variable assignments
  • Explores constraint relationships systematically
  • Goal: Discover valid configuration
  • Example: Sudoku, scheduling, configuration
Emphasis on satisfaction of multiple constraints
VS

How to Set Up Problems the Right Way

Setting up a problem correctly is half the battle. If you describe the problem wrong, even the best solution methods won't work well.

Problem Setup Steps:
1. Identify what decisions need to be made
2. List what choices are available for each decision
3. Write down all the rules and restrictions
4. Double-check that everything important is included
  • Pick the Right Things: Choose things that represent actual decisions, not calculated results
  • Balance Choices: Not too few options (might miss solutions) or too many (gets complicated)
  • Find All Rules: Look for both obvious and hidden rules that limit choices
  • Check for Conflicts: Make sure the rules don't make the problem impossible to solve
  • Verify Completeness: Confirm all real-world requirements are captured in the rules

Master this systematic approach before jumping into specific problems. A well-described problem is much easier to solve.

Graph Coloring Problems

Systematic Constraint Checking and Conflict Resolution

Interactive Graph Coloring Demonstration

1 2 3 4
Click a node, then select a color to assign

CSP Formulation

Variables: V = {1, 2, 3, 4}

Domain: D = {Red, Green, Blue}

Constraints:

  • Adjacent nodes must have different colors
  • 1 ≠ 2, 1 ≠ 3, 2 ≠ 4, 3 ≠ 4
Try assigning colors to see constraint propagation in action!

Node Domains:

Real-World Applications of Graph Coloring

Understanding how graph coloring relates to scheduling, register allocation, and frequency assignment problems demonstrates the practical importance of this fundamental CSP.

  • Course Scheduling: Assign time slots to courses such that students with overlapping enrollments don't have conflicts
  • Register Allocation: Assign CPU registers to program variables with overlapping lifetimes
  • Frequency Assignment: Assign radio frequencies to transmitters to avoid interference
  • Map Coloring: Color geographical regions so adjacent areas have different colors
  • Sudoku Solving: Each cell represents a variable with constraints on rows, columns, and blocks
  • Compiler Optimization: Graph coloring for optimal code generation and resource utilization
Key Insight: Graph coloring provides a general framework for any problem involving resource allocation with conflict avoidance.

The systematic approach to constraint checking and conflict resolution in graph coloring translates directly to these complex real-world scenarios.

Graph Coloring Solution Process

Step 1

Initialize All Domains

Start with all nodes having full domain: {Red, Green, Blue}. No assignments made yet, all possibilities remain open.

Node 1: RGB | Node 2: RGB | Node 3: RGB | Node 4: RGB
Step 2

Assign Node 1 = Red

Make first assignment. Apply constraint propagation: adjacent nodes (2, 3) can no longer be Red.

Node 1: R | Node 2: GB | Node 3: GB | Node 4: RGB
Step 3

Assign Node 2 = Green

Choose Green for node 2. Propagate constraint: node 4 (adjacent to 2) cannot be Green.

Node 1: R | Node 2: G | Node 3: GB | Node 4: RB
Step 4

Assign Node 3 = Blue

Assign Blue to node 3. Propagate: node 4 (adjacent to 3) cannot be Blue. Domain becomes {Red}.

Node 1: R | Node 2: G | Node 3: B | Node 4: R
Step 5

Complete Assignment

Node 4 automatically gets Red (only remaining option). Verify all constraints satisfied.

Final: 1=Red | 2=Green | 3=Blue | 4=Red

When Backtracking Becomes Necessary

Understanding conflict scenarios and recovery mechanisms is essential for mastering constraint satisfaction algorithms.

Conflict Scenario: What happens when our current assignments lead to an empty domain for some variable?

Consider a different assignment sequence for our 4-node graph:

Initial: Node 1: RGB | Node 2: RGB | Node 3: RGB | Node 4: RGB
Step 1: Node 1 = Red → Node 2: GB | Node 3: GB | Node 4: RGB
Step 2: Node 2 = Green → Node 1: R | Node 3: B | Node 4: RB
Step 3: Node 4 = Red → Node 1: R | Node 2: G | Node 3: B | Node 4: R
SUCCESS! All constraints satisfied with this assignment.
  • Conflict Detection: Recognize when domain becomes empty or constraint violated
  • Backtrack Point: Return to most recent decision that can be changed
  • Alternative Exploration: Try next available value in domain
  • Constraint Re-propagation: Update all affected domains after backtrack

This systematic process ensures we explore all possibilities without missing valid solutions.

Graph Coloring Complexity Metrics

O(k^n)
Worst Case
k colors, n nodes - exponential without pruning
80%
Pruning Effect
Constraint propagation reduces search space significantly
NP-C
Complexity Class
Graph k-coloring is NP-Complete for k ≥ 3
4CT
Four Color Theorem
Planar graphs always 4-colorable (proven 1976)
Practical Insight: While theoretically hard, real-world graph coloring problems often have structure that makes them tractable with proper heuristics and constraint propagation.

Advanced Constraint Propagation Techniques

Forward Checking

  • After each assignment, remove inconsistent values from future variables
  • Detects conflicts early in search process
  • Significantly reduces backtracking overhead
  • Maintains arc consistency during search

Variable Ordering Heuristics

  • Most Constrained Variable: Choose variable with smallest domain
  • Most Constraining Variable: Choose variable involved in most constraints

Value Ordering Heuristics

  • Least Constraining Value: Choose value that eliminates fewest options
  • Preserves maximum flexibility for future assignments
  • Reduces likelihood of backtracking
  • Particularly effective in dense constraint graphs

Arc Consistency

  • Ensures every value in domain has supporting value in adjacent variables
  • AC-3 algorithm for preprocessing
  • Dramatically reduces search space

Cryptarithmetic Problems

Complex Constraint Propagation and Intelligent Backtracking

Letter-to-Number Puzzles

Cryptarithmetic puzzles are like secret codes where letters hide numbers. You need to figure out which number each letter represents to make the math work correctly.

The Challenge: Replace each letter with a number (0-9) so the math equation is correct, following all the rules.
  • One Letter, One Number: Each letter can only represent one specific number
  • No Sharing: No two letters can represent the same number
  • Math Must Work: The equation must be mathematically correct when solved
  • No Leading Zeros: The first letter in a word usually can't be zero
  • Carrying Numbers: Addition might involve carrying over, just like regular math

These puzzles teach us advanced problem-solving skills like making smart guesses, systematic backtracking, and rule checking.

Learning Goal: Practice making systematic choices and checking rules to develop problem-solving intuition.

Interactive Cryptarithmetic: TO + GO = OUT

TO
+ GO
-------
OUT
T
?
{0,1,2,3,4,5,6,7,8,9}
O
?
{1,2,3,4,5,6,7,8,9}
G
?
{0,1,2,3,4,5,6,7,8,9}
U
?
{0,1,2,3,4,5,6,7,8,9}
Click a letter, then enter a digit to assign

Constraint Analysis

  • Uniqueness: T ≠ O ≠ G ≠ U
  • Leading Zero: T ≠ 0, O ≠ 0 (leftmost digits)
  • Arithmetic: TO + GO = OUT
  • Single Carry: Maximum one carry operation
Strategy: Start with leftmost column analysis - O must equal 1 for valid carry

Key Insight: The leftmost result is O, so T + G must generate exactly 10 (carry of 1).

Step-by-Step Solution: TO + GO = OUT

Step 1

Analyze Leftmost Column

In position: T + G = O (with possible carry from right)

Since result starts with O, and we need single carry: O = 1

T + G = 10 (to produce carry and O=1)
Step 2

Determine T from Carry Analysis

Since T + G = 10 and digits are 0-9, and O = 1:

The equation becomes: T = O + O = 1 + 1 = 2

T = 2, O = 1
Step 3

Solve for G

From T + G = 10 and T = 2:

2 + G = 10, therefore G = 8

T = 2, O = 1, G = 8
Step 4

Determine U from Rightmost Column

Rightmost: O + O = UT (where T=2, O=1)

1 + 1 = 2, but we need carry generation: U = 0

Final: T=2, O=1, G=8, U=0
Verify

Solution Verification

Check: 21 + 81 = 102 ✓

All constraints satisfied: unique digits, valid arithmetic, single carry

Solution: T=2, O=1, G=8, U=0

Part II: AI Planning

Strategic Action Sequence Generation for Goal Achievement

Thank You

Questions & Discussion

Continue exploring AI • Build intelligent systems • Shape the future