[#368826] ANN: home_run 0.9.1 Released — Jeremy Evans <code@...>

= home_run

14 messages 2010/09/01

[#368894] uninitialized constant NArray (Name Error) — Abder-Rahman Ali <abder.rahman.ali@...>

Following section (2) here:

12 messages 2010/09/02

[#368914] p vs. print — Abder-Rahman Ali <abder.rahman.ali@...>

I wrote the following scripts from section (2) here:

24 messages 2010/09/02
[#368915] Re: p vs. print — Alex Stahl <astahl@...5.com> 2010/09/02

Ruby uses "puts", not "print". "p" is short for "puts".

[#368977] Read cookie — Pål Bergström <pal@...>

How can I get the value of a browser cookie with Ruby?

29 messages 2010/09/03
[#368978] Re: Read cookie — Brian Candler <b.candler@...> 2010/09/03

P奪l Bergstr旦m wrote:

[#368984] Re: Read cookie — Pål Bergström <pal@...> 2010/09/03

Brian Candler wrote:

[#369036] ruby_archive 0.1.0 released — Jonathan Nielsen <jonathan@...>

After a summer of working on various ways to implement it, I'm happy to

10 messages 2010/09/03

[#369106] A better idiomatic way of doing this?! — Tim Romberg <tim.jakobsson@...>

Hi Im new at Ruby and been struggling with this lab I have for a course

12 messages 2010/09/05

[#369113] unable to open X server `' (Magick::ImageMagickError) — Abder-Rahman Ali <abder.rahman.ali@...>

I have written a Ruby script "dicom_info.rb", and when I try running

16 messages 2010/09/06
[#369119] Re: unable to open X server `' (Magick::ImageMagickError) — Brian Candler <B.Candler@...> 2010/09/06

On Mon, Sep 06, 2010 at 12:42:11PM +0900, Abder-Rahman Ali wrote:

[#369132] Re: unable to open X server `' (Magick::ImageMagickError) — Abder-Rahman Ali <abder.rahman.ali@...> 2010/09/06

Thanks a lot Brian.

[#369139] Re: unable to open X server `' (Magick::ImageMagickError) — Brian Candler <B.Candler@...> 2010/09/06

On Mon, Sep 06, 2010 at 11:55:32PM +0900, Abder-Rahman Ali wrote:

[#369140] Re: unable to open X server `' (Magick::ImageMagickError) — Abder-Rahman Ali <abder.rahman.ali@...> 2010/09/06

So, do you suggest installing "cygwin"?

[#369159] Re: unable to open X server `' (Magick::ImageMagickError) — Roger Pack <rogerpack2005@...> 2010/09/06

> you suggest installing "cygwin"?

[#369124] Odd functional programming question — Peter Hickman <peterhickman386@...>

Ok this is probably not really functional programming but I was just

10 messages 2010/09/06

[#369169] How do I request a HTTPS page? — Samuel Sternhagen <samatoms@...>

I would like to access a https page from irb

14 messages 2010/09/06

[#369226] What OS do you use for Ruby development? — Nick Hird <nrhird@...>

I don't want to start any OS wars. I was just curious as to what OS

67 messages 2010/09/07

[#369301] Nokogiri and LibXML — unbewusst.sein@... (Une B騅ue)

Each time i launch a script using Nokogiri i get :

12 messages 2010/09/08

[#369302] Receiving array naturally? — Terry Michaels <spare@...>

As I learn Ruby, I find a lot of flexibility in the syntax. I was

14 messages 2010/09/08

[#369389] Key Associated w/ Maximum Value in Hash — Timothy Baron <timothy.baron@...>

Simple question: what's the cleanest way to retrieve a key associated

11 messages 2010/09/09

[#369477] How to do foo.chomp!.rstrip!.downcase! ? — Geometric Patterns <geometric.patterns@...>

15 messages 2010/09/10

[#369623] Ruby packaging in Debian and Ubuntu: Mythbusting and FAQ — Lucas Nussbaum <lucas@...>

Hi,

11 messages 2010/09/12

[#369638] Declarative relations between object attributes — Knut Franke <knut.franke@...>

Some time ago I stumbled over Cells[1], a Common Lisp extension allowing

16 messages 2010/09/12

[#369710] Encoding error while installing rails on ruby 1.9.2 — Bek Bek <bekis3@...>

Hello everybody,

11 messages 2010/09/14

[#369796] Ruby Multi-threading? — Terry Michaels <spare@...>

I read a Ruby e-book recently that indicated that although Ruby has

12 messages 2010/09/15

[#369952] Developing for Ruby on Windows? — Tom Wardrop <tom@...>

I've heard a lot of criticism about developing for Ruby on Windows, but

11 messages 2010/09/17

[#370039] Ruby-based data language — Intransition <transfire@...>

Has anyone ever endeavored to create a data/configuration file format

14 messages 2010/09/19

[#370053] Getting GUI for ruby for Linux running (QT or wxWidget)? — Markus Fischer <markus@...>

Hi,

23 messages 2010/09/19
[#370054] Re: Getting GUI for ruby for Linux running (QT or wxWidget)? — Markus Fischer <markus@...> 2010/09/19

On 20.09.2010 01:14, Markus Fischer wrote:

[#370116] Re: Getting GUI for ruby for Linux running (QT or wxWidget)? — Quintus <sutniuq@...> 2010/09/20

-----BEGIN PGP SIGNED MESSAGE-----

[#370164] Re: Getting GUI for ruby for Linux running (QT or wxWidget)? — Ryan Melton <ryanmelt@...> 2010/09/21

qt does have a new gem I put together:

[#370205] QT works! (was: Re: Getting GUI for ruby for Linux running (QT or wxWidget)) — Markus Fischer <markus@...> 2010/09/21

Hi,

[#370127] An elegant way... — "F. Senault" <fred@...>

Hello everybody.

23 messages 2010/09/20

[#370210] The Great Ruby GUI Toolkit Roundup — Ed Howland <ed.howland@...>

Hi,

15 messages 2010/09/21

[#370257] having problems with open4 and stuck forked processes — Tim Uckun <timuckun@...>

I am running a batch process which uses the wkhtmltoimage-i386 binary

13 messages 2010/09/22
[#370268] Re: having problems with open4 and stuck forked processes — Robert Klemme <shortcutter@...> 2010/09/22

On Wed, Sep 22, 2010 at 2:31 PM, Tim Uckun <timuckun@gmail.com> wrote:

[#370294] Re: having problems with open4 and stuck forked processes — Tim Uckun <timuckun@...> 2010/09/22

> What do you mean by that? =C2=A0Goes the timeout undetected? =C2=A0Can't =

[#370309] Re: having problems with open4 and stuck forked processes — Robert Klemme <shortcutter@...> 2010/09/23

On 23.09.2010 01:59, Tim Uckun wrote:

[#370289] Sorting problem with an Array of Arrays — Paul <tester.paul@...>

Hi there, I have an array of arrays that looks like the following:

15 messages 2010/09/22

[#370296] Ruby Installation Error — Tridib Bandopadhyay <tridib04@...>

I am trying this command to build the ruby interpreter

20 messages 2010/09/23
[#370689] Re: Ruby Installation Error — Brian Candler <b.candler@...> 2010/09/29

Tridib Bandopadhyay wrote:

[#370319] to make dot method dot method work? — Pen Ttt <myocean135@...>

here is the class

14 messages 2010/09/23

[#370373] how do i force ruby to release memory — Amit Tomar <amittomer25@...>

Hi all,

19 messages 2010/09/24
[#370374] Re: how do i force ruby to release memory — Robert Klemme <shortcutter@...> 2010/09/24

On Fri, Sep 24, 2010 at 7:36 AM, Amit Tomar <amittomer25@yahoo.com> wrote:

[#370379] Re: how do i force ruby to release memory — Amit Tomar <amittomer25@...> 2010/09/24

Robert Klemme wrote:

[#370380] Re: how do i force ruby to release memory — Jes俍 Gabriel y Gal疣 <jgabrielygalan@...> 2010/09/24

On Fri, Sep 24, 2010 at 10:31 AM, Amit Tomar <amittomer25@yahoo.com> wrote:

[#370383] Re: how do i force ruby to release memory — Amit Tomar <amittomer25@...> 2010/09/24

Jes炭s Gabriel y Gal叩n wrote:

[#370388] How to delete the browser cache through ruby — Arihan Sinha <arihan_sinha@...>

Hi All,

11 messages 2010/09/24

[#370590] Point me to help w/ multithreading in 1.9.2-p0 — Alex Stahl <astahl@...5.com>

Hi Folks - A week or two ago, I pinged this list for recommendations on

11 messages 2010/09/28
[#370593] Re: Point me to help w/ multithreading in 1.9.2-p0 — Alex Stahl <astahl@...5.com> 2010/09/28

Nevermind... figured it out.

[#370640] puts and return — Jim Haungs <jhaungs@...>

10.times do |i|

14 messages 2010/09/28

[#370661] Color sequences in ri on Windows — Eric Christopherson <echristopherson@...>

After installing some gems, the system recommended that I refresh ri

11 messages 2010/09/28

[#370721] The beauty of Ruby through examples — Adriano Ferreira <adrfer@...>

Hey all,

33 messages 2010/09/29

[#370740] Can't upgrade ruby on Snow Leopard — Ast Jay <azzzz@...>

I've followed the instructions here:

13 messages 2010/09/29

[#370796] How to prevent overwriting methods by accident? — Stefan Salewski <mail@...>

In Ruby we can add new methods to existing classes.

13 messages 2010/09/30
[#370797] Re: How to prevent overwriting methods by accident? — Jeremy Bopp <jeremy@...> 2010/09/30

On 9/30/2010 2:15 PM, Stefan Salewski wrote:

[#370800] Re: How to prevent overwriting methods by accident? — Alex Stahl <astahl@...5.com> 2010/09/30

But is there a way to call the original method instead of just quitting

Re: NP-Hard Geolocation Problem

From: "Dalthon [BR]" <efqdalton@...>
Date: 2010-09-17 02:00:11 UTC
List: ruby-talk #369932
   I found a heuristic solution that has complexity O(n*log(n)) per
step (for 1000 elements and 16 areas, I got a good solution in 500
steps).

   The code has some constraints that are easy to remove:
   - All areas must have exactly the same amount of elements
   - Distances calculated assuming flat space (just rewrite Point's
function distance_to)

   It's easy to customize heuristic params and remove those
constraints

   Ps.: Not sure about the complexity, you can check yourself, because
I solved the problem during a sleepless, but it's gone now and I'm
going to bed. If you have some doubts ask me and I'll answer
tomorrow...

Solution:

class Point
  attr_accessor :x, :y, :distances, :at
  def initialize(x, y)
    @x, @y = x.to_f, y.to_f
  end

  def distance_to(p)
    Math.sqrt sum_of_squares_to(p)
  end

  def sum_of_squares_to(p)
    (self.x-p.x)**2 + (self.y-p.y)**2
  end

  def calc_distances_to(areas)
    @distances = areas.inject({}){ |d, a| d[a] = distance_to a.mean;
d }
  end

  def self.new_by_rand
    Point.new(rand(100), rand(100))
  end

  def to_s
    "(#{x},#{y})"
  end
  alias :inspect :to_s
end

class Area < Array
  def mean
    @mean || mean!
  end

  def entropy
    self.inject(0) do |ent, p|
      ent += mean.sum_of_squares_to p
    end
  end

  def mean!
    ps = self.inject( Point.new(0, 0) ) do |ps, p|
      ps.x += p.x
      ps.y += p.y
      ps
    end
    ps.x = ps.x/self.size
    ps.y = ps.y/self.size
    self.sort_by!{ |p| p.distance_to ps }
    @mean = ps
  end

  def fix!
    self.each do |p|
      p.at = self
    end
  end

  def self.refine(areas, points, n)
    area_size = areas.first.size
    refresh_distances(areas, points)
    doubt_points = areas.inject([]) do |dp, area|
      dp.concat area[n..-1]
    end

    doubt_points.each do |point|
      point.at.delete point
      point.at = nil
    end

    doubt_points.each do |point|
      ordered_areas = point.distances.sort_by{ |k, v| v }
      nearest_area, distance = ordered_areas.pop
      until(nearest_area.size < area_size)
        nearest_area, distance = ordered_areas.pop
      end
      nearest_area << point
      point.at = nearest_area
    end
  end

  def self.refresh_distances(areas, points)
    areas.each &:mean!
    points.each do |p|
      p.calc_distances_to areas
    end
  end

  def self.all_areas_same(areas_1, areas_2)
    areas_1.each_with_index do |a, i|
      return false if areas_2[i] != a
    end
    return true
  end

  def self.refine_until_good_solution(areas, points, good_ratio =
0.01, max = 10_000, n = (areas.first.size*0.9).to_i, doubt_region =
max*0.05)
    areas, points   = areas.clone, points.clone
    current_entropy = last_entropy = areas.inject(0){ |ent, a| ent +=
a.entropy }
    enhance         = 10*good_ratio
    count           = 0
    best_solution   = areas.clone
    best_entropy    = current_entropy
    while( count < doubt_region || ( count < max && enhance >
good_ratio ) )
      last_entropy = current_entropy
      Area.refine areas, points, n
      current_entropy = areas.inject(0){ |ent, a| ent += a.entropy }
      enhance = (current_entropy - best_entropy)/best_entropy
      if best_entropy > current_entropy
        best_entropy  = current_entropy
        best_solution = areas.clone
      end
      count += 1
      puts "Step: #{count}, Enhance: #{enhance}, Entropy:
#{current_entropy}"
    end
    best_solution.each &:fix!
    [ best_solution, best_entropy ]
  end
end

# Example:
points = []
areas = 16.times.map do |n|
  area = Area.new
  (1000/16).times do |i|
    p = Point.new_by_rand
    p.at = area
    area << p
    points << p
  end
  area
end
Area.refine_until_good_solution(areas, points)

On 16 set, 20:08, Markus Schirp <m...@seonic.net> wrote:
> Hi,
>
> I'm not calling myself an expert on those problems, but here are my toughs:
>
> In a first step you can classify each person to a "neighbor group", this
> group could include persons in a specified region.
>
> So the rest of your solution can work with "group" distances instead of
> inter person distances. When the "neighbor groups" include enough
> persons you'll save computational resources.
>
> You could vary the "neighbor group" region size on demand, in your
> example Southern California would/should get twice as much neighbor
> groups as NY.
>
> Than your algorithm "just" has to choose "target groups" with no
> "neighbor group" duplicates to get an "initial solution".
>
> Now you can start optimizing the "total-distance", just randomly (or
> more intelligently) interchange members between the target groups and
> calculate the total distance. Once you are happy you are done.
>
> Possible Strategy for selecting an group member to interchange:
>
> Look at group A, find two members A1 and A2 where (group) distance
> between A1, and A2 is minimal. Try to push A1 to another group without
> negatively affecting the "total-distance", if okay: proceed with group
> B, if not try to push A2, and so on.
>
> Additionally you can apply any scheme from:
>
> http://en.wikipedia.org/wiki/Combinatorial_optimization
>
> Once I have to implement an Vehicle Routing Problem Solver in *evil* VBA
> (Bachelor Thesis for a friend), I did not do the math part, but it was
> an interesting challenge.
>
> Please let me know how you solved your problem, I'll have to solve one
> similar in the future ;)
>
> Regards,
>
> Markus
>
> On 09/16/2010 11:09 PM, J.R. Gutierrez wrote:
>
>
>
> > I am trying to create a program that maximizes the distances of
> > addresses in Y amount of groups, essentially trying to decrease the
> > chance that you are in the same group as your neighbors.
>
> > Here is an example n it's simplest form. Say there are four people, two
> > living in Los Angeles, one in New York, and one in Chicago that needed
> > to be divided into two groups. The logical grouping would be {LA, CHI}
> > and {LA, NY).
>
> > Now a more complex example. Imagine 1000 people, 400 of which reside in
> > the Southern California area, 200 in the NY area, 100 in the Northern
> > California area, and the rest peppered in the area within the country.
> > We need to separate them into 16 groups. Ideally, depending on
> > distances, there would be 400/16 SoCal residents in a group.
>
> > I've been trying hard to find out how to characterize this problem in a
> > way that can be calculated with a computer using Ruby. The only way I
> > can get an optimal answer by brute-forcing the distance between X people
> > (X! calculations) and then doing something with that information to
> > divide them into evenly distributed groups. I've also tried to think of
> > this as reverse gravity problem, where the closer two people live to
> > each other, the more they repel each other when deciding groups.
>
> > So my question is, is there any kind of similar problem where I can
> > borrow some kind of algorithm to compute an optimal answer? Or can
> > anyone at least point me in the right direction?


In This Thread