[#35036] Intentional Programming — "John" <nojgoalbyspam@...>
Hi all
Noone here interested in Intentional Programming? Anybody have an idea of
[#35057] Re: Ruby Regular Expression problem — "Olonichev Sergei" <olonichev@...>
[#35058] here documents as method parameter problem — mrp@...
in the following code, the first 2 "puts" work, but the last produces:
[#35060] Just noticed: 1.6.7 — Dave Thomas <Dave@...>
[#35112] RDoc question — Michael Davis <mdavis@...>
I have a question about RDoc. I would like to reference an external
Dave Thomas wrote:
Michael Davis <mdavis@sevainc.com> writes:
On Sun, Mar 03, 2002 at 08:07:52AM +0900, Dave Thomas wrote:
[#35118] TestUnit 0.1.4 — <nathaniel@...>
From the README:
[#35162] string to array and back — Ron Jeffries <ronjeffries@...>
I am needing to convert strings to arrays of bytes and back. I see pack and
Javier Fontan wrote:
[#35175] Readline loses stdin? — Massimiliano Mirra <list@...>
When I run the following code...
[#35182] RubyStudio UI Question — Chris Gehlker <gehlker@...>
I've been noodling all day about how the editing window in RubyStudio should
[#35186] ruby-dev summary 16040-16125 — Minero Aoki <aamine@...>
Hi all,
[#35200] Ruby and Parrot in The Perl Review — "Paul E.C. Melis" <melis@...>
Hi all,
[#35244] require 'file path' ? — Audun Tonnesen <aut@...2i.net>
This is a stupid question from a newbie. I have installed the windows version, and I wanted to try a graphic example from the 'pragmatic' using tk.
[#35276] Please help me!!!!!!!!!!!!! — rahmanian mohsen <rahmanian60@...>
where I can ask a question?
[#35322] How Ruby differs from Other Languages? — S Sridevi <shridevi@...>
Hi,
[#35341] Ruby Serial Ports under Windows — David Wende <DWende@...>
I've started using Ruby a week ago as my first OOP
[#35364] file reading impossibly slow? — Ron Jeffries <ronjeffries@...>
So I'm doing this benchmark to work with my set program. Part of the problem is
On Thu, 07 Mar 2002 13:52:41 GMT, nobu.nokada@softhome.net wrote:
I'm jumping into this thread late, so apologies if I'm repeating well-known
[#35378] RDoc now generates .chm files — Dave Thomas <Dave@...>
[#35386] What are the Ruby 1.8 plans? — Matt Armstrong <matt@...>
There have been two recent threads about slow Ruby IO under Win32
[#35388] Re: file reading impossibly slow? 1.6.6 vs. 1.6.2 numbers — Pete McBreen <pete@...>
Matt Armstrong wrote
[#35393] net/http; 302 — Tobias Reif <tobiasreif@...>
Hi,
[#35409] Talking Trash About Ruby — Lyle Johnson <lyle@...>
All,
[#35429] Interesting link on static/dynamic typing... — Robert Feldt <feldt@...>
...relevant to Ruby compared to other languages discussion:
On Fri, Mar 08, 2002 at 05:34:43PM +0900, Robert Feldt wrote:
On 3/8/02 7:56 AM, "Paul Brannan" <paul@atdesk.com> wrote:
Robert Feldt <feldt@ce.chalmers.se> writes:
[#35430] Spooky backtick bug w/large file support — jonathan@... (Jonathan Baker)
Discovered that the patch for large files caused a nasty side effect:
[#35439] Opinions wanted (long) — Massimiliano Mirra <list@...>
These are some embryonic ideas that generated after a discussion with
[#35443] RE: Text stuff and appending to a file — Wyss Clemens <WYS@...>
By heart I would guess:
[#35460] Spam, ruby-talk, and me — Dave Thomas <Dave@...>
Dave Thomas <Dave@PragmaticProgrammer.com> writes:
On Sat, Mar 09, 2002 at 07:12:56AM +0900, Yohanes Santoso wrote:
[#35477] is there any way ... — Ron Jeffries <ronjeffries@...>
is there any way we could fix the bug whereby a..b is /longer/ than a...b ?
[#35478] file closing — Ron Jeffries <ronjeffries@...>
So I'm going to create an object that wraps a file and gives it some new kind of
[#35519] Open Watcom — Massimiliano Mirra <list@...>
I'm not directly interested in this since I run Linux, but I stumbled
[#35537] Confusion — David Corbin <dcorbin@...>
The following is from my debugging through xmlc.rb
David Corbin wrote:
[#35553] Fiddling with ruby/tk canvas — Thomas Sondergaard <tsondergaard@...>
I've got a TkCanvas with a number of TkcImage items on it. I've set it
[#35557] Issue with trapping errors in instance_eval — Michael Davis <mdavis@...>
I need to be able to trap error during a call to instance_eval. Here is
[#35579] RE: WIN32OLE and LDAP — "Morris, Chris" <chris.morris@...>
> The new version 0.4.2 of Win32OLE has WIN32OLE.bind method.
ehlo.
[#35580] packages (jar-alike) — Vladimir Dozen <Vladimir.Dozen@...>
ehlo.
[#35608] Using 'uniq' question — edjbaker@... (Ed Baker)
If I have an array of data, where each record looks like the example
[#35609] Config::CONFIG['build_alias'] ? — Massimiliano Mirra <list@...>
Which are the build aliases of the platforms ruby runs on?
[#35636] gzip again... — Massimiliano Mirra <list@...>
I can't seem to process from within Ruby with gzip files that exceed a
On Tue, Mar 12, 2002 at 12:34:29PM +0900, Massimiliano Mirra wrote:
[#35639] Controlling Mouse/Keyboard — "Norman Makoto Su" <normsu@...>
Hi,
[#35653] Some potential RCRs — "Bob Alexander" <bobalex@...>
Here are a few thing I am considering submitting as RCRs. I'm looking =
Following are summarized responses to the passle of RCR candidates I posted
Hi,
On Wed, Mar 13, 2002 at 03:58:01AM +0900, Yukihiro Matsumoto wrote:
Hello --
"Bob Alexander" <balexander@rsv.ricoh.com> wrote in message
[#35692] Module Syntax — "Sean O'Dell" <sean@...>
Being primarily a C++ programmer, I'm happy with Ruby's Module concept
[#35694] rpkg 0.3 — Massimiliano Mirra <list@...>
>
james@rubyxml.com writes:
Dave Thomas <Dave@PragmaticProgrammer.com> writes:
On Wed, Mar 13, 2002 at 08:48:03PM +0900, Piers Cawley wrote:
[#35718] RE: testunit, was RE: [ANN] rpkg 0.3 — Thomas Sdergaard <tsondergaard@...>
> I believe the reason is because your standard Ruby
It is the merging of Lapidary and RubyUnit (backward compatibility APIs for
Rich Kilmer [mailto:rich@infoether.com] wrote:
On Wed, Mar 13, 2002 at 11:48:15PM +0900, nathaniel@talbott.ws wrote:
[#35742] how do i: add_observer( { small bit of code } ) — mrp@...
observing an object, i want to run a small bit of code when update is
[#35757] process two arrays pairwise? — Ron Jeffries <ronjeffries@...>
Is there somewhere in Ruby a way to process the elements of two arrays (of equal
[#35766] Ruby/zlib 0.5.0 — UENO Katsuhiro <unnie@...>
Hello,
[#35776] Anyone using the WASTE editing library with Ruby? — ptkwt@...1.aracnet.com (Phil Tomson)
[#35787] testunit - setup -> set_up ? — "Morris, Chris" <chris.morris@...>
I'm just starting to use testunit instead of rubyunit ... I noticed with an
Morris, Chris [mailto:chris.morris@snelling.com] wrote:
"Nathaniel Talbott" <nathaniel@talbott.ws> writes:
dave@thomases.com [mailto:dave@thomases.com] wrote:
"Nathaniel Talbott" <nathaniel@talbott.ws> writes:
Hi,
On Fri, 15 Mar 2002 02:10:16 GMT, "Nathaniel Talbott" <nathaniel@talbott.ws>
[#35790] RE: Some potential RCRs — "Morris, Chris" <chris.morris@...>
> > - - A much better solution would be added support for file "type"
[#35825] Test::Unit — "Steve Merrick" <Steve.Merrick@...>
Can someone explain to me the *details* of how to use Test::Unit,
[#35845] Debugger problem — "Nathaniel Talbott" <nathaniel@...>
Perhaps this is a known issue, but given the following program:
[#35866] new user confused by multidimensional Ruby hashes — Ian Macdonald <ian@...>
Hi all,
[#35898] camelCase and underscore_style — "Morris, Chris" <chris.morris@...>
First, a question. If underscore_style is the Ruby norm for methods and the
Phil Tomson wrote:
Guy N. Hurst [mailto:gnhurst@hurstlinks.com] wrote:
On Sat, Mar 16, 2002 at 09:14:30AM +0900, Nathaniel Talbott wrote:
[#35900] Re: camelCase and underscore_style — Andrew Hunt <andy@...>
>I noticed code samples in the pickaxe book used camelCase. Dave/Andy, was
[#35929] Reading from a string — David Corbin <dcorbin@...>
Is there a class that provides the IO interface from a String? It seems
Hi,
On Sat, 2002-03-16 at 07:33, nobu.nokada@softhome.net wrote:
On Sat, Mar 16, 2002 at 05:28:27PM +0900, Thomas Sondergaard wrote:
[#35937] rpkg 0.3.1 — Massimiliano Mirra <list@...>
rpkg is a system for quick installation, removal, and browsing of Ruby
On 3/15/02 6:00 PM, "Massimiliano Mirra" <list@chromatic-harp.com> wrote:
[#35947] Newbie problem — Liorean <Liorean@...>
In a small program I wrote at school, using mswin32, I used $stdin to get
Hi,
At 15:43 2002-03-16 +0900, nobu.nokada@softhome.net wrote:
Hi,
At 17:23 2002-03-16 +0900, nobu.nokada@softhome.net wrote:
Hi,
At 16:26 2002-03-17 +0900, nobu.nokada@softhome.net wrote:
[#35973] how does gtk curve work? — Massimiliano Mirra <list@...>
I'm trying to initialize the curve in the Gtk::Curve widget.
[#35986] Good example Ruby program? — jennyw <jennyw@...>
I was hoping someone could suggest a good example Ruby program for me to
I haven't read it yet (planning on buying it), but I understand that
I totally agree with Dennis. I own "The Ruby Way" by Hal Fulton.
[#35989] ANN: Locana GUI and GUI Builder version 0.81 — Michael Davis <mdavis@...>
I am pleased to announce release 0.81 of Locana. Locana is a GUI
[#35992] XPath — Michael Schuerig <schuerig@...>
Tobias Reif wrote:
[#36004] Rubicon -> Test::Unit — Bil Kleb <W.L.Kleb@...>
Are there plans a foot for Rubicon to use Test::Unit?
[#36034] Mini Rant: Indenting — Thomas Hurst <tom.hurst@...>
Why is it that I see *so* much code like:
Thomas Hurst <tom.hurst@clara.net> writes:
[#36042] instance_respond_to? — Thomas Sondergaard <tsondergaard@...>
Shouldn't module have an instance_respond_to? method?
[#36049] web templating for static sites? — Massimiliano Mirra <list@...>
I'm using the Template Toolkit for generating static web sites and I
> I am fascinated by the approach of tools like Iowa or Walrus, and how
Massimiliano Mirra <list@chromatic-harp.com> wrote in message news:<20020317204303.C5717@prism.localnet>...
On Mon, Mar 18, 2002 at 04:23:46PM +0900, Patrick May wrote:
Massimiliano Mirra <list@chromatic-harp.com> wrote in message news:<20020319153126.B3694@prism.localnet>...
How do you Ruby/HTML guys deal with the different versions of
Albert Wagner wrote:
> People who don't care about current standards or nice
Jason Voegele wrote:
> > I apologize for continuing an off-topic thread, but I've heard several
* Carl Parrish (cparrish@cox.net) wrote:
[#36052] Xml Serialization for Ruby — "Chris Morris" <chrismo@...>
=Xml Serialization for Ruby
On Mon, Mar 18, 2002 at 05:20:56AM +0900, Chris Morris wrote:
> </MyClass>
On Mon, Mar 18, 2002 at 12:51:14PM +0900, Chris Morris wrote:
> These two are mostly equivalent. The main reasons I prefer the first
> I agree that that smells ... the inconsistency of "root element is class
Hi Chris,
[#36067] eval/Module question — David Corbin <dcorbin@...>
If I have a String src that is similar to the following:
Let me try again.
[#36093] Test::Unit GTk GUI — Bil Kleb <W.L.Kleb@...>
While trying to get a "green bar" with Test::Unit using the GTk
Bil Kleb wrote:
Bil Kleb [mailto:W.L.Kleb@LaRC.NASA.Gov] wrote:
[#36107] Extconf.rb: how to add specific include/lib dirs? — "Paul E.C. Melis" <melis@...>
Is it possible to specify a complete include or lib directory that is needed
[#36142] Why is Ruby so slow? — Venherm.Borchers@... (Venherm Borchers)
WHY IS RUBY SO SLOW?
Venherm Borchers wrote:
Kent Dahl wrote:
[#36157] Development of Windows version of Ruby — ptkwt@...1.aracnet.com (Phil Tomson)
Now that we've dumped the cygwin requirement for the Windows version of
Something like all the PC programs in the world are written for Windows.
On Tue, 19 Mar 2002 14:05:27 GMT, "Albert L. Wagner" <alwagner@uark.edu> wrote:
Dennis Newbold <dennisn@pe.net> wrote in message news:<Pine.GSO.3.96.1020320113603.22242B-100000@shell2>...
Some thoughts on the 2 first Windows issues, plus a 4th one...
"Christian Boos" <cboos@bct-technology.com> writes:
Hi,
nobu.nokada@softhome.net writes:
Hi,
A couple of times I've posted questions to this list,
[#36171] Weekly RCR Summary — RubyGarden@...
This is an automatically generated list of Ruby Change Requests.
[#36175] Wanted: slick rubyesqe algorithm — David Corbin <dcorbin@...>
Say I've got a list of Objects
On Tue, Mar 19, 2002 at 09:36:59AM +0900, David Corbin wrote:
[#36211] dots in Dir.entries — matz@... (Yukihiro Matsumoto)
Hi,
At 4:22 PM +0900 3/19/02, Yukihiro Matsumoto wrote:
[#36231] style choice — Ron Jeffries <ronjeffries@...>
A style question for the community ... which of the following do you prefer, and
[#36294] RE: Development of Windows version of Ruby — "Morris, Chris" <chris.morris@...>
Here's an overview of fork on Windows with Perl. (Google rocks):
[#36298] Other than fork, what is vc++ ruby win missing? — "Morris, Chris" <chris.morris@...>
Is there anything other than fork (remember popen works) that Ruby on
On Tue, 19 Mar 2002 18:27, Morris, Chris wrote:
[#36301] another Test::Unit question — Pat Eyler <pate@...>
Okay, so I'm moving along doing unit testing to build a small application
[#36310] Re: Why is Ruby so slow? - Solution — Venherm.Borchers@... (Venherm Borchers)
Dear colleagues,
[#36318] Increased traffic? — Massimiliano Mirra <list@...>
Is it just my impression or has the traffic on the list increased
[#36322] Why no String#bin? — ptkwt@...1.aracnet.com (Phil Tomson)
We've got:
[#36345] ANN: REXML 2.0 — Sean Russell <ser@...>
I have a feeling there will only be three major revisions of REXML. Version
[#36367] Newsfeed dropping messages? — Bil Kleb <W.L.Kleb@...>
I read via the newsgroup gateway, i.e., news://comp.lang.ruby
[#36396] Archives — Massimiliano Mirra <list@...>
Those interested in archive-like containers like Tar and Zip but also
[#36401] building latest cvs ruby on win — "Morris, Chris" <chris.morris@...>
I'm trying to build the latest cvs on Windows with msvc ... I found the
[#36402] Ruby/Tk on OSX — jack_d_herrington@... (Jack Herrington)
Has anyone had any success running Ruby/Tk on OSX.
[#36423] Linux Journal Ruby article — mike@... (Mike Stok)
I just noticed this ... http://www.linuxjournal.com//article.php?sid=5915
Mike Stok wrote:
[#36448] Ruby speak — Carl Parrish <cparrish@...>
[#36491] erb: how to include(import,load) another erb file? — Norbert Gawor <ngawor@...>
Sorry for not being able to find this by myself,
[#36580] www.selfruby.de — "Jonas Hoffmann" <ruby@...>
Hallo !
[#36597] RE: Hello! Can you help me? — "Morris, Chris" <chris.morris@...>
> -Can you tel me that ,is a way for convert Ruby source to .EXE file?
[#36608] Unicode in Regexp followup — ser@... (Sean Russell)
In fact, the unicode regular expressions have problems with the
[#36610] Re: Windows version of Ruby (proposals) — Ron Jeffries <ronjeffries@...>
On Thu, 21 Mar 2002 14:11:55 GMT, Dave Thomas <Dave@PragmaticProgrammer.com> wrote:
Another dumb question about syntax, but I haven't been
> I think Ruby is great, and I think that like it or not, Windows has
[#36613] Unicode in Regexp (a question) — ser@... (Sean Russell)
Does anybody know how to specify UTF-8 characters in regular
[#36617] Etiquette of RCRs — Chris Gehlker <gehlker@...>
I have a specific addition I would like to see in mkmf. I also have some
Hi,
On 3/22/02 8:30 PM, "nobu.nokada@softhome.net" <nobu.nokada@softhome.net>
[#36642] extracting multi-line <a> tags? — Tobias DiPasquale <anany@...>
Hi all,
[#36644] ruby-gtk fatal error — Patrik Sundberg <ps@...>
hi,
[#36645] Ruby for Mac OS 10.1 — Jim Freeze <jim@...>
Hi:
Chris Gehlker <gehlker@fastq.com> wrote:
On 3/25/02 1:19 PM, "Jayce Piel" <jayce@mosx.net> wrote:
On Tue, Mar 26, 2002 at 10:25:57AM +0900, Chris Gehlker wrote:
In article <1f9nwp5.1k8346q140f6ocN%jayce@mosx.net>,
[#36670] sendmail undisclosed-recipients — "Chris Morris" <chrismo@...>
Have the following code:
[#36690] CGI testing — "Norman Makoto Su" <normsu@...>
Hi,
[#36691] ruby-dev summary 16301-16500 — Minero Aoki <aamine@...>
Hi all,
[#36712] ruby -n -e doesn't find things ... — Ron Jeffries <ronjeffries@...>
I'm confused. This line
[#36721] How to split an Array efficiently? + non-inplace Delete_if —
Hi,
[#36726] A mode-ruby.el for xemacs ? — jayce@... (Jayce Piel)
[#36733] dbm/gdbm/sdbm — Urban Hafner <ruby-lists@...>
Hey hey,
[#36768] Re: Difference between 'do' and 'begin' — Clemens Hintze <c.hintze@...>
In <slrna9ulvi.f2h.mwg@fluffy.isd.dp.ua> Wladimir Mutel <mwg@fluffy.isd.dp.ua> writes:
james@rubyxml.com wrote:
On Tue, 2002-03-26 at 11:27, Kent Dahl wrote:
Hi,
> Using direct translation, we use "block" for the former (do), "statement
[#36771] yield in iterator's body - — Wladimir Mutel <mwg@...>
Can we write in Ruby something like this :
[#36808] Error calling Tk in a loop — <james@...>
I'm trying to write some code that pops up a Tk window when for certain
Hi,
[#36829] Experience with larger web-projects in Ruby? — "Jonas Delfs" <jonas@...>
Hi -
[#36841] RE: Windows version of Ruby (proposals) — "Andres Hidalgo" <sol123@...>
I believe that Ruby has a place in windows (Office), I happened to have
I looked in the FAQ and didn't see this, but can someone give me their opinion
[#36863] Hash.new(Hash.new) doesn't use Hash.new as default value — "Jonas Delfs" <jonas@...>
Hi -
>>>>> "J" == Jonas Delfs <jonas@NOSPAMdelfs.dk> writes:
"Yukihiro Matsumoto" <matz@ruby-lang.org> skrev i en meddelelse
"Jonas Delfs" <jonas@NOSPAMdelfs.dk> writes:
Hi,
[#36871] RE: File change notification? — Dale Martenson <dmartenson@...>
Hello,
[#36879] Ruby SWIG problems — "James Adam" <james@...>
Hi
[#36882] Webrick book ?? — Markus Jais <mjais@...>
hello
[#36910] Variable variables in Ruby? — "Jonas Delfs" <jonas@...>
Hi -
[#36934] parsing strings into numbers — "Chris Morris" <chrismo@...>
Ruby knows that:
[#36944] Anyone in or around Bergen want to talk Ruby? — Dave Thomas <Dave@...>
[#36977] Dir.glob => Enumerable.glob? — Thomas Sdergaard <thomass@...>
Why not?
[#36990] rubydbi in debian? — Tom Robinson <tom@...>
It would be nice to have this as a package in debian. Any ruby debian
On Fri, 29 Mar 2002 12:00:22 GMT, Massimiliano Mirra
[#37005] Matz's book ?? — Markus Jais <info@...>
hello
[#37009] optimization questions — George Moschovitis <gmosx@...>
Hi there,
[#37010] Now that's surprising. — Chris Gehlker <gehlker@...>
Does anyone else think that the following little program is an instance of
[#37036] My sprintf methods and props for FXRuby — Jonathan Gillette <jonathan@...>
I've had a blast with Ruby over the past seven or so months and thought I'd pass on a bit of favorite code. I always find myself laying out my strings with sprintf and found it handy to add sprintf methods to arrays, hashes, and the REXML::Element class. I thought someone else might find this useful or might clue me in on some optimizations.
[#37038] RUNIT: mixin instead of inheriting? — ptkwt@...1.aracnet.com (Phil Tomson)
[#37043] Creating an instance of a class without calling initialize() — harryo@... (Harry Ohlsen)
For reasons that I'll go into if someone's interested,
[#37060] Re: Creating an instance of a class without calling initialize() — "Joseph Girgis" <jbgirgis@...>
Why don't you want the initialize() method?
"Joseph Girgis" <jbgirgis@msn.com> wrote in message news:<OE74EzcT1ePyu91wCJW00002df4@hotmail.com>...
[#37080] Why isn't Math object-oriented? — Bil Kleb <W.L.Kleb@...>
So I'm reading along in the Pixaxe book (yet again), and I am told
On Sun, 31 Mar 2002 15:44:46 GMT, matz@ruby-lang.org (Yukihiro Matsumoto) wrote:
Hi,
[#37093] Timezone name -> UTC hour offset? — Sean Chittenden <sean@...>
Is there any way of going from -0800 to (PST|PDT) ? Is there a module
Sean Chittenden wrote:
[#37115] rbot - ruby IRC bot — Tom Gilbert <tom@...>
Hi,
i've not used ruby for that long, but i've found the need to do the
[#37119] Detecting class variables.... — Sean Chittenden <sean@...>
I have a class that will have many objects and each object has a
Hello --
> > I have a class that will have many objects and each object has a
Hi --
[#37121] String#begins?(s) — timsuth@... (Tim Sutherland)
class String
Hi,
disease model (fwd)
Damien Joly wrote:
> I'm a population ecologist interested in wildlife
> disease, and have used modeling extensively in my
> research.
I actually played with some similar problems for a project in my Numeric
Analasys II class. It was just comparing different methods for controlling
a population of Impalas (the animals, not the cars).
It wasn't based too closely to any real situation,
but it was kinda fun.
I was actually pretty suprised to find a copy lying around,
i thought i had deleted it.
Oh, i don't really have any place to put it up on the web,
but i guess it may be useful for it to exist at least once,
so i'll just include it with my message (sorry).
it's three files total.
oh, and the last little part that tries to come up with a stable killing
rate doesn't work.
i think it may be oscilatory around the equilibrium point or something like
that,
cause when i do the calculations by hand (matrix theory, Jacobian analysis,
etc.),
i come up with rates around 15%,
unlike the 80% i've gotten with the program.
oh well, i still got an A ^_^
------------------------------>8---------------------------
#!/usr/local/bin/ruby -w
# Copyright (c) 2002, Martin Chase
#
# This software is really boring, as it's my homework.
# Feel free to use this however, subject to the
# artistic license, as per perl's at:
# http://www.perl.com/lang/misc/Artistic.html
#
# Impala modeling assignment
# Assumptions: females only live for 11 years, males for 10
# the initial population is evenly distributed
require "Rules.rb"
module Impala
### Module constants
$MALE = 1
$FEMALE = 2
$NEITHER = 0
$JUVENILE_MALES = (0..0)
$YOUNG_ADULT_MALES = (1..5)
$ADULT_MALES = (6..10)
$JUVENILE_FEMALES = (0..0)
$YOUNG_ADULT_FEMALES = (1..5)
$ADULT_FEMALES = (6..11)
class ImpalaPop
attr_accessor :males, :females, :rules
protected
################################
### initialize
### Arguments: hash of named parameters:
### 'initial' = initial population, to be spread evenly
throughout
### 'rules' = the rules set to use (Rules)
### 'males' = male population spread (Array)
### 'females' = female population spread (Array)
def initialize(*args)
args = args[0]
if (args.has_key?('initial'))
initial = args['initial']
remainder = initial % 21
@males = Array.new
@females = Array.new
0.upto(9) do |age|
@males << (initial / 21)
if ((remainder -= 1) >= 0);
@males[-1] += 1
end
end
0.upto(10) do |age|
@females << (initial / 21)
if ((remainder -= 1) > 0)
@females[-1] += 1
end
end
end
if (args.has_key?('rules'))
@rules = args['rules']
end
if (args.has_key?('males'))
@males = args['males']
end
if (args.has_key?('females'))
@females = args['females']
end
end
public
################################
### nextYear
### returns a ImpalaPop object representing the population of next years
impalas,
### based on the rules provided, or defaults.
def nextYear (rules = nil)
next_males = Array.new(1) #first entry undefined
next_females = Array.new(1) #first entry undefined
(0..10).each {|i|
next_males[i+1] = @males[i] * @rules.male_survival[i] if @males[i]
next_females[i+1] = @females[i] * @rules.female_survival[i]
}
births = expected_births
if (births * 2 > 3 * adult_males)
births = 3 / 2 * adult_males
end
### this algorithm matches pam's, but is wrong. a male is only
### needed to fertilize a female.
# fertile_females = young_adult_females + adult_females
# if (fertile_females > adult_males * 3)
# births = adult_males * 3
# else
# births = expected_births
# end
next_males[0] = next_females[0] = births #gender proportional births
return ImpalaPop.new('males' => next_males, 'females' => next_females,
'rules' => @rules)
end
################################
### expected_births
### ignoring males, how many female babies should be born
def expected_births
births = 0
@females.each_index {|i|
births += @females[i] * @rules.birthrate[i]
}
return births
end
################################
### population
def population (gender = $NEITHER, range = nil)
total_pop = 0
@females.each {|f| total_pop += f}
@males.each {|m| total_pop += m}
return total_pop
end
################################
### gives a string of the population in each section of each gender
def to_s
r =("Impala population: %d [Juvenile Males: %d, Young Males: %d, Adult
Males:" +
"%d, Juvenile Females: %d, Young Females: %d, " +
"Adult Females: %d]") % [population,
juvenile_males,
young_adult_males,
adult_males,
juvenile_females,
young_adult_females,
adult_females]
return r
end
################################
### adult_males
def adult_males
dracula = 0
(6..10).each do |i|
dracula += @males[i] if @males[i]
end
return dracula
end
################################
### young_adult_males
def young_adult_males
dracula = 0
(1..5).each do |i|
dracula += @males[i]
end
return dracula
end
################################
### juvenile_males
def juvenile_males
return @males[0]
end
################################
### adult_females
def adult_females
dracula = 0
(6..11).each do |i|
dracula += @females[i]
end
return dracula
end
################################
### young_adult_females
def young_adult_females
dracula = 0
(1..5).each do |i|
dracula += @females[i]
end
return dracula
end
################################
### juvenile_females
def juvenile_females
return @females[0]
end
end
end
----------------------------->8---------------------------
#!/usr/local/bin/ruby -w
# Copyright (c) 2002, Martin Chase
#
# This software is really boring, as it's my homework.
# Feel free to use this however, subject to the
# artistic license, as per perl's at:
# http://www.perl.com/lang/misc/Artistic.html
#
# Impala modeling assignment
# Assumptions: females only live for 11 years, males for 10
# the initial population is evenly distributed
# one adult male is needed to fertilized up to 3 females
class NilClass
def coerce (*args)
return [0,0] #this is to smooth over math by coercing 'nil' into zero
end
def + (arg)
return arg
end
end
module Impala
class Rules
attr_accessor :male_survival, :female_survival, :birthrate
private
##################################
### initialize
### arguments: ([male death rates], [female death rates], [birth rates])
def initialize (males, females, births)
@male_survival = males
@female_survival = females
@birthrate = births
end
public
##################################
### alter_survival(!)?
### arguments:
### gender - one of the module constants $MALE or $FEMALE
### age - the age group to be affected (can be a range)
### degree - the (in|de)crease in survival, as expressed by a decimal
def alter_survival!(gender, age, degree)
age = (age.is_a?(Integer)) ? [age] : age.to_a
gender = case gender
when $MALE
@male_survival
when $FEMALE
@female_survival
end
degree = degree / age.length #apply equally to ages
age.each {|a|
gender[a] += degree
}
end
def alter_survival(gender, age, degree)
(self.dup).alter_survival!(gender, age, degree)
end
def clone
return Rules.new(@male_survival.dup, @female_survival.dup,
@birthrate.dup)
end
end
end
------------------------>8----------------------------
#!/usr/local/bin/ruby -w
# Copyright (c) 2002, Martin Chase
#
# This software is really boring, as it's my homework.
# Feel free to use this however, subject to the
# artistic license, as per perl's at:
# http://www.perl.com/lang/misc/Artistic.html
#
# Impala modeling assignment
# Assumptions: females only live for 11 years, males for 10
# the initial population is evenly distributed
require "ImpalaPop"
require "Rules"
class Array
################################
### sum - add the values of the array together (using '+')
def sum
value = self[0]
self.each_index { |v| value += self[v] unless (v == 0)}
return value
end
################################
### average - add the values and divide by the length
def average
self.sum / self.length
end
################################
### applyAndSum - apply a method to each element, combining the results
### argument:
### symbol - the symbol for the method to apply
### this is intended for use with things like '+', '*', &c., but
### may have other uses.
def applyAndSum (symbol)
value = self[0]
self.each_index { |v|
value = value.send(symbol,self[v]) unless (v == 0)}
return value
end
end
module Impala
$rules = Rules.new([.6,.8,.95,1,1,1,1,.75,.34,0,0],
[.6,.9,.95,.97,.97,.95,.95,.95,.8,.7,0],
[0,.35,.45,.45,.45,.45,.45,.45,.45,.45,.45])
###################################
### calculate_finals - get numbers (final_pop, growth_rates,
### avg_growth) for a given rule set and
### a given amount of time.
### returns: [ImpalaPop, growth_rates, avg_growth_rate]
### arguments:
### rules - the rule set to use
### iterations - the # of time frames to iterate through
### initial - the initial population
def calculate_finals(rules, iterations, initial = 220)
pop = ImpalaPop.new('rules' => rules,
'initial' => initial)
growth_rates = Array.new
i = 0
i.upto(iterations) do
last = pop.population
pop = pop.nextYear
growth_rates << (pop.population / last)
end
return [pop, growth_rates, growth_rates.average]
end
###################################
### print_results - in the style of the day
### args:
### title - name it, baby!
### rate - how fast can you burn
### male, female, juvenile, y_adult, adult - rates per group
def print_results(title, rate, male, female, juvenile,
y_adult, adult)
puts "\n#{title}\n\n"
puts "Same initial population.\n"
rules = $rules.clone
rules.alter_survival!($MALE, $JUVENILE_MALES,
rate*male*juvenile)
rules.alter_survival!($MALE, $YOUNG_ADULT_MALES,
rate*male*y_adult)
rules.alter_survival!($MALE, $ADULT_MALES,
rate*male*adult)
rules.alter_survival!($FEMALE, $JUVENILE_FEMALES,
rate*female*juvenile)
rules.alter_survival!($FEMALE, $YOUNG_ADULT_FEMALES,
rate*female*y_adult)
rules.alter_survival!($FEMALE, $ADULT_FEMALES,
rate*female*adult)
iterations = 15
(pop, growth, avg) = calculate_finals(rules, iterations)
puts "\nAfter #{iterations} years:\n" + pop.to_s
puts "\nGrowth rates:\n" + growth.inspect
puts "Average: " + avg.to_s
puts "\n\n"
end
###################################
### stabalize - find the population management rate that
### stabalizes the population growth. prints.
### arguments:
### title - label me.
### iterations - the number of years to test at
### tolerance - the allowable error in the growth rate (a
### decimal < .01, for any useful info).
### step_size - the starting step size to alter the rate.
### starting_rate - the initial rate to start testing at.
### male, ..., adult - the specific rates to apply to the
### population.
def stabalize (title, iterations, tolerance, step_size, starting_rate,
male, female, juvenile, y_adult, adult)
puts "\nEquilibrium rate: #{title}\n"
puts "\nWithin #{tolerance} error, the equilibrium solution is:\n"
rate = starting_rate - step_size
sign_change = false
(a, growths, c) = calculate_finals($rules, 15)
last = growths[-1]
growth = nil
until ((tolerance > (1 - last).abs) || (last == growth)) do
break if rate > 0 #prevent badness
step_size /= 2 if sign_change
rate = rate - ((1-last>0) ? -step_size : step_size )
rules = $rules.clone
rules.alter_survival!($MALE, $JUVENILE_MALES,
rate*male*juvenile)
rules.alter_survival!($MALE, $YOUNG_ADULT_MALES,
rate*male*y_adult)
rules.alter_survival!($MALE, $ADULT_MALES,
rate*male*adult)
rules.alter_survival!($FEMALE, $JUVENILE_FEMALES,
rate*female*juvenile)
rules.alter_survival!($FEMALE, $YOUNG_ADULT_FEMALES,
rate*female*y_adult)
rules.alter_survival!($FEMALE, $ADULT_FEMALES,
rate*female*adult)
(pop, growth, avg) = calculate_finals(rules, iterations)
growth = growth[-1]
sign_change = ( ((last > 1) && (growth < 1)) ||
((last < 1) && (growth > 1)) ) ? true : false
# puts rate.to_s + " -- " + growth.to_s + ":" + last.to_s +
# " -- " + step_size.to_s + "." + sign_change.to_s
last, growth = growth, last
end
puts rate.to_s + "\n\n"
end
end
if __FILE__ == $0
include Impala
puts "IMPALA " * 4 + "PROJECT!!!!\n\n"
### UNREGULATED GROWTH
puts "\nUnregulated growths\n"
pop = ImpalaPop.new('rules' => $rules,
'initial' => 220)
puts "\nInitial population:\n" + pop.to_s
iterations = 15
(pop, growth_rates, avg) = calculate_finals($rules, iterations)
puts "\nAfter #{iterations} years:\n" + pop.to_s
puts "\nGrowth rates:\n" + growth_rates.inspect
puts "\nAverage: " + avg.to_s
puts "\n\n"
### PREDATION - LOW
title = "Predation - Low"
rate = -.06 # six percent predation rate
male = .5
female = .5
juvenile = .45
y_adult = .2
adult = .35
print_results(title, rate, male, female, juvenile, y_adult, adult)
### PREDATION - HIGH
title = "Predation - High"
rate = -.16 # sixteen percent predation rate
male = .5
female = .5
juvenile = .45
y_adult = .2
adult = .35
print_results(title, rate, male, female, juvenile, y_adult, adult)
### TROPHY HUNTING - LOW
title = "Trophy Hunting - Low"
rate = -.06 # six percent predation rate
male = .7
female = .3
juvenile = .025
y_adult = .025
adult = .95
print_results(title, rate, male, female, juvenile, y_adult, adult)
### TROPHY HUNTING - HIGH
title = "Trophy Hunting - High"
rate = -.16 # sixteen percent predation rate
male = .7
female = .3
juvenile = .025
y_adult = .025
adult = .95
print_results(title, rate, male, female, juvenile, y_adult, adult)
### GAME RANCHING - LOW
title = "Game Ranching - Low"
rate = -.06 # six percent predation rate
male = .7
female = .3
juvenile = .05
y_adult = .75
adult = .2
print_results(title, rate, male, female, juvenile, y_adult, adult)
### GAME RANCHING - HIGH
title = "Game Ranching - High"
rate = -.16 # six percent predation rate
male = .7
female = .3
juvenile = .05
y_adult = .75
adult = .2
print_results(title, rate, male, female, juvenile, y_adult, adult)
###############################
### E Q U I L I B R I U M S ###
###############################
iterations = 15
tolerance = .001
step_size = .01
starting_rate = -.01
### PREDATION
title = "Predation"
male = .5
female = .5
juvenile = .45
y_adult = .2
adult = .35
stabalize(title, iterations, tolerance, step_size, starting_rate,
male, female, juvenile, y_adult, adult)
### TROPHY HUNTING
title = "Trophy Hunting"
male = .7
female = .3
juvenile = .025
y_adult = .025
adult = .95
stabalize(title, 50, tolerance, step_size, starting_rate,
male, female, juvenile, y_adult, adult)
#:!: use 50 above because 15 wasn't producing feasable results
### GAME RANCHING
title = "Game Ranching"
male = .7
female = .3
juvenile = .05
y_adult = .75
adult = .2
stabalize(title, iterations, tolerance, step_size, starting_rate,
male, female, juvenile, y_adult, adult)
end