(C++) Implement Genetic Algorithm to solve the 8-puzzle problem.
Please display output.
C++ Program
#include <iostream>
#include <cmath>
using namespace std;
bool ok ( int board[8][8] )
{
for ( int c=7; c >= 0; c--)
{
int r = 0;
while ( board[r][c] != 1)
{
r++;
}
for ( int i=1; i <= c; i++)
{
if ( board[r][c-i] == 1 )
return false;
else if ( board[r-i][c-i] == 1)
return false;
else if ( board[r+i][c-i] == 1)
return false;
}
}
return true;
}
void print ( int board[8][8], int count )
{
cout<<endl;
cout << "Solution =" << count << ":" <<
endl;
for (int i=0; i < 8; i++)
{
for (int j=0; j < 8; j++)
{
cout << board[i][j];
}
cout << endl;
}
}
int main ()
{
int board[8][8] = {0};
int count = 0;
for ( int i0=0; i0 < 8; i0++)
for ( int i1=0; i1 < 8; i1++)
for ( int i2=0; i2 < 8; i2++)
for ( int i3=0; i3 < 8; i3++)
for ( int i4=0; i4 < 8; i4++)
for ( int i5=0; i5 < 8; i5++)
for ( int i6=0; i6 < 8; i6++)
for ( int i7=0; i7 < 8; i7++)
{
board[i0][0]=1;
board[i1][1]=1;
board[i2][2]=1;
board[i3][3]=1;
board[i4][4]=1;
board[i5][5]=1;
board[i6][6]=1;
board[i7][7]=1;
if ( ok(board)) print( board, ++count);
board[i0][0]=0;
board[i1][1]=0;
board[i2][2]=0;
board[i3][3]=0;
board[i4][4]=0;
board[i5][5]=0;
board[i6][6]=0;
board[i7][7]=0;
}
return 0;
}
OUTPUT:
Solution =1: 00000001 00010000 10000000 00100000 00000100 01000000 00000010 00001000 Solution =2: 00000100 00010000 00000010 10000000 00100000 00001000 01000000 00000001 Solution =3: 01000000 00000100 00000001 00100000 10000000 00010000 00000010 00001000 Solution =4: 00000010 01000000 00000100 00100000 10000000 00010000 00000001 00001000 Solution =5: 00000001 01000000 00001000 00100000 10000000 00000010 00010000 00000100 Solution =6: 00010000 01000000 00000010 00001000 10000000 00000001 00000100 00100000 Solution =7: 00000100 00100000 00000010 00010000 10000000 00000001 01000000 00001000 Solution =8: 00001000 00000010 01000000 00000100 00100000 10000000 00010000 00000001 Solution =9: 00000010 00010000 01000000 00001000 00000001 10000000 00100000 00000100 Solution =10: 00010000 00000010 00001000 01000000 00000100 10000000 00100000 00000001 Solution =11: 00010000 01000000 00000010 00100000 00000100 00000001 10000000 00001000 Solution =12: 00001000 01000000 00010000 00000100 00000001 00100000 10000000 00000010 Solution =13: 00000100 00100000 00000010 01000000 00010000 00000001 10000000 00001000 Solution =14: 00001000 01000000 00010000 00000010 00100000 00000001 00000100 10000000
(C++) Implement Genetic Algorithm to solve the 8-puzzle problem. Please display output.
Exercise 1: (Greedy Search) Solve the following 8-puzzle problem using Greedy search algorithm as search strategy and h10 as heuristic hl(n): the number of misplaced tiles for the current node n 7 6
you will implement the A* algorithm to solve the sliding tile puzzle game. Your goal is to return the instructions for solving the puzzle and show the configuration after each move. A majority of the code is written, I need help computing 3 functions in the PuzzleState class from the source code I provided below (see where comments ""TODO"" are). Also is this for Artificial Intelligence Requirements You are to create a program in Python 3 that performs the following:...
need help with java In this program you will use a Stack to implement backtracking to solve Sudoku puzzles. Part I. Implement the stack class. Created a generic, singly-linked implementation of a Stack with a topPtr as the only instance variable. Implement the following methods only: public MyStack() //the constructor should simply set the topPtr to null public void push(E e) public E pop() Test your class thoroughly before using it within the soduku program Part II. Create...
Generate a large number of instances of the following problems: 8 × 8 Puzzle and 8-Queens Problem and solve these problems (if possible) using different local search algorithms (Hill Climbing Algorithm, Random Restart Hill Climbing Algorithm and Simulated annealing). Measure the cost of each search and the percentage of problems solved and make a graphical representation of these values based on the optimal cost. Comment on your results. Programming language can be either Python, C++ or Java. + code comments...
Design & Analysis of Algorithms Implement the algorithm in C++ of the following problem
Apply the A" algorithm to the 8-puzzle problem to the initial tile pattern shown below to arrive at the goal node. Show expansion of the tiles as illustrated in lecture notes and book chapter, along with evaluation value f g+h, numeric order of selected nodes and backtracking arrows Numeric order of chosen node #of search bles where n is a node 47 displaced nitial node 81 Goal node 12 5 8 13 7 4 3 6 2 5 6 25...
Please find the complexity of the algorithm used to solve the problem below. Also find the approximate problem size we could solve in time t, given that we double the speed of the original machine. Thank you Suppose that a computer can run an algorithm on a problem of size 1,024 in time t. We do not know the complexity of the algorithm. We note that when we run the same algorithm on a computer 8 times faster, in the...
Problem: Implement (in C) the dynamic program algorithm for the coin-change algorithm, discussed in class. Assume that the coins with which you make change are quarters, dimes, nickels and pennies. Thus you are going to set n = 4 in your program. The amount k for which you have to make change will be provided by the user and your program will return the minimum number of coins needed and also the break-up of the change in terms of the...
Major Homework #2 Implement a C program major_hw2.c to solve the 15-puzzle problem using the A* search algorithm. 1. Objectives • To gain more experience on using pointers and linked lists in C programs. • To learn how to solve problems using state space search and A* search algorithm. 2. Background A* search and 15-puzzle problem have been introduced in the class. For more information, please read the wiki page of 15-puzzle problem at https://en.wikipedia.org/wiki/15_puzzle, and the wiki page of...