try/tsp.rb
# Generate points in a random manner on which the traveling salesman visits.
# Currently, only two-dimensional point is supported.
# @param pnum [Integer] Number of points.
# @param xrange [Integer] Range of x-axis on the field.
# @param yrange [Integer] Range of y-axis on the field.
# @param uniq [Boolean] Flag to indicate to allow some of points are placed on the same coordinate point.
# @return points [Array] Set of the points.
Generate points in a random manner on which the traveling salesman visits.
Currently, only two-dimensional point is supported.
Generate points in a random manner on which the traveling salesman visits . Currently only two - dimensional point is supported .
def generate_points(pnum=20, xrange=50, yrange=50, uniq=true)
  points = []
  pnum.times do |i|
    points << [rand(xrange) - xrange/2, rand(yrange) - yrange/2]
  end
  if uniq == true
    points = points.uniq
    while(points.size < pnum)
      points << [rand(xrange) - xrange/2, rand(yrange) - yrange/2]
    end
  end
  return points
end
def generate_points ( pnum = 20 , xrange = 50 , yrange = 50 , uniq = true ) points = [ ] pnum . times do | i | points << [ rand ( xrange ) - xrange / 2 , rand ( yrange ) - yrange / 2 ] end if uniq == true points = points . uniq while ( points . size < pnum ) points << [ rand ( xrange ) - xrange / 2 , rand ( yrange ) - yrange / 2 ] end end return points end
Generate points in a random manner on which the traveling salesman visits.
Generate points in a random manner on which the traveling salesman visits .
points  Set of the points.
points Set of the points .
Array
pnum
Number of points.
Number of points .
xrange
Range of x-axis on the field.
Range of x - axis on the field .
yrange
Range of y-axis on the field.
Range of y - axis on the field .
uniq
Flag to indicate to allow some of points are placed on the same coordinate point.
Flag to indicate to allow some of points are placed on the same coordinate point .