Name / Mutlag Faisal AL-Ajme Id/ 426102739 Name / Osama Khalaf AL-Friedy Id /426103322.

Slides:



Advertisements
Similar presentations
Artificial Intelligence
Advertisements

Algorithm Design Techniques
Cooperating Intelligent Systems
Informed search algorithms
Review: Search problem formulation
Heuristic Search techniques
Announcements Course TA: Danny Kumar
Informed search algorithms
CS6800 Advanced Theory of Computation
BackTracking Algorithms
Informed Search Methods How can we improve searching strategy by using intelligence? Map example: Heuristic: Expand those nodes closest in “as the crow.
Problem Solving by Searching Copyright, 1996 © Dale Carnegie & Associates, Inc. Chapter 3 Spring 2007.
Types of Algorithms.
Techniques for Dealing with Hard Problems Backtrack: –Systematically enumerates all potential solutions by continually trying to extend a partial solution.
Part2 AI as Representation and Search
Problem Solving Agents A problem solving agent is one which decides what actions and states to consider in completing a goal Examples: Finding the shortest.
Solving Problems by Searching Currently at Chapter 3 in the book Will finish today/Monday, Chapter 4 next.
Solving Problem by Searching Chapter 3. Outline Problem-solving agents Problem formulation Example problems Basic search algorithms – blind search Heuristic.
Graphs Graphs are the most general data structures we will study in this course. A graph is a more general version of connected nodes than the tree. Both.
September 26, 2012Introduction to Artificial Intelligence Lecture 7: Search in State Spaces I 1 After our “Haskell in a Nutshell” excursion, let us move.
Tuesday, May 14 Genetic Algorithms Handouts: Lecture Notes Question: when should there be an additional review session?
Review: Search problem formulation
1 Lecture 8: Genetic Algorithms Contents : Miming nature The steps of the algorithm –Coosing parents –Reproduction –Mutation Deeper in GA –Stochastic Universal.
Artificial Intelligence
Branch and Bound Similar to backtracking in generating a search tree and looking for one or more solutions Different in that the “objective” is constrained.
November 10, 2009Introduction to Cognitive Science Lecture 17: Game-Playing Algorithms 1 Decision Trees Many classes of problems can be formalized as search.
Intelligent Agents What is the basic framework we use to construct intelligent programs?
Uninformed Search Reading: Chapter 3 by today, Chapter by Wednesday, 9/12 Homework #2 will be given out on Wednesday DID YOU TURN IN YOUR SURVEY?
Blind Search-Part 2 Ref: Chapter 2. Search Trees The search for a solution can be described by a tree - each node represents one state. The path from.
CSC344: AI for Games Lecture 4: Informed search
Solving problems by searching
Backtracking.
Review: Search problem formulation Initial state Actions Transition model Goal state (or goal test) Path cost What is the optimal solution? What is the.
Busby, Dodge, Fleming, and Negrusa. Backtracking Algorithm Is used to solve problems for which a sequence of objects is to be selected from a set such.
Solving Problems by Searching CPS Outline Problem-solving agents Example problems Basic search algorithms.
1 B Trees - Motivation Recall our discussion on AVL-trees –The maximum height of an AVL-tree with n-nodes is log 2 (n) since the branching factor (degree,
Artificial Intelligence Lecture 9. Outline Search in State Space State Space Graphs Decision Trees Backtracking in Decision Trees.
Backtracking. N-Queens The object is to place queens on a chess board in such a way as no queen can capture another one in a single move –Recall that.
WAES 3308 Numerical Methods for AI
Lecture 5: Backtracking Depth-First Search N-Queens Problem Hamiltonian Circuits.
HISTORY The problem was originally proposed in 1848 by the chess player Max Bezzel, and over the years, many mathematicians, including Gauss have worked.
BackTracking CS335. N-Queens The object is to place queens on a chess board in such as way as no queen can capture another one in a single move –Recall.
Dr.Abeer Mahmoud ARTIFICIAL INTELLIGENCE (CS 461D) Dr. Abeer Mahmoud Computer science Department Princess Nora University Faculty of Computer & Information.
Games. Adversaries Consider the process of reasoning when an adversary is trying to defeat our efforts In game playing situations one searches down the.
1 Combinatorial Problem. 2 Graph Partition Undirected graph G=(V,E) V=V1  V2, V1  V2=  minimize the number of edges connect V1 and V2.
CSCI 5582 Fall 2006 CSCI 5582 Artificial Intelligence Fall 2006 Jim Martin.
1 Solving problems by searching 171, Class 2 Chapter 3.
Search CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Introduction to Genetic Algorithms. Genetic Algorithms We’ve covered enough material that we can write programs that use genetic algorithms! –More advanced.
Goal-based Problem Solving Goal formation Based upon the current situation and performance measures. Result is moving into a desirable state (goal state).
Types of Algorithms. 2 Algorithm classification Algorithms that use a similar problem-solving approach can be grouped together We’ll talk about a classification.
Introduction to Artificial Intelligence (G51IAI) Dr Rong Qu Blind Searches - Introduction.
Search in State Spaces Problem solving as search Search consists of –state space –operators –start state –goal states A Search Tree is an efficient way.
N- Queens Solution with Genetic Algorithm By Mohammad A. Ismael.
Chapter 13 Backtracking Introduction The 3-coloring problem
February 11, 2016Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II 1 State-Space Graphs There are various methods for searching.
State space search Represented by a four-tuple [N,A,S,GD], where: N is the problem space A is the set of arcs (or links) between nodes. These correspond.
1 Combinatorial Problem. 2 Graph Partition Undirected graph G=(V,E) V=V1  V2, V1  V2=  minimize the number of edges connect V1 and V2.
Genetic Algorithms And other approaches for similar applications Optimization Techniques.
Chapter 3 Solving problems by searching. Search We will consider the problem of designing goal-based agents in observable, deterministic, discrete, known.
CSG3F3/ Desain dan Analisis Algoritma
BackTracking CS255.
Heuristic Search A heuristic is a rule for choosing a branch in a state space search that will most likely lead to a problem solution Heuristics are used.
Problem Solving by Searching
Applied Combinatorics, 4th Ed. Alan Tucker
adapted from Recursive Backtracking by Mike Scott, UT Austin
Searching for solutions: Genetic Algorithms
Backtracking and Branch-and-Bound
The N-Queens Problem Search The N-Queens Problem Most slides from Milos Hauskrecht.
Solving Problems by Searching
Presentation transcript:

Name / Mutlag Faisal AL-Ajme Id/ Name / Osama Khalaf AL-Friedy Id /

Traveling Salesman Problem TSP

Traveling Salesman Problem Traveling Salesman Problem (TSP) using a Genetic Algorithm (GA). In the Traveling Salesman Problem, the goal is to find the shortest distance between N different cities. The path that the salesman takes is called a tour. Testing every possibility for an N city tour would be N! math additions. A 30 city tour would have to measure the total distance of be 2.65 X different tours. Assuming a trillion additions per second, this would take 252,333,390,232,297 years. Adding one more city would cause the time to increase by a factor of 31. Obviously, this is an impossible solution. A genetic algorithm can be used to find a solution is much less time. Although it might not find the best solution, it can find a near perfect solution for a 100 city tour in less than a minute. There are a couple of basic steps to solving the traveling salesman problem using a GA. First, create a group of many random tours in what is called a population. This algorithm uses a greedy initial propulation that gives preference to linking cities that are close to each other. Second, pick 2 of the better (shorter) tours parents in the population and combine them to make 2 new child tours. Hopefully, these children tour will be better than either parent. A small percentage of the time, the child tours are mutated. This is done to prevent all tours in the population from looking identical. The new child tours are inserted into the population replacing two of the longer tours. The size of the population remains the same. New children tours are repeatedly created until the desired goal is reached. As the name implies, Genetic Algorithms mimic nature and evolution using the principles of Survival of the Fittest.

Traveling Salesman Problem The two complex issues with using a Genetic Algorithm to solve the Traveling Salesman Problem are the encoding of the tour and the crossover algorithm that is used to combine the two parent tours to make the child tours. In a standard Genetic Algorithm, the encoding is a simple sequence of numbers and Crossover is performed by picking a random point in the parent's sequences and switching every number in the sequence after that point. In this example, the crossover point is between the 3 rd and 4 th item in the list. To create the children, every item in the parent's sequence after the crossover point is swapped. F A B | E C G DParent1 D E A | C G B FParent 2 F A B | C G B FChilde 1 D E A | E C G DChilde 2

Traveling Salesman Problem The difficulty with the Traveling Salesman Problem is that every city can only be used once in a tour. If the letters in the above example represented cities, this child tours created by this crossover operation would be invalid. Child 1 goes to city F & B twice, and never goes to cities D or E. The encoding cannot simply be the list of cities in the order they are traveled. Other encoding methods have been created that solve the crossover problem. Although these methods will not create invalid tours, they do not take into account the fact that the tour "A B C D E F G" is the same as "G F E D C B A". To solve the problem properly the crossover algorithm will have to get much more complicated. My solution stores the links in both directions for each tour. In the above tour example, Parent 1 would be stored as: Second connectionFirst connectionCity BFA EAB GEC FGD CBE ADF DCG

Traveling Salesman Problem The crossover operation is more complicated than combining 2 strings. The crossover will take every link that exists in both parents and place those links in both children. Then, for Child 1 it alternates between taking links that appear in Parent 2 and then Parent 1. For Child 2, it alternates between Parent 2 and Parent 1 taking a different set of links. For either child, there is a chance that a link could create an invalid tour where instead of a single path in the tour there are several disconnected paths. These links must be rejected. To fill in the remaining missing links, cities are chosen at random. Since the crossover is not completely random, this is considered a greedy crossover. Eventually, this GA would make every solution look identical. This is not ideal. Once every tour in the population is identical, the GA will not be able to find a better solution. There are two ways around this. The first is to use a very large initial population so that it takes the GA longer to make all of the solutions the same. The second method is mutation, where some child tours are randomly altered to produce a new unique tour. This Genetic Algorithm also uses a greedy initial population. The city links in the initial tours are not completely random. The GA will prefer to make links between cities that are close to each other. This is not done 100% of the time, becuase that would cause every tour in the initial population to be very similar.

Traveling Salesman Problem There are 6 parameters to control the operation of the Genetic Algorithm: Population Size - The population size is the initial number of random tours that are created when the algorithm starts. A large population takes longer to find a result. A smaller population increases the chance that every tour in the population will eventually look the same. This increases the chance that the best solution will not be found. Neighborhood / Group Size - Each generation, this number of tours are randomly chosen from the population. The best 2 tours are the parents. The worst 2 tours get replaced by the children. For group size, a high number will increase the likelyhood that the really good tours will be selected as parents, but it will also cause many tours to never be used as parents. A large group size will cause the algorithm to run faster, but it might not find the best solution. Mutation % - The percentage that each child after crossover will undergo mutation When a tour is mutated, one of the cities is randomly moved from one point in the tour to another. # Nearby Cities - As part of a greedy initial population, the GA will prefer to link cities that are close to each other to make the initial tours. When creating the initial population this is the number of cities that are considered to be close. Nearby City Odds % - This is the percent chance that any one link in a random tour in the initial population will prefer to use a nearby city instead of a completely random city. If the GA chooses to use a nearby city, then there is an equally random chance that it will be any one of the cities from the previous parameter. Maximum Generations - How many crossovers are run before the algorithm is terminated. The other options that can be configured are (note: these are only available in the downloadable version): Random Seed - This is the seed for the random number generator. By having a fixed instead of a random seed, you can duplicate previous results as long as all other parameters are the same. This is very helpful when looking for errors in the algorithm. City List - The downloadable version allows you to import city lists from XML files. Again, when debugging problems it is useful to be able to run the algorithm with the same exact parameters. The starting parameter values are:

Traveling Salesman Problem Initial valueParameter 10000Population size 5Group size 3 %Mutation 5# Nearby cities 90 %Nearby city odds

Traveling Salesman Problem Note: I originally wrote this program in 1995 in straight C. The tours in the population were stored as an array of 32 bit int's, where each bit indicated a connection. Ex: If tour[0] = in binary, then city 0 connected to city 11 and 19. That implementation was much faster than the current C# version. The greedy part of crossover could be performed by doing a binary AND on the two tours. While that code was very fast, it had a lot of binary operations, was limited in the number of cities it could support, and the code wasn't readable. Hopefully, this new version will allow for more re-use. Click here to execute program. Click here to execute program

N-Queens Problem

“The standard 4 by 4 Queens problem asks how to place 4 queens on an ordinary chess board so that none of them cannot hit any other in one move.” Our Problem More specifically the problem we were asked to address is an N by N Queens Problem, in which we are to create an integer program model that will give us a solution for any integer N value.

Movements A queen can move in any direction Horizontal Vertical Diagonal It can move any amount of space, meaning it can move from one end of the board to the other end

Constraints No queen can hit another queen when moved Only one queen can be located in each row Only one queen can be located in each column Only one queen can be located in each diagonal path

Integer Model Decision Variables i represents rows j represents columns x ij, position on board at row i and column j x ij is binary 0 = no queen 1 = queen j  i  X 1,1 X 1,2 X 3,3 X i, j

Integer Model Parameter N, dimensions of board & number of queens

Integer Model Objective Minimize We have to satisfy the constraints Only solutions you get will be feasible solutions

Integer Model Constraints There must be 1 (and only one) queen in row i:, for all i = 1,…,N

Integer Model Constraints There must be 1 (and only one) queen in column j:, for all j = 1,…,N

Integer Model Constraints There can be no more than one queen in each backward diagonal ( \ ): N………………………1 1……………….……N

Integer Model Constraints There can be no more than one queen in each forward diagonal ( / ): N………………………1 1……………….……N

8-puzzle problem

What is 8-puzzle? The 8 puzzle is a simple game which consists of eight sliding tiles, numbered by digits from 1 to 8, placed in a 3x3 squared board of nine cells. One of the cells is always empty, and any adjacent (horizontally and vertically) tile can be moved into the empty cell. The objective of the game is to start from an initial configuration and end up in a configuration which the tiles are placed in ascending number order.

8-puzzle problem The 8-puzzle is a square board with 9 positions, filled by 8 numbered tiles and one gap. At any point, a tile adjacent to the gap can be moved into the gap, creating a new gap position. In other words the gap can be swapped with an adjacent (horizontally and vertically) tile. The objective in the game is to begin with an arbitrary configuration of tiles, and move them so as to get the numbered tiles arranged in ascending order either running around the perimeter of the board or ordered from left to right, with 1 in the top left-hand position.

8-puzzle problem An example scenario is shown below Initial state Goal State Here the goal state can be reached from the initial state at 5 simple steps given below. Blank Up Blank Left Blank Down Blank Right

8-puzzle Algorithm 8 puzzle is a very interesting problem for software developers around the world. It always has been an important subject in articles, books and become a part of course material in many universities. It is a well known problem especially in the field of Artificial Intelligence. This page is designed to tell you the very basic understanding of the algorithm to solve the 8 puzzle problem. You may find "what the problem is" from the 8 puzzle problem page If you still don't have any idea about it.

8-puzzle Algorithm As it's mentioned in the 8 puzzle problem page, the game has an initial state and the objective is to reach to the goal state from the given initial state. An example initial state and corresponding goal state is shown below Initial state Goal state

8-puzzle Algorithm before beginning to tell how to reach from the initial state to the goal state, we have to solve a sub problem which is "choosing the goal state to be reached". As it's mentioned in the 8 puzzle problem page, the game has two possible arrangements. We have to choose one of the goal states to be reached because only one of them is reachable from the given initial state. Sounds interesting? Lets see why the 8-puzzle states are divided into two disjoint sets, such that no state in one set can be transformed into a state in the other set by any number of moves. Goal state A Goal state B

8-puzzle Algorithm First we begin with the definition of the order of counting from the upper left corner to the lower right corner as shown in the figure below. Order of Counting

8-puzzle Algorithm This definition is given because we need to determine the number of smaller digits which are coming after a chosen tile. Its a little bit trick to tell with words. So lets have an example. Counting Example

8-puzzle Algorithm In this example above we see the tiles which comes right after tile #8 and smaller than 8, in yellow. So if we count the yellow tiles, we get 6. We will apply this counting for every tile in the board. But first lets have another example to make things crystal clear. Counting Example 2

8-puzzle Algorithm This time we count the tiles which comes right after tile #6 and smaller than 6, in yellow. As a result we get 2. Now we made things clear on how to count. Now we will do this counting for every tile in the board. Counting the Board

8-puzzle Algorithm In the figure below you see that counting for tile #1 is skipped. That's because the result is always 0 (1 is the smallest tile). Counting for each tile has been done and then the results are summed. Finally we get 11 as the result. Now I believe that most of you have the question "So, what?". The answer is simple. As you can imagine the result is always either even or odd. And this will be the key to solve the problem of "choosing the goal state to be reached". Lets call the result as N.

8-puzzle Algorithm Goal state A Goal state B If N is odd we can only reach to the Goal State A as shown below. If N is even we can only reach to the Goal State B as shown below.

8-puzzle Algorithm Now we have determined which goal state to reach, so we can start a search. The search will be an uninformed search which means searching for the goal without knowing in which direction it is. We have 3 choices for the search algorithm in this case. These are: Breadth-first search algorithm Depth-first search algorithm Iterative deepening search algorithm

8-puzzle Algorithm The three algorithms given above differs on the choice of the search path (node to node). Below you will find summarized descriptions Breadth-first search algorithm: finds the solution that is closest (in the graph) to the start node that means it always expands the shallowest node. Depth-first search algorithm: starts at the root (selecting some node as the root in the graph case) and explores as far as possible along each branch before backtracking. Iterative deepening search algorithm: is a modified version of the dept first search algorithm. It can be very hard to determine an optimum limit (maximum depth) for depth first search algorithm. That's why we use iteration starting from the minimum expected depth and search until the goal state or the maximum depth limit of the iteration has been reached.