np hard report

33
Project Titled ”OPTIMISATION OF A CONSTRAINT SATISFACTION PROBLEM USING HEURISTIC AND EVOLUTIONARY ALGORITHMS” Submitted by Swapnil B.Deore(132190010) M.tech(Software Engg.) 2014-15 Under the Guidance Prof.V.K.Sambhe Department of Computer Engg and Information Technology. Veermata Jijabai Technological Institute (An Autonomous Institute affliated to Mumbai University) Mumbai-400019

Upload: sudammerya

Post on 14-Nov-2015

232 views

Category:

Documents


1 download

TRANSCRIPT

  • Project Titled

    OPTIMISATION OF A CONSTRAINT SATISFACTION PROBLEM USING HEURISTICAND EVOLUTIONARY ALGORITHMS

    Submitted by

    Swapnil B.Deore(132190010)

    M.tech(Software Engg.)

    2014-15

    Under the Guidance

    Prof.V.K.Sambhe

    Department of Computer Engg and Information Technology.

    Veermata Jijabai Technological Institute

    (An Autonomous Institute aiated to Mumbai University)

    Mumbai-400019

  • STATEMENT OF CANDIDATE

    I state that work embodied in this Project titled OPTIMISATION OF CONSTRAINT SATIS-FACTION PROBLEM USING HEURISTICS AND EVOLUTIONARY ALGORITHMS formsmy own contribution of work under the guidance of Prof.V.K.Sambhe at the Department ofComputer Technology, Veermata Jijabai Technological Institute. The report reflects the workdone during the period of candidature but may include related preliminary material providedthat it has not contributed to an award of previous degree. No part of this work has been usedby me for the requirement of another degree except where explicitly stated in the body of thetext and the attached statement.

    Swapnil B.Deore

  • ACKNOWLEDGEMENT

    I am overwhelmed in all humbleness to acknowledge my depth to all those who have helpedme to put these ideas, well above the level of simplicity and into something concrete.I would liketo thank all those people whose support and cooperation has been an invaluable asset duringthe course of this Project especially my Project guide Prof. V. K. Sambhe sir who gave it thepresent shape. It would have been impossible to complete the project without their support,valuable suggestions, criticism, encouragement and guidance.

    I convey my gratitude also to Dr G. P Bhole, Head of Department for his motivation andproviding various facilities, which helped me greatly in the whole process of this Project.

    I am also grateful to all other teaching and non-teaching staff members of the ComputerTechnology Department for directly or indirectly helping us for the completion of this seminarand the resources provided.

    Swapnil B.Deore

  • Contents

    1 Introduction 21.1 Problem Formulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41.2 Significance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51.3 Objective and Scope of work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61.4 Methodology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61.5 Significant Contribution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7

    2 Literature Review 82.1 Randomisation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.2 Different Heuristic approaches . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.3 Genetic Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

    3 Implementation 143.1 Proof for NP-Completeness of C.S.P . . . . . . . . . . . . . . . . . . . . . . . . 143.2 Randomisation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

    1

  • Chapter 1

    Introduction

    Various problem solving Paradigm such as Dynamic programming,Greedy approach,Branchand bound etc. has been used in Computer Science to design efficient Algorithms,but thereare certain class of problems which cannot be solved by the above mentioned paradigm.Theproblems which come under these class are called as Non-Deterministic Polynomial time prob-lems(NP).The problems which have the time complexity as N !,2N etc. come under this cate-gory.We consider a task of scheduling of jobs on two processors,the scheduling of jobs on theprocessors should be such that minimum time is taken for the scheduling.As there is no perfectalgorithm for the above task ,we have to consider all possible subsets for the above task.If wetake input as N=1000,then the number of all possible subsets 21000.

    There are two types of problems :One is Polynomial time(P) problems and other is NP(NonDeterministic Polynomial time)problems.We categorise NP again in to subtypes such as NPComplete problems,NP-Hard problems and NP problems.NP Complete problems are the prob-lems which are verifiable in polynomial time.For e.g.:Consider a Prover and a Verifier,a Proverhas all sorts of Knowledge,he can prove anything in the world whereas a Verifier has limitedKnowledge.On basis of answer given by Prover,the Verifier has to verify the answers on thebasis of his limited Knowledge.To prove a problem is NP-Hard,we have to use Reducibilitytechnique.If we want to prove a problem R as NP-Hard and we know that problem Q is alreadyNP-Hard problem,then somehow if we are able to reduce Q to R,then it is proved that R is NP-Hard problem.Now we will mathematically try to prove that these problems take exponentialtime.

    Consider that the worlds fastest computer excutes 1020 instructions/seconds.The total number of computers in the world are 1020. The number of instructions executed byall the computers in the world is as follows:

    = 1020 1020 60 60 24 365Now we will approximate the above statement:

    1020 1020 102 102 102 103

    = 1050

    2200(approx)

    Now the total time taken is as follows:

    =21000

    2200

    = 2800

    2

  • The Mother problem of NP is the SATISFIABILITY problem.Satisfiability consists of aconjunction of clauses and in turn clause is a disjunction of literals.We have to find an assign-ment such that the given equation evaluates to true.If there are k-literals then the all possiblecombinations of truth table are 2k.Any problem which is reducible from satisfiability problemis treated as an NP-Hard problem. The famous Scientist Stephen Cook has told that:If thereis a problem in NP which is solvable in polynomial time,then every other problemin NP is also solvable in polynomial time..The reason behind this is that all problemsare convertible in to each other.

    Fig 1:Reducibility

    The concept of NP-completeness was introduced in 1971 by Stephen Cook in a paper entitled.Atthat computer science conference, there was a fierce debate among the computer scientists aboutwhether NP-complete problems could be solved in polynomial time on a deterministic Turingmachine. John Hopcroft brought everyone at the conference to a consensus that the question ofwhether NP-complete problems are solvable in polynomial time should be put off to be solvedat some later date, since nobody had any formal proofs for their claims one way or the other.This is known as the question of whether P=NP.Nobody has yet been able to determine con-clusively whether NP-complete problems are in fact solvable in polynomial time, making thisone of the great unsolved problems of Mathematics.In Cooks theorem, Cook proved that theBoolean satisfiability problem is NP-complete (a simpler, but still highly technical proof of thisis available). In 1972, Richard Karp proved that several other problems were also NP-complete(see Karps 21 NP-complete problems); thus there is a class of NP-complete problems (besidesthe Boolean satisfiability problem). Since Cooks original results, thousands of other problemshave been shown to be NP-complete by reductions from other problems previously shown tobe NP-complete.

    Fig 2a:The first state of P and NP.

    3

  • Fig 2b:The second state of P and NP.

    At present, all known algorithms for NP-complete problems require time that is superpolynomial in the input size, and it is unknown whether there are any faster algorithms.Thefollowing techniques can be applied to solve computational problems in general, and they oftengive rise to substantially faster algorithms:

    Approximation: Instead of searching for an optimal solution, search for an almostoptimal one. Randomization: Use randomness to get a faster average running time, andallow the algorithm to fail with some small probability. Note: The Monte Carlo method is notan example of an efficient algorithm, although evolutionary approaches like Genetic algorithmsmay be. Restriction: By restricting the structure of the input (e.g., to planar graphs), fasteralgorithms are usually possible. Parameterization: Often there are fast algorithms if certainparameters of the input are fixed. Heuristic: An algorithm that works reasonably well inmany cases, but for which there is no proof that it is both always fast and always produces agood result. Metaheuristic approaches are often used. One example of a heuristic algorithm isa suboptimal O(nlogn) greedy coloring algorithm used for graph coloring during the registerallocation phase of some compilers, a technique called graph-coloring global register allocation.Each vertex is a variable, edges are drawn between variables which are being used at the sametime, and colors indicate the register assigned to each variable. Because most RISC machineshave a fairly large number of general-purpose registers, even a heuristic approach is effectivefor this application.

    1.1 Problem Formulation

    The N-Queen problem is solvable for smaller values of N.As the value of N increases,the ef-ficiency decreases.N Queen problem faces three types of constraints which are column,rowand diagonal conflict.It has applications in areas such as Traffic signalling,Railway schedul-ing,parallel processing,load balancing,parity codes etc.It is not the case that we can convertone problem in to another(N Queen to one of the above mentioned application).The similarityis that whatever are constraints faced by N Queen, same are constraints faced by above applica-tions.The mentioned applications may have more constraints.The main task before Researchersis to solve the above problem for higher values of N,so that we are able to solve complex realworld problems. Hence,the main focus it to solve the problem for higher values of Nusing Heuristics and Evolutionary Algorithms.The main motive behind Heuristicsis to reduce the search space(It should be tried to reduce the search space from N !to N).It also motivates to provide stronger search space elements which will helpsthe next steps in finding the solutions in faster manner.

    4

  • 1.2 Significance

    The problem has significance in the field of Artificial Intelligence.In Artificial Intelligence ,anysort of problem,puzzle etc can be selected.After selecting the problem or puzzle,we map thesimilarities between the problem(puzzle) and any real world problem.Upon maximum match ofthe constraints,we state that If there happens any sort of Optimisation in the problem,then the same Optimisation can be applied to the real world problems.It is not thecase that the problems are convertible in to each other,it is the case that they have similaritiesin their constraints.The Heuristics we will discuss in this report aims at minimizing the searchspace(the reduction of the search space can happen from N ! to N).Suppose the time complexityprior to the application of Heuristics is O(N !),then the application of Heuristics reduces thetime complexity to O(N).This improvement is a huge improvement.The problem comes underthe subsection of game playing.In game playing ,we have to play a certain game following therules and constraints of the games.The goal of the individual is to win the game with maximumscore.Different Individuals are asked to play the game following the rules and constraints in thegame.Suppose there are n players,each one of them plays the game and everybodys score isnoted down and level to which he has followed the rules of the game is also noted down.Thusthe analysis of above game playing helps us in designing a efficient Heuristics.This Heuristicscan be applied in any real world problem.

    Due to the constraint that above problem faces we call this problem as the Constraint Sat-isfaction Problem (C.S.P.).We need to satisfy all the constraints simultaneously.Suppose thereare five constraints named as C1,C2,C3,C4 and C5.For the satisfaction of all the constraintssimultaneously we design the following mathematical expression C1 C2 C3 C4 C5.TheExpression tells us that all the constraints need to be satisfied simultaneously,but many of timeswe are not able to handle all the constraints.Dissatisfaction of one or more constraints keepsthe problem unsolved.Due to these reasons some of the C.S.P.problems come under the classNP(Non Deterministic Polynomial time).

    One thing also about Laws of Unintended Consequences also wants to be stated Whenevera problem is discovered along with a solution then at that particular moment we cannot predicthow applicative it will be in future.Different Heuristic techniques can used such as generate andtest,Hill Climbing,Global Search,Backtracking,Simulated Annealing and Tabu Search.We canuse Genetic Algorithm,Ant Colony Optimisation,Pre-Shaking and Shaking Algorithms,GeneticAlgorithm with modification in mutation probability.Thus the Heuristic above can be used tofind the Solution efficiently.We can use Randomisation for finding the average case Runningtime.After application of Randomisation, we can take average over all possible Solution spaceset.Due to this average we get the expected running time.Because of this Randomisation we areable to avoid the worst case and convert the worst case in to average case.The above problemcan be encoded in to Satisfiability problem.After encoding we get the truth table of the size2N

    2where N is the input size.The Significance of the above problem is that it can be encoded

    as many different problem.This fact indicates that if we are able to find Solution for one we areable to find Solution for many others.

    5

  • 1.3 Objective and Scope of work

    Major Objectives finalized in line with the problem formulation are as under:

    1. To use Randomisation in the placement of the Queens followed by the application ofMinimum Conflict Algorithm to get stronger elements of Solution space.On these strongerelements of Solution space we apply genetic algorithm to get the Solution.

    2. To apply Constrained and Modified A.C.O on the chess board from left to right.In firststep we try to eliminate the row and column conflict.In succeeding steps we have to assignweights to the edges of the graph(based on Pheromone concentration)to avoid diagonalconflicts.

    3. To use Randomisation in the placement of the Queens followed by Shaking and Pre-Shaking Algorithms.To avoid the conflicts which are not covered by Pre-Shaking andShaking Algorithms we use Tabu Search and Local Search Heuristics.

    1.4 Methodology

    In Randomisation we use randomise function to place the Queens.For the placement of theQueen we use Randomise Generator.One instance of the randomised generator must be consid-ered.In the below diagram,the following strategy will be taken in to consideration.

    After the placement of the Queens,we have to calculate the conflicts for every square and af-ter calculation of the Conflicts we have to do the movement of the Queen within the column.TheQueen must be moved to the position whichever has minimum Conflicts.The Motive behindthis is that we have to generate more efficient Elements of Solution Space.Now follow the dia-gram below and check out modified movement of the Queens. Now we can derive one SolutionSpace from the above diagram 3,6,4,1,4,5,7,8. Similarly ,follow the process of Randomizationfollowed by Minimum Conflict Algorithm and try to get atleast five Solution Space and thenapply Genetic Algorithm on them.We do not use here Random approach for the movement ofthe Queens but use a greedy approach.Genetic Algorithm consists of following steps:

    1)Creation of initial population:In this step we have to choose the elements of the Solution space in such a way that we are able toreach the solution in a faster and effective manner.What Problem usually happens with this sortof problems is that is the exponential Solution Space because of Brute Force Approach.GeneticAlgorithms aims to reduce the Solution Space from N! to N(because of such improvement thisstep is important and so Genetic Algorithms are preferred over other Algorithms).

    2)Calculation of Fitness Function:Fitness Function helps us in reaching the Solution in a faster manner.Fitness Function mayvary from problem to problem.This step is the looping step which keeps on looping until wereach a zero attack position.If we get a zero attack position then we are done with the solution.

    3)Applying Crossover on the Population:Crossover helps us in reaching the Solution to some extent with minimized attacks or moreattacks.In Crossover operation we select two elements of the Solution Space.Apply crossover onthem as required such as two point crossover,three point crossover and then measure the fitnessof the solution space.This is a continuous ongoing process until we get a efficient solution.

    6

  • 4)Applying Mutation on the Population Space:Mutation includes flipping one of the bits of the element of the Solution space.Flipping of oneof the bits of the Solution space gives us the Solution.

    The Minimum Conflict Algorithm covers the above two steps(step 1 and step 2).Suppose ifwe consider that the elements of population space are :

    4, 2, 6, 3, 5, 8, 1, 7 and 1, 3, 7, 5, 2, 8, 6, 4

    Applying Crossover on them we get,

    4, 2, 6, 5, 2, 8, 6, 4 and 1, 3, 7, 3, 5, 8, 1, 7

    Applying Mutation over them we get,

    4, 2, 6, 5, 2, 3, 6, 4

    Check the fitness of the above solution space and iterate over it until you get a solution spacewith zero attack.We apply Randomisation N times.The reason behind applying this N times isthat in certain cases we get worst case,in certain cases we get best case and in certain cases weget average case,but the average(expected) time over all of them is average case.

    1.5 Significant Contribution

    7

  • Chapter 2

    Literature Review

    Many approaches are available for solving the N Queen problem such as brute force approach,Backtracking approach, Ant Colony Optimisation, Genetic Algorithm, Randomisation but eachapproach is able to give solution up to certain value of N [4]. As the value of N grows larger,theproblem tries to fall in the class NP [10].As these NP-Complete Problems are reducible toeach other, if we provide efficient solution for one NP-Complete problem for higher valuesof N, then we can provide solution to every other NP-Complete problem [1].Thus we needto examine each and every approaches, its limitations,its advantages and disadvantages.Useefforts to eliminate the limitations and disadvantages carrying the advantages with the prob-lem.Brute force approach usually works on the generate and test heuristics which generatestime complexity of N !,its extra memory requirement is N(excluding the N2) [4].Backtrackingapproach imposes more recursion with time complexity NN .There are many practical appli-cations of N Queen problem to real world applications such as real time systems,computerresource management,VLSI circuit design,VLSI testing,task scheduling,traffic control,deadlockprevention,parallel processing etc.So study of N Queen is important [7].

    2.1 Randomisation

    Probabilistic analysis is the use of probability in the analysis of problems.Probabilistic anal-ysis to analyze the running time of an algorithm as presented in [1].For e.g.Hiring assistantproblem.We use Expected Running time of random variable X is

    E[X] =

    x.Pr(X = x)............as given in[2]

    In Brute force Randomisation approach if we place the Queens at < 1, 2, 3, 4, 5......., N > thenthe

    total no. of conflicts : N(N 1)/2For e.g.:If value of N is 10 then the total no of conflicts are 45.If we follow the following Algorithmic Steps:

    for(i = 1 to n)do

    Q[i] = i

    shuffle(i)

    The no. of conflicts are reduced to 2n3

    .If the prior conflicts are 45 then the no of conflicts afterimplementing above code are

    =2 10

    3= 7........as presented in[3]

    8

  • . Thus,the no. of conflicts which were avoided are as follows 45-7=38.We take the example of Quick Sort when the pivot is not fixed.Every time we pick up the

    pivot randomly and execute the algorithm and get different time complexity every time.Sometimeswe get worst case,sometimes average case and some time best and the expected value over all ofthem gives us the average case i.e.O(nlogn) as proved in [4].Randomisation helps in the gener-ation of one element of solution space.There are more elements needed in the solution space.soPermutation approach can also be used which results in efficient crossover as suggested in [5].NQueen problem can also be encoded in to Satisfiability problem.The formation of the truthtable results in 2N

    2possibilties which is tremendous as the value of N increases as given in [6].

    In short we can summarise the steps for building our randomisation function:Place the Queens on the even positions and then place the Queens on the odd places.Thisstep helps us in minimizing the conflicts up to greater extent.Now we will roughly design theRandomise Function as follows:We take a two dimensional array of the form A[i][j].Queens areof the form Q[1],Q[2],.......Q[n].We have to place the Queen Q[i] on the board A[i][j] such thatfor the value i=1 in Q[1] the value remains the same in A[1][j].Now we have to keep j even andkeep on incrementing it until j value is less than or equal to N as explained in [7].

    for(i = 1; i

  • find any position in the column or in the row not been attacked.While changing the positionof the queen in the ith row ,we have to again change the position of the queen in (i-1) rowand then again to place the Queen at (i-1) position we have to again change the position ofthe Queen at (i-2) as presented in [11].Thus we have to keep on Backtracking.As the Searchspace is large(exponential),backtracking would be inefficient.The Third Heuristics we consideris Local Search(Hill Climbing).In this Local Search Strategy we have to first randomly placethe Queens,such that every Queen occupies different row.Random Placement does not guar-antee a solution as clarified in [12].Now there will be a pair of Queen which we will be underattack.We have to find a position for the Queen which is under zero attack.If all the positionsare under attack we have to place the Queen which are under minimum attack.The name localmodification comes from the fact that we do limited modifications and hence called as LocalSearch as depicted in [13].In local Search this method is not able to give a solution in someconditions.In Local Search mechanism,if this method is not able to give solution,it can performinfinite local modifications.On the contrary,global searching techniques tell us that no solutionexists for a problem which is not possible with local search technique.Global Search methodsare capable of telling that the whole search space has been explored and no solution has beenfound as explained in [14].

    In hill climbing search we select any local changes that improve the current value of theObjective Function.Greedy local Search is a form of hill climbing where we select a local movethat leads to largest improvement of the Objective Function as shown in [18].Traditionally onewould terminate hill climbing and greedy search methods when no local move could furtherimprove the Objective Function.Upon termination ,the search would have reached a local butnot necessarily global optimum as mentioned in [15].For many Optimisation Problems such asT.S.P,such a local optimum is not possible(acceptable),since it is often reasonable approxima-tion of global optimum value.However when a globally Optimal Solution is required such as NQueen local Optimal is not possible.Allow the local Search to continue by accepting sidewaysor even downhill moves i.e. local moves to state with, respectively,the same or worse Objectivevalues, one can still reach a global optimum.For e.g.:Such non improving moves are a key com-ponents of of local search methods.For e.g.:Boolean Satisfiability(SAT) problems.These localSearch methods for SAT outperform the traditional back Search strategies for a no. of SATproblem classes.Many combinatorial problems can be encoded as BOOLEAN SAT problems,Sothese local search algorithms provide a general mechanism for solving combinatorial problemsas given in [16].The Output of Randomisation is shown as follows:

    3 4 2 Q 1 1 2 21 4 Q 1 2 2 2 1Q 3 3 4 2 3 1 23 2 1 4 Q 1 3 12 1 3 1 3 Q 1 21 Q 2 2 2 3 4 22 2 2 2 2 1 Q 42 1 2 2 1 3 1 Q

    The Output of Minimum Conflict Algorithm is shown as follows:

    10

  • 3 3 2 Q 1 2 2 21 3 3 0 2 1 1 0Q 3 3 4 2 3 1 23 3 Q 5 Q 2 4 22 2 3 2 3 Q 1 22 Q 2 2 3 3 3 12 2 2 2 2 2 Q 32 1 2 2 1 3 2 Q

    The next Heuristic is Backtracking.Backtracking is one of the main methods for solvingproblems like N-Queens.But we dont want to create an algorithm just for solving N-Queens.Weneed to express N-Queens as an instance of a general class of problems and then design algo-rithms for solving this general class of problems.Backtracking may go in to infinite loop beforefinding the solution as shown in [17]. The next Heuristics is Simulated Annealing and TabuSearch.Simulated Annealing is an example of local Search Technique that incorporates sidewayand downhill moves as presented in [2, 18].In Simulated Annealing ,the downhill moves areaccepted with the probability based on the size of the Objective Function,with the worst movesbecoming the least likely.The fraction of accepted local changes is controlled by formal param-eter,called the temperature.At a high temperature almost any possible local move accepted.When lowering the temperature parameter ,fewer moves are accepted that moves that worsenthe Objective value,and search starts to resemble a purely greedy strategy. In Simulated An-nealing,inspired by physical process of annealing ,inspired by physical process of annealing ,thetemperature starts high and slowly lowered down during search process.Tabu Search is a localsearch method that contains the most recent local moves, the local search method is preventedfrom undoing those modifications.The Tabu list is limited length and updated after each localmove as given in [4].Therefore any particular change is prevented for a limited period of time.ATabu list provides a powerful way of forcing local search method to explore a larger part ofsearch space.

    The Next Heuristic we consider is the Evolution as shown in [19].We will consider now asmall n=4. Now the solution space of this is as follows:1 2 3 4 , 2 1 4 3 , 2 4 3 1 , 3 4 2 1 , 1 2 4 3 , 2 1 3 4 , 3 1 2 4 , 4 1 2 3, 1 4 2 3 , 2 3 1 4 , 3 2 1 4, 4 1 3 2, 1 4 3 2 , 2 3 4 1 , 3 2 4 1 , 4 3 1 2, 1 3 4 2 , 2 4 1 3 , 3 4 1 2 , 4 3 2 1Consider the no. of diagonals which are under attack. 1 4 2 3 -> 1 Attack, 2 1 3 4 -> 2 Attacks,3 2 4 1 -> 1 Attack, 4 2 3 1 -> 1 Attack, Now this is our Fitness Function. Lesser the attacksmore is the Fitness.Now we apply crossover on the selected solution space(population). 1 4 2 3, 3 2 4 1, 1 4 3 2 and 2 3 4 1(we are applying two point crossover). We can experiment here byapplying different crossovers (1,3 crossovers etc).Now the Population which is generated out ofcrossover is : 3 2 4 1 , 1 4 3 2, 4 1 3 1 , 2 3 4 1, 1 4 4 2 , 2 3 3 1, 3 2 4 2, 4 1 3 1 Now Evaluate themusing Fitness Function. If we get the Solution, stop here, otherwise apply mutation operator.Now after flipping the bits we get the solution and i.e. 3 2 4 2(after flipping bit 2 to 1)->3 14 2(Solution got).It is not guaranteed that we will find the Solution in every case as suggestedin [20].Out of 100 in 90 cases we are able to find the solution.

    Now comes the time to show N Queen as C.S.P.We can represent the N-queens as a con-straint satisfaction problem.A Constraint Satisfaction Problem consists of 3 components.A setof variables.A set of values for each of the variables.A set of constraints between various col-lections of variables. We must find a value for each of the variables that satisfies all of theconstraints as specified in [4, 17].

    The Minimum Conflict Algorithm generates efficient element for solution space.First weplace the Queens based on our Randomisation Function.The Randomisation Function helpsto minimise the attack up to certain extent in the first step only.We are taking the help ofthe Randomisation Function and the Minimal Conflict Algorithm to generate solution space

    11

  • with efficient elements with reference to [5, 11].If we have efficient solution space then oursucceeding tasks become easy and help us in finding out the solution efficiently.The incomingHeuristics we consider is Ant Colony Optimisation(A.C.O).Application of some constraints onit makes it applicable for N Queen suggested in [12] but the problem is that it requires morememory.Solving the N Queen problem using diagonal method also does not guarantee solutionbecause after some period of time for certain N value will keep on looping as suggested in [6].

    2.3 Genetic Algorithms

    Genetic Algorithm runs through the following four steps which are as follows:1)Intialization ofPopulation.2)Calculation of the Fitness Function 3)Crossover between the elements of solutionspace.4)Mutation on the element of solution space as shown in [16].Traditional approach suggestus to randomly select the elements of the population but randomly selecting the element of thesolution space does not guarantee us efficient solution.So we require modification in the stepsof genetic algorithm.First we will do modification in the step of population initialization asspecified in [17].We will use a perfect Randomise function for the placement of Queen whichwill help in minimising the attacks.As the elements of the population space consists of evenpositions followed by odd position,we apply permutation on the even part and odd part.Theresult of this step is that we get a varied solution space less than N !.Now we apply Minimalconflict Algorithm on the initial placement of Queens and get some solution space out ofit.Count the fitness of the elements of the Solution and pick up the top stronger elements of thesolution space out of it as given in [18].This is going to be beneficial for the succeeding steps ofthe genetic algorithm.Now related to the modification in the crossover step:In situation wherebreak-point is selected randomly, candidates resulting from crossover operation (= offspringcandidates) might be better or worse than their parents. But if we look at the results of allpossible break-points and choose the best one, each generation will always equal or better thanprevious generation.Minimal conflicts operator applied to each candidates after crossover andmutation as a third operator of recombination phase as shown in [19].

    A novel algorithm for solving combinatorial optimization problems using genetic algorithms(GA) with self-adaptive mutation. We selected the N-Queens problem as our benchmarkingtest suite, as they are highly multi-modal with huge numbers of global optima.Optimal staticmutation probabilities for the traditional GA approach are determined for each N to use asa best-case scenario benchmark in our conducted comparative analysis as depicted in [15].Despite an unfair advantage with traditional GA using optimized fixed mutation probabilities,in large problem sizes multi-objective analysis showed the self-adaptive approach yielded a 65 to584 improvement in the number of distinct solutions generated as per [5, 6, 7]; the self-adaptiveapproach also produced the first distinct solution faster than traditional GA with a 1.90 to 70speed improvement. Self-adaptive mutation control is valuable because it adjusts the mutationrate based on the problem characteristics and search process stages accordingly as given in [14].This is not achievable with an optimal constant mutation probability which remains unchangedduring the search process.

    In the light of the above literature we have found that Improved Randomisation will help usin the minimisation of the attacks and help us in getting more fit solution space for the GeneticAlgorithm.The initial step of Initialization of Population space is of prime importance.Theelements of the solution space must be such that crossover and mutation takes us nearer tothe solution.In this the contribution of Minimal Conflict Algorithm is also tremendous.MinimalConflict Algorithm gives us much improved Solution Space.It helps in minimizing the attackby local moving along the given column and then placing the queen on the minimal attackposition.The Problem we had with prior approaches is that we had to randomly pick up anyelements of the solution space.Now with the help of Randomisation and Minimal Conflict

    12

  • Algorithm, we are able to refine the elements of the Solution up to much extent.Then thetask goes with the Genetic Algorithm to apply all its strategy to find the solution.If we arenot getting Solution after mutation step then simply we have to keep on looping until we getthe Solution.Many Researchers use Genetic Algorithm by Randomly selecting the elements ofthe Solution Space which doesnot give that much efficient Results.So for getting efficient andstronger results we take the help of Randomisation and Minimum Conflict Algorithm. In thismanner we get the correct solution with right Heuristics in an efficient and optimised manner.

    13

  • Chapter 3

    Implementation

    3.1 Proof for NP-Completeness of C.S.P

    A Formal Proof is given for proving the N-Queen problem as NP-Complete. We will consider4 Queen problem:

    1,1 1,2 1,3 1,42,1 2,2 2,3 2,43,1 3,2 3,3 3,44,1 4,2 4,3 4,4

    To Prove that a problem is NP-Complete:1)It is in the Class NP(Non -Deterministic Polynomial time).2)To Prove a Problem is NP-Hard.(Use Reducibility technique)

    To Prove that a Problem is in the Class NP, we have to prove that it is verifiable in Polyno-mial time.Given a certificate for a Solution, it must be verifiable in Polynomial time.Considerthe example of a Prover and a Verifier.A Prover has all sorts of power.He can prove anythingin the world.He can perform computationally any task in the world within limited time.A Ver-ifier has limited Knowledge.He has the power of the Verifiability. Satisfiability problem is theMother problem.Now consider that the Prover gives the Solution for N=10.The Solution forN=10 is given as follows:

    QQ

    QQ

    QQ

    QQ

    QQ

    Verifier has written polynomial time algorithm to verify the Solution to the problem.He is ableto verify the Solution in polynomial time.So is first part proved.If Prover gives him Solution for N=100,then the Verifier has to apply the same strategy andverify the Solution.For Second Part, we take the help of Satisfiability problem. Boolean Satisfiability consists of

    14

  • C1 , C2 ,C3.....Cn. The Final Clause is a conjunction of literals and the each Clause is adisjunction of literals.We will write an Expression in the form of Boolean Satisfiability(Column Attack C):(P1,1P1,2P1,3P1,4)(P2,1P2,2P2,3P2,4)(P3,1P3,2P3,3P3,4)(P4,1P4,2P4,3P4,4) (P1,1 P1,2 P1,3 P1,4) (P2,1 P2,2 P2,3 P2,4) (P3,1 P3,2 P3,3 P3,4) (P4,1 P4,2 P4,3 P4,4).

    Applying De-Morgans Law:(P1,1P1,2P1,3P1,4)(P2,1P2,2P2,3P2,4)(P3,1P3,2P3,3P3,4)(P4,1P4,2P4,3P4,4)(P1,1 P1,2 P1,3 P1,4)( P2,1 P2,2 P2,3 P2,4)( P3,1 P3,2 P3,3 P3,4) ( P4,1 P4,2 P4,3 P4,4).

    We will write an Expression in the form of Boolean Satisfiability(Row Attack R): ((P1,1 P2,1 P3,1 P4,1) (P1,2 P2,2 P3,2 P4,2) (P1,3 P2,3 P3,3 P4,3) (P1,4 P2,4 P3,4 P4,4)).

    Applying De-Morgans Law:( P1,1 P2,1 P3,1 P4,1) ( P1,2 P2,2 P3,2 P4,2) ( P1,3 P2,3 P3,3 P4,3) ( P1,4 P2,4 P3,4 P4,4).

    We will write an Expression in the form of Boolean Satisfiability(Diagonal Attack D):

    ((P1,1P2,2P3,3P4,4P5,5)(P1,4P2,3P3,2P4,1)(P3,1P4,1)(P2,1P3,2P4,3)(P1,2P2,3P3,4)(P1,3P2,4)(P2,1P1,2)(P3,1P2,2P1,3)(P4,2P3,3P2,4)(P4,3P3,4))

    Applying De-Morgans Law:( P1,1 P2,2 P3,3 P4,4) ( P1,4 P2,3 P3,2 P4,1) ( P3,1 P4,2) (P2,1 P3,2 P4,3) ( P1,2 P2,3 P3,4) ( P1,3 P2,4) ( P2,1 P1,2) (P3,1 P2,2 P1,3) ( P4,2 P3,3 P2,4) ( P4,3 P3,4)

    For Solution Model C R D must be true.Now we will use truth table to prove that some Solutions space are true and some are false.

    There are 16 literals and the numbers of possibilities in the truth table are 242.In generalised

    fashion we can say that the numbers of possibilities for N Queen board in the truth table are2N

    2Instead of considering so many large possibilities of truth values.We Consider the number

    of possibilities as 4! as we have considered a 4 Queen problem.We will list the elements of the Solution Space and only check for them.(1,2,3,4),(1,2,4,3),(1,4,2,3),(1,4,3,2),(1,3,4,2),(1,3,2,4)(2,1,4,3),(2,1,3,4),(2,4,1,3),(2,4,3,1),(2,3,4,1),(2,3,1,4)(3,1,4,2),(3,1,2,4),(3,4,1,2),(3,4,2,1),(3,2,4,1),(3,2,1,4)(4,1,3,2),(4,1,2,3),(4,2,1,3),(4,2,3,1),(4,3,1,2),(4,3,2,1)

    15

  • P1,1 P1,2 P1,3 P1,4 P2,1 P2,2 P2,3 P2,4 P3,1 P3,2 P3,3 P3,4 P4,1 P4,2 P4,3 P4,4T F F F F T F F F F T F F F F TT F F F F T F F F F F T F F T FT F F F F F T F F T F F F F F TT F F F F F F T F T F F F F T FT F F F F F T F F F F T F T F FT F F F F F F T F F T F F T F FF T F F T F F F F F T F F F F TF T F F T F F F F F F T F F T FF F T F T F F F F F F T F T F FF F F T T F F F F F T F F T F FF F F T T F F F F T F F F F T FF F T F T F F F F T F F F F F TF T F F F F F T T F F F F F T FF F T F F F F T T F F F F T F FF F F T F F T F T F F F F T F FF F F T F T F F T F F F F F T FF F T F F T F F T F F F F F F TF T F F F F F T F F T F T F F FF T F F F F T F F F F T T F F FF F T F F T F F F F F T T F F FF F F T F T F F F F T F T F F FF F T F F F F T F T F F T F F FF F F T F F T F F T F F T F F F

    16

  • C R D ST T F FT T F FT T F FT T F FT T F FT T F FT T F FT T F FT T F FT T T T(2,4,1,3)T T F FT T F FT T F FT T T T (3,1,4,2)T T F FT T F FT T F FT T F FT T F FT T F FT T F FT T F FT T F FT T F F

    Now we will verify that for whichever Solution Space we have got truth value as True(T) actu-ally has correct Solution or not.

    QQ

    QQ

    There are no Attacks. So this is one of the correct Solution(2,4,1,3).

    QQ

    QQ

    There are no Attacks. So this is one of the correct Solution(3,1,4,2).We can also write generalize expressions for Column(C),Row(R),Diagonal(D) which can beapplied for any value of N. Thus,we have satisfied both the conditions and thus we have provedthat the N Queen problem is NP-Complete.

    17

  • Now we will consider 5 Queen problem,

    1,1 1,2 1,3 1,4 1,52,1 2,2 2,3 2,4 2,53,1 3,2 3,3 3,4 3,54,1 4,2 4,3 4,4 4,55,1 5,2 5,3 5,4 5,5

    We will write an Expression in the form of Boolean Satisfiability(Column Attack C):(P1,1P1,2P1,3P1,4P1,5) (P2,1P2,2P2,3P2,4P2,5) (P3,1P3,2P3,3P3,4P3,5)(P4,1P4,2P4,3P4,4P4,5)(P5,1P5,2P5,3P5,4P5,5) (P1,1P1,2P1,3P1,4P1,5) (P2,1P2,2P2,3P2,4P2,5) (P3,1P3,2P3,3P3,4P3,5) (P4,1P4,2P4,3P4,4P4,5) (P5,1 P5,2 P5,3 P5,4 P5,5).

    Applying De-Morgans law:(P1,1P1,2P1,3P1,4P1,5)(P2,1P2,2P2,3P2,4P2,5)(P3,1P3,2P3,3P3,4P3,5)(P4,1P4,2 P4,3 P4,4 P4,5) (P5,1 P5,2 P5,3 P5,4 P5,5) ( P1,1 P1,2 P1,3 P1,4 P1, 5) ( P2,1 P2,2 P2,3 P2,4 P2,5) ( P3,1 P3,2 P3,3 P3,4 P3,5) ( P4,1 P4,2 P4,3 P4,4 P4,5) ( P5,1 P5,2 P5,3 P5,4 P5,5).

    We will write an Expression in the form of Boolean Satisfiability(Row Attack R): ((P1,1 P2,1 P3,1 P4,1 P5,1) (P1,2 P2,2 P3,2 P4,2 P5,2) (P1,3 P2,3 P3,3 P4,3 P5,3) (P1,4 P2,4 P3,4 P4,4 P5,4) (P1,5 P2,5 P3,5 P4,5 P5,5).

    Applying De-Morgans Law:( P1,1 P2,1 P3,1 P4,1 P5,1) ( P1,2 P2,2 P3,2 P4,2 P5,2) (P1,3 P2,3 P3,3 P4,3 P5,3) ( P1,4 P2,4 P3,4 P4,4 P5,4) ( P1,5 P2,5 P3,5 P4,5 P5,5).

    We will write an Expression in the form of Boolean Satisfiability(Diagonal Attack D): ((P4,1P5,2)(P3,1P4,2P5,3)(P2,1P3,2P4,3P5,4)(P1,1P2,2P3,3P4,4P5,5)(P1,2P2,3P3,4P4,5)(P1,3P2,4P3,5)(P1,4P2,5(P2,1P1,2)(P3,1P2,2P1,3)(P4,1P3,2P2,3P1,4)(P5,1P4,2P3,3P2,4P1,5)(P5,2P4,3P3,4P2,5)(P5,3P4,4P3,5)(P5,4P4,5))

    Applying De-Morgans Law:( P4,1 P5,2) ( P3,1 P4,2 P5,3) ( P2,1 P3,2 P4,3 P5,4) ( P1,1 P2,2 P3,3 P4,4 P5,5) ( P1,2 P2,3 P3,4 P4,5) ( P1,3 P2,4 P3,5) ( P1,4 P2,5) ( P2,1 P1,2) ( P3,1 P2,2 P1,3) ( P4,1 P3,2 P2,3 P1,4) ( P5,1 P4,2 P3,3 P2,4 P1,5) ( P5,2 P4,3 P3,4 P2,5) ( P5,3 P4,4 P3,5) ( P5,4 P4,5)

    For Solution Model C R D must be true.

    Now we will use truth table to prove that some Solutions space are true and some are false.There are 25 literals and the numbers of possibilities in the truth table are 25

    2.In generalised

    fashion we can say that the numbers of possibilities for N Queen board in the truth table are2N

    2Instead of considering so many large possibilities of truth values.We Consider the number

    of possibilities as 5! as we have considered a 5 Queen problem.We will list the elements of the Solution Space and only check for them.The Size of table is very large, its size is (120x29).The number of entries generated in the truthtable for 5 Queen problem are nearly 25

    2= 225

    18

  • For 6 Queen problem the number of entries are nearly 262

    = 236 which is greater than 1GBFor 7 Queen problem the number of entries are nearly 27

    2= 249 which is 64GB

    For 8 Queen Problem the number of entries are nearly 282

    = 264 andFor 100 Queen problem the number of entries are nearly 2100

    2= 210000.As the value of N in-

    creases the memory requirement goes on increasing exponentially.In generalised fashion we canwrite down that for N Queen problem the number of entries in the truth table are 2N

    2.This is

    an over approximation.We are considering only the nearby values.

    We will now write generalised Expression which can be made applicable for any value of N.

    For Column Attack(i=1,n is as inputed by user)C:(Pi,iPi,i+1......Pi,i+n1)(Pi+1,iPi+1,i+1.......Pi+1,i+n1).........(Pi+n1,iPi+n1,i+1.........Pi+n1,i+n1) (Pi,iPi,i+1 ......Pi,i+n1) (Pi+1,iPi+1,i+1 .......Pi+1,i+n1)...... (Pi+n1,i Pi+n1,i+1 ......... Pi+n1,i+n1)

    Applying De-Morgans law we get simplified expression:(Pi,iPi,i+1......Pi,i+n1)(Pi+1,iPi+1,i+1.......Pi+1,i+n1).........(Pi+n1,iPi+n1,i+1......... Pi+n1,i+n1) ( Pi,i Pi,i+1 ...... Pi,i+n1) ( Pi+1,i Pi+1,i+1 ....... Pi+1,i+n1) ...... ( Pi+n1,i Pi+n1,i+1 ......... Pi+n1,i+n1)

    For Row Attack(i=1,n is as inputted by user)R: ((Pi,i Pi+1,i ....... Pi+n1,i) (Pi,i+1 Pi+1,i+1 Pi+2,i+1 ...... Pi+n1,i+1) ............. (Pi,i+n1 Pi+1,i+n1 ......... Pi+n1,i+n1))

    Applying De-Morgans law we get simplified expression:( Pi,i Pi+1,i ....... Pi+n1,i) ( Pi,i+1 Pi+1,i+1 Pi+2,i+1 ...... Pi+n1,i+1)............. ( Pi,i+n1 Pi+1,i+n1 ......... Pi+n1,i+n1))

    For Diagonal Attack(i=1,n is as inputted by user)D: ((Pn1,iPn,i+1) (Pn2,iPn1,i+1Pn,i+2) (Pn3,iPn2,i+1 ..........Pn,i+3) (Pn4,iPn3,i+1 ....... Pn,i+4) (Pi,n3 Pi+1,n2 .......... Pi+3,n) (Pi,n2 Pi+1,n1 Pi+2,n (Pi,n1Pi+1,n)(Pi,n3Pn3,i)(Pi,n2Pi+1,n3Pi+2,n4)(Pi,niPi+1,ni1Pi+2,ni2Pi+3,ni3) (Pi,n Pi+1,n1 ... Pi+n1,n))

    Applying De-Morgans law we get simplified expressions.( Pn1,i Pn,i+1) ( Pn2,i Pn1,i+1 Pn,i+2) ( Pn3,i Pn2,i+1 .......... Pn,i+3)( Pn4,i Pn3,i+1....... Pn,i+4)( Pi,n3 Pi+1,n2.......... Pi+3,n)(Pi,n2 Pi+1,n1 Pi+2,n Pi,n1 Pi+1,n) ( Pi,n3 Pn3,i) ( Pi,n2 Pi+1,n3 Pi+2,n4) ( Pi,ni Pi+1,ni1 Pi+2,ni2 Pi+3,ni3) ( Pi,n Pi+1,n1 ... Pi+n1,n)

    Base on the Expressions above generate truth tables and locate the Truth T for C R D.Those entries which have truth value T are the correct Solutions.Correspondingly the truthtable is going to have 2N

    2.

    19

  • DEFINITION OF INJECTIVE FUNCTION(ONE TO ONE FUNCTION):A function f is said to be an Injective function(one to one), iff f(b) = f(c) implies that b=cfor all b and c in the domain of f .

    Formulation of Queens problem as a Injective Function: nxn Queens problems Solutiondenoted by can be given as follows:

    {(1), (2), (3).................(n)}

    rather than

    = {((1), 1), ((2), 2), ((3), 3)...................((n), n)}OR

    1 = {(1, (1)), (2, (2)), (3, (3))...................(n, (n))}

    Both and 1 are Solutions.For e.g.: For n=4,Solution:

    {(2, 1), (4, 2), (1, 3), (3, 4)}

    OR{(1, 2), (2, 4), (3, 1), (4, 3)}

    can be written as

    {2, 4, 1, 3}

    For n=8,Solution:

    {(1, 1), (8, 2), (5, 3), (3, 4), (6, 5), (9, 6), (2, 7), (4, 8), (7, 9)}

    OR{(1, 1), (2, 8), (3, 5), (4, 3), (5, 6), (6, 9), (7, 2), (8, 4), (9, 7)}

    can be written as

    {1, 8, 5, 3, 6, 9, 2, 4, 7}

    : f(Q1, Q2, Q3, .............Qn) > (1, 2, 3..................n)

    is an injective function and 1 is an injective function.We are doing this type of formulation to make the problem applicable for Solving throughGenetic Algorithm. We note that the permutation can be thought of as map from columns torows.We note that the permutation of {0, 1, ................n 1} represents a Solution for nxn

    20

  • standard board iff

    (x) + x and (x) xare injective functions.Now we will see how we can represent Queens problem as as injectivefunction.As the value of N increases ,the memory requirement also increases exponentially.

    21

  • On X axis, we have plotted N Values and on Y axis,we have plotted 2N2

    but for simplicity andapproximation purpose we have considered the plotting of N2 which gives rise to an exponentialcurve.In Conclusion we require to show the exponential requirement of memory as the value ofN increases.

    22

  • 3.2 Randomisation

    In direction of the Literature Survey the placement of the Queens was done sequentially(1,2,3,4....n).There is a class of algorithms, known as randomized algorithms, which incorporate random-ness in their execution. In actual practice, these algorithms use a random value, generated byrandom number generator, to decide the next step at different stages of their execution. For ex-ample, in randomized quicksort, at every recursive step, the pivot element is selected randomlyto impose randomness in the input instances. Worst case complexity analysis of the quicksortshows that there are a few input instances for which quicksort takes longer amount of timecompared to its average execution time. Therefore, in repeated applications of this algorithm,it is desirable to impose randomness in the input instances to prevent excessive occurrence ofunfavorable instances. In these kinds of randomized algorithm.The below for loop depicts it:

    for(i = 1; i < n; i+ +)

    Q[i] = i

    For implementation of randomized algorithms, generation of random numbers is essential.Moreover, a simulation of any process which involves an inherent random component, makeuse of random numbers. In this article we are trying to indicate a few methods for drawingrandom values from a uniform probability distribution over the range [0,1]. It may be notedthat if we can generate uniform random variates, it is possible to get samples from most of thecommon distributions using suitable transformations. In tabular format the Queens seem tobe as follows.We will consider a 4 Queen problem.

    Q1Q2

    Q3Q4

    The total no. of Conflicts is given by the formula:

    n(n 1)2

    By putting the values in the above formula for 4 Queen we get,

    4 32

    = 6

    Now we will try to list the Conflicts as follows: Q1Q2 , Q1Q3 , Q1Q4 , Q2Q3 ,Q2Q4 , Q3Q4.Now we will consider 7 Queen problem as our line of direction and try to show how we improvedfrom initial state to final state.In 7 Queen problem there are are 21 conflicts.

    Q1Q2

    Q3Q4

    Q5Q6

    Q7

    The Conflicting pairs listed are as follows:Q1Q2 , Q1Q3 , Q1Q4 , Q1Q5 , Q1Q6 , Q1Q7 ,Q2Q3 , Q2Q4 , Q2Q5 , Q2Q6 , Q2Q7 , Q3Q4 ,

    23

  • Q3Q5 , Q3Q6 , Q3Q7 ,Q4Q5 , Q4Q6 , Q4Q7 , Q5Q6 , Q5Q7, Q6Q7.In programming terms we can modify the code lines as follows:

    for(i = 1; i

  • 6, 3, 6, 3, 5, 2, 4

    3 point crossover:

    1, 7, 6, 7, 4, 2, 1

    6, 3, 5, 3, 5, 2, 4

    4 point crossover:

    1, 7, 6, 3, 4, 2, 1

    6, 3, 5, 7, 5, 2, 4

    5 point crossover:

    1, 7, 6, 3, 5, 2, 1

    6, 3, 5, 7, 4, 2, 4

    6 point crossover:

    1, 7, 6, 3, 5, 2, 1

    6, 3, 5, 7, 4, 2, 4

    In the next step we have to apply the mutation operator(mutation means flipping the bitsof the Solution Space).We must walk through the elements of the Solution Space and find thegene which is repeated in the chromosome and after finding out which genes repeats in theelement of the Solution Space and replace it with gene which is not present in the element ofthe Solution Space.

    We choose N=7 and N=50 and run the Randomisation program for 1000 times and notedown the Conflicts for each run, average them and represent them in the form of graphs.Nowwe averaged the Conflicts value and found that the average is 7.4 which is far better than 21.

    13.6 10021

    = 64.76

    On X axis >Conflict values.On Y axis >Frequency of Conflicts.We plotted the line graph for Conflicts against the frequency of Conflicts and found that averageis 7.4 which is far better than the number of Conflicts 21.

    25

  • As we have observed the speed up for N=7 is 6.4.Now we will check the speed up forN=50.By putting the values in the formulas we get the Conflicts as :

    =n(n 1)

    2

    =50 49

    2= 1225

    Now we will consider how initial search is performed using 4 Queen as a supporting example:

    QQ

    QQ

    Fig : 4 Queen problem

    The above Output for 4 Queen (4,2,1,3 ) is the Output of Randomisation.Now we will consider Diagonals with negative slope.Suppose the Queen is placed at position(i,j),then (i+j) is constant for every position on the diagonal with negative slope.For positiveslope diagonals (i-j) is constant.Consider Queen as qi as the row number and i as the columnnumber.For qi ,its diagonal line are calculated as i+qi and i-qi.For n-queen problem there 2n1positive slope diagonals and 2n 1 negative slope diagonals.We design arrays of 2n 1 size forpositive slope diagonals and negative slope diagonals.We keep track of the numbers of Queensin these arrays.We will consider above 4 Queen problem for designing these arrays:

    For Negative-slope diagonals:1 0 0 1 1 1 0

    On Negative-slope Diagonals there are no conflicts.

    For Positive-slope diagonals:0 1 0 1 2 0 0

    On Positive-slope Diagonals there are conflicts on array position five.Using two arrays it takesconstant time to find the number of collisions on diagonal lines.Now we will consider how initial search is performed using 8 Queen as a supporting example:

    QQ

    QQ

    QQ

    QQ

    For Negative-slope diagonals:0 0 1 1 0 0 1 2 1 0 1 0 0 1 0

    On Negative-slope Diagonals there are conflicts on array position eight.For Positive-slope diagonals:1 0 0 0 0 0 1 3 1 1 0 0 1 0 0

    On Positive-slope Diagonals there are conflicts on array position eight.

    26

  • Following a common mathematical technique, we first transform the problem from discretedomain to continuous domain.The original chessboard is mapped to a unit square.A position(i,j) on original nxn board is mapped to a point ( i

    n, jn) in the unit square.Let a and b be two

    diagonal lines that cross each other.Let p(a) represent the probability that there is a queenon diagonal a and Let p(b) represent the probability that there is a queen on diagonal b.Thecombined probability p(a+b) that a common position is attacked from diagonal a or diagonalb is computed as probability of sum a and b:

    p(a+ b) = p(a) + p(b) p(a)p(b)We will consider the magnified image of unit square for 4 Queen problem:

    (14, 14) (1

    4, 12) (1

    4, 34) (1

    4, 1)

    (12, 14) (1

    2, 12) (1

    4, 34) (1

    2, 1)

    (34, 14) (3

    4, 12) (3

    4, 34) (3

    4, 1)

    (1, 14) (1, 1

    2) (1, 3

    4) (1, 1)

    Let f(x) denote the number of steps for placing the first x queens.The value of f(1) is the totalnumber of steps during the initial search.Let p(x) be the probability that the random queenon column x is attacked by some previously placed queen to the left.The value of f(x) can becomputed from p(x) as follows:

    f(x) =

    x0

    1

    1 p(x)dx

    We split the calculation of p(x) into two parts :the interval with 0 < x < 0.5 and with in-terval 0.5 < x < 1.The probabilities of a collision in these two intervals are denoted asp1(x) = p(x, x < 0.5) and p2(x) = p(x, x > 0.5), respectively.The algorithm prevents theconstruction of row and column collisions, so we take into account diagonal collisions.First we calculate p1(x).Let x denote a column between 0 and 0.5, and y be a point on thiscolumn.Let a and b be two left diagonal lines that pass through point (x,y).It follows from(1)that point (x,y) is occupied with following probability:

    p(x, y) = p(a+ b) = p(a) + p(b) p(a)p(b)We separate the values into three intervals:

    1. x < y < 1 x2. y < x

    3. y > 1 xcase 1:If x < y < 1 x, then a and b have equal length.In this case, p(a) = x and p(b)=x.It follows that point(x,y) is attacked by a queen with the following probability:

    p(x, y) = p(a+ b) = x+ x x2 = 2x x2case 2:If y < x,then p(a)= y and p(b) = x, point (x,y) is attacked by a queen with thefollowing probability:

    p(x, y) = p(a+ b) = y + x yx

    27

  • case 3:If y > 1 x,the probability p1(x),that a random position in column x is attackedby previously placed queens, we need to find the average over all y between 0 and 1.Theaverage is computed by summing probabilities over all y as follows:

    p1(x) = 2

    x0

    y + x yxdy + 1xx

    2x x2dy = 2x 2x2 + x3

    To calculate p2(x) let x denote a column between 0.5 and 1,and let y be a point on thiscolumn.Let a and b be two left diagonal lines that pass through point(x,y).We separate thevalues of y in three intervals as follows:

    1. 1 x < y < x2. y < 1 x3. y > x case 1:If 1 x < y < x, then p(a)=y and p(b)=1-y.Point (x,y) is attacked by a

    queen with the following probability:

    p(x, y) = p(a+ b) = 1 y + y (1 y)y = 1 y + y2case 2:If y < 1 x, then p(a)=x and p(b)=y.The probability p(x,y) is as follows:

    p(x, y) = p(a+ b) = x+ y xycase 3:If y > x, the probability is equivalent to the case of y < 1 x.The probabilityp2(x) that a random position in column x is attacked by a queen from left is computedby the following integral:

    p2(x) = 2

    1x0

    x+ y xy dy + x1x

    1 y + y2 dy = 16

    + x x3

    3

    Using p1(x) and p2(x) we can calculate the number of steps f(x) to place x queens.If x isless than 0.5, then we have the following formula:

    f(x) =

    x0

    1

    1 p1(x) dx

    If x is greater than 0.5, then we have the following formula:

    f(x) =

    0.50

    1

    1 p1(x) dx+ x0.5

    1

    1 p2(x) dx

    The number of steps required to place all queens without collision is equal to f(1) = 3.08,whichmeans that for a problem size of n, the initial search will attempt on an average 3.08n positionsbefore all queens are placed.The initial search takes time that is linear in n.

    28

  • Bibliography

    [1] Donald Knuth, Fundamental Algorithms, Volume 1 of Art of Algorithms, Addison Wes-ley limited.

    [2] Thomas H.Cormen, Charles E.Leiserson, Ronald L.Rivest, Clifford Stein,Introduction toAlgorithms ,PHI learning limited.

    [3] Marian Kovac, Zilina Slovakia, N Queen Problem by efficient Non Backtracking usingLocal Search Algorithm, Heuristics and Tabu Search Elements,The 10th InternationalConference on Digital Technologies , 978-1-4799-3303-7/2014.

    [4] C.Hoare, Analysis of Quick Sort ,2011 International Conference on Information Man-agement and Industrial Engg. .

    [5] Yahaya Abd.Rahim, Shahrin Sahib, Randomisation Techniques in privacy stud-ies,International Conference on Privacy studies.

    [6] Kenneth Rosen, A Book on discrete Mathematics,Tata Mcgraw hill publication.

    [7] Daniel Smullen, Jonathan Gillett, Joseph Heron, Shahryar Rahnamayan, Genetic Al-gorithm with self Adaptive Mutation Controlled by Chromosome Similarity ,2014 IEEECongress on Evolutionary Computation (CEC)Beijing ,China, 978-1-4799-1488-3/2014.

    [8] Jalal eddin Aghazadeh heris, Mohammadreza Asgari Oskoei, Modified Genetic Algorithmfor solving N Queen problem,2013 IEEE Congress on Evolutionary Computation,978-1-4799-3351-8/2014.

    [9] Elaine Rich, Kevin Knight, Peter Norvig,A Book on Artificial Intelligence,Tata McgrawHill publication.

    [10] Bart Selman, Carla P.Gomes, Hill Climbing Search,An Intermiediate article of CornellUniversity-2011.

    [11] Rok Sosic, Jun Gu, Fast Search Algorithms on N Queen,IEEE transactions on Sys-tems,Man and Cybernetics Vol 21 No.6,Nov/Dec 1991.

    [12] Omid E.David, H.Jaap van den Herik, Moshe Koppel, Nathan S.Netanyahu, Genetic Al-gorithm for Evolving Chess Programs ,IEEE Transactions on Evolutionary ComputationVol 18 NO 5,October 2014.

    [13] Parasumanna Gokulan Balaji, Dipti Srinivasan, Modified Symbiotic Evolutionary learn-ing for Type-2 Fuzzy Systems , IEEE System Journal Vol 8 NO 2,June 2014.

    [14] Antonio Gonzalez, David Camacho, A New CSP Graph-Based Representation toResource-Constrained Project Scheduling Problem ,IEEE Congress on EvolutionaryComputation(CEC)July 6-11,2014,Beijing China.

    29

  • [15] Antonio Gonzalez-Pardo, David Camacho, A New CSP Graph-Based Representation forAnt Colony Optimisation ,IEEE Congress on Evolutionary Computation(CEC)June 20-23,2013,Cancun Mexico.

    [16] Yuh-Rau Wang, Hsieh-Liang Lin, Ling Yang, Swarm Refinement PSO for Solving NQueen Problem ,Third International Conference on Innovations on Bio-Inspired Com-puting and Applications.

    [17] Ayad M.Turky, Mohd Sharifuddin Ahmad, Using Genetic Algorithm for Solving N QueenProblem,IEEE Conference on Evolutionary Computation.

    [18] Salabat Khan, Mohsin Bilal, M.Sharif, Malik Sajid, Rauf Baig Solution of N-Queen prob-lem using Ant Colony Optimisation.

    [19] I.Martinjak, M. Golub, Comparison of Heuristic Algorithms for the N-Queen Problem,Proceedings of the ITI 2007 29th Int. Conf. on Information Technology Interfaces, June25-28, Islamabad, Pakistan.

    [20] Alfred V.Aho, John E.Hopcroft, Jeffrey D.Ulman, Design and Analysis of ComputerAlgorithms,Pearson Publication Always Learning.

    30