-1

I am given a n x n matrix where n ranges from 3 to 5. The matrix is then assigned random values from 1-n^2. Given the matrix I am to optimize the board such that I arrive to a solution of magic square.

Random board example: n = 3

    3 5 6
    1 7 8
    2 4 9

I have a little knowledge about PSO but I atleast know this:

1. Randomly initialize a set of particles at random positions in the search space;
2. Evaluate all positions and update the global best position and the personal best positions;
3. Update each velocity based on the relative position of the global best position, the current velocity of the particle, the personal best position of the particle and some random vector;
4. goto 2.

I have also been told that the problem is not suited for algorithms such as PSO, but I have no choice but use it for this problem since it is the algorithm required.

I am thinking the the particles are the numbers assigned in the array, but how do I evaluate its position and update the particles position?

Thank you!

false
  • 10,264
  • 13
  • 101
  • 209
Holmes
  • 53
  • 6

1 Answers1

0

You need to have an optimization problem to apply PSO. If you can define a fitness function, you may do the following:

For instance, your target sum is 20 and your fitness function is f(currentSum) = |20 - currentSum| for each row, column and diagonal.

You change the value of a square. After that, if changing that value decreased the value of f(), that means, your velocity should be directed to that solution. If it increased the value, you should go and look somewhere else.

You need two types of operations, which are exploition and exploration.

Exploition menas, searching the neighborhood for a solution. When a the value of a suqare is changed, looking for solutions such that making the row and the column of that value closer to your targetSum.

Exploration means, changing the whole picture. You do exploitation (usually after randomization of the whole board) after you apply this step.

For starters, you need to define

  • Model of the problem
  • What is a solution? How do you define a solution?
  • Objective function
  • Fitness function
  • Velocity
  • Poisiton
  • Neighborhood
  • Exploration

But my advice would be not to use PSO for a problem which is not an optimization problem. It is likely PSO will work with same performance as random search.

padawan
  • 1,295
  • 1
  • 17
  • 45