in reply to Re: Evolving a faster filter? (code)
in thread Evolving a faster filter?
Heh, I just had what might be a great idea on how to do the first sort.
It is trivial to do a two-item optimization in your sort comparison routine. This is "cheating" because you can end up telling sort that you want $a < $b and $b < $c but $c < $a. On old versions of Perl, that might even cause a core dump. I think it is actually documented as safe on modern Perl, however.
my @order = sort { $Costs[$a]+$Trims[$a]*$Costs[$b] <=> $Costs[$b]+$Trims[$b]*$Costs[ +$a] } 0..$#Costs; @Trims = @Trims[@order]; @Costs = @Costs[@order];
It is that simple. It worked reasonable well in a couple of test cases. It even found an optimal solution on the first try for my prior example above (but took too long to declare success, probably indicating a bug).
- tye
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Evolving a faster filter? (optimal solution?)
by LanX (Saint) on Jan 04, 2013 at 21:22 UTC | |
by tye (Sage) on Jan 04, 2013 at 21:32 UTC | |
by LanX (Saint) on Jan 04, 2013 at 21:42 UTC | |
by tye (Sage) on Jan 04, 2013 at 22:35 UTC |
In Section
Seekers of Perl Wisdom