Measuring With Jugs A Solution in Finite Domain. Outline The Puzzle The Algorithm Introduction to Oz3 Implementation in Oz3.

Slides:



Advertisements
Similar presentations
The Algorithmic problems?
Advertisements

Andrew C. Samuels, Information Technology Specialist Trainer c/o Ministry of Education Mona High School, Kingston, Jamaica 1 Problem Solving Section 2:
State Space Search I Chapter 3
What is a State Transition Diagram? Why are they used? How to draw them.
Search in Python Chapter 3.
Chapter 1 An Overview of Computers and Programming Languages.
Section 4.1: The Basics of Counting As we have seen, one way to count the number of objects in a finite set S is to produce a one-to-one correspondence.
State Space Search Classic AI.
4. PROLOG Data Objects And PROLOG Arithmetic
Best-First Search: Agendas
Your Guide to Successfully Using Scientific Method! Created for the teachers at Mauro-Sheridan Interdistrict Magnet School by Monique M. Gibbs.
Expert System Human expert level performance Limited application area Large component of task specific knowledge Knowledge based system Task specific knowledge.
Trees Chapter Chapter Contents Tree Concepts Hierarchical Organizations Tree Terminology Traversals of a Tree Traversals of a Binary Tree Traversals.
Using Search in Problem Solving
Trees. 2 Definition of a tree A tree is like a binary tree, except that a node may have any number of children Depending on the needs of the program,
Is ASCII the only way? For computers to do anything (besides sit on a desk and collect dust) they need two things: 1. PROGRAMS 2. DATA A program is a.
Measuring With Jugs A Solution in Finite Domain. Intro to Oz * variables -- a set of alphanumeric characters starting with a CAPITAL letter * atoms --
Aho-Corasick String Matching An Efficient String Matching.
Trees. Definition of a tree A tree is like a binary tree, except that a node may have any number of children –Depending on the needs of the program, the.
Measuring With Jugs A Solution in Finite Domain. Intro to Mozart - Oz variables -- a set of alphanumeric characters statring with a CAPITOL letter – you.
Mini-Pascal Compiling Mini-Pascal (MPC) language
Programming Fundamentals (750113) Ch1. Problem Solving
Methods: a first introduction Two ways to make tea: 1: boil water; put teabag into cup;... etc : tell your younger brother: makeTea(1 milk, 0 sugar);
Lexical Analysis The Scanner Scanner 1. Introduction A scanner, sometimes called a lexical analyzer A scanner : – gets a stream of characters (source.
CSE341: Programming Languages Lecture 11 Type Inference Dan Grossman Winter 2013.
The Fundamentals: Algorithms, the Integers & Matrices.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
DEDUCTIVE DATABASE.
Fundamentals of Python: From First Programs Through Data Structures Chapter 14 Linear Collections: Stacks.
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Production Systems A production system is –a set of rules (if-then or condition-action statements) –working memory the current state of the problem solving,
1 Introduction to Quantum Information Processing CS 467 / CS 667 Phys 467 / Phys 767 C&O 481 / C&O 681 Richard Cleve DC 653 Course.
State Space Search. State Space representation of a problem is a graph  Nodes correspond to problem states  Arcs correspond to steps in a solution process.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Today’s Topics FREE Code that will Write Your PhD Thesis, a Best-Selling Novel, or Your Next Methods for Intelligently/Efficiently Searching a Space.
Introduction to Algorithms By Mr. Venkatadri. M. Two Phases of Programming A typical programming task can be divided into two phases: Problem solving.
Problems, Problem Spaces and Search
Programming Test #1 Solutions. Multiple Choice 1. B) the grammar of the coding language 2. C) String 3. A) Single 4. C) 2Burgers4Me 5. B) Design Time.
1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture of a compiler PART II:
Introduction to Algorithms Chapter 16: Greedy Algorithms.
Prog. techniques. Standard prog. techniques Complex programs can be broken down into simpler parts called “Modules” These come in 2 types,“Procedures”
CPSC 433 Artificial Intelligence Search Modeling Practice Problems M. Reza Zakerinasab Please include [CPSC433] in the subject line.
JAVA: An Introduction to Problem Solving & Programming, 6 th Ed. By Walter Savitch ISBN © 2012 Pearson Education, Inc., Upper Saddle River,
22/11/ Selection If selection construct.
1 Introduction  Algorithms  Data structures  Abstract data types  Programming with lists and sets © 2008 David A Watt, University of Glasgow Algorithms.
ITP © Ron Poet Lecture 6 1 More on if. ITP © Ron Poet Lecture 6 2 Remembering Tests  We often want to remember the result of a test, so that we can use.
Your brain and the machine ACO101: Introduction to Computer Science.
Clearly Visual Basic: Programming with Visual Basic 2008 Chapter 11 So Many Paths … So Little Time.
Chapter 10 So Many Paths … So Little Time (Multiple-Alternative Selection Structures) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Overview of Previous Lesson(s) Over View  A token is a pair consisting of a token name and an optional attribute value.  A pattern is a description.
Jugs An Investigation Jugs A girl wishes to measure out 4 litres of water. She has only two jugs which, when full, hold 3 litres and 5 litres respectively.
CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014 Design and Analysis of Algorithms.
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
CS0004: Introduction to Programming
Maths problem-solving with Bruce Willis and Samuel L. Jackson
CSE341: Programming Languages Lecture 11 Type Inference
Chapter 15 Recursion.
DDC 2423 DATA STRUCTURE Main text:
Computational Thinking, Problem-solving and Programming: General Principals IB Computer Science.
Chapter 15 Recursion.
Introduction to Programming
Introduction Defining the Problem as a State Space Search.
Section 3.2c Strings and Method Signatures
OPERATORS (1) CSC 111.
Optimizing Malloc and Free
Affiliation of presenter
Unit-1 Introduction to Java
Programming Fundamentals (750113) Ch1. Problem Solving
Declarative Computation Model Single assignment store (VRH 2
Presentation transcript:

Measuring With Jugs A Solution in Finite Domain

Outline The Puzzle The Algorithm Introduction to Oz3 Implementation in Oz3

The Puzzle Given a set of jugs, and an unlimited supply of water, how would you measure out a quantity of water. Rules Unlimited Supply of water When a jug is poured into, it must be filled to capacity( unless there is not enough to fill it) Any jug may be emptied.

Example Given a 5 liter jug, a 3 liter jug, how do you measure out exactly 4 liters? Solution: Fill the 5 liter jug, empty it into the 3 liter jug leaving the 5 liter with 2 liters. Empty the 3 liter jug. Pour 2 liters from the 5 liter jug into the 3 liter jug. Fill the 5 liter jug. Pour 1 liter into the 3 liter jug to fill it. % liter jug now has 4 liters!

A Bit of History “Classic Mind Teaser” Puzzle was explored in “Measuring With Jugs” by Boldi, Santini and Vigna. In “Die Hard III”

The Algorithm This can be broken down fairly since the only important quantities are the capacities of the jugs and the final volume. So… Number of filling operations-Number of emptying operations=Final CapA*TimesA-CapB*TimesB=Final

Constraint Programming Constraint programming applies constraints given by the programmer to limit choices …

Intro to Oz variables -- a set of alphanumeric characters starting with a CAPITOL letter atoms -- set of alphanumeric characters beginning with a lower case letter (anAtom in Java would be "anAtom") keywords – declare, fun, Browse, Search

Other Neat Stuff Virtual string: a#b#C Virtual string: a#b#C Record: root(a b e o p) Record: root(a b e o p) List: [a 1 r B 24.6] List: [a 1 r B 24.6] Anonymous function: Anonymous function: fun{$ A B} ……. end fun{$ A B} ……. end

Oz Program declare declare fun{Factors Number} fun{Factors Number} fun{FactsIter Fact Number} fun{FactsIter Fact Number} if Fact == Number then [Fact] if Fact == Number then [Fact] elseif (Number mod Fact==0) then Fact|{FactsIter 2 (Number div Fact)} elseif (Number mod Fact==0) then Fact|{FactsIter 2 (Number div Fact)} else {FactsIter Fact+1 Number} else {FactsIter Fact+1 Number} end end in in {FactsIter 2 Number} {FactsIter 2 Number} end end {Browse {Factors 740}} {Browse {Factors 740}}

Constraint Programming Applied CapA*TimesA-CapA*TimesANeg Each jug is represented by a virtual string CapX#XTimesX#Conts show output explain output numbers

Numbers to Operations Introduction Structure of functions Code bits Final output

Overview Each jug is represented by a virtual string CapX#XTimesX#Conts Series of operations is represented by a List

Main Functions in JugsExten.oz DoSomething - all of the emptying and filling operations are performed in this function Combine2 – combines the contents of a list of jugs and writes a path that pours all into largest Combine -- combines all jugs into largest and writes a path WritePath -- Uses previous functions to Write a path describing all operations Jugs -- finite domain portion of program to find numbers

Bits Of Code -- Combine % Combines contents of all of the jugs into the largest fun{Combine Jugs} X List Total in {GCap Jugs List X _} Total={SumList3 X|List _} {Combine2 List X.1}|[to get Total] end

Output from Jugs7.oz CapA=6 CapB=10 CapC=15

JugsExten.oz Output

Conclusion This shows that Finite Domain Constraint Programming is useful for areas where it might not at first seem useful.