Hashiwokakero. T. Morsink. August 31, 2009

Similar documents
The Central Limit Theorem

Kalman Filtering Based Object Tracking in Surveillance Video System

Subcarrier exclusion techniques

Analysis. Control of a dierential-wheeled robot. Part I. 1 Dierential Wheeled Robots. Ond ej Stan k

Sampling Theory MODULE XIII LECTURE - 41 NON SAMPLING ERRORS

Parallel DCMs APPLICATION NOTE AN:030. Introduction. Sample Circuit

Mechatronics Laboratory Assignment 5 Motor Control and Straight-Line Robot Driving

Lab 7 Rev. 2 Open Lab Due COB Friday April 27, 2018

Active vibration isolation for a 6 degree of freedom scale model of a high precision machine

RESEARCH ON NEAR FIELD PASSIVE LOCALIZATION BASED ON PHASE MEASUREMENT TECHNOLOGY BY TWO TIMES FREQUENCY DIFFERENCE

BY ROD SOLAR AND LAURA LIVESEY

Supervised Information-Theoretic Competitive Learning by Cost-Sensitive Information Maximization

Identification of Image Noise Sources in Digital Scanner Evaluation

Gemini. The errors from the servo system are considered as the superposition of three things:

Sloppy Addition and Multiplication

Revisiting Cross-channel Information Transfer for Chromatic Aberration Correction

HEURISTIC APPROACHES TO SOLVE THE U-SHAPED LINE BALANCING PROBLEM AUGMENTED BY GENETIC ALGORITHMS. Ulises Martinez William S. Duff

Resonant amplifier L A B O R A T O R Y O F L I N E A R C I R C U I T S. Marek Wójcikowski English version prepared by Wiesław Kordalski

Family Edition. Components. Substitute Markers

Control of Electromechanical Systems using Sliding Mode Techniques

Midterm: In Perspective

CIRCULAR SYNTHETIC APERTURE SONAR WITHOUT A BEACON

COST OF TRANSMISSION TRANSACTIONS: Comparison and Discussion of Used Methods

A Faster and Accurate Method for Spectral Testing Applicable to Noncoherent Data

AN EVALUATION OF DIGILTAL ANTI-ALIASING FILTER FOR SPACE TELEMETRY SYSTEMS

Frequency Calibration of A/D Converter in Software GPS Receivers

Basic Study of Radial Distributions of Electromagnetic Vibration and Noise in Three-Phase Squirrel-Cage Induction Motor under Load Conditions

Design of Control for Battery Storage Unit Converter

Adaptive Space/Frequency Processing for Distributed Aperture Radars

Design Calculation and Performance Testing of Heating Coil in Induction Surface Hardening Machine

Active Harmonic Elimination in Multilevel Converters Using FPGA Control

MEASUREMENT OF STRESS WITH AC MAGNETIC BRIDGES. Otto H. Zinke Department of Physics University of Arkansas Fayetteville, AR 72701

Self-Programmable PID Compensator for Digitally Controlled SMPS

A Simple DSP Laboratory Project for Teaching Real-Time Signal Sampling Rate Conversions

Design Calculation and Performance Testing of Heating Coil in Induction Surface Hardening Machine

A Two-Stage Optimization PID Algorithm

HIGH VOLTAGE DC-DC CONVERTER USING A SERIES STACKED TOPOLOGY

Voltage Analysis of Distribution Systems with DFIG Wind Turbines

Published in: Proceedings of the 26th European Solid-State Circuits Conference, 2000, ESSCIRC '00, September 2000, Stockholm, Sweden

A New Technique to TEC Regional Modeling using a Neural Network.

NOISE BARRIERS CERC 1. INTRODUCTION

IE 361 Module 6. Gauge R&R Studies Part 2: Two-Way ANOVA and Corresponding Estimates for R&R Studies

1 ft 1 ft border tile

MODAL ANALYSIS OF A BEAM WITH CLOSELY SPACED MODE SHAPES

Observational Uncertainty in Plan Recognition Among Interacting. Robots. Marcus J. Huber. Edmund H. Durfee

Produced in cooperation with. Revision: May 26, Overview

e-motion! LabQuest OBJECTIVES MATERIALS PROCEDURE Part I Creating Straight-Line Graphs Such as M, N, and W

Comm 502: Communication Theory. Lecture 5. Intersymbol Interference FDM TDM

(a) frequency (b) mode (c) histogram (d) standard deviation (e) All the above measure

Deterministic Deployment for Wireless Image Sensor Nodes

STRUCTURAL SEMI-ACTIVE CONTROL DEVICE

A COMPARISON OF METHODS FOR EVALUATING THE TEST ZONE PERFORMANCE OF ANECHOIC CHAMBERS DESIGNED FOR TESTING WIRELESS DEVICES

Hardware-in-the-loop tuning of a feedback controller for a buck converter using a GA

Making Use Of What You Don t See: Negative Information In Markov Localization

ISO Assistive products for blind and visionimpaired persons Tactile walking surface indicators

Point-to-point radio link variation at E-band and its effect on antenna design Al-Rawi, A.N.H.; Dubok, A.; Herben, M.H.A.J.; Smolders, A.B.

Differential GPS supported navigation for a mobile robot

e-motion! Evaluation copy

Power Conversion Efficiency of Airborne Parametric Array

International Journal of Engineering Research & Technology (IJERT) ISSN: Vol. 1 Issue 6, August

A moving sound source localization method based on TDOA

Optimal Control for Single-Phase Brushless DC Motor with Hall Sensor

Available online at ScienceDirect. Procedia Technology 17 (2014 )

New Resonance Type Fault Current Limiter

Chapter Introduction

PERFORMANCE ASSESSMENT OF PID CONTROLLERS

Time-Domain Coupling to a Device on Printed Circuit Board Inside a Cavity. Chatrpol Lertsirimit, David R. Jackson and Donald R.

Regarding the Load Capacity of the Cosinus Slide Profile

AN INTERACTIVE DESIGN OF THE WINDING LAYOUT IN PERMANENT MAGNET MACHINES

ELEC353 Practice Problem Set #6

Phase-Locked Loops (PLL)

Experiment 8: Active Filters October 31, 2005

PREDICTION AND MEASUREMENT OF RADIATED EMISSIONS BASED ON EMPIRICAL TIME DOMAIN CONDUCTED MEASUREMENTS

Position Control of a Large Antenna System

Ephemeris Type A Fault Analysis and Mitigation for LAAS

DESIGN OF SECOND ORDER SIGMA-DELTA MODULATOR FOR AUDIO APPLICATIONS

(12) Patent Application Publication (10) Pub. No.: US 2009/ A1

Before the beginning of the Q wave At the top of the R wave After the end of the S wave

SETTING UP A GRID SIMULATOR A. Notholt 1, D. Coll-Mayor 2, A. Engler 1

M.Sc.(Eng) in building services MEBS Utilities services Department of Electrical & Electronic Engineering University of Hong Kong

Comparison Study in Various Controllers in Single-Phase Inverters

Final Report: Design and Implementation of a Binary Neural Network

Massachusetts Institute of Technology Haystack Observatory WESTFORD, MASSACHUSETTS DATE 07/15/2009

CHAPTER 2 WOUND ROTOR INDUCTION MOTOR WITH PID CONTROLLER

Modulation Extension Control for Multilevel Converters Using Triplen Harmonic Injection with Low Switching Frequency

Interactive Machine Learning

Instantaneous Cycle-Slip Detection and Repair of GPS Data Based on Doppler Measurement

Tensile Capacity of U-bar Loop Connections with Precast Fiber Reinforced Dowels

A simple low rate turbo-like code design for spread spectrum systems

Synthetic aperture radar raw signal simulator for both pulsed and FM-CW modes

/09/$ IEEE 472

California State University, Bakersfield Computer & Electrical Engineering & Computer Science ECE 3220: Digital Design with VHDL Laboratory 6

Observations on Windows

A Feasibility Study on Frequency Domain ADC for Impulse-UWB Receivers

Stability Analysis in a Cognitive Radio System with Cooperative Beamforming

A Flyback Converter Fed Multilevel Inverter for AC Drives

DIGITAL COMMUNICATION

Method to Improve Range and Velocity Error Using De-interleaving and Frequency Interpolation for Automotive FMCW Radars

Feedback Control Design of Off-line Flyback Converter

An analytic technique

Transcription:

Hahiwokakero T. Morink Augut 31, 2009

Content 1 Introduction 3 2 What i Hahiwokakero? 3 2.1 The rule............................. 3 2.2 Eay olving tatement..................... 4 3 Building an Own Solver 4 3.1 The eay olver.......................... 4 3.2 The better olver......................... 5 3.3 Single connected group...................... 6 4 Solving the Puzzle with the Sugar CSP-Solver 7 4.1 Getting the input file format right................ 7 4.2 Uing Sugar............................ 10 4.3 Expectation Sugar v own olver................ 12 5 Making a Puzzle Generator 12 6 Reult 13 6.1 Experiment............................ 14 6.2 Reult............................... 14 6.2.1 Time............................ 14 6.2.2 Own olver........................ 15 6.2.3 Sugar........................... 16 6.2.4 Generator v own olver v Sugar............ 16 7 Concluion 19 8 Acknowledgement 19 Reference 19 Appendix 21 2

1 Introduction Thi thei i the reult of a Bachelor Project at the Univerity of Leiden in the Netherland. The project wa upervied by Dr. W.A. Koter. It i about Hahiwokakero, a Japanee puzzle. The object of the puzzle i to connect iland by mean of bridge into a ingle connected group. With thi thei we will how how efficient our own olver i in contrat to another proven one. 2 What i Hahiwokakero? 2.1 The rule Hahiwokakero (alo known a Bridge) i an intereting Japanee puzzle from Nikoli [1], the publiher of puzzle like Sudoku and Nonogram. The rule are quite imple, yet within the rule one can make pretty difficult puzzle. Hahiwokakero i played on a rectangular grid. The ize of the grid doen t really matter. In the grid the player will find node, alo known a iland (ee the left picture of Figure 1). Thee node have a value in them ranging from 1 through 8. The goal i to connect all thee iland with bridge. In the end thi hould be a ingle connected group. The player draw bridge between the iland in a traight line. Thee bridge cannot cro other bridge and/or iland, and each bridge connect exactly two iland. Every pair of iland ha a maximum of 2 bridge connecting them. In the end you will have a ingle connected group with on each iland the number of connected bridge matching the value in the iland (ee the right picture in Figure 1). 1 3 6 1 3 6 1 3 4 1 3 4 Figure 1: Example puzzle with olution 3

2.2 Eay olving tatement To olve thee puzzle there are a number of eay thing to remember. If you have, for example, an iland with value 4 in the corner of your grid, you have only one way to build bridge. Since a pair of iland cannot be connected with more than 2 bridge, the iland with value 4 will have 2 bridge to hi firt neighbouring iland and 2 bridge to hi econd neighbour. Thi imple fact i eaily tranlated into a bit more formal tatement: If an iland ha value n, with n even, and preciely n/2 neighbour, you can draw two bridge to each of n neighbour. If an iland ha value n 1, with n even, with n/2 neighbour, you cannot put two bridge to each of n neighbour, but you do know already omething ele. If an iland ha value n 1, you can draw at leat one bridge to each of it neighbour. With thee two imple tatement you can olve mot puzzle of eay difficulty. However, the puzzle of hard difficulty will give you ome problem. Hard puzzle will ue the fact that it need to be a ingle connected group of iland and give you the illuion there i more than one way to olve the puzzle. 3 Building an Own Solver 3.1 The eay olver A a firt part in thi reearch project, a program in C ++ wa built to olve thee puzzle, uing baically the two imple rule of olving mentioned in Section 2. Thi i a pretty imple program, but a oon a puzzle needed the ingle connected group rule to get olved, it fail. Alo the program had ome difficultie olving certain puzzle, for example it connected two iland of value 1 to each other, or did not draw a bridge where there clearly hould be one due to lack of check or the fact that it needed o many check that i wa better to work on a new program. Thi new program wa deigned to baically jut olve the puzzle without the ingle connected group rule. The approach wa a bit different. If you have a node of value k, calculate the maximum of bridge (after thi called max) you can attach to thi node, ignoring the value of k, but not ignoring the value of the neighbour. If after thi calculation k = max, draw all bridge to the neighbour. If k = max 1 AND k > m, with m being the number of neighbour of the node, you can draw one extra bridge to all neighbour 4

(except to node with a value left of 1, thee are only drawn with the firt rule), i.e., if there i one bridge draw the econd, and if there i no bridge then draw one. From now on if the lat approach i ued, we will refer to it a the eay olver. 2 2 2 8 2 2 7 2 2 2 Figure 2: n = 8. Left: neighbour have value 2. Right: neighbour have value 2 and the middle node ha value n 1 Note in Figure 2 in the left picture with n being 8, that every neighbour of that node will need at leat a value of 2 or higher to let the node with value 8 draw all of it bridge. If any of the neighbour would have a value of 1 or even 0, the middle node would only be able to draw, repectively, even or ix bridge. In the right picture of Figure 2 you ee what happen when a node ha a value of 7. If every neighbouring node ha at leat a value of 2 and you have 7 bridge to ditribute, there i no indication of which pair of node hould only be connected with only one bridge. The only real fact we know i that every pair of node hould be connected with at leat one bridge, becaue you till need to ditribute 7 bridge over four pair of node. 3.2 The better olver After eeing that the eay olver wa not going to olve puzzle with the ingle connected group rule in them, we needed ome extra olving capabilitie in the program. The eaiet way to get ome extra olving power in the program wa to let the program gue once and then ue the ame olving paramater a in the Eay Solver. So the tep in the new program were going to be: 1. Solve the puzzle a bet you can with the eay olver. 5

2. Let the program draw a ingle bridge (a double one if there already i one; thi i referred to a an extenion) and, after the one gue, olve the puzzle again with the eay olver. 3. Check if a olution i found and if the olution i a ingle connected group, if not make a note that on that pot no bridge extenion can be drawn again. 4. Repeat tep 2 and 3 for every poible bridge extenion. Note that in thi cae, if every poible bridge lead to an unolvable puzzle, the program might alo indicate that a olution i not poible. Note that, contradictory to normal reearch behavior, if after the one gue and olving it again the olver happen to find a olution, the program will end aying it ha found a olution to the problem. Thi olution i probably a non-unique olution. 3.3 Single connected group The check to ee if the puzzle i a ingle connected group require ome extra explanation. The check will tart at every node and will try to reach every other node in the puzzle. If it cannot reach a node it will check why the puzzle till i not a ingle connected group. There are a two ditinct cae in which you will ee the gue of the olver fail, cauing it to ban all bridge between two iland, and one cae in which option are till open, and the check olver cannot ay if the puzzle i olvable, but it can ay that at the moment it i not unolvable. Thee three ituation are hown in Figure 3. Note that the picture are not complete puzzle, but mall portion of a larger one. The three ituation are: 1. There i a group of iland with at leat a poibility to draw a bridge to another node completely cut off from poibilitie around it. Thi will caue the olver to fail; ee Figure 3.1. 2. There i a group of iland connected together, with no more poibilitie going outward to another part of the puzzle. Jut to be clear, thi i not a complete puzzle. Thi will caue the olver to fail; ee Figure 3.2. 3. There i a group of iland connected together, with one or more poibilitie to draw a bridge to another part of the puzzle, connecting thoe two or more group of iland; ee Figure 3.3. 6

1 2 2 2 2 2 2 1 2 2 1 2 3 Figure 3: Example of the option above. A part of the puzzle i depicted. 4 Solving the Puzzle with the Sugar CSP- Solver While looking for way to olve thee puzzel, a olver called Sugar wa found, made by Naoyuki Tamura [2]. Sugar i a SAT-baed Contraint Solver. It i baed on a new SAT-encoding method called order encoding. We wanted to find out how well or how fat thi olver could olve the puzzle in comparion with the olving method from the programmed olver. Thoe method ue random function a bit more, o they could take a lot of time. 4.1 Getting the input file format right Sugar need to get the problem handed in a pecial way. Firt a lit of all variable with the appropriate contraint it i to be given. In our cae the variable are potential bridge with a value between 0 and 2 (being the minimum and maximum number of bridge between two iland). In general the notation would be (<variabletype> <variablename> <bottomcontraint> <topcontraint>). So for example, (int x 0 2) would mean that the integer x would have a value 0 x 2.And (int x 00 06 0 2) mean that the integer variable x 00 06 (the bridge between coordinate (0,0) and (0,6)) ha to be between 0 and 2. After declaration of the variable you get a lit of tatement that um the variable to a certain value. In thi cae thi value wa the value of the node and the variable umming to that value are the potential bridge attached to that node. So, for example, (= (+ x 00 50 x 00 06) 2) mean that variablex 00 50 ummed with variablex 00 06 hould equal 2, meaning that the cro ection of the line going from (0,0) to (5,0) and from (0,0) to (0,6), o in thi cae the point (0,0), will need two bridge going from that point. 7

To accomplih thi format we made a parer that would take a puzzle we created in the form we ue in all our program and write it to the form required for Sugar, a een in Figure 4. ;bridge (int x_00_50 0 2) (int x_00_06 0 2) (int x_06_66 0 2) (= (+ x_00_50 x_00_06) 2) (= (+ x_06_66 x_00_06 ) 2) (= (+ x_00_50 ) 1) (= (+ x_06_66 ) 1) 2 2 0/1/2 0/1/2 1 0/1/2 1 Figure 4: Example inputfile.cp format, with correponding puzzle. Here 0/1/2 denote the poible value for bridge. A line that tart with ; contain a comment. No attempt i made to guarantee connectedne. The problem with the the inputfile.cp from Figure 4 i that there i no way to enure that the olution i a ingle connected group. To that end you need a ytem to build a panning tree. Naoyuki Tamura [2] made a cript that, beide making the tatement that our elf built cp code generator alo doe, make uch a tree. The new inpufile.cp generated from thi cript i een in Figure 5. A you can ee in Figure 5 the firt even line are baically (if noted omewhat different) the ame command a in Figure 4. The difference i in that the bridge have direction. The number in the variable name are till the coordinate only for thi example v 0 0 mean the vertical bridge that i drawn from node (0,0) and h 0 0 i the horizontal bridge drawn from node (0,0). The value 1 and 2 mean in thi cae, that vertical bridge have a direction upward and horizontal bridge have a direction to the left. The value 1 and 2 are for direction down and right. The um of the abolute value of the bridge attached to a node (the horizontal and vertical one) are again the value of the node. Now thi i etablihed we introduce a group of new variable, z -variable and r -variable, correponding to the node in the puzzle. The z -variable alway have a value between 1 and the number of node in the puzzle, while the r -variable alway have a value of either 0 or 1. Now there i a group of iff-tatement. For example, (iff (= z 0 0 1) (= r 0 0 1)) mean that the variable z 0 0 i 1 if and only if r 0 0 i 1. The next important thing to note i the line: 8

(int v 0 0-2 2) (int h 0 0-2 2) (= (+ (ab v 0 0) (ab h 0 0)) 2) (int v 0 6-2 2) (= (+ (ab v 0 6) (ab h 0 0)) 2) (= (+ (ab v 0 0)) 1) (= (+ (ab v 0 6)) 1) (int z 0 0 1 4) (int r 0 0 0 1) (iff (= z 0 0 1) (= r 0 0 1)) (int z 0 6 1 4) (int r 0 6 0 1) (iff (= z 0 6 1) (= r 0 6 1)) (int z 5 0 1 4) (int r 5 0 0 1) (iff (= z 5 0 1) (= r 5 0 1)) (int z 6 6 1 4) (int r 6 6 0 1) (iff (= z 6 6 1) (= r 6 6 1)) (= (+ r 0 0 r 0 6 r 5 0 r 6 6) 1) (=> (> v 0 0 0) (< z 0 0 z 5 0)) (=> (> h 0 0 0) (< z 0 0 z 0 6)) (=> (= r 0 0 0) (or (< v 0 0 0) (< h 0 0 0))) (=> (> v 0 6 0) (< z 0 6 z 6 6)) (=> (< h 0 0 0) (< z 0 6 z 0 0)) (=> (= r 0 6 0) (or (< v 0 6 0) (> h 0 0 0))) (=> (< v 0 0 0) (< z 5 0 z 0 0)) (=> (= r 5 0 0) (or (> v 0 0 0))) (=> (< v 0 6 0) (< z 6 6 z 0 6)) (=> (= r 6 6 0) (or (> v 0 6 0))) Figure 5: Example of a better inputfile.cp file for the puzzle in Figure 4 Here connectedne i taken into account. (= (+ r 0 0 r 0 6 r 5 0 r 6 6) 1) Thi line ay that the um of all r -variable i 1. Thi mean that preciely one of thee variable can have the value 1. The idea behind thi i, that from all the node in the puzzle, one i choen to be the root of the panning tree, we are trying to make. In thi example we will choe r 0 0 a the root, thu giving it a value of 1. Now becaue thi i choen, there are a few other effect that will happen. Firt off all, becaue of the line (iff (= z 0 0 1) (= r 0 0 1)) the variable z 0 0 which could have had a value between 1 and 4, will now have value 1. Alo, becaue all of the r -variable together can only have a value of 1, every other r -variable except r 0 0 ha a value of 0 and thu the z -variable will not have a value of 1. Now becaue of the line and (=> (= r 5 0 0) (or (> v 0 0 0))) 9

(=> (= r 6 6 0) (or (> v 0 6 0))) we ee that v 0 0 will be larger than 0 and v 0 6 will alo be larger than 0, meaning that both thee bridge have a direction downward. Now we only need the direction of the horizontal bridge. Thi i deducted from the line: (=> (= r 0 6 0) (or (< v 0 6 0) (> h 0 0 0))) Since r 0 6 equal 0 either v 0 6 mut be maller than 0 or h 0 0 mut be larger than 0. We jut etablihed that both vertical bridge run downward and have a value greater than 0, o v 0 6 i not maller than 0, thu h 0 0 mut be larger than 0 and conequently thi bridge ha a direction to the right. Now we have all the direction we need and we can look at the final part of building a tree. The line (=> (> v 0 0 0) (< z 0 0 z 5 0)) (=> (> h 0 0 0) (< z 0 0 z 0 6)) (=> (> v 0 6 0) (< z 0 6 z 6 6)) tell u the lat piece of information. In all the line of the building of the tree, we have not given any value to z -variable of the node, except we choe the root to have value 1. We till need to aign number to the other three z -variable correponding to the other three node. In the three tatement above the firt part i true, all the variable are larger than 0. We can ee that z 0 0 < z 5 0, which hould not be hard to do ince z 0 0 equal 1, o we, perhap, aign a value of 2 to z 5 0. Thi i acceptable ince the z -variable all have value between 1 and the number of node, in thi cae 4. Other value are alo poible a long a it i a value between 1 and the number of node and a path from the root of the tree to a leaf will only encounter increaing number. The next two line how u that z 0 0 < z 0 6 < z 6 6, which i alo doable within the rule. Aign a value of 2 to z 0 6 and a value of 3 to z 6 6. Now we have a graph with direction and value increaing in value the further away from the root they are, ee Figure 6. Here we ee that we have a panning tree to all node and thu we have a ingle connected group within the olution. In general, a panning tree can be contructed (thu having a connected group) preciely when the formula can be atified. 4.2 Uing Sugar After the file i pared, it i time to tart olving the puzzle. One of the more intereting thing of uing Sugar i that you alo need to ue a SAT-Solver. In 10

1 > 2 h 0 0 > 0 v 0 0 > 0 2 v 0 6 > 0 3 Figure 6: The panning tree correponding to the puzzle in Figure 4, with the z -value in the node our cae we ued MiniSat [3], a very eay to ue olver with no configuration needed. When that i et up, it i time to let Sugar encode the input file to a file that MiniSat can ue to olve your puzzle. Uing the command java -jar./ugar.jar -encode <file.cp> <file.cnf> <file.map> will do that for you; here ugar.jar i the current verion of the java archive from which Sugar i run. In thi cae Sugar i intalled in the ame directory a the ret of the file. The.cp file i the input file containing the problem you want to olve. The.cnf file i an output file from Sugar ued a an input file for MiniSat to olve the problem. The.map file ued here are file ued by Sugar to tore the variable data with the contraint, o called mapping file. After encoding the file a imple command./minisat <file.cnf> <file.out> will olve the puzzle. The.out file will be ued again by Sugar a an input file. You will immediately ee if the puzzle wa olvable or not. Now you have a couple of file with the olution to the puzzle, which are till not eaily readable. To make it clear and immediately undertandable what the olver did you need to decode the file again with Sugar uing the command java -jar./ugar.jar -decode <file.out> <file.map>. Thi will give you a lit with the variable you declared in your file with their value behind it. To give you a bit of a clearer idea, here are the.cnf,.map and.out file correpeonding to Figure 4. Firt the.cnf file: Secondly the.map file: p cnf 0 0 11

int x 00 06 1 1..1 int x 00 50 1 1..1 int x 06 66 1 1..1 Lat the.out file: SAT 4.3 Expectation Sugar v own olver 0 Sugar will probably be able to olve mot to all puzzle given, but we are not ure at the timeframe. Inputting the three different command doe take a bit of time, which i not really efficient. On the other hand with larger puzzle the programmed olver will probably have to take a couple of guee randomly which can be completely wrong and then it will take a lot of time to find the correct olution, o then the time you need to enter the three Sugar command will be fater. In the chapter Reult, you will find the reult of the tet to ee which i fater. 5 Making a Puzzle Generator Another part of thi project wa to make a puzzle generator. Copying puzzle from internet ite i a good way to know you have uniquely olvable puzzle, but it i time conuming. To enure that the puzzle the generator make are within the rule of the puzzle the generator followed thee tep: 1. Put a ingle random node omewhere on the board. 2. From a random node already on the board, draw a ingle or double bridge (decided randomly) in a random direction. Thi will not happen if the node ha no more option to draw a bridge and a new node from where to draw a bridge will randomly be choen. 3. During thi traveral, on every grid point decide whether to go on drawing the bridge or to top and put an iland on that pot. If you encounter a croing bridge at the grid point, place the node on the bridge, if poible, or otherwie place the node one tep back, if poible. 12

4. Continue tep 2 through 4 until you have reached the number of node you d like to have (given in the command line when tarting the generator). 5. Check at each node how many bridge are connected and give the node the proper value. 6. Remove the bridge from the puzzle and it i complete. What you ee in Figure 7 i a puzzle with three node being generated tep by tep. In tep I a ingle iland i put on the board. In tep II the generator will chooe automatically that one node and decide to either draw a ingle or double bridge. In thi cae a double bridge wa choen and it will go down to when it decide to top and put down a node. In tep III another node i choen to draw a bridge from and thi time it the lower of the two. A ingle bridge i drawn to the right, until it top again and a node i placed. In tep III the value of the node are alo inerted a a final tep in making the puzzle complete. Step IV, the final tep, how the puzzle a it will be aved. No bridge, jut node that need olving. In thi example, the puzzle i uniquely olvable. Furthermore, the reulting olution ha a ingle connected group. 2 3 1 2 3 1 I II III IV Figure 7: Generating a puzzle 6 Reult In thi ection, we will how how the elf built olver (called jut olver in the next part) did againt the Sugar program. We would like to how how efficient the olver i in time and number of olved puzzle. 13

6.1 Experiment For the experiment we needed to tet the generator, the elf written olver and Sugar. Thi wa done in two different way. Firt we generated and olved with our elf built olver 7 7 puzzle, 10 10 puzzle and 15 15 puzzle. The 7 7 puzzle were generated with a maximum number of 7 node, and thu uually with 7 node in the puzzle. The 10 10 puzzle were generated with a maximum of 15 node, uually generating puzzle with 15 node. The 15 15 puzzle were generated with a maximum of 30 node, again uually generated with 30 node. In generating the puzzle there i a random chance which could caue, for example, to let the generator put node in all 4 corner of the puzzle and connecting them all with one bridge between them. In thi cae you have only 4 node and the generator will try 10,000 time to put another bridge from a node, which will fail, thu, for example, a 15 15 puzzle with only 4 node i created. There are more cenario in which thi can happen. That i why we ay that puzzle are uually generated with the number of node pecified. Secondly we olved the ame puzzle with Sugar. Firt the 10,000 7 7 puzzle were generated and olved with the olver and then with ugar. After thi wa done the ame wa done for the 10,000 10 10 puzzle and the 10,000 15 15 puzzle. Every run made a lot of output file, merging them into a few at the end. We meaured a few intereting key point like time taken to do a job of 10,000 puzzle and how many were olved. Alo we examined how the generator generated the puzzle and if the olver and Sugar olved it in the ame way or that there were different olution to a puzzle. 6.2 Reult 6.2.1 Time The average time it took the generator to generate 10,000 puzzle and the olver to olve thee puzzle and generate output, wa about 25 minute on an AMD Turion 64 Mobile machine (791 MHz) with 512 MB of internal memory. The fact that the 15 15 puzzle were much larger than the 7 7 did not reult in any larger run time of the batch. The average time it took the generator to generate the ame 10,000 puzzle and then let Sugar olve them took a lot longer, about 1h45m. Thi i mainly due to the fact that the way Sugar olve puzzle create a lot more file than the elf built olver. Moving, reading and copying thee file took mot of thi time. If you look at a ingle puzzle being olved by MiniSat [3], it took le than a econd, a well a the encoding and decoding by Sugar. 14

6.2.2 Own olver To ee how our own olver did, we have ome tatitic to review. A can be een in Figure 8 (left) in the 7 7 puzzle only 2% wa undecided by the olver, i.e., it did not olve the puzzle. A one can ee in Figure 8 (right) from all the olved puzzle 15% wa olved differently than the generator intended. Figure 8: Diagram of (left) percentage of how much the program olved of the 7 7 puzzle and (right) the percentage of puzzle being olved differently than the generator intended them. A we look at the 10 10 puzzle, we notice that the percentage of undecided puzzle ha grown to 10%, ee Figure 9 (left). The number of puzzle that i olved differently i almot doubled to 28%, a you can be een in Figure 9 (right). Figure 9: Diagram of (left) percentage of how much the program olved of the 10 10 and (right) the percentage of puzzle being olved differently than the generator intended them. Finally we look at the 15 15 puzzle. The percentage of undecided puzzle i now 12%, which i not that big an increae, ee Figure 10 (left). 15

We aume that the number of undecided puzzle will increae till with the larger puzzle. Alo with increaed ize of the puzzle, the percentage of puzzle olved differently from the generator rie to a value of 38%, ee Figure 10 (right). Thi will alo be common the larger the puzzle get. Figure 10: Diagram of (left) percentage of how much the program olved of the 15 15 and (right) the percentage of puzzle being olved differently than the generator intended them. 6.2.3 Sugar Sugar olved every ingle puzzle given by the generator. Thi did not come a a urprie, ince the generator generate only ingle connected group puzzle and Sugar olve thee with eae. It did however took a coniderable time to olve the puzzle. 6.2.4 Generator v own olver v Sugar Lat but not leat we checked how many of the puzzle were olved the ame way by either the generator, olver or Sugar. Thi wa done by comparing the output file of the job they were given. Both the generator olution file and the olver program olution file had to be rewritten in the ame way a Sugar output the olution. In Figure 11 one can find table of a comparion of the way the program olved the puzzle. Every poibility ha a label, decribed in the lit below. one can alo find example for each poibility, in Sugar output form, in the appendix. In reading the output there were eight ditinct poibilitie: 1. All three olution were identical. The olver olved the puzzle without having to gue a bridge, making the puzzle a puzzle with a unique olution. Thi i labeled 1=2=3, unique in Figure 11. For an example of a olution in Sugar output form where thi i the cae, ee Figure 13. 16

2. All three olution were identical. The olver gueed and o we can not be ure that the olution i unique. Thi i labeled 1=2=3, gue in Figure 11. For an example ee Figure 14. 3. The generator and Sugar had the ame olution, but the olver program found a different one. Thi i mainly due to the guee the olver take. See Figure 11, labeled 1=2, not 3. For an example ee Figure 15. 4. The generator and the olver program had the ame olution, but Sugar found a different one. See Figure 11, labeled 1=3, but not 2. For an example ee Figure 16. 5. The generator had a olution, but Sugar and the olver program found another, both the ame, olution. See Figure 11, labeled 2=3, not 1. For an example ee Figure 17. 6. All three program have a different olution to the puzzle. See Figure 11, labeled All different. For an example ee Figure 18. 7. The olver program could not olve the puzzle, but the generator and Sugar had the ame olution. See Figure 11, labeled 3 fail, 1=2. For an example ee Figure 19. 8. The olver program could not olve the puzzle, and the generator and Sugar had a different olution. See Figure 11, labeled 3 fail, 1 not 2. For an example ee Figure 20. A can be een in Figure 11, the part where all three program have the ame olution and the olver doe not gue, hrink a the puzzle get bigger. Thi i becaue in larger puzzle the chance of a puzzle with cycle, which are olvable in multiple way, become higher. For an example of uch a cycle ee Figure 12. The number of puzzle that are olved the ame way but with ome guee from the olver, doe increae with the puzzle ize. In the ret of the cae, where the olver program doen t fail, we can peak of puzzle with more than one olution. In the cae that the olver program fail to give a olution there are, a mentioned in the lit above, two poibilitie. The generator and Sugar agree on the olution or diagree. In both cae, auming that the olver program can olve all puzzle with a unique olution, we can peak of puzzle with more than one olution. If the generator and Sugar till give the ame olution, thi might be jut a coincidence. When comparing the olution of the eight example hown in the appendix, we notice that a certain ituation occur rather frequently. In a cycle of four node it happen that one program olve it a certain way, and the 17

Situation 7 7 10 10 15 15 1=2=3, unique 7267 5181 4000 1=2=3, gue 562 851 902 1=2, not 3 718 1371 1635 1=3, not 2 528 566 570 2=3, not 1 587 587 641 All different 126 554 1010 3 fail, 1=2 114 419 447 3 fail, 1 not 2 98 471 795 Total 10000 10000 10000 Figure 11: Table with data comparion of the eight poibilitie mentioned in the lit above. Here 1 i the generator, 2 i Sugar and 3 i the olver. other program olve it with 2 bridge turned 90. So one bridge turn 90 counterclockwie and the oppoite bridge in the cycle turn 90 clockwie. 1 2 2 2 1 1 1 1 2 Figure 12: An example of how in a cycle the bridge can flip to create a different olution. Value along bridge are the number of bridge. A can be een in Figure 12 there are two different olution. In Figure 12.1 there are two et of node connected with vertical double bridge and a et of node with a horizontal ingle bridge. In thi cae the two vertical bridge flip into a ingle bridge, for example, the left clockwie and the right one counterclockwie. Thi create Figure 12.2, and thu a different olution while till all node having the ame amount of bridge attached to them. Thi i a noticably common ituation between two different olution of the ame puzzle. 18

7 Concluion A we can ee in Section 6 our own olver wa really a bit quicker in olving the puzzle. The only problem i that it did not olve all puzzle, ometing that the program Sugar did. A can be een in Figure 11 the generator doe generate a fair number of puzzle with a unique olution. Due to the random factor in generating thee puzzle, we ee that the larger the puzzle get the more difficult it i to generate uch a puzzle. We alo ee that the larger puzzle have a larger chance that all program find a different olution. Thi i becaue the chance of getting cycle that can be flipped i larger. From the perpective of a peron who want to olve the puzzle, having a puzzle with more than one olution can create a more difficult, or even an eaier puzzle, depending on what choice have to be made. The own olver proved to be quite a good olver. Having the number of puzzle it could not olve increaed when the puzzle ize increaed i unfortunate, but it did not grow into a really large percentage (with 15 15 it wa only 12%). The larger the puzzle get, the better it i to ue Sugar to olve them intead of the own olver. It doe take more time, but the reult are a lot better. A further reearch, we mention a further invetigation into the relation between the quantitie in Figure 11. 8 Acknowledgement I d like to thank Naoyuki Tamura for hi help and quick email replie, containing ueful cript and example data. Without that the project would have been a lot harder (if not impoible). Alo I d like to thank my upervior Dr. Walter Koter, who made it eem he had all the time in the world to help me, while juggling hi own buy chedule. Without hi contantly giving hint and idea I d till be at Section 1. Lat but not leat I d like to thank Sandra, my girlfriend, for giving me hope, energy and hug to continue on thi project. Reference [1] Webite Nikoli, http://www.nikoli.co.jp/en/ [retrieved Augut 18, 2009] 19

[2] Webite Sugar, http://bach.itc.kobe-u.ac.jp/ugar/ [retrieved Augut 12, 2009] [3] Webite MiniSat, http://miniat.e/ [retrieved Augut 12, 2009] 20

Appendix In thi appendix we give example of the eight poibilitie obtainable by comparing the generator, Sugar and olver olution. With thi output it i ometime not poible to obtain the poition of all node, but for our purpoe the example eem ufficient. generator: c Decoding puzzle0.out a h 1 0 1 a v 1 2 1 a h 1 2 1 a v 1 4 1 a h 1 4 2 a v 3 4 1 Sugar: c Decoding puzzle0.out SATISFIABLE a h 1 0 1 a v 1 2 1 a h 1 2 1 a v 1 4 1 a h 1 4 2 a v 3 4 1 olver: c Decoding puzzle0.out a h 1 0 1 a v 1 2 1 a h 1 2 1 a v 1 4 1 a h 1 4 2 a v 3 4 1 Figure 13: Example of a 7 7 puzzle, with generator (top), Sugar (middle) and olver (bottom) having the ame olution. Alo, the olver did not gue, o thi i a puzzle with a unique olution 21

generator: c Decoding puzzle55.out a h 0 1 1 a h 0 3 1 a v 0 6 1 a h 2 3 1 a v 2 6 2 a h 6 4 1 Sugar: c Decoding puzzle55.out SATISFIABLE a h 0 1 1 a h 0 3 1 a v 0 6 1 a h 2 3 1 a v 2 6 2 a h 6 4 1 olver: c Decoding puzzle55.out a h 0 1 1 a h 0 3 1 a v 0 6 1 a h 2 3 1 a v 2 6 2 a h 6 4 1 Figure 14: Example of a 7 7 puzzle, with generator (top), Sugar (middle) and olver (bottom) having the ame olution. Alo, the olver did gue, o thi i a puzzle with more than one olution. 22

generator: c Decoding puzzle8.out a v 0 0 1 a h 0 0 2 a v 0 3 1 a h 0 3 1 a h 3 0 1 a v 3 3 2 a h 5 0 1 Sugar: c Decoding puzzle8.out SATISFIABLE a v 0 0 1 a h 0 0 2 a v 0 3 1 a h 0 3 1 a h 3 0 1 a v 3 3 2 a h 5 0 1 olver: c Decoding puzzle8.out a v 0 0 2 a h 0 0 1 a v 0 3 2 a h 0 3 1 a v 3 3 2 a h 5 0 1 Figure 15: Example of a 7 7 puzzle, with generator (top) having ame olution a Sugar (middle), but not with olver (bottom). 23

generator: c Decoding puzzle21.out a v 0 0 2 a h 0 0 1 a v 0 3 1 a v 3 0 1 a h 3 0 1 a v 3 3 1 a h 3 3 2 Sugar: c Decoding puzzle21.out SATISFIABLE a v 0 0 1 a h 0 0 2 a v 3 0 1 a h 3 0 2 a v 3 3 1 a h 3 3 2 olver: c Decoding puzzle21.out a v 0 0 2 a h 0 0 1 a v 0 3 1 a v 3 0 1 a h 3 0 1 a v 3 3 1 a h 3 3 2 Figure 16: Example of a 7 7 puzzle, with generator (top) having ame olution a olver (bottom), but not with Sugar (middle). 24

generator: c Decoding puzzle26.out a h 1 0 2 a h 1 3 1 a v 1 5 1 a h 3 1 2 a v 3 3 1 a h 3 3 2 Sugar: c Decoding puzzle26.out SATISFIABLE a h 1 0 2 a v 1 3 1 a v 1 5 2 a h 3 1 2 a v 3 3 1 a h 3 3 1 olver: c Decoding puzzle26.out a h 1 0 2 a v 1 3 1 a v 1 5 2 a h 3 1 2 a v 3 3 1 a h 3 3 1 Figure 17: Example of a 7 7 puzzle, with Sugar (middle) having ame olution a olver (bottom), but not with generator (top). 25

generator: c Decoding puzzle22.out a v 0 0 2 a h 0 0 1 a v 0 6 1 a v 3 0 1 a h 3 0 2 a v 3 6 1 a h 6 0 2 Sugar: c Decoding puzzle22.out SATISFIABLE a v 0 0 1 a h 0 0 2 a v 3 0 2 a h 3 0 2 a v 3 6 2 a h 6 0 1 olver: c Decoding puzzle22.out a v 0 0 2 a h 0 0 1 a v 0 6 1 a v 3 0 2 a h 3 0 1 a v 3 6 2 a h 6 0 1 Figure 18: Example of a 7 7 puzzle, with every program having different olution. 26

generator: c Decoding puzzle53.out a v 0 0 1 a h 0 0 1 a v 0 2 1 a h 0 2 2 a h 2 0 1 a v 2 2 2 a h 2 2 1 Sugar: c Decoding puzzle53.out SATISFIABLE a v 0 0 1 a h 0 0 1 a v 0 2 1 a h 0 2 2 a h 2 0 1 a v 2 2 2 a h 2 2 1 olver FAILS: c Decoding puzzle53.out a h 0 2 2 a h 2 0 1 a v 2 2 2 a h 2 2 1 Figure 19: Example of a 7 7 puzzle, with the olver (bottom) failing and generator (top) and Sugar (middle) having the ame olution. 27

generator: c Decoding puzzle253.out a h 0 0 2 a v 0 2 2 a v 0 5 2 a h 2 2 1 a v 2 5 1 a h 5 2 1 Sugar: c Decoding puzzle253.out SATISFIABLE a h 0 0 2 a v 0 2 1 a h 0 2 1 a v 0 5 1 a v 2 2 1 a h 2 2 1 a v 2 5 2 olver FAILS: c Decoding puzzle253.out a h 0 0 2 a v 0 2 1 a h 2 2 1 a v 2 5 1 a h 5 2 1 Figure 20: Example of a 7 7 puzzle, with the olver (bottom) failing and generator (top) and Sugar (middle) having a different olution. 28