Preview

Constraint Logic Programming in Prolog: Hanjie Puzzle Solver

Good Essays
Open Document
Open Document
9928 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Constraint Logic Programming in Prolog: Hanjie Puzzle Solver
Constraint Logic Programming in Prolog:
Hanjie Puzzle Solver
Lu´ıs Cleto and Jo˜ao Marinheiro
FEUP-PLOG, Turma 3MIEIC05, Group 23
{ei11077,ei11129}@fe.up.pt
http://www.fe.up.pt

Abstract. The purpose of this project was to use constraint logic programming in Prolog to implement a solver for the 2D puzzle, Hanjie. For this purpose we used the clp(FD) library provided by SICStus Prolog
4.2.3, specifically the sum/3 and automaton/3 combinatorial constraints.
The program we developed is able to solve puzzles with dimensions up to 88x88, with only one possible solution, in less than one second. When there are multiple solutions, the execution time for the obtaining the first solution varies with the number of possible solutions.
These results show that the execution time of the program is primarily affected by the amount of possible results. While larger grid dimensions do increase the execution time, the increase is linear if the number of possible solutions is maintained. On the other hand, increasing the number of possible solutions will lead to an exponential growth in execution time. 1

Introduction

The goal of this project is to use constraint logic programming in Prolog to develop a logic program capable of solving a decision problem in the form of the 2D puzzle, Hanjie. This puzzle consists of a rectangular grid with ’clues’ on top of every column and to the left of every row that indicate the number and length of gray blocks in that column/row. To achieve this goal, first had to be chosen the data structures that would be used to represent the problem. It was decided to use lists of lists, containing the clues for each column/row in every sublist, and a similar structure for the puzzle grid where every sublist is a row of the grid. Every square of the grid can be either a 0 or a 1 where a 0 represents a blank square and 1 represents a gray square. Our implementation also allows the lists of clues to be partially or completely



References: 1. Russel, Stuart; Norvig, Peter: Artificial Intelligence: A Modern Approach. Pearson, New Jersey (2009) 2. Sterling, Lehon; Shapiro, Ehud: The Art of Prolog: Advanced Programming Techniques. The MIT Press, Massachusetts (1994) 3 5. Ullman, Jeffrey; Motwani, Rajeev; Hopcroft, John: Introduction to Automata Theory, Languages, and Computation. Addison-Wesley (2001) 6

You May Also Find These Documents Helpful

  • Good Essays

    CGS 2531 Notes Ch. 1-5

    • 2861 Words
    • 11 Pages

    Right click the letter or row number for which you want to insert a new column to the left or a new row above……

    • 2861 Words
    • 11 Pages
    Good Essays
  • Satisfactory Essays

    8 T | Rather than put several values in a single column, you should create several columns and number them like column1, column2, etc.…

    • 313 Words
    • 1 Page
    Satisfactory Essays
  • Good Essays

    metcs520 W4 Assignment

    • 637 Words
    • 8 Pages

    of the first red block in the bottom row. The next two values are the…

    • 637 Words
    • 8 Pages
    Good Essays
  • Powerful Essays

    Ap Calculus

    • 2722 Words
    • 11 Pages

    | The identification of a specific cell by its intersecting column letter and row number.…

    • 2722 Words
    • 11 Pages
    Powerful Essays
  • Good Essays

    Ic3 Study Guide

    • 2207 Words
    • 9 Pages

    12. What can be used to change the height of an Excel 2007 spreadsheet row?…

    • 2207 Words
    • 9 Pages
    Good Essays
  • Good Essays

    Biology 3201

    • 431 Words
    • 2 Pages

    Punnett Square - simple grid used to illustrate all possible combinations of gametes from a given set of parents. (See "Punnett Square 08-01-13.png")…

    • 431 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Compter Science

    • 819 Words
    • 4 Pages

    truth table construction, subexpression construction using AND and NOT gates, subexpression combination using OR gates, circuit diagram production…

    • 819 Words
    • 4 Pages
    Good Essays
  • Good Essays

    7- An unbounded solution to a linear programing problem is usually due to omitting a constraint.…

    • 715 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    Lab 3 Student

    • 1264 Words
    • 7 Pages

    This lab accompanies Chapter 2 (pp. 56-68) of Starting Out with Programming Logic & Design.…

    • 1264 Words
    • 7 Pages
    Satisfactory Essays
  • Satisfactory Essays

    doesn’t work because in the 2x7 rectangle the diagonal passes through 8 squares. There are…

    • 511 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    The iconic red crane on the cover of this new edition of Hurley’s, A Concise Introduction to Logic symbolizes the qualities that make it the most successful logic text on the market. We have chosen origami to symbolize this text’s careful sequencing, precision, elegance, and clarity.…

    • 373320 Words
    • 1494 Pages
    Good Essays
  • Good Essays

    Chapter 6 solutions

    • 4145 Words
    • 41 Pages

    b. Modify the reverse-display program so that the user can enter up to 10 numbers…

    • 4145 Words
    • 41 Pages
    Good Essays
  • Powerful Essays

    Boolean Search Operators

    • 1581 Words
    • 7 Pages

    The Internet is a vast computer database. As such, its contents must be searched according to the rules of computer database searching. Much database searching is based on the principles of Boolean logic. Boolean logic refers to the logical relationship among search terms, and is named for the British-born Irish mathematician George Boole.…

    • 1581 Words
    • 7 Pages
    Powerful Essays
  • Satisfactory Essays

    Test Puzzle

    • 452 Words
    • 2 Pages

    In a logic puzzle you are given a series of categories, and an equal number of options within each category. Each option is used once and only once. Your goal is to figure out which options are linked together based on a series of given clues. Each puzzle has only one unique solution, and each can be solved using simple logical processes (i.e. educated guesses are not required).…

    • 452 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    Cupl

    • 10116 Words
    • 41 Pages

    A TMEL – WinCUPL ............................................................ USER’S MANUAL 2 Table of Contents Section 1 Introduction to Programmable Logic ................................................ 1-1 1.1 What is Programmable Logic? ................................................ 1-1 1.2 Device Technologies and Packaging ...................................... 1-6 1.3 Programming Logic Devices ................................................... 1-7 1.4 Functionally Testing Logic Devices ......................................... 1-7 Section 2 Designing with the CUPL™ Language ............................................. 2-1 2.1 Declaration of Language Elements ......................................... 2-1 2.2 Usage of the Language Syntax ............................................... 2-2 2.3 Advanced Language Syntax ................................................. 2-14 Section 3 Using the CUPL Compiler ............................................................... 3-1 3.1 About The Compiler ................................................................ 3-1 3.2 Output File Format Descriptions .............................................. 3-6 Section 4 CUPL Tutorial .................................................................................. 4-1 4.1 Tutorial for Gates .................................................................... 4-1 4.2 Tutorial for COUNT10 ............................................................. 4-3 4.3 Tutorial for SQUARE.PLD ....................................................... 4-5 Section 5 CUPL Software Features ................................................................. 5-1 5.1 CUPL - PALexpert ................................................................... 5-1 5.2 CUPL - PLDmaster .................................................................. 5-1 5.3 CUPL - Total Designer ............................................................ 5-1 5.4 CUPL -…

    • 10116 Words
    • 41 Pages
    Powerful Essays

Related Topics