Constraint propagation is your friend Ian Horswill and Leif Foged Northwestern University.

Slides:



Advertisements
Similar presentations
Im not paying that! Mathematical models for setting air fares.
Advertisements

CS492B Analysis of Concurrent Programs Lock Basics Jaehyuk Huh Computer Science, KAIST.
Sub Exponential Randomize Algorithm for Linear Programming Paper by: Bernd Gärtner and Emo Welzl Presentation by : Oz Lavee.
Efficiency of Algorithms
Techniques for Dealing with Hard Problems Backtrack: –Systematically enumerates all potential solutions by continually trying to extend a partial solution.
Lecture 2. A Day of Principles The principle of virtual work d’Alembert’s principle Hamilton’s principle 1 (with an example that applies ‘em all at the.
Constraint Processing and Programming Introductory Exemple Javier Larrosa.
CSE 380 – Computer Game Programming Pathfinding AI
P Chapter 6 introduces the stack data type. p Several example applications of stacks are given in that chapter. p This presentation shows another use called.
Example 6.1 Capital Budgeting Models | 6.3 | 6.4 | 6.5 | 6.6 | Background Information n The Tatham Company is considering seven.
CSE506: Operating Systems Block Cache. CSE506: Operating Systems Address Space Abstraction Given a file, which physical pages store its data? Each file.
Operations Management Dr. Ron Lembke
CS448f: Image Processing For Photography and Vision Graph Cuts.
CSE332: Data Abstractions Lecture 12: Introduction to Sorting Tyler Robison Summer
Concurrent & Distributed Systems Lecture 3: Processes interacting by sharing resources Asynchronous processes can interact by sharing a common resource.
Ryan Kinworthy 2/26/20031 Chapter 7- Local Search part 1 Ryan Kinworthy CSCE Advanced Constraint Processing.
Quicksort.
A game of logic where the player must assign the numbers 1..9 to cells on a 9x9 grid. The placement of the numbers must be such that every number must.
CS121 Heuristic Search Planning CSPs Adversarial Search Probabilistic Reasoning Probabilistic Belief Learning.
Code Generation CS 480. Can be complex To do a good job of teaching about code generation I could easily spend ten weeks But, don’t have ten weeks, so.
Scientific Method Study Guide
State-Space Searches.
CSCI 101 Introduction to Software Development and Design.
Final Exams!. Where do I go/What do I do? After break, report to the gym. You will need to find your row and seat numbers. See below for Monday’s seating.
Noadswood Science,  To know the basics of Python coding and decoding Monday, September 07, 2015.
Session Title: Managing by Influence Presenter Name: Thierry Roullier
CP Summer School Modelling for Constraint Programming Barbara Smith 1.Definitions, Viewpoints, Constraints 2.Implied Constraints, Optimization,
Test Taking Skills. Study in a comfortable place where you won’t be distracted. Schedule review time. Don’t leave it to the last minute. Write a study.
Example 15.1 Daily Scheduling of Postal Employees Workforce Scheduling Models.
Using Hardware Scheduling Methods Peter Lieber ECEn December 2009.
Week 5 - Monday.  What did we talk about last time?  Linked list implementations  Stacks  Queues.
Week 5 - Wednesday.  What did we talk about last time?  Exam 1!  And before that?  Review!  And before that?  if and switch statements.
Local Search Algorithms This lecture topic Chapter Next lecture topic Chapter 5 (Please read lecture topic material before and after each lecture.
Tips to Help you Study. Time management is hard for a lot of us. If you divide what you have to study into manageable chunks, it makes it a lot easier.
State-Space Searches. 2 State spaces A state space consists of A (possibly infinite) set of states The start state represents the initial problem Each.
CP Summer School Modelling for Constraint Programming Barbara Smith 2. Implied Constraints, Optimization, Dominance Rules.
Constraint Satisfaction CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Honors Track: Competitive Programming & Problem Solving Optimization Problems Kevin Verbeek.
The Science of Procrastination. How often do you put off something you SHOULD be doing and wait until much, much later to try to get it done? How often.
Schreiber, Yevgeny. Value-Ordering Heuristics: Search Performance vs. Solution Diversity. In: D. Cohen (Ed.) CP 2010, LNCS 6308, pp Springer-
Sorting: Implementation Fundamental Data Structures and Algorithms Klaus Sutner February 24, 2004.
Announcement "A note taker is being recruited for this class. No extra time outside of class is required. If you take clear, well-organized notes, this.
INSTRUCTIONS 1. Click SAVE AS – “NAME’s user name Info Book” 2. Type all of your information first, paying careful attention to what goes where. These.
How to Improve Your Grades Are your grades rather low? Maybe it's the beginning of school, and your not getting off to a good start. Well, this easy to.
Management Science 461 Lecture 3 – Covering Models September 23, 2008.
Tank Game Part 3 of 6. Secondary Weapons and Pick ups Pick ups will appear randomly in the battle area and can be collected by driving into them. Each.
Lecture 8CSE Intro to Cognitive Science1 Interpreting Line Drawings II.
Copyright © 2014 Curt Hill Algorithms From the Mathematical Perspective.
Sliding blocks puzzle solver Mike Clancy U.C. Berkeley CS Division.
Nuclear Throne Evaluation -By Chris Murdoch. Nuclear Throne Info -Developed by Vlambeer -Roguelike Overhead Shooter -$13 on Steam Store.
Review Array Array Elements Accessing array elements
CS Fall 2016 (Shavlik©), Lecture 11, Week 6
Local Search Algorithms
Using a Stack Chapter 6 introduces the stack data type.
Using a Stack Chapter 6 introduces the stack data type.
Experimental Plan? Who needs a plan anyway??.
Game Evaluation Bloodborne
Using a Stack Chapter 6 introduces the stack data type.
Constraints and Search
Using a Stack Chapter 6 introduces the stack data type.
Constraint satisfaction problems
Artificial Intelligence
Min Heap Update E.g. remove smallest item 1. Pop off top (smallest) 3
State-Space Searches.
Constraint Satisfaction
Local Search Algorithms
State-Space Searches.
State-Space Searches.
Constraint satisfaction problems
Local Search Algorithms
Presentation transcript:

Constraint propagation is your friend Ian Horswill and Leif Foged Northwestern University

Constraint programming ● Declarative programming technique ● For configuration problems ● Choices (variables) ● Requirements (constraints) ● Find choices that satisfy requirements

Take-home messages ● Constraint programming can be fast ● It can solve useful problems ● It’s not mysterious rocket science ● You can implement it in a weekend ● Relatively designer friendly

Simple example: level population ● Placing items and enemies (e.g. for roguelikes) ● One variable for each room ● Possible values ● Enemies (zombie, ghost, etc.) ● Resources (ammo, health) ● Keys and locks ● Boss

Common constraints ● There should be one boss ● One variable should have the value “boss”, but I don’t care which one ● There should be 5-10 enemies ● Again, don’t care where

Common constraints ● There should be enough bullets ● #enemies < k×#ammo ● Adjust k to taste ● There shouldn’t be too many bullets ● Change

Shigi lite™

Quick example ● 6 rooms ● One variable per room ● Values: health pack, enemy, ammo, nothing ● Constraints ● 1 health pack ● At least 1 enemy ● As many ammo packs as enemies

Solving it Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Constraints 1 health pack At least 1 enemy #ammo = #enemies Assume any room can have any value

Solving it Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Constraints 1 health pack At least 1 enemy #ammo = #enemies Pick a room

Solving it Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Constraints 1 health pack At least 1 enemy #ammo = #enemies Pick a value (cross off other values)

Solving it Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Constraints 1 health pack At least 1 enemy #ammo = #enemies No other room can have a health pack (cross off health)

Solving it Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Constraints 1 health pack At least 1 enemy #ammo = #enemies Pick another room

Solving it Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Constraints 1 health pack At least 1 enemy #ammo = #enemies Pick a value

Solving it Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Constraints 1 health pack At least 1 enemy #ammo = #enemies Pick another room

Solving it Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Constraints 1 health pack At least 1 enemy #ammo = #enemies Pick a value

Solving it Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Constraints 1 health pack At least 1 enemy #ammo = #enemies Pick another room

Solving it Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Constraints 1 health pack At least 1 enemy #ammo = #enemies Pick a value

Solving it Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Constraints 1 health pack At least 1 enemy #ammo = #enemies Not enough rooms left for more enemies (cross off enemy)

Solving it Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Constraints 1 health pack At least 1 enemy #ammo = #enemies Pick a room

Solving it Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Constraints 1 health pack At least 1 enemy #ammo = #enemies Pick a value

Solving it Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Constraints 1 health pack At least 1 enemy #ammo = #enemies Last room has to be ammo

Solving it Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Enemy Health Ammo Nothing Constraints 1 health pack At least 1 enemy #ammo = #enemies Done

Constraint propagation (AC-3) ● Track remaining values for variables ● Repeat until all variables have 1 value ● Pick a variable w/more than 1 value ● Pick a value from its remaining values ● Narrow values for other variables ● No possible values remaining? ● Then you picked wrong, backtrack

Wait! Room order matters! weapon you need to kill boss boss Bad: boss weapon you need to kill boss Good:

Constraints on resource availability ● Add extra variable for each room ● Resource acquired on path to room ● Minus amount used on path to room ● Handle forks/joins by taking min or max ● This example: +1 for weapon, -1 for boss ● Constraint: ≥0 ● This example: (weapon-boss)≥0

Boss with weapon availability weapon you need to kill boss boss Bad: boss weapon you need to kill boss Good: Weapon: 1Weapon: 0 Weapon: -1Weapon: 0

This trick works for ● Lock and key puzzles ● Ensure key before lock ● Health/ammo survivability ● Ensure health/ammo is sufficient ● Ensure health/ammo is in useful locations ● Health/ammo difficulty ● Ensure there isn’t too much health/ammo

A more interesting level ● Resident Evil 1F mansion west wing ● 17 rooms, 16 doors ● Item/enemy placement ● Health/ammo survivability

Speed (C# implementation) ● Easy: minimal constraints (94μsec) ● 1-7 health packs, 1-5 zombies, 1-3 double zombies ● Medium: cram stuff into limited rooms (900μsec) ● 1-40 HP, ammo, zombie & double zombie; 1-2 dogs, 1 trap ● Hard: force exact numbers of items (8ms) ● 1-40 HP; exactly 3 ammo, 2 zombie, 2 double zombie, 1 trap; 1-2 dogs 1-5kW RAM for data structures and stack

Demo 1: This is fast

Model ● 15 rooms 15 variables 0 constraints Avg. solve time: 15µs

Model ● 53 variables 36 constraints Avg. solve time: 235µs

Model ● 170 variables 175 constraints Avg. solve time: 1ms

Demo 2: You can give designers control

Dynamic difficulty ● Pin the content the player has seen ● Regenerate everything else to satisfy objectives

Design checkers/automators See the work of Gillian Smith and Adam Smith for great examples!

Build-a-bears

The catch ● Easy CP problems run in linear time ● E.g. lots of rooms, few objects and constraints ● Lots and lots of solutions ● System usually hits one on the first try ● Hard ones run in exponential time ● E.g. barely enough rooms, highly constrained ● Very few solutions ● System has to try all/most possible assignments

When should you use it? ● When there are lots of solutions ● You don’t care which you use ● Want random choice for variety

Links ● “How to build a constraint propagator in a weekend”: bit.ly/constraints-how-to ● Reference solver (C#): bit.ly/constraint-thingybit.ly/constraint-thingy ● AIIDE paper: bit.ly/aiide-paperbit.ly/aiide-paper ● Unity starter kit: bit.ly/angry-bots-constraintbit.ly/angry-bots-constraint