Question

In: Computer Science

Q7. Does Simulated Anealing (with 10 iterations) solve the 14-Queens Problem? What about SA (with 50...

Q7. Does Simulated Anealing (with 10 iterations) solve the 14-Queens Problem? What about SA (with 50 iterations). Show your answer.

Solutions

Expert Solution

Lets see the answer:-

Lets see C# PROGRAM FOR SOLVING QUEEN PROBLEM

using System;

     

class GFG

{

    readonly int N = 4;

void printSolution(int [,]board)

    {

        for (int i = 0; i < N; i++)

        {

            for (int j = 0; j < N; j++)

                Console.Write(" " + board[i, j]

                                  + " ");

            Console.WriteLine();

        }

    }

bool isSafe(int [,]board, int row, int col)

    {

        int i, j;

for (i = 0; i < col; i++)

            if (board[row,i] == 1)

                return false;

        for (i = row, j = col; i >= 0 &&

             j >= 0; i--, j--)

            if (board[i,j] == 1)

                return false;

        for (i = row, j = col; j >= 0 &&

                      i < N; i++, j--)

            if (board[i, j] == 1)

                return false;

        return true;

    }

    bool solveNQUtil(int [,]board, int col)

    {

        if (col >= N)

            return i;

        for (int i = 0; i < N; i++)

{

            if (isSafe(board, i, col))

            {

                /* Place this queen in board[i,col] */

                board[i, col] = 1;

                if (solveNQUtil(board, col + 1) == true)

                    return true;

board[i, col] = 0; // BACKTRACK

            }

        }

        return false;

    }

    bool solveNQ()

    {

        int [,]board = {{ 0, 0, 0, 0 },

                        { 0, 0, 0, 0 },

                        { 0, 0, 0, 0 },

                        { 0, 0, 0, 0 }};

if (solveNQUtil(board, 0) == false)

        {

            Console.Write("Solution does not exist");

            return false;

        }

        printSolution(board);

        return true;

    }

    public static void Main(String []args)

    {

        GFG Queen = new GFG();

        Queen.solveNQ();

    }

}

NAVIE ALGORITHM:

while there are untried configurations
{
   generate the next configuration
   if queens don't attack in this configuration then
   {
      print this configuration;
   }
}

BACKTRACKING ALGORITHM:

1) Start in the leftmost column
2) If all queens are placed
    return true
3) Try all rows in the current column. 
   Do following for every tried row.
    a) If the queen can be placed safely in this row 
       then mark this [row, column] as part of the 
       solution and recursively check if placing
       queen here leads to a solution.
    b) If placing the queen in [row, column] leads to
       a solution then return true.
    c) If placing queen doesn't lead to a solution then
       unmark this [row, column] (Backtrack) and go to 
       step (a) to try other rows.
3) If all rows have been tried and nothing worked,
   return false to trigger backtracking.

Related Solutions

solve travelling salesman problem using different simulated annealing cooling schedule
solve travelling salesman problem using different simulated annealing cooling schedule
Write a python script to solve the 4-queens problem using. The code should allow for random...
Write a python script to solve the 4-queens problem using. The code should allow for random starting, and for placed starting. "The 4-Queens Problem[1] consists in placing four queens on a 4 x 4 chessboard so that no two queens can capture each other. That is, no two queens are allowed to be placed on the same row, the same column or the same diagonal." Display the iterations until the final solution Hill Climbing (your choice of variant)
Write and Compile a python script to solve the 4-queens problem using Forward Checking algorithm ....
Write and Compile a python script to solve the 4-queens problem using Forward Checking algorithm . The code should allow for random starting, and for placed starting. Random Starting means randomly place a queen position on the chessboard. Placed Starting means asked for the user input to place a queen position on the chessboard. Display the iterations until the final solution "The 4-Queens Problem[1] consists in placing four queens on a 4 x 4 chessboard so that no two queens...
Write and Compile a python script to solve the 4-queens problem using. The code should allow...
Write and Compile a python script to solve the 4-queens problem using. The code should allow for random starting, and for placed starting using numpy "The 4-Queens Problem[1] consists in placing four queens on a 4 x 4 chessboard so that no two queens can capture each other. That is, no two queens are allowed to be placed on the same row, the same column or the same diagonal." Display the iterations until the final solution Arc consistency
talk in two pages about the Hill Climbing and Simulated Annealing Algorithms. solve by word file...
talk in two pages about the Hill Climbing and Simulated Annealing Algorithms. solve by word file not by hand .
What is the problem of evil? In what way does Augustine attempt to solve it?
What is the problem of evil? In what way does Augustine attempt to solve it?
Problem 14-27 (Algo) (LO 14-3, 14-9, 14-10) The following is the current balance sheet for a...
Problem 14-27 (Algo) (LO 14-3, 14-9, 14-10) The following is the current balance sheet for a local partnership of doctors: Cash and current assets $ 44,000 Liabilities $ 46,000 Land 154,000 A, capital 26,000 Building and equipment (net) 142,000 B, capital 46,000 C, capital 96,000 D, capital 126,000 Totals $ 340,000 Totals $ 340,000 The following questions represent independent situations: E is going to invest enough money in this partnership to receive a 25 percent interest. No goodwill or bonus...
I don't know how to solve this accounting problem. The problem is about Variance Analyses. Problem:...
I don't know how to solve this accounting problem. The problem is about Variance Analyses. Problem: Materials, Labor and Factory Overhead.(CPA, adapted) The Palmtown Furniture Company uses a standard cost system in accounting for its production costs. The standard cost of a unit of furniture follows:                     Lumber, 100 feet @$150 per 1,000 feet                                $15.00           Direct labor, 4 hours @ 2.50 per hour                                    10.00           Factory overhead:                       Fixed (30% of direct labor)                $3.00                       Variable (60% of...
Use what you learned about [H3O(+)] and pH formulas to solve the following problem Calculate the...
Use what you learned about [H3O(+)] and pH formulas to solve the following problem Calculate the pH of a (1.99x10^-1) M solution of Na2S03 (Kb1 = 1.56E-7, Kb2 = 5.88E-13)
How does the multiverse solve the problem of our universe being just right for life? What...
How does the multiverse solve the problem of our universe being just right for life? What evidence can you cite (a) in favor of the multiverse, and (b) against the multiverse? Explain briefly each level of Max Tegmark's universe? It has often been argued that the multiverse theory has no merit because it can't be disproved. How do you respond to this critique?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT