hello everybody i write pso code for optimizing a simple function. it has no problem. now i want to solve tsp problem with pso. for example a swarm vector content is [1 2 4 3 1] and best swarm vector is [2 3 1 4 2]. when i want to update new value for [1 2 4 3 1] the values is something like [1.2 2.3 3.8 3.4 1.2]. and this is not true or acceptable answer. How can i map this answer to a true one?
if you have some sources for this problem please share it.
(i use matlab for my codes).
thanks in advance

- 91
- 11
1 Answers
Matlab is using floating point operations to do the calculations. This leads to errors. Epsilon is a measure of precision (eps
command in matlab). It is the smallest number > 0 for which 1 + eps != 1 .
It depends on the calculations how this rounding error is going to affect you. For example if you want to add 10 numbers of different magnitudes, then the error is the smallest if you sort the numbers by their absolute value and add them ascending. Subtracting two almost equal numbers from each other will lose a lot of precision or power can be bad too.
==> You would have to rewrite your algorithm and take these effects into account for a "perfect" solution. The easy solution is just to round the numbers, you could additionally define a threshold, lets say 0.25, and if a number changes more than that you output a warning (like matlab is doing with almost singular matrices when calculating the inverse).
> A = [1.2 2.3 3.8 3.4 1.2] ;
> A = round(A)
A =
1 2 4 3 1

- 8,468
- 3
- 23
- 45
-
thanks for your answer but if i do this the solution changed and as a result this is not the pso algorithm. Also the answer is not true – zara-T Jul 03 '15 at 18:03
-
1@zara-T what is not true? It converts a floating point number to an integer like it says in the title of your question. Without any code of the implementation nobody can guess what the problem is. – maraca Jul 03 '15 at 20:53
-
this is not true because in normal form of pso the progress of solution is not static , i mean if 4 changed to 3.8 in first iteration in next iteration 3.8 maybe changed to 3.2 and in your solution for first iteration it value is rounded to 4 and in next one 4 changed to 3.8 again and if we rounded it, the value is 4 . this is not true because the algorithm is going to close to swarm 1 for this point and in our solution this is not occur , i think the answer is in discrete PSO concept – zara-T Jul 03 '15 at 22:16
-
Why not use a genetic algorithm? Much better suited to this kind of problem. – transversality condition Jul 08 '15 at 01:26