drp 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS ADDED
@@ -0,0 +1,6 @@
1
+ DRP was conceived of and developed by Christophe McKeon, mailto:polypus@yahoo.com
2
+
3
+ Additional bug fixes and suggestions have come from:
4
+
5
+ nobody as of yet.
6
+
data/CHANGES ADDED
File without changes
data/INTRO ADDED
@@ -0,0 +1,309 @@
1
+
2
+
3
+ = DRP, Directed Ruby Programming
4
+
5
+ <em>N.B., all example code below can be found in the examples/intro directory</em>
6
+
7
+ Directed Programming is a new generative programming technique developed by Christophe McKeon which is a generalisation of Grammatical Evolution (http://www.grammatical-evolution.org) allowing one not only to do GE, but also to do Genetic Programming (http://www.genetic-programming.org) in pure Ruby without explicitly generating a program string as output. DP even allows you to set up hybrids of GP and GE where part of a GE subtree is calculated using normal Ruby functions/operators/etc. via. GP. DRP is the first ever implementation of DP and is written in pure Ruby.
8
+
9
+ DRP however manages to dispense with two problems which affects these two systems, at least in their canonical forms. It cirumvents the so called closure problem of GP simply by stepping over it, a property which it neatly inherits from GE. It also avoids the aborted run problem of GE by having a maximum allowed recursive depth for each expression in a production rule. DRP also allows for a kind of meta-evolution in which rules can be evolved right out of the grammar, or take on a more or less significant a role. It accomplishes this by weighting the right hand sides of rules, as well as limiting the maximum recursive depth of a given rule, which can be evolved right down to zero.
10
+
11
+ GE and DRP are especially well suited to interactive evolutionary/generative applications because they allow arbitrarily tight control over program structure and output. This is important in my view because in interactive systems the biggest bottleneck by far is the fitness function, i.e. the user, and so it is advantageous to be able to *easily* 'engineer' the specification so as to favour certain outcomes. There simply is not enough time for the large populations and many generations used in non-interactive systems. GE is in fact used in several such systems[http://projects.csail.mit.edu/emergentDesign/genr8]. And then of course Ruby itself is no hot-rod, which for interactive sytems is nowhere near as much of a problem as in strictly engineering applications.
12
+
13
+ === A Quick Intro to Genetic Programming
14
+
15
+ GP in it's most commonly known form is an evolutionary computation technique which evolves LISP S-expressions, which are similar to Abstract Syntax Trees if you know about compiler internals. GP was invented and pioneered by John Koza.
16
+
17
+ First a population of trees using the user supplied operators is randomly generated. The evolutionary aspect of it involves running the S-Expressions against some fitness function and determining which are the best performing, which then become the most likely to have 'offspring'. Offspring are generated by snipping off subtrees of both parents and switching them so that each parent gets the subtree of the other 'grafted' back onto the splice point. Other evolutionary operators are also sometimes used such as point mutation where a single node such as an operator, or a constant value (which in GP have the beautiful apelation of 'ephemeral random constants'), are mutated.
18
+
19
+ As you can imagine if in a GP system you have operators which return values of incompatible types, you cannot just snip subtrees anywhere you like and expect the program to run, this is what is usually called the closure problem of GP. There have been various solutions to the problem put forth including several extensions to GP, but the most interesting, and certainly the most elegant, in my view are Lee Spector's PUSH language (which is not relevant to DRP), and Grammatical Evolution.
20
+
21
+ === A Quick Intro to Grammatical Evolution
22
+
23
+ GE is a generative programming technique which unlike GP or PUSH separates the search algorithm from the program representation. For this reason the word evolution in it's name is a bit of a misnomer since other search algorithms besides evolutionary ones can be used, as long as they involve the generation of streams of integral values. It was pioneered by Connor Ryan, JJ Collins and Micheal O'Neil.
24
+
25
+ GE allows for the automatic generation of programs in any language. It does this by using BNF grammars, as follows:
26
+
27
+ <foobar> ::= 'foo ' <foobar>
28
+ <foobar> ::= 'bar!'
29
+
30
+ The above grammar specifies a language consisting of zero or more 'foo's followed by a 'bar!'.
31
+
32
+ For instance, <tt>'foo foo foo bar!'</tt>, <tt>'foo bar!'</tt>, and <tt>'bar!'</tt> are strings in the language, but <tt>'bar! foo'</tt> is not. First the algorithm must be given a start symbol, which in our above language is easy because we only have one left hand side, namely <tt><foobar></tt>, and so we have no choice. But we have two possible right hand sides, and so the algorithm must make a choice between the two possibilities. GE usually does so by iterating over values in a Genetic Algorithm, wrapping back to the beginning if need be, and uses the current integral value in the iteration modulo the number of choices to index into the list of possible right hand sides and make the choice.
33
+
34
+ This brings us to GE's main problem. What if we had a freak GA which consisted of all even numbers. Using the 'foo bar!' example above, for all of x in the GA, 2 modulo x would yield 0, so that the first right hand side would always be chosen, and the algorithm would never halt. But it doesn't have to be that extreme, a GA can be produced which will eventually halt but which still runs long enough to generate a monstrously long machine/process halting output string. GE solves this by simply limiting the number of times that the GA can be wrapped over, and aborting any runs which exceed the limit.
35
+
36
+ Another problem is that in GE, for any given 'gene', each right hand side always has the same probability as it's siblings of being chosen. This means that if some RHS is more or less important to the solution, it will still have the same arbitrarily imposed importance as the other choices, possibly detrimentally to the efficacy of the algorithm. The GE team have recently done work on evolving the grammars themselves using GE in order to alleviate the problem, called GE by GE, but the problem still remains to a degree, in that the RHSs which make it into the second grammar are still equally weighted. DRP has a different take on this kind of meta-evolution.
37
+
38
+ == The DRP System
39
+
40
+ === A Quick Intro
41
+
42
+ DRP grew out of a first attempt I had called Easy GE, which was a GE system which did not allow for direct GP the way DRP does, but which used a few of the improvements to GE which I'll describe below. It had a hand-rolled parser/scanner and interpreter for a little mini-language to represent BNF grammars. At one stage I decided that it would be really great to add parameterization, where rules could be invoked, and passed arguments which could themselves be rules. Although it looked much cleaner in my language, it went something like:
43
+
44
+ <foo> ::= 'foo' <foo(<bar>)>
45
+ <bar> ::= ...
46
+
47
+ This would be useful for certain kinds of output languages, like XML where you might want to pass a tag_name determined by a rule, to another rule, say xml_tag, which would use the name for both the opening and closing tags. As I considered various hypothetical situations, some in languages more expressive than XML, I determined that it would be a really great feature. I also wanted to add a few data types and operators to the language to be able to do some simple math at the generation stage, for numbering identifier names and doing things which very static languages make it hard to do at run-time. But to add all of those things comes very close to just implementing another full scale language where rules are basically just functions which may or may not return strings. Why not just leverage the Ruby interpreter itself then, which is what I did, dividing the number of lines in the project by 5.
48
+
49
+ DRP is designed for extreme ease of use. I'm a big believer in ease of use and 'hand-holding' in documentation. Why waste time reading code when a simple explanation will usually do. If you are considering adopting a project out of a choice of 10, you are much more likely to choose the well documented one, but I digress. Here's an example of the first grammar above using DRP:
50
+
51
+ :include:toy_example.rb
52
+
53
+ Don't rub your eyes, it's not your monitor malfunctioning either, foobar is defined twice, and some metaprogramming magic fixes it such that whenever foobar is called one of the two <em>rule methods</em> (methods between begin and end rule statements) will be called according to how their weights and max_depths have been set, which in the above example are set to the global defaults.
54
+
55
+ === Codons
56
+
57
+ In DRP 'genes' are floating point numbers in the range 0..(1-Float::EPSILON) and are called codons. I prefer the word codons because it has fewer biological overtones, as similarly to GE, it can run using any number of search algorithms, not just genetically inspired ones. For instance Particle Swarm Optimization (http://www.swarmintelligence.org) is a very good match with DRP.
58
+
59
+ You may have noticed that in the above toy example there is no code for a GA or PSO algorithm in sight. That's because to supply a stream of codons yourself, all you have to do is override the default next_codon method, which by default simply calls and returns rand. There is another method which you can override, 'next_meta_codon' which is called for setting weights and max_depths. By default next_meta_codon simply calls next_codon, so you should only override it if you want to separate the 'meta evolutionary' part of your search algorithm from the code generation part.
60
+
61
+ === Setting Max Depths
62
+
63
+ As described above, the main problem with GE is that there can be any number of aborted runs in one generation or iteration of the search algorithm. This is due to the fact that a BNF grammar does not have at it's disposal a mechanism for specifying the maximum recursive depth which any one rule can take. BNF grammars were initially developed for parsing Algol-60 programs, and then were adopted for a wide variety of other tasks, usually of a parsing or descriptive nature, as opposed to generative one. If maximum recursive depths are allowed for individual rule methods not only does GE's main problem disappear, but a new and powerful method of controlling the form of the generated code becomes available.
64
+
65
+ In DRP all rule methods have individually assigned maximum recursive depths, even rule methods with the same name. In the following example two different simple static max_depths are assigned to two rule methods called 'foo'. Because both rule methods have the same name, first the process of choosing which rule method to call is performed every time the method foo is called (described in more detail in the next section). Since they have the same weight they have an equal chance of being called for any given codon, which is what accounts for the different random ordering of the output string for each top level call. Because there is no terminating condition for the recursive call the only thing stopping the recursion is the max_depth, which also accounts for the number of each type of foo printed. You will also notice that max_depth works just as well for indirect recursion as for direct recursive calls.
66
+
67
+ This example also introduces the default_rule_method method, which should always be defined as a normal method (not between begin_rules and end_rules). It is called whenever there are no more available rule_methods of a given name because they have exceeded their max depths. There is a default default_rule_method defined for you which just returns nil.
68
+
69
+ :include:max_depths_example.rb
70
+
71
+ Which prints the following to the screen:
72
+
73
+ foo2 foo1 foo2 foo2 foo1 bar!
74
+ foo1 foo1 foo2 foo2 foo2 bar!
75
+ foo2 foo2 foo1 foo1 foo2 bar!
76
+
77
+ In the following example the singular max_depth class method defines the maximum depth for both of the rule methods which follow. It essentially says, for all following rule methods call next_meta_codon and map the returned codon to the range given, at object initialization time, i.e. each object of class MaxDepthsExample2 will be given different maximum depths for each of it's foo rule methods.
78
+
79
+ :include:max_depths_example_2.rb
80
+
81
+ Which prints the following to the screen:
82
+
83
+ foo2 foo1 foo1 foo1 foo2
84
+ foo2 foo1 foo2 foo1 foo1
85
+ foo1 foo2 foo2 foo1 foo1
86
+
87
+ foo1 foo2
88
+ foo1 foo2
89
+ foo2 foo1
90
+
91
+ foo2 foo2 foo2
92
+ foo2 foo2 foo2
93
+ foo2 foo2 foo2
94
+
95
+ Note that in the third set of output strings foo1 has been 'evolved' right out of the grammar, because the range started at 0.
96
+
97
+ There is also a way of specifying a function to use for the mapping by writing
98
+
99
+ max_depth x..y, :name_of_function
100
+
101
+ ... but for the moment only :i_linear is implemented, so there is no reason to use it.
102
+
103
+ There is a third way of setting the maximum depth which works exactly like the range example in terms of how and when it sets depths for rule methods. It takes a user supplied block and requests enough meta_codons to satisfy the arity of the block. If the arity is 0 then no meta_codons are requested.
104
+
105
+ max_depth { |x,y,z| use_meta_codons_to_define_max_depth(x,y,z) }
106
+
107
+ === Setting Weights
108
+
109
+ In the following example, max_depth is set to 3 for both rule methods, but their weights are set individually. Weights are normalized every time a choice must be made between several rule methods. For some given array of weights, normalization simply divides each weight by the sum of all the weights. The next_codon method is then called to make a choice according to the normalized weights.
110
+
111
+ It may seem inefficient to normalize for every choice, but the weights and the relationship between weights are constantly changing, both because rule methods are constantly dropping out due to exceeding their max_depth, and also because weight can be set to be a function of the current depth, but more on that in a moment.
112
+
113
+ You will notice that in the output foo2 has a much greater chance of being picked at first, but once it has exceeded its max_depth, it is no longer an option so foo1 is then called until it also exceeds its max_depth.
114
+
115
+ :include:weights_example.rb
116
+
117
+ Which prints the following to the screen:
118
+
119
+ foo2 foo2 foo2 foo1 foo1 foo1
120
+ foo2 foo2 foo2 foo1 foo1 foo1
121
+ foo2 foo1 foo2 foo2 foo1 foo1
122
+
123
+ foo2 foo2 foo2 foo1 foo1 foo1
124
+ foo2 foo2 foo2 foo1 foo1 foo1
125
+ foo1 foo2 foo1 foo2 foo2 foo1
126
+
127
+ foo2 foo2 foo2 foo1 foo1 foo1
128
+ foo2 foo2 foo2 foo1 foo1 foo1
129
+ foo2 foo2 foo2 foo1 foo1 foo1
130
+
131
+ You can also map a codon to a Range, or supply a block. In both cases it works just like with max_depth. The weights are set for each rule method of each new object calling next_meta_codon when need be. In the below example the first set generated were fairly evenly weighted, the second weighted towards, foo2, and the third, foo1.
132
+
133
+ :include:weights_example_2.rb
134
+
135
+ Which prints the following to the screen:
136
+
137
+ foo1 foo2 foo2 foo1
138
+ foo1 foo2 foo2 foo1
139
+ foo1 foo2 foo1 foo2
140
+
141
+ foo2 foo2 foo1 foo1
142
+ foo1 foo2 foo1 foo2
143
+ foo2 foo2 foo1 foo1
144
+
145
+ foo2 foo1 foo1 foo2
146
+ foo1 foo1 foo2 foo2
147
+ foo1 foo1 foo2 foo2
148
+
149
+ === Setting Weights as a Function of the Current Depth
150
+
151
+ This feature *is* powerful. It allows you to generate a weight for any given rule method, as a mapping of the current depth as measured against the maximum allowable depth, to a Range. And it allows you to evolve the Range's min and max values themselves using next_meta_codon!
152
+
153
+ In English that means that if some rule method has a max_depth of 3 and you supply a Range of 1..2, then counting from 0, when the rule_method is at a recursive depth of 0 it will have a weight of 1, and when at a depth of 1 going on 2, it will have a weight of 1.5 and when at a depth of 2 going on 3, it will have a weight of 2, that is unless you specify some non-linear mapping.
154
+
155
+ If you supply two Ranges, then at object initialization time, 2 codons are pulled out of next_meta_codon, one for each Range to set the min and max of the Range used to calculate the weight at code generation time. You can follow the Range or Ranges with a symbolic function name, which in both cases is used to map the current depth to a weight at code generation time. Note that in the second case the function is not used to affect the mapping of the two meta codons to the min and max values, which is always just a linear mapping.
156
+
157
+ In the following example the lists of 'foo ... bar!' are generally longer than the lists of 'mama ... mia!', where both mama rule methods have a weight of 1, yet they are constrained from reaching a length of 25 'foo's, because 'bar!', also with a weight of 1, becomes more and more likely to be picked as the first foo rule method approaches it's max_depth.
158
+
159
+ :include:weight_fcd_example.rb
160
+
161
+ Which prints the following to the screen:
162
+
163
+ foo foo foo foo foo foo foo foo foo foo foo bar!
164
+ bar!
165
+ foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo bar!
166
+
167
+ mama mia!
168
+ mama mama mama mia!
169
+ mama mia!
170
+
171
+ foo foo foo bar!
172
+ foo foo foo foo foo foo foo foo foo foo foo foo bar!
173
+ foo foo foo bar!
174
+
175
+ mia!
176
+ mama mia!
177
+ mia!
178
+
179
+ bar!
180
+ foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo bar!
181
+ foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo bar!
182
+
183
+ mia!
184
+ mama mama mia!
185
+ mia!
186
+
187
+ You can also supply a block to weight_fcd. The block should accept the max_depth of the rule method as a parameter, and should return a proc or lambda which will be called whenever a weight is needed for the rule method and passed the current depth, something like:
188
+
189
+ weight_fcd { |the_max_depth|
190
+ ...
191
+ proc {|the_depth| ... }
192
+ }
193
+
194
+ Note that the weight is only ever calculated, and the weights normalized if there is a choice to be made. If there is only one rule method to choose from, then weights are not needed, and hence not calculated. If there are no rule methods, then default_rule_method is called, and if all the weights sum to 0, then they are all given an equal chance of being picked according to a next_codon. This last paragraph pertains to weights specified through both the weight and weight_fcd methods. But to make it more explicit...
195
+
196
+ === El Corazon
197
+
198
+ For those who like the aroma of internal organs, this is the heart of DRP (don't call this stuff directly). After rule methods are culled for having exceeded max_depth (<tt>meth.expressed?</tt>), if there are more than one rule methods left, they are then passed to __drp__choose__method for the choice to be made. <tt>meth.weight</tt> is first called to get all the weights, some of which are calculated on the spot, then the weights are normalized and arranged to make a roulette wheel style of selection possible using next_codon.
199
+
200
+ ...
201
+
202
+ useable_methods = @__drp__rule__methods[name].select do |meth|
203
+ meth.expressed?
204
+ end
205
+
206
+ case useable_methods.size
207
+
208
+ when 0
209
+ default_rule_method *args
210
+
211
+ when 1
212
+ __drp__call__method(useable_methods.first, args)
213
+
214
+ else
215
+ __drp__call__method(__drp__choose__method(useable_methods), args)
216
+
217
+ end
218
+
219
+ ...
220
+
221
+ def __drp__choose__method useable_methods
222
+
223
+ weights = useable_methods.collect do |meth|
224
+ meth.weight
225
+ end
226
+ scale_by = weights.inject(0) do |weight, prev|
227
+ prev + weight
228
+ end
229
+
230
+ weights = if scale_by == 0
231
+ sz = weights.size
232
+ weight = 1.0/sz
233
+ prev_weight = 0
234
+ Array.new(sz) do
235
+ prev_weight = weight + prev_weight
236
+ end
237
+ else
238
+ prev_weight = 0
239
+ weights.collect do |weight|
240
+ prev_weight = weight / scale_by + prev_weight
241
+ end
242
+ end
243
+
244
+ index, codon = -1, next_codon
245
+ weights.detect do |weight|
246
+ index += 1;
247
+ codon < weight
248
+ end
249
+
250
+ useable_methods[index]
251
+
252
+ end
253
+
254
+ === Parameterization, Or, Rule Methods are Really Just Ruby Methods
255
+
256
+ The following example just displays how rule methods in DRP behave for the most part just like regular Ruby methods. Note that if you have parameterized rule methods then if you supply a default_rule_method, then it should have the right arity. The default default_rule_method accepts any number of args and returns nil.
257
+
258
+ :include:parameterization_example.rb
259
+
260
+ Which prints the following to the screen:
261
+
262
+ [<1>[[<3><3><<6>>!!]]]
263
+ [<1><1><1>[[<<6>>!!]]]
264
+ <0><0><0>[[[<<6>>!!]]]
265
+
266
+ === Odds & Ends
267
+
268
+ This example demonstrates the many bells and whistles DRP makes available to you, as well as setting up a simple next_codon method similar to what might be used with a GA. The map method gets a next_codon and maps it linearly to the given Range, unless a function name is specified as a second argument, in which case it uses that function for the mapping. You can also pass a block to map. Note that you can query for depth and max_depth from within rule methods.
269
+
270
+ :include:odds_and_ends.rb
271
+
272
+ Which prints the following to the screen:
273
+
274
+ querying for the max_depth:
275
+ max_depth = 4
276
+
277
+ simple depth example:
278
+ 1 2 3 4 !
279
+
280
+ indirect depth example:
281
+ 1 1 2 2 3 3 4 4 !
282
+
283
+ map a range:
284
+ 9.7869297362342 1.72293103036786 4.44993903945105 1.94575318883587 !
285
+
286
+ map an integer range:
287
+ sunset hotpants lollypop hotpants !
288
+
289
+ map a block:
290
+ 3.6621640486161 0.461957811182177 3.8542419427911 0.972153552533642 !
291
+
292
+ you can even get the next_codon: 0.164435008276921,
293
+ and next_meta_codon: 0.936878472838206
294
+
295
+ === Bringing it All Together, an Example Using an HTML Canvas Tag
296
+
297
+ The below is what a real world example might look like, using many of the features of DRP. Of course you would normally want it to be interactive using a GA or something. Note that IE currently does not support the canvas tag, but Firefox, Safari, and Opera do.
298
+
299
+ :include:canvas_example.rb
300
+
301
+ Which generates http://drp.rubyforge.org/canvas_example.html
302
+
303
+ === Conclusion
304
+
305
+ I hope that I have made everything clear, please feel free to contact me if you have any questions, or better yet, improvements to this file. You may also want to have a look through the test directory, as that may give you a few more hints as to what behaviour I expect of the system. Cheers, and Happy Hacking!
306
+
307
+ Copyright (c) 2006, Christophe McKeon
308
+ Software License: Distributed under the GNU GPL, see LICENSE
309
+ Documentation and Website: Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License
data/LICENSE ADDED
@@ -0,0 +1,281 @@
1
+
2
+ GNU GENERAL PUBLIC LICENSE
3
+ Version 2, June 1991
4
+
5
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
6
+ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7
+ Everyone is permitted to copy and distribute verbatim copies
8
+ of this license document, but changing it is not allowed.
9
+
10
+ Preamble
11
+
12
+ The licenses for most software are designed to take away your
13
+ freedom to share and change it. By contrast, the GNU General Public
14
+ License is intended to guarantee your freedom to share and change free
15
+ software--to make sure the software is free for all its users. This
16
+ General Public License applies to most of the Free Software
17
+ Foundation's software and to any other program whose authors commit to
18
+ using it. (Some other Free Software Foundation software is covered by
19
+ the GNU Library General Public License instead.) You can apply it to
20
+ your programs, too.
21
+
22
+ When we speak of free software, we are referring to freedom, not
23
+ price. Our General Public Licenses are designed to make sure that you
24
+ have the freedom to distribute copies of free software (and charge for
25
+ this service if you wish), that you receive source code or can get it
26
+ if you want it, that you can change the software or use pieces of it
27
+ in new free programs; and that you know you can do these things.
28
+
29
+ To protect your rights, we need to make restrictions that forbid
30
+ anyone to deny you these rights or to ask you to surrender the rights.
31
+ These restrictions translate to certain responsibilities for you if you
32
+ distribute copies of the software, or if you modify it.
33
+
34
+ For example, if you distribute copies of such a program, whether
35
+ gratis or for a fee, you must give the recipients all the rights that
36
+ you have. You must make sure that they, too, receive or can get the
37
+ source code. And you must show them these terms so they know their
38
+ rights.
39
+
40
+ We protect your rights with two steps: (1) copyright the software, and
41
+ (2) offer you this license which gives you legal permission to copy,
42
+ distribute and/or modify the software.
43
+
44
+ Also, for each author's protection and ours, we want to make certain
45
+ that everyone understands that there is no warranty for this free
46
+ software. If the software is modified by someone else and passed on, we
47
+ want its recipients to know that what they have is not the original, so
48
+ that any problems introduced by others will not reflect on the original
49
+ authors' reputations.
50
+
51
+ Finally, any free program is threatened constantly by software
52
+ patents. We wish to avoid the danger that redistributors of a free
53
+ program will individually obtain patent licenses, in effect making the
54
+ program proprietary. To prevent this, we have made it clear that any
55
+ patent must be licensed for everyone's free use or not licensed at all.
56
+
57
+ The precise terms and conditions for copying, distribution and
58
+ modification follow.
59
+
60
+ GNU GENERAL PUBLIC LICENSE
61
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
62
+
63
+ 0. This License applies to any program or other work which contains
64
+ a notice placed by the copyright holder saying it may be distributed
65
+ under the terms of this General Public License. The "Program", below,
66
+ refers to any such program or work, and a "work based on the Program"
67
+ means either the Program or any derivative work under copyright law:
68
+ that is to say, a work containing the Program or a portion of it,
69
+ either verbatim or with modifications and/or translated into another
70
+ language. (Hereinafter, translation is included without limitation in
71
+ the term "modification".) Each licensee is addressed as "you".
72
+
73
+ Activities other than copying, distribution and modification are not
74
+ covered by this License; they are outside its scope. The act of
75
+ running the Program is not restricted, and the output from the Program
76
+ is covered only if its contents constitute a work based on the
77
+ Program (independent of having been made by running the Program).
78
+ Whether that is true depends on what the Program does.
79
+
80
+ 1. You may copy and distribute verbatim copies of the Program's
81
+ source code as you receive it, in any medium, provided that you
82
+ conspicuously and appropriately publish on each copy an appropriate
83
+ copyright notice and disclaimer of warranty; keep intact all the
84
+ notices that refer to this License and to the absence of any warranty;
85
+ and give any other recipients of the Program a copy of this License
86
+ along with the Program.
87
+
88
+ You may charge a fee for the physical act of transferring a copy, and
89
+ you may at your option offer warranty protection in exchange for a fee.
90
+
91
+ 2. You may modify your copy or copies of the Program or any portion
92
+ of it, thus forming a work based on the Program, and copy and
93
+ distribute such modifications or work under the terms of Section 1
94
+ above, provided that you also meet all of these conditions:
95
+
96
+ a) You must cause the modified files to carry prominent notices
97
+ stating that you changed the files and the date of any change.
98
+
99
+ b) You must cause any work that you distribute or publish, that in
100
+ whole or in part contains or is derived from the Program or any
101
+ part thereof, to be licensed as a whole at no charge to all third
102
+ parties under the terms of this License.
103
+
104
+ c) If the modified program normally reads commands interactively
105
+ when run, you must cause it, when started running for such
106
+ interactive use in the most ordinary way, to print or display an
107
+ announcement including an appropriate copyright notice and a
108
+ notice that there is no warranty (or else, saying that you provide
109
+ a warranty) and that users may redistribute the program under
110
+ these conditions, and telling the user how to view a copy of this
111
+ License. (Exception: if the Program itself is interactive but
112
+ does not normally print such an announcement, your work based on
113
+ the Program is not required to print an announcement.)
114
+
115
+ These requirements apply to the modified work as a whole. If
116
+ identifiable sections of that work are not derived from the Program,
117
+ and can be reasonably considered independent and separate works in
118
+ themselves, then this License, and its terms, do not apply to those
119
+ sections when you distribute them as separate works. But when you
120
+ distribute the same sections as part of a whole which is a work based
121
+ on the Program, the distribution of the whole must be on the terms of
122
+ this License, whose permissions for other licensees extend to the
123
+ entire whole, and thus to each and every part regardless of who wrote it.
124
+
125
+ Thus, it is not the intent of this section to claim rights or contest
126
+ your rights to work written entirely by you; rather, the intent is to
127
+ exercise the right to control the distribution of derivative or
128
+ collective works based on the Program.
129
+
130
+ In addition, mere aggregation of another work not based on the Program
131
+ with the Program (or with a work based on the Program) on a volume of
132
+ a storage or distribution medium does not bring the other work under
133
+ the scope of this License.
134
+
135
+ 3. You may copy and distribute the Program (or a work based on it,
136
+ under Section 2) in object code or executable form under the terms of
137
+ Sections 1 and 2 above provided that you also do one of the following:
138
+
139
+ a) Accompany it with the complete corresponding machine-readable
140
+ source code, which must be distributed under the terms of Sections
141
+ 1 and 2 above on a medium customarily used for software interchange; or,
142
+
143
+ b) Accompany it with a written offer, valid for at least three
144
+ years, to give any third party, for a charge no more than your
145
+ cost of physically performing source distribution, a complete
146
+ machine-readable copy of the corresponding source code, to be
147
+ distributed under the terms of Sections 1 and 2 above on a medium
148
+ customarily used for software interchange; or,
149
+
150
+ c) Accompany it with the information you received as to the offer
151
+ to distribute corresponding source code. (This alternative is
152
+ allowed only for noncommercial distribution and only if you
153
+ received the program in object code or executable form with such
154
+ an offer, in accord with Subsection b above.)
155
+
156
+ The source code for a work means the preferred form of the work for
157
+ making modifications to it. For an executable work, complete source
158
+ code means all the source code for all modules it contains, plus any
159
+ associated interface definition files, plus the scripts used to
160
+ control compilation and installation of the executable. However, as a
161
+ special exception, the source code distributed need not include
162
+ anything that is normally distributed (in either source or binary
163
+ form) with the major components (compiler, kernel, and so on) of the
164
+ operating system on which the executable runs, unless that component
165
+ itself accompanies the executable.
166
+
167
+ If distribution of executable or object code is made by offering
168
+ access to copy from a designated place, then offering equivalent
169
+ access to copy the source code from the same place counts as
170
+ distribution of the source code, even though third parties are not
171
+ compelled to copy the source along with the object code.
172
+
173
+ 4. You may not copy, modify, sublicense, or distribute the Program
174
+ except as expressly provided under this License. Any attempt
175
+ otherwise to copy, modify, sublicense or distribute the Program is
176
+ void, and will automatically terminate your rights under this License.
177
+ However, parties who have received copies, or rights, from you under
178
+ this License will not have their licenses terminated so long as such
179
+ parties remain in full compliance.
180
+
181
+ 5. You are not required to accept this License, since you have not
182
+ signed it. However, nothing else grants you permission to modify or
183
+ distribute the Program or its derivative works. These actions are
184
+ prohibited by law if you do not accept this License. Therefore, by
185
+ modifying or distributing the Program (or any work based on the
186
+ Program), you indicate your acceptance of this License to do so, and
187
+ all its terms and conditions for copying, distributing or modifying
188
+ the Program or works based on it.
189
+
190
+ 6. Each time you redistribute the Program (or any work based on the
191
+ Program), the recipient automatically receives a license from the
192
+ original licensor to copy, distribute or modify the Program subject to
193
+ these terms and conditions. You may not impose any further
194
+ restrictions on the recipients' exercise of the rights granted herein.
195
+ You are not responsible for enforcing compliance by third parties to
196
+ this License.
197
+
198
+ 7. If, as a consequence of a court judgment or allegation of patent
199
+ infringement or for any other reason (not limited to patent issues),
200
+ conditions are imposed on you (whether by court order, agreement or
201
+ otherwise) that contradict the conditions of this License, they do not
202
+ excuse you from the conditions of this License. If you cannot
203
+ distribute so as to satisfy simultaneously your obligations under this
204
+ License and any other pertinent obligations, then as a consequence you
205
+ may not distribute the Program at all. For example, if a patent
206
+ license would not permit royalty-free redistribution of the Program by
207
+ all those who receive copies directly or indirectly through you, then
208
+ the only way you could satisfy both it and this License would be to
209
+ refrain entirely from distribution of the Program.
210
+
211
+ If any portion of this section is held invalid or unenforceable under
212
+ any particular circumstance, the balance of the section is intended to
213
+ apply and the section as a whole is intended to apply in other
214
+ circumstances.
215
+
216
+ It is not the purpose of this section to induce you to infringe any
217
+ patents or other property right claims or to contest validity of any
218
+ such claims; this section has the sole purpose of protecting the
219
+ integrity of the free software distribution system, which is
220
+ implemented by public license practices. Many people have made
221
+ generous contributions to the wide range of software distributed
222
+ through that system in reliance on consistent application of that
223
+ system; it is up to the author/donor to decide if he or she is willing
224
+ to distribute software through any other system and a licensee cannot
225
+ impose that choice.
226
+
227
+ This section is intended to make thoroughly clear what is believed to
228
+ be a consequence of the rest of this License.
229
+
230
+ 8. If the distribution and/or use of the Program is restricted in
231
+ certain countries either by patents or by copyrighted interfaces, the
232
+ original copyright holder who places the Program under this License
233
+ may add an explicit geographical distribution limitation excluding
234
+ those countries, so that distribution is permitted only in or among
235
+ countries not thus excluded. In such case, this License incorporates
236
+ the limitation as if written in the body of this License.
237
+
238
+ 9. The Free Software Foundation may publish revised and/or new versions
239
+ of the General Public License from time to time. Such new versions will
240
+ be similar in spirit to the present version, but may differ in detail to
241
+ address new problems or concerns.
242
+
243
+ Each version is given a distinguishing version number. If the Program
244
+ specifies a version number of this License which applies to it and "any
245
+ later version", you have the option of following the terms and conditions
246
+ either of that version or of any later version published by the Free
247
+ Software Foundation. If the Program does not specify a version number of
248
+ this License, you may choose any version ever published by the Free Software
249
+ Foundation.
250
+
251
+ 10. If you wish to incorporate parts of the Program into other free
252
+ programs whose distribution conditions are different, write to the author
253
+ to ask for permission. For software which is copyrighted by the Free
254
+ Software Foundation, write to the Free Software Foundation; we sometimes
255
+ make exceptions for this. Our decision will be guided by the two goals
256
+ of preserving the free status of all derivatives of our free software and
257
+ of promoting the sharing and reuse of software generally.
258
+
259
+ NO WARRANTY
260
+
261
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
262
+ FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
263
+ OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
264
+ PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
265
+ OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
266
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
267
+ TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
268
+ PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
269
+ REPAIR OR CORRECTION.
270
+
271
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
272
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
273
+ REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
274
+ INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
275
+ OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
276
+ TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
277
+ YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
278
+ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
279
+ POSSIBILITY OF SUCH DAMAGES.
280
+
281
+ END OF TERMS AND CONDITIONS