├── VERSION
├── examples
├── values.txt
├── gnu
│ ├── builtin.cc
│ ├── bitdo1.h
│ ├── makefile
│ ├── bitset1.c
│ ├── bitinvert.c
│ ├── bitclear.c
│ ├── bitany.c
│ ├── README
│ ├── bitand.c
│ ├── bitcopy.c
│ ├── bitxor.c
│ ├── AllocRing.h
│ ├── error.cc
│ ├── bitcount.c
│ ├── bitstr.h
│ ├── AllocRing.cc
│ ├── bitlcomp.c
│ ├── bitblt.c
│ ├── builtin.h
│ └── Obstack.cc
├── graphic
│ ├── TSPView.ad
│ ├── tsp_rect_20.txt
│ ├── settings.txt
│ ├── bitmaps
│ │ ├── stop.xbm
│ │ ├── ffst.xbm
│ │ ├── ffwd.xbm
│ │ ├── fwds.xbm
│ │ ├── rew.xbm
│ │ └── gaview.xbm
│ ├── GAView.ad
│ └── makefile
├── tsp_rect_20.txt
├── smiley.txt
├── pvmpop
│ ├── settings.txt
│ ├── genome.h
│ ├── master.C
│ ├── Makefile.aimk
│ ├── PVMDemeGA.h
│ ├── slave.C
│ └── README
├── settings.txt
├── ChangeLog
├── pvmind
│ ├── genome.h
│ ├── Makefile.aimk
│ ├── slave.C
│ └── README
├── makefile.vcpp
├── makefile.bcc
├── makefile
├── ex25.C
├── results
│ ├── test_stats-win2k.txt
│ ├── test_stats-irix.txt
│ ├── test_stats-hpux11.txt
│ ├── test_stats-cygwin-x86.txt
│ ├── test_stats-linux-x86.txt
│ ├── test_stats-linux-ppc.txt
│ ├── test_stats-macosx-gcc2.txt
│ └── test_stats-macosx-gcc3.txt
├── ex9.C
├── ex1.C
└── solve.cpp
├── doc
├── images
│ ├── GAArray.gif
│ ├── GAList.gif
│ ├── GATree.gif
│ ├── GAHierarchy.gif
│ ├── Generational.gif
│ ├── SteadyState.gif
│ ├── GenomeHierarchy.gif
│ ├── NCubeMigration.gif
│ ├── ListOrderCrossover.gif
│ ├── ScalingHierarchy.gif
│ ├── SelectionHierarchy.gif
│ ├── ListSwapNodeMutation.gif
│ ├── TreeSwapNodeMutation.gif
│ ├── TreeSwapTreeMutation.gif
│ ├── ArrayUniformCrossover.gif
│ ├── ListDestructiveMutation.gif
│ ├── ListGenerativeMutation.gif
│ ├── SteppingStoneMigration.gif
│ ├── TreeDestructiveMutation.gif
│ ├── ArraySinglePointCrossover.gif
│ ├── ListSinglePointCrossover.gif
│ ├── ListSwapSequenceMutation.gif
│ ├── TreeSinglePointCrossover.gif
│ └── ArraySinglePointCrossover1.gif
├── OtherSites.html
├── Copyright.html
├── References.html
└── GAlib.html
├── makefile.bcc
├── makefile.vcpp
├── ga
├── gaversion.h
├── GADCrowdingGA.h
├── GAEvalData.h
├── gatypes.h
├── makefile
├── makefile.vcpp
├── makefile.bcc
├── GAMask.h
├── std_stream.h
├── makefile.sources
├── gabincvt.h
├── GABinStr.C
├── GADCrowdingGA.C
├── GASimpleGA.h
├── GAGenome.C
├── GAStringGenome.h
├── GAListGenome.h
├── GABinStr.h
├── GASStateGA.h
├── GATreeGenome.h
├── GARealGenome.h
├── GAArray.h
├── GAStringGenome.C
├── GAIncGA.h
├── GANode.h
└── gaerror.h
├── ChangeLog
├── makevars.bcc
├── TODO
├── makefile
├── LICENSE
├── COPYRIGHT
├── makevars.vcpp
├── README
└── makevars
/VERSION:
--------------------------------------------------------------------------------
1 | 2.4.7
2 |
--------------------------------------------------------------------------------
/examples/values.txt:
--------------------------------------------------------------------------------
1 | 6
2 | 10.2 32.5 66.0 99.234 0.003 210.0
--------------------------------------------------------------------------------
/doc/images/GAArray.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/GAArray.gif
--------------------------------------------------------------------------------
/doc/images/GAList.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/GAList.gif
--------------------------------------------------------------------------------
/doc/images/GATree.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/GATree.gif
--------------------------------------------------------------------------------
/doc/images/GAHierarchy.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/GAHierarchy.gif
--------------------------------------------------------------------------------
/doc/images/Generational.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/Generational.gif
--------------------------------------------------------------------------------
/doc/images/SteadyState.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/SteadyState.gif
--------------------------------------------------------------------------------
/examples/gnu/builtin.cc:
--------------------------------------------------------------------------------
1 | #ifdef __GNUG__
2 | #pragma implementation
3 | #endif
4 | #include
5 |
--------------------------------------------------------------------------------
/doc/images/GenomeHierarchy.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/GenomeHierarchy.gif
--------------------------------------------------------------------------------
/doc/images/NCubeMigration.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/NCubeMigration.gif
--------------------------------------------------------------------------------
/doc/images/ListOrderCrossover.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/ListOrderCrossover.gif
--------------------------------------------------------------------------------
/doc/images/ScalingHierarchy.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/ScalingHierarchy.gif
--------------------------------------------------------------------------------
/doc/images/SelectionHierarchy.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/SelectionHierarchy.gif
--------------------------------------------------------------------------------
/doc/images/ListSwapNodeMutation.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/ListSwapNodeMutation.gif
--------------------------------------------------------------------------------
/doc/images/TreeSwapNodeMutation.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/TreeSwapNodeMutation.gif
--------------------------------------------------------------------------------
/doc/images/TreeSwapTreeMutation.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/TreeSwapTreeMutation.gif
--------------------------------------------------------------------------------
/doc/images/ArrayUniformCrossover.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/ArrayUniformCrossover.gif
--------------------------------------------------------------------------------
/doc/images/ListDestructiveMutation.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/ListDestructiveMutation.gif
--------------------------------------------------------------------------------
/doc/images/ListGenerativeMutation.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/ListGenerativeMutation.gif
--------------------------------------------------------------------------------
/doc/images/SteppingStoneMigration.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/SteppingStoneMigration.gif
--------------------------------------------------------------------------------
/doc/images/TreeDestructiveMutation.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/TreeDestructiveMutation.gif
--------------------------------------------------------------------------------
/doc/images/ArraySinglePointCrossover.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/ArraySinglePointCrossover.gif
--------------------------------------------------------------------------------
/doc/images/ListSinglePointCrossover.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/ListSinglePointCrossover.gif
--------------------------------------------------------------------------------
/doc/images/ListSwapSequenceMutation.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/ListSwapSequenceMutation.gif
--------------------------------------------------------------------------------
/doc/images/TreeSinglePointCrossover.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/TreeSinglePointCrossover.gif
--------------------------------------------------------------------------------
/doc/images/ArraySinglePointCrossover1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ruslankerimov/GA/HEAD/doc/images/ArraySinglePointCrossover1.gif
--------------------------------------------------------------------------------
/examples/graphic/TSPView.ad:
--------------------------------------------------------------------------------
1 | ! Application defaults for the TSP demo program
2 | ! mbw 17jan96
3 |
4 | TSPView*background: thistle4
5 | TSPView.function: 0
6 |
7 | TSPView*canvas.width: 500
8 | TSPView*canvas.height: 300
9 |
--------------------------------------------------------------------------------
/examples/tsp_rect_20.txt:
--------------------------------------------------------------------------------
1 | 1 1 1
2 | 2 1 2
3 | 3 1 3
4 | 4 1 4
5 | 6 2 1
6 | 7 2 2
7 | 8 2 3
8 | 9 2 4
9 | 11 3 1
10 | 12 3 2
11 | 13 3 3
12 | 14 3 4
13 | 16 4 1
14 | 17 4 2
15 | 18 4 3
16 | 19 4 4
17 | 21 5 1
18 | 22 5 2
19 | 23 5 3
20 | 24 5 4
21 |
--------------------------------------------------------------------------------
/examples/graphic/tsp_rect_20.txt:
--------------------------------------------------------------------------------
1 | 1 1 1
2 | 2 1 2
3 | 3 1 3
4 | 4 1 4
5 | 6 2 1
6 | 7 2 2
7 | 8 2 3
8 | 9 2 4
9 | 11 3 1
10 | 12 3 2
11 | 13 3 3
12 | 14 3 4
13 | 16 4 1
14 | 17 4 2
15 | 18 4 3
16 | 19 4 4
17 | 21 5 1
18 | 22 5 2
19 | 23 5 3
20 | 24 5 4
21 |
--------------------------------------------------------------------------------
/examples/graphic/settings.txt:
--------------------------------------------------------------------------------
1 | # settings for GAlib applications
2 | population_size 250
3 | mutation_probability 0.05
4 | crossover_probability 1.0
5 | score_filename bog.dat
6 | score_frequency 1
7 | flush_frequency 0
8 | select_scores 31 # 1=mean, 2=max, 4=min, 8=dev, 16=div
9 | number_of_generations 40000
10 |
--------------------------------------------------------------------------------
/examples/smiley.txt:
--------------------------------------------------------------------------------
1 | 14
2 | 16
3 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
4 | 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0
5 | 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0
6 | 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0
7 | 0 0 1 0 0 1 1 0 0 1 1 0 0 1 0 0
8 | 0 1 0 0 0 1 1 0 0 1 1 0 0 0 1 0
9 | 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0
10 | 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0
11 | 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0
12 | 0 0 1 0 1 0 0 0 0 0 0 1 0 1 0 0
13 | 0 0 1 0 0 1 1 1 1 1 1 0 0 1 0 0
14 | 0 0 0 1 1 0 0 0 0 0 0 1 1 0 0 0
15 | 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0
16 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
17 |
--------------------------------------------------------------------------------
/examples/graphic/bitmaps/stop.xbm:
--------------------------------------------------------------------------------
1 | #define stop_width 24
2 | #define stop_height 24
3 | static unsigned char stop_bits[] = {
4 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
5 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xff, 0x01,
6 | 0x80, 0xff, 0x01, 0x80, 0xff, 0x01, 0x80, 0xff, 0x01, 0x80, 0xff, 0x01,
7 | 0x80, 0xff, 0x01, 0x80, 0xff, 0x01, 0x80, 0xff, 0x01, 0x80, 0xff, 0x01,
8 | 0x80, 0xff, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
9 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
10 |
--------------------------------------------------------------------------------
/makefile.bcc:
--------------------------------------------------------------------------------
1 | # -*- Mode: makefile -*-
2 | # Makefile to build GAlib with Borland tools
3 | # Copyright (c) 1996-2005 Matthew Wall, all rights reserved
4 |
5 | all: lib ex
6 |
7 | lib:
8 | cd ga
9 | make -f makefile.bcc
10 | cd ..
11 |
12 | ex:
13 | cd examples
14 | make -f makefile.bcc
15 | cd ..
16 |
17 | test:
18 | cd examples
19 | make -f makefile.bcc test
20 | cd ..
21 |
22 | clean:
23 | cd ga
24 | make -f makefile.bcc clean
25 | cd ..
26 | cd examples
27 | make -f makefile.bcc clean
28 | cd ..
29 |
30 | install:
31 | cd ga
32 | make -f makefile.bcc install
33 | cd ..
34 |
--------------------------------------------------------------------------------
/examples/pvmpop/settings.txt:
--------------------------------------------------------------------------------
1 | # sample settings for GAlib applications
2 |
3 | # GAlib expects parameters in name-value pairs. The name should be a single
4 | # string (no whitespace allowed). The value should be of a type appropriate
5 | # for the named parameter. Anything after a # character will be ignored.
6 | # The file must end with a blank line.
7 |
8 | number_of_populations 10
9 | population_size 50
10 | mutation_probability 0.01
11 | crossover_probability 1.0
12 | score_filename bog.dat
13 | score_frequency 1
14 | flush_frequency 10
15 | select_scores 7 # 1=mean, 2=max, 4=min, 8=dev, 16=div
16 | number_of_generations 50
17 |
--------------------------------------------------------------------------------
/makefile.vcpp:
--------------------------------------------------------------------------------
1 | # -*- Mode: makefile -*-
2 | # Makefile to build GAlib with Microsoft tools
3 | # Copyright (c) 1996-2005 Matthew Wall, all rights reserved
4 |
5 | all: lib ex
6 |
7 | lib:
8 | cd ga
9 | nmake /nologo /f makefile.vcpp
10 | cd ..
11 |
12 | ex:
13 | cd examples
14 | nmake /nologo /f makefile.vcpp
15 | cd ..
16 |
17 | test:
18 | cd examples
19 | nmake /nologo /f makefile.vcpp test
20 | cd ..
21 |
22 | clean:
23 | cd ga
24 | nmake /nologo /f makefile.vcpp clean
25 | cd ..
26 | cd examples
27 | nmake /nologo /f makefile.vcpp clean
28 | cd ..
29 |
30 | install:
31 | cd ga
32 | nmake /nologo /f makefile.vcpp install
33 | cd ..
34 |
--------------------------------------------------------------------------------
/examples/graphic/bitmaps/ffst.xbm:
--------------------------------------------------------------------------------
1 | /* VCR controls bitmap */
2 | /* Copyright (c) 1996 matthew wall, all rights reserved */
3 |
4 | #define ffst_width 24
5 | #define ffst_height 24
6 | static unsigned char ffst_bits[] = {
7 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8 | 0x00, 0x00, 0x00, 0x08, 0x08, 0x18, 0x18, 0x18, 0x18, 0x38, 0x38, 0x18,
9 | 0x78, 0x78, 0x18, 0xf8, 0xf8, 0x18, 0xf8, 0xf9, 0x19, 0xf8, 0xfb, 0x1b,
10 | 0xf8, 0xfb, 0x1b, 0xf8, 0xf9, 0x19, 0xf8, 0xf8, 0x18, 0x78, 0x78, 0x18,
11 | 0x38, 0x38, 0x18, 0x18, 0x18, 0x18, 0x08, 0x08, 0x18, 0x00, 0x00, 0x00,
12 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
13 |
--------------------------------------------------------------------------------
/examples/graphic/bitmaps/ffwd.xbm:
--------------------------------------------------------------------------------
1 | /* VCR controls bitmap */
2 | /* Copyright (c) 1996 matthew wall, all rights reserved */
3 |
4 | #define ffwd_width 24
5 | #define ffwd_height 24
6 | static unsigned char ffwd_bits[] = {
7 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8 | 0x00, 0x00, 0x00, 0x40, 0x40, 0x00, 0xc0, 0xc0, 0x00, 0xc0, 0xc1, 0x01,
9 | 0xc0, 0xc3, 0x03, 0xc0, 0xc7, 0x07, 0xc0, 0xcf, 0x0f, 0xc0, 0xdf, 0x1f,
10 | 0xc0, 0xdf, 0x1f, 0xc0, 0xcf, 0x0f, 0xc0, 0xc7, 0x07, 0xc0, 0xc3, 0x03,
11 | 0xc0, 0xc1, 0x01, 0xc0, 0xc0, 0x00, 0x40, 0x40, 0x00, 0x00, 0x00, 0x00,
12 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
13 |
--------------------------------------------------------------------------------
/examples/graphic/bitmaps/fwds.xbm:
--------------------------------------------------------------------------------
1 | /* VCR controls bitmap */
2 | /* Copyright (c) 1996 matthew wall, all rights reserved */
3 |
4 | #define fwds_width 24
5 | #define fwds_height 24
6 | static unsigned char fwds_bits[] = {
7 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8 | 0x00, 0x00, 0x00, 0x40, 0xc0, 0x00, 0xc0, 0xc0, 0x00, 0xc0, 0xc1, 0x00,
9 | 0xc0, 0xc3, 0x00, 0xc0, 0xc7, 0x00, 0xc0, 0xcf, 0x00, 0xc0, 0xdf, 0x00,
10 | 0xc0, 0xdf, 0x00, 0xc0, 0xcf, 0x00, 0xc0, 0xc7, 0x00, 0xc0, 0xc3, 0x00,
11 | 0xc0, 0xc1, 0x00, 0xc0, 0xc0, 0x00, 0x40, 0xc0, 0x00, 0x00, 0x00, 0x00,
12 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
13 |
--------------------------------------------------------------------------------
/examples/graphic/bitmaps/rew.xbm:
--------------------------------------------------------------------------------
1 | /* VCR controls bitmap */
2 | /* Copyright (c) 1996 matthew wall, all rights reserved */
3 |
4 | #define rew_width 24
5 | #define rew_height 24
6 | static unsigned char rew_bits[] = {
7 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8 | 0x00, 0x00, 0x00, 0x00, 0x02, 0x02, 0x00, 0x03, 0x03, 0x80, 0x83, 0x03,
9 | 0xc0, 0xc3, 0x03, 0xe0, 0xe3, 0x03, 0xf0, 0xf3, 0x03, 0xf8, 0xfb, 0x03,
10 | 0xf8, 0xfb, 0x03, 0xf0, 0xf3, 0x03, 0xe0, 0xe3, 0x03, 0xc0, 0xc3, 0x03,
11 | 0x80, 0x83, 0x03, 0x00, 0x03, 0x03, 0x00, 0x02, 0x02, 0x00, 0x00, 0x00,
12 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
13 |
--------------------------------------------------------------------------------
/ga/gaversion.h:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | version.h
3 | mbwall 10oct98
4 |
5 | This is the header file to keep track of the versions and revisions of the
6 | GA library. You can use the ident command to extract the version and other
7 | build information from the galib object file.
8 | ---------------------------------------------------------------------------- */
9 | #ifndef _ga_version_h_
10 | #define _ga_version_h_
11 |
12 | #include
13 |
14 | #define GALIB_LIBRARY_IDENTIFIER \
15 | "$Date: 2004-12-29 11:24:43 -0500 (Wed, 29 Dec 2004) $"\
16 | "$Revision: 43 $"\
17 | "$Configuration: " GALIB_OS "-" GALIB_CPU "-" GALIB_COMPILER " $"
18 |
19 | const char* GAConfig();
20 |
21 | #endif
22 |
--------------------------------------------------------------------------------
/examples/gnu/bitdo1.h:
--------------------------------------------------------------------------------
1 | #ifndef ONES
2 | #define ONES ((_BS_word)(~0L))
3 | #endif
4 | register int nwords;
5 | register _BS_word mask;
6 | if (offset == 0)
7 | ;
8 | else if (offset + length >= _BS_BITS_PER_WORD)
9 | {
10 | mask = ONES _BS_RIGHT offset;
11 | DOIT(*ptr++, mask);
12 | length -= _BS_BITS_PER_WORD - offset;
13 | }
14 | else
15 | {
16 | mask = (ONES _BS_RIGHT (_BS_BITS_PER_WORD - length))
17 | _BS_LEFT (_BS_BITS_PER_WORD - length - offset);
18 | DOIT(*ptr, mask);
19 | goto done;
20 | }
21 | nwords = _BS_INDEX(length);
22 | while (--nwords >= 0)
23 | {
24 | DOIT(*ptr++, ONES);
25 | }
26 | length = _BS_POS (length);
27 | if (length)
28 | {
29 | mask = ONES _BS_LEFT (_BS_BITS_PER_WORD - length);
30 | DOIT(*ptr, mask);
31 | }
32 | done: ;
33 |
--------------------------------------------------------------------------------
/ga/GADCrowdingGA.h:
--------------------------------------------------------------------------------
1 | // $Header$
2 | /* ----------------------------------------------------------------------------
3 | dcrowdingga.h
4 | mbwall 29mar99
5 | Copyright (c) 1999 Matthew Wall, all rights reserved
6 |
7 | Header file for the steady-state genetic algorithm class.
8 | ---------------------------------------------------------------------------- */
9 | #ifndef _ga_deterministic_crowding_ga_h_
10 | #define _ga_deterministic_crowding_ga_h_
11 |
12 | #include
13 |
14 | class GADCrowdingGA : public GAGeneticAlgorithm {
15 | public:
16 | GADefineIdentity("GADeterministicCrowdingGA", 241);
17 |
18 | GADCrowdingGA(const GAGenome& g) : GAGeneticAlgorithm(g) {}
19 | virtual ~GADCrowdingGA() {}
20 |
21 | virtual void initialize(unsigned int seed=0);
22 | virtual void step();
23 | GADCrowdingGA& operator++() { step(); return *this; }
24 | };
25 |
26 | #endif
27 |
--------------------------------------------------------------------------------
/examples/settings.txt:
--------------------------------------------------------------------------------
1 | # sample settings for GAlib applications
2 |
3 | # GAlib expects parameters in name-value pairs. The name should be a single
4 | # string (no whitespace allowed). The value should be of a type appropriate
5 | # for the named parameter. Anything after a # character will be ignored.
6 | # The file must end with a blank line. If you specify parameters that depend
7 | # on other parameters, the last parameter will override the first or act on
8 | # data modified by the first (the parameters are applied in the order they
9 | # are listed).
10 |
11 | population_size 100
12 | mutation_probability 0.01
13 | crossover_probability 0.9
14 | score_filename bog.dat
15 | score_frequency 1
16 | flush_frequency 25
17 | select_scores 7 # 1=mean, 2=max, 4=min, 8=dev, 16=div
18 | #select_scores 31
19 | number_of_generations 10
20 | #replacement_percentage 0.8
21 | #replacement_number 10
22 |
--------------------------------------------------------------------------------
/examples/ChangeLog:
--------------------------------------------------------------------------------
1 | 2005-01-11 Matthew Wall
2 |
3 | * graphic/gaview.C: keep gcc3 happy.
4 |
5 | 2005-01-06 Matthew Wall
6 |
7 | * randtest.C: accommodate some strangeness from ms vcpp 7
8 |
9 | 2004-12-28 Matthew Wall
10 |
11 | * makefile.win32: added time stamps (sort of) and for loop. windows
12 | scripting *really* sucks.
13 | * makefile: do not assume that . is in the path
14 | * ex8.C: adhere to c++ standard
15 | * ex11.C: adhere to c++ standard
16 | * ex14.C: adhere to c++ standard
17 | * ex16.C: adhere to c++ standard
18 | * ex17.C: adhere to c++ standard
19 | * ex26.C: adhere to c++ standard
20 | * ex6.C: adhere to c++ standard
21 |
22 | 2004-12-28 Matthew Wall
23 |
24 | * ex15.C: avoid unsigned int comparison warning
25 | * ex13.C: avoid unsigned in comparison warning
26 |
27 |
--------------------------------------------------------------------------------
/ChangeLog:
--------------------------------------------------------------------------------
1 | 2005-01-12 Matthew Wall
2 |
3 | * makefile: rev to final release number
4 |
5 | 2005-01-11 Matthew Wall
6 |
7 | * COPYRIGHT: consolidate
8 | * LICENSE: consolidate to COPYRIGHT
9 | * README: update quick start section with borland instructions
10 |
11 | 2004-12-28 Matthew Wall
12 |
13 | * makevars.win32: do not use precompiled headers - vcpp6 chokes on them
14 | and cannot manage them properly.
15 |
16 | 2004-12-28 Matthew Wall
17 |
18 | * makefile.win32: added test rule
19 | * makevars: added ranlib. some platforms need explicit link to
20 | c++ standard libs (e.g. macosx with gcc2)
21 | * makefile: split rules for library and examples. added rule for test.
22 |
23 | 2004-12-27 Matthew Wall
24 |
25 | * README: minor update and cleanup
26 | * makefile: remove ancient cruft
27 |
28 |
--------------------------------------------------------------------------------
/ga/GAEvalData.h:
--------------------------------------------------------------------------------
1 | // $Header$
2 | /* ----------------------------------------------------------------------------
3 | eval.h
4 | mbwall 3dec95
5 | Copyright (c) 1995 Massachusetts Institute of Technology
6 | all rights reserved
7 |
8 | DESCRIPTION:
9 | This is the basic interface for the object that contains evaluation data. It
10 | can be used with genomes and/or populations in combination with their
11 | respective evaluation methods.
12 | ---------------------------------------------------------------------------- */
13 | #ifndef _ga_eval_h_
14 | #define _ga_eval_h_
15 |
16 | class GAEvalData {
17 | public:
18 | GAEvalData() {}
19 | GAEvalData(const GAEvalData&) {}
20 | virtual ~GAEvalData() {}
21 | GAEvalData& operator=(const GAEvalData& orig)
22 | { if(&orig != this) copy(orig); return *this; }
23 | virtual GAEvalData* clone() const =0;
24 | virtual void copy(const GAEvalData&) =0;
25 | };
26 |
27 | #endif
28 |
--------------------------------------------------------------------------------
/ga/gatypes.h:
--------------------------------------------------------------------------------
1 | // $Header$
2 | /* ----------------------------------------------------------------------------
3 | gatypes.h
4 | mbwall 29apr95
5 | Copyright (c) 1995 Massachusetts Institute of Technology
6 | all rights reserved
7 | ---------------------------------------------------------------------------- */
8 | #ifndef _ga_types_h_
9 | #define _ga_types_h_
10 |
11 |
12 | typedef float GAProbability;
13 | typedef float GAProb;
14 |
15 | // This enforces return values and arguments to functions that want strict
16 | // boolean arguments.
17 | typedef enum _GABoolean {
18 | gaFalse=0,
19 | gaTrue
20 | } GABoolean, GABool;
21 |
22 | typedef enum _GAStatus {
23 | gaSuccess=0,
24 | gaFailure=-1
25 | } GAStatus;
26 |
27 | // This defines what type to use for the bitstream data storage. Use the
28 | // smallest type available on your platform.
29 | typedef unsigned char GABit;
30 |
31 |
32 | #define GAMax(a,b) ((a) > (b) ? (a) : (b))
33 | #define GAMin(a,b) ((a) < (b) ? (a) : (b))
34 |
35 |
36 | #endif
37 |
--------------------------------------------------------------------------------
/ga/makefile:
--------------------------------------------------------------------------------
1 | # -*- Mode: makefile -*-
2 | # Copyright (c) 1994-1996 Massachusetts Institute of Technology
3 | # Copyright (c) 1996-2005 Matthew Wall
4 | # -----------------------------------------------------------------------------
5 |
6 | include ../makevars
7 | include makefile.sources
8 |
9 | INC_DIRS= -I..
10 |
11 | .SUFFIXES: .C
12 | .C.o:
13 | $(CXX) $(CXXFLAGS) $(INC_DIRS) -c $<
14 |
15 | $(LIB): $(OBJS)
16 | $(PRELINK)
17 | $(AR) $(LIB) $?
18 | $(RANLIB) $(LIB)
19 | echo "$(CXX) $(CXXFLAGS)" > BUILD
20 | @echo $(LIB) is now up-to-date
21 | .C.a:;
22 |
23 | clean:
24 | $(RM) $(LIB) BUILD
25 | $(RM) *.o *~ .#* *.bak core ii_files ptrepository
26 |
27 | install:: $(LIB)
28 | $(INSTALL) $(LIB) $(LIB_DEST_DIR)
29 | $(RM) $(HDR_DEST_DIR)/ga; $(MKDIR) $(HDR_DEST_DIR)/ga
30 | $(CP) $(HDRS) $(TMPL_SRCS) ../VERSION BUILD $(HDR_DEST_DIR)/ga
31 |
32 | uninstall:
33 | $(RM) $(LIB_DEST_DIR)/$(LIB)
34 | $(RM) $(HDR_DEST_DIR)/ga
35 |
36 | depend:
37 | $(MKDEPEND) $(INC_DIRS) $(SRCS)
38 |
39 | # DO NOT DELETE THIS LINE -- make depend depends on it.
40 |
--------------------------------------------------------------------------------
/examples/graphic/GAView.ad:
--------------------------------------------------------------------------------
1 | ! Application defaults for the graphic genetic algorithm program
2 | ! Copyright (c) 1996 Matthew Wall
3 | ! mbw 17jan96
4 |
5 | *bestColor: yellow
6 | *populationColor1: green
7 | *populationColor2: blue
8 | *populationColor3: cyan
9 | *populationColor4: orange
10 | *populationColor5: red
11 | *ga: 2
12 | *genome: 0
13 | *function: 3
14 | *generationsPerStep: 10
15 |
16 | *background: thistle4
17 |
18 | *leftOffset: 3
19 | *rightOffset: 3
20 | *topOffset: 3
21 | *bottomOffset: 3
22 |
23 | *canvas.width: 400
24 | *canvas.height: 300
25 | *canvas.background: black
26 |
27 | ! these are motif-specific
28 |
29 | *fontList: -*-helvetica-bold-r-*-*-*-140-*-*-*-*-*-*
30 |
31 | *score.labelString: score
32 | *stats.labelString: stats
33 | *params.labelString: params
34 |
35 | ! these are athena-specific
36 |
37 | *font: -*-helvetica-bold-r-*-*-*-140-*-*-*-*-*-*
38 |
39 | *rewind.label: reset
40 | *stop.label: stop
41 | *step.label: one
42 | *some.label: some
43 | *evolve.label: all
44 | *score.label: score
45 | *stats.label: stats
46 | *params.label: params
47 |
--------------------------------------------------------------------------------
/makevars.bcc:
--------------------------------------------------------------------------------
1 | # -*- Mode: makefile -*-
2 | # Copyright (c) 1999 Matthew Wall, all rights reserved
3 | # makefile variables for compiling on windows
4 | # -----------------------------------------------------------------------------
5 |
6 | LIB_NAME= ga
7 |
8 | ### Set these directories to whatever is appropriate for your system. These
9 | ### used only if you do a 'make install'. They specify where the library and
10 | ### header files should be installed.
11 | DESTDIR=c:\temp
12 | HDR_DEST_DIR=$(DESTDIR)\include
13 | LIB_DEST_DIR=$(DESTDIR)\lib
14 |
15 |
16 | MKDEPEND = echo
17 | MKDIR = mkdir
18 | CP = xcopy
19 | RM = del /f
20 |
21 | CXX = bcc32.exe
22 | LD = ilink32.exe
23 | AR = tlib.exe
24 | INSTALL = copy
25 | CXX_INC_DIR = c:\Borland\BCC55\Include
26 | CXX_LIB_DIR = c:\Borland\BCC55\Lib
27 |
28 | CFLAGS =
29 | CXXFLAGS = -q -P -RT -I$(CXX_INC_DIR) -w-var -w-inl
30 | LDFLAGS = -q -c -x -Gn -L$(CXX_LIB_DIR)
31 | ARFLAGS =
32 |
33 | .SUFFIXES:
34 | .SUFFIXES: .C
35 | .C.o:
36 | $(CXX) $(CXXFLAGS) -o$*.o -c $<
37 | .C.obj:
38 | $(CXX) $(CXXFLAGS) -o$*.obj -c $<
39 |
--------------------------------------------------------------------------------
/TODO:
--------------------------------------------------------------------------------
1 | this is a running list of things to be done to galib.
2 |
3 | todo:
4 |
5 | - make the library thread-safe
6 | - include rules for building both shared and static libraries
7 | - remove ancient pseudo rtti cruft
8 | - remove accommodations for ancient compilers
9 | - xml input and output for saving the state of genomes and evolutions
10 | - proper use of namespaces
11 | - use double rather than float
12 | - allow run-time modification of the random number generator
13 | - get rid of all the casts (e.g. GASelector.C) for signed/unsigned
14 | - be consistent in use of signed/unsigned in the class apis
15 | - use bits for the bit-based genomes so that we reduce memory use
16 | by a factor of 8
17 | - enable concurrent builds on the same source tree
18 | - make galib 64-bit clean (remove the dangerous casts)
19 | - doxygen for all the documentation
20 |
21 | completed:
22 |
23 | - fix stream references in examples (includes and cout/cerr)
24 | - properly and automatically accommodate both and
25 | inclusions
26 | - rewrite gaconfig.h to use consistent naming for options and make clear which
27 | are defaults, e.g. USE_ANSI_HEADERS/USE_NO_ANSI_HEADERS.
28 |
--------------------------------------------------------------------------------
/ga/makefile.vcpp:
--------------------------------------------------------------------------------
1 | # -*- Mode: makefile -*-
2 | # Copyright (c) 1994-1996 Massachusetts Institute of Technology
3 | # Copyright (c) 1996-2005 Matthew Wall
4 | # -----------------------------------------------------------------------------
5 |
6 | !include ../makevars.vcpp
7 | !include makefile.sources
8 |
9 | CXXFLAGS = $(CXXFLAGS) /I..
10 |
11 | STATIC = $(LIB_NAME)
12 | LIB = $(STATIC).lib
13 |
14 | all: $(LIB)
15 |
16 | $(LIB): $(OBJS)
17 | $(AR) $(ARFLAGS) /out:$(LIB) $?
18 | @echo $(LIB_NAME) is now up-to-date
19 |
20 | install: install.lib install.hdr
21 | @echo installation complete
22 |
23 | install.lib: $(LIB) lib_directories
24 | $(INSTALL) $(LIB) $(LIB_DEST_DIR)
25 |
26 | install.hdr: hdr_directories
27 | @for %i in ( $(HDRS) ) do \
28 | $(CP) /Q %i $(HDR_DEST_DIR)\$(LIB_NAME)
29 | @for %i in ( $(TMPL_SRCS) ) do \
30 | $(CP) /Q %i $(HDR_DEST_DIR)\$(LIB_NAME)
31 |
32 | lib_directories:
33 | @if not exist $(LIB_DEST_DIR) \
34 | $(MKDIR) $(LIB_DEST_DIR)
35 | hdr_directories:
36 | @if not exist $(HDR_DEST_DIR)\$(LIB_NAME) \
37 | $(MKDIR) $(HDR_DEST_DIR)\$(LIB_NAME)
38 |
39 | remove:
40 | $(RM) $(LIB_DEST_DIR)\$(LIB)
41 | $(RM) $(HDR_DEST_DIR)\$(LIB_NAME)
42 |
43 | clean:
44 | $(RM) *.obj *.o *.pdb vc*
45 | $(RM) $(LIB_NAME).lib
46 |
47 |
--------------------------------------------------------------------------------
/examples/pvmind/genome.h:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | genome.h
3 | mbwall 5dec95
4 | Copyright (c) 1995-1996 Massachusetts Institute of Technology
5 |
6 | DESCRIPTION:
7 | This file contains the information needed to evaluate an operate on a
8 | genome in these examples.
9 | ---------------------------------------------------------------------------- */
10 | #ifndef _genome_h_
11 | #define _genome_h_
12 |
13 | #include
14 |
15 | float GenomeEvaluator(GAGenome&);
16 | void GenomeInitializer(GAGenome&);
17 | void PopulationInitializer(GAPopulation&);
18 | void PopulationEvaluator(GAPopulation&);
19 |
20 | int SendGenomeData(GAGenome&, int);
21 | int RecvGenomeData(GAGenome&);
22 | int SendGenomeScore(GAGenome&, int);
23 | int RecvGenomeScore(GAGenome&);
24 | int SendGenomeInitialize(GAGenome&, int);
25 | int RecvGenomeInitialize(GAGenome&);
26 |
27 | int SendReady(int);
28 |
29 | typedef struct _PVMData {
30 | int masterid;
31 | int* tid; // task ids of all slave processes
32 | int ntasks; // number of slave tasks that are running
33 | int nreq; // number of tasks that we asked for
34 | } PVMData, *PVMDataPtr, **PVMDataHdl;
35 |
36 | const int MSG_READY=10;
37 | const int MSG_DONE=100;
38 | const int MSG_GENOME_DATA=50;
39 | const int MSG_GENOME_SCORE=51;
40 | const int MSG_GENOME_INITIALIZE=52;
41 |
42 | #endif
43 |
--------------------------------------------------------------------------------
/makefile:
--------------------------------------------------------------------------------
1 | # -*- Mode: makefile -*-
2 | # Makefile for GAlib
3 | # Copyright (c) 1996-2005 Matthew Wall, all rights reserved
4 | #
5 | # If you need to customize the build of galib, you should first modify the
6 | # variables in the makevars file.
7 |
8 | GALIB_VERSION=2.4.7
9 | GALIB_VER=247
10 | TMPDIR=/var/tmp
11 | RELDIR=$(TMPDIR)/galib$(GALIB_VER)
12 |
13 | all: lib ex
14 |
15 | lib:
16 | cd ga; $(MAKE)
17 |
18 | ex:
19 | cd examples; $(MAKE)
20 |
21 | test: lib ex
22 | cd examples; $(MAKE) test
23 |
24 | install:
25 | cd ga; $(MAKE) install
26 |
27 | uninstall:
28 | cd ga; $(MAKE) uninstall
29 |
30 | clean:
31 | cd ga; $(MAKE) clean
32 | cd examples; $(MAKE) clean
33 |
34 | release: clean
35 | rm -rf $(RELDIR)
36 | mkdir -p $(RELDIR)
37 | cp -rp * $(RELDIR)
38 | rm -rf `find $(RELDIR) -name CVS`
39 | rm -rf `find $(RELDIR) -name .svn`
40 | rm -f `find $(RELDIR) -name "*~"`
41 | echo $(GALIB_VERSION) > $(RELDIR)/VERSION
42 | perl -pi -e 's/evision: \d+\.\d+ /evision: $(GALIB_VERSION) /' $(RELDIR)/ga/gaversion.h
43 | perl -pi -e 'chop($$dt=`date +"%Y/%m/%d %H:%M:%S"`); s/Date: ..\/..\/.. ..:..:.. /Date: $$dt /' $(RELDIR)/ga/gaversion.h
44 | cd $(RELDIR)/..; tar cvfz galib$(GALIB_VER).tgz galib$(GALIB_VER) > $(TMPDIR)/galib$(GALIB_VER)-manifest-tar.txt
45 | cd $(RELDIR)/..; zip -r galib$(GALIB_VER).zip galib$(GALIB_VER) > $(TMPDIR)/galib$(GALIB_VER)-manifest-zip.txt
46 | @echo " GAlib $(GALIB_VERSION) has been released to $(TMPDIR)"
47 |
--------------------------------------------------------------------------------
/ga/makefile.bcc:
--------------------------------------------------------------------------------
1 | # -*- Mode: makefile -*-
2 | # Copyright (c) 1994-1996 Massachusetts Institute of Technology
3 | # Copyright (c) 1996-2005 Matthew Wall
4 | # -----------------------------------------------------------------------------
5 |
6 | !include ../makevars.bcc
7 | !include makefile.sources
8 |
9 | CXXFLAGS = $(CXXFLAGS) -I..
10 |
11 | STATIC = $(LIB_NAME)
12 | LIB = $(STATIC).lib
13 |
14 | all: $(LIB)
15 |
16 | # this really sucks, but i have not yet found documentation about the borland
17 | # make or link that will let me avoid the for loop.
18 | $(LIB): $(OBJS)
19 | @for %i in ( $(OBJS) ) do \
20 | $(AR) $(ARFLAGS) $(LIB) +%i
21 | @echo $(LIB_NAME) is now up-to-date
22 |
23 | install: install.lib install.hdr
24 | @echo installation complete
25 |
26 | install.lib: $(LIB) lib_directories
27 | $(INSTALL) $(LIB) $(LIB_DEST_DIR)
28 |
29 | install.hdr: hdr_directories
30 | @for %i in ( $(HDRS) ) do \
31 | $(CP) /Q %i $(HDR_DEST_DIR)\$(LIB_NAME)
32 | @for %i in ( $(TMPL_SRCS) ) do \
33 | $(CP) /Q %i $(HDR_DEST_DIR)\$(LIB_NAME)
34 |
35 | lib_directories:
36 | @if not exist $(LIB_DEST_DIR) \
37 | $(MKDIR) $(LIB_DEST_DIR)
38 | hdr_directories:
39 | @if not exist $(HDR_DEST_DIR)\$(LIB_NAME) \
40 | $(MKDIR) $(HDR_DEST_DIR)\$(LIB_NAME)
41 |
42 | remove:
43 | $(RM) $(LIB_DEST_DIR)\$(LIB)
44 | $(RM) $(HDR_DEST_DIR)\$(LIB_NAME)
45 |
46 | clean:
47 | $(RM) *.obj *.o *.tds
48 | $(RM) $(LIB_NAME).lib
49 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Providing credit where credit is due
2 | -------------------------------------------------------------------------------
3 | GAlib is available under a BSD-style license found in the COPYRIGHT file.
4 | You can use GAlib for any purpose, and you can distribute GAlib subject
5 | to the terms in the license. If you distribute GAlib, you must include
6 | the contents of the COPYRIGHT file in your distribution.
7 |
8 | If you use GAlib in a commercial product, you should provide credit as
9 | follows (typically in the 'about box'):
10 |
11 | This product includes GAlib, a library of genetic algorithm components.
12 | Copyright Massachusetts Institute of Technology and Matthew Wall.
13 |
14 | To refer to GAlib from a research publication, you should provide credit
15 | as follows:
16 |
17 | This research was performed using GAlib, a library of genetic algorithm
18 | components (http://lancet.mit.edu/ga/).
19 |
20 | The GNU portions of the GAlib distribution
21 | -------------------------------------------------------------------------------
22 | The portions of GAlib that contain code from the GNU g++ library are
23 | covered under the terms of the GNU Public License. As such they are
24 | freely available and do not fall under the terms of the GAlib licensing.
25 |
26 | The portions of GAlib that are based upon GNU code are all in the
27 | 'gnu' directory in the examples directory (in GAlib release 2.3.2
28 | and later).
29 |
--------------------------------------------------------------------------------
/examples/pvmpop/genome.h:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | genome.h
3 | mbwall 5dec95
4 | Copyright (c) 1995-1996 Massachusetts Institute of Technology
5 |
6 | DESCRIPTION:
7 | This file contains the information needed to evaluate an operate on a
8 | genome in these examples.
9 | ---------------------------------------------------------------------------- */
10 | #ifndef _genome_h_
11 | #define _genome_h_
12 |
13 | #include
14 | #include
15 |
16 | #define GENOME_LENGTH 64
17 |
18 | float GenomeEvaluator(GAGenome&);
19 | int RecvMigration(GAGeneticAlgorithm& ga);
20 | int SendMigration(int toid, GAGeneticAlgorithm& ga, int count);
21 | int RecvPopulation(GAPopulation&);
22 | int SendPopulation(int toid, const GAPopulation&);
23 | int RecvStatistics(GAStatistics&);
24 | int SendStatistics(int toid, const GAStatistics&);
25 |
26 | const int MSG_DONE =1;
27 | const int MSG_INITIALIZE =2;
28 | const int MSG_STEP =3;
29 | const int MSG_RECEIVE_MIGRATION =4;
30 | const int MSG_SEND_MIGRATION =5;
31 | const int MSG_SEND_POPULATION =6;
32 | const int MSG_SEND_STATISTICS =7;
33 | const int MSG_INCOMING_MIGRATION =8;
34 | const int MSG_INCOMING_POPULATION =9;
35 | const int MSG_INCOMING_STATISTICS =10;
36 | const int MSG_STEP_COMPLETE =11;
37 | const int MSG_SET_POPULATION_SIZE =12;
38 | const int MSG_READY =100;
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/ga/GAMask.h:
--------------------------------------------------------------------------------
1 | // $Header$
2 | /* ----------------------------------------------------------------------------
3 | binstr1.h
4 | mbwall 19apr95
5 | Copyright (c) 1995 Massachusetts Institute of Technology
6 | all rights reserved
7 | ---------------------------------------------------------------------------- */
8 | #ifndef _ga_mask_h_
9 | #define _ga_mask_h_
10 |
11 | #include
12 |
13 | #define GA_MASK_TYPE char
14 |
15 | class GAMask {
16 | public:
17 | GAMask() { _n=0; _mask=(GA_MASK_TYPE*)0; }
18 | GAMask(const GAMask& m) { _n=0; _mask=(GA_MASK_TYPE*)0; copy(m); }
19 | GAMask& operator=(const GAMask& m) { copy(m); return *this; }
20 | ~GAMask() { delete [] _mask; }
21 | void copy(const GAMask& m) {
22 | size(m.size());
23 | memcpy(_mask, m._mask, _n*sizeof(GA_MASK_TYPE));
24 | }
25 |
26 | void clear() { memset(_mask, 0, _n*sizeof(GA_MASK_TYPE)); }
27 | int size() const {return _n;}
28 | int size(unsigned int s){
29 | if(s > _n){
30 | _n = s;
31 | delete [] _mask;
32 | _mask = new GA_MASK_TYPE [_n];
33 | }
34 | return _n;
35 | }
36 | GA_MASK_TYPE mask(unsigned int i) const { return _mask[i]; }
37 | GA_MASK_TYPE & mask(unsigned int i) { return _mask[i]; }
38 | GA_MASK_TYPE operator[] (unsigned int i) const { return _mask[i]; }
39 | GA_MASK_TYPE & operator[] (unsigned int i) { return _mask[i]; }
40 |
41 | protected:
42 | GA_MASK_TYPE * _mask;
43 | unsigned int _n;
44 | };
45 |
46 | #endif
47 |
--------------------------------------------------------------------------------
/examples/gnu/makefile:
--------------------------------------------------------------------------------
1 | # makefile for compiling some of g++ library components with GAlib extensions
2 | # Copyright 1995 Massachusetts Institute of Technology
3 | # mbwall 10sep95
4 | #
5 | # This code can be freely distributed and modified under the terms of the GNU
6 | # public license. See the COPYING file for details.
7 |
8 | CC_INC_DIR=/usr/include/CC
9 | INC_DIRS= -I. -I../..
10 | LIB_DIRS= -L. -L../../ga
11 | CCFLAGS= +w +pp -O -g $(INC_DIRS)
12 | C++C= DCC
13 |
14 | LIB= libbitstr.a
15 | SRCS= gnuex.C bitstr.C
16 | OBJS= gnuex.o bitstr.o
17 | GNUSRCS= AllocRing.cc Obstack.cc BitString.cc builtin.cc bitand.c bitany.c bitblt.c bitclear.c bitcopy.c bitcount.c bitinvert.c bitlcomp.c bitset1.c bitxor.c error.cc
18 | GNUOBJS= AllocRing.o Obstack.o BitString.o builtin.o bitand.o bitany.o bitblt.o bitclear.o bitcopy.o bitcount.o bitinvert.o bitlcomp.o bitset1.o bitxor.o error.o
19 |
20 | .SUFFIXES: .o .c
21 | .SUFFIXES: .o .cc
22 | .SUFFIXES: .o .C
23 | .c.o:
24 | $(C++C) $(CCFLAGS) -c $<
25 | .cc.o:
26 | $(C++C) $(CCFLAGS) -c $<
27 | .C.o:
28 | $(C++C) $(CCFLAGS) -c $<
29 |
30 | gnuex: $(OBJS) $(LIB)
31 | $(C++C) $(PF) $(OBJS) -o $@ $(LIB_DIRS) -lbitstr -lga -lm
32 |
33 | $(LIB): $(GNUOBJS)
34 | ar rv $(LIB) $?
35 | @echo $(LIB) is now up-to-date
36 | .c.a:;
37 | .C.a:;
38 |
39 | clean:
40 | rm -rf gnuex $(LIB) *~ *.bak *.out *.o core bog.dat
41 |
42 | depend:
43 | makedepend -I$(CC_INC_DIR) $(INC_DIRS) $(SRCS) $(GNUSRCS)
44 |
45 | # DO NOT DELETE THIS LINE -- make depend depends on it.
46 |
--------------------------------------------------------------------------------
/ga/std_stream.h:
--------------------------------------------------------------------------------
1 | // $Header$
2 | // Copyright (c) 2005 Matthew Wall, all rights reserved
3 | // ----------------------------------------------------------------------------
4 | #ifndef _ga_std_stream_h_
5 | #define _ga_std_stream_h_
6 |
7 | #include
8 |
9 | #if defined(GALIB_USE_STREAMS)
10 | #if defined(GALIB_USE_ANSI_HEADERS)
11 |
12 | #include
13 | #include
14 |
15 | #else
16 |
17 | #include
18 | #include
19 |
20 | #endif
21 |
22 | #if defined(GALIB_USE_STD_NAMESPACE)
23 |
24 | #define STD_ISTREAM std::istream
25 | #define STD_OSTREAM std::ostream
26 | #define STD_IFSTREAM std::ifstream
27 | #define STD_OFSTREAM std::ofstream
28 | #define STD_IOS_IN std::ios::in
29 | #define STD_IOS_OUT std::ios::out
30 | #define STD_IOS_TRUNC std::ios::trunc
31 | #define STD_IOS_APP std::ios::app
32 | #define STD_IOS_BADBIT std::ios::badbit
33 | #define STD_ENDL std::endl
34 | #define STD_COUT std::cout
35 | #define STD_CERR std::cerr
36 |
37 | #else
38 |
39 | #define STD_ISTREAM istream
40 | #define STD_OSTREAM ostream
41 | #define STD_IFSTREAM ifstream
42 | #define STD_OFSTREAM ofstream
43 | #define STD_IOS_IN ios::in
44 | #define STD_IOS_OUT ios::out
45 | #define STD_IOS_TRUNC ios::trunc
46 | #define STD_IOS_APP ios::app
47 | #define STD_IOS_BADBIT ios::badbit
48 | #define STD_ENDL endl
49 | #define STD_COUT cout
50 | #define STD_CERR cerr
51 |
52 | #endif
53 |
54 | #endif
55 |
56 | #endif
57 |
--------------------------------------------------------------------------------
/examples/gnu/bitset1.c:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 1994 Free Software Foundation
2 |
3 | This file is part of the GNU BitString Library. This library is free
4 | software; you can redistribute it and/or modify it under the
5 | terms of the GNU General Public License as published by the
6 | Free Software Foundation; either version 2, or (at your option)
7 | any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this library; see the file COPYING. If not, write to the Free
16 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 |
18 | As a special exception, if you link this library with files
19 | compiled with a GNU compiler to produce an executable, this does not cause
20 | the resulting executable to be covered by the GNU General Public License.
21 | This exception does not however invalidate any other reasons why
22 | the executable file might be covered by the GNU General Public License. */
23 |
24 | /* Written by Per Bothner (bothner@cygnus.com) */
25 |
26 | #include "bitprims.h"
27 |
28 | void
29 | /*
30 | _BS_set (ptr, offset, length)
31 | register _BS_word *ptr;
32 | int offset;
33 | _BS_size_t length;
34 | */
35 | _BS_set (register _BS_word *ptr,int offset,_BS_size_t length)
36 | {
37 | #undef DOIT
38 | #define DOIT(WORD, MASK) ((WORD) |= (MASK))
39 | #include "bitdo1.h"
40 | }
41 |
--------------------------------------------------------------------------------
/examples/gnu/bitinvert.c:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 1994 Free Software Foundation
2 |
3 | This file is part of the GNU BitString Library. This library is free
4 | software; you can redistribute it and/or modify it under the
5 | terms of the GNU General Public License as published by the
6 | Free Software Foundation; either version 2, or (at your option)
7 | any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this library; see the file COPYING. If not, write to the Free
16 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 |
18 | As a special exception, if you link this library with files
19 | compiled with a GNU compiler to produce an executable, this does not cause
20 | the resulting executable to be covered by the GNU General Public License.
21 | This exception does not however invalidate any other reasons why
22 | the executable file might be covered by the GNU General Public License. */
23 |
24 | /* Written by Per Bothner (bothner@cygnus.com) */
25 |
26 | #include "bitprims.h"
27 |
28 | void
29 | /*
30 | _BS_invert (ptr, offset, length)
31 | register _BS_word *ptr;
32 | int offset;
33 | _BS_size_t length;
34 | */
35 | _BS_invert (register _BS_word *ptr,int offset,_BS_size_t length)
36 | {
37 | #undef DOIT
38 | #define DOIT(WORD, MASK) ((WORD) ^= (MASK))
39 | #include "bitdo1.h"
40 | }
41 |
--------------------------------------------------------------------------------
/examples/pvmpop/master.C:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | master.C
3 | mbwall 5dec95
4 | Copyright (c) 1995-1996 Massachusetts Institute of Technology
5 |
6 | DESCRIPTION:
7 | Example program to illustrate use of GAlib with PVM. This example uses a
8 | master-slave configuration to parallelize the genetic algorithm. In this case,
9 | the master controls the evolution by specifying migrations between populations
10 | on various processes.
11 | ---------------------------------------------------------------------------- */
12 | #include
13 | #include
14 | #include "PVMDemeGA.h"
15 | #include "genome.h"
16 |
17 | int
18 | main(int argc, char** argv) {
19 | cout << "This program tries to fill a 1DBinaryStringGenome with\n";
20 | cout << "alternating 1s and 0s using a simple genetic algorithm. It runs\n";
21 | cout << "in parallel using PVM and a population on each process.\n\n";
22 | cout.flush();
23 |
24 | GA1DBinaryStringGenome genome(GENOME_LENGTH);
25 | PVMDemeGA ga(genome);
26 | ga.parameters(argc, argv);
27 | ga.parameters("settings.txt");
28 | if(ga.spawn("slave") < 0) exit(1);
29 |
30 | cout << "initializing..." << endl;
31 | ga.initialize();
32 | cout << ga.statistics().bestIndividual() << endl;
33 | cout << "evolving..." << endl;
34 | while(!ga.done()){
35 | ga.step();
36 | cout << ga.statistics().bestIndividual() << endl;
37 | }
38 | ga.flushScores();
39 |
40 | cout << "\nThe GA found an individual with a score of ";
41 | cout << ga.statistics().bestIndividual().score() << endl;
42 |
43 | return 0;
44 | }
45 |
--------------------------------------------------------------------------------
/examples/gnu/bitclear.c:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 1994 Free Software Foundation
2 |
3 | This file is part of the GNU BitString Library. This library is free
4 | software; you can redistribute it and/or modify it under the
5 | terms of the GNU General Public License as published by the
6 | Free Software Foundation; either version 2, or (at your option)
7 | any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this library; see the file COPYING. If not, write to the Free
16 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 |
18 | As a special exception, if you link this library with files
19 | compiled with a GNU compiler to produce an executable, this does not cause
20 | the resulting executable to be covered by the GNU General Public License.
21 | This exception does not however invalidate any other reasons why
22 | the executable file might be covered by the GNU General Public License. */
23 |
24 | /* Written by Per Bothner (bothner@cygnus.com) */
25 |
26 | #include "bitprims.h"
27 |
28 | void
29 | /*
30 | _BS_clear (ptr, offset, length)
31 | register _BS_word *ptr;
32 | int offset;
33 | _BS_size_t length;
34 | */
35 | _BS_clear (register _BS_word *ptr,
36 | int offset,
37 | _BS_size_t length)
38 | {
39 | #undef DOIT
40 | #define DOIT(WORD, MASK) ((WORD) &= ~(MASK))
41 | #include "bitdo1.h"
42 | }
43 |
--------------------------------------------------------------------------------
/examples/gnu/bitany.c:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 1994 Free Software Foundation
2 |
3 | This file is part of the GNU BitString Library. This library is free
4 | software; you can redistribute it and/or modify it under the
5 | terms of the GNU General Public License as published by the
6 | Free Software Foundation; either version 2, or (at your option)
7 | any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this library; see the file COPYING. If not, write to the Free
16 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 |
18 | As a special exception, if you link this library with files
19 | compiled with a GNU compiler to produce an executable, this does not cause
20 | the resulting executable to be covered by the GNU General Public License.
21 | This exception does not however invalidate any other reasons why
22 | the executable file might be covered by the GNU General Public License. */
23 |
24 | /* Written by Per Bothner (bothner@cygnus.com) */
25 |
26 | #include "bitprims.h"
27 |
28 | int
29 | /*
30 | _BS_any (ptr, offset, length)
31 | register const _BS_word *ptr;
32 | int offset;
33 | _BS_size_t length;
34 | */
35 | _BS_any (register const _BS_word *ptr,
36 | int offset,
37 | _BS_size_t length)
38 | {
39 | #undef DOIT
40 | #define DOIT(WORD, MASK) if ((WORD) & (MASK)) return 1;
41 | #include "bitdo1.h"
42 | return 0;
43 | }
44 |
--------------------------------------------------------------------------------
/examples/graphic/makefile:
--------------------------------------------------------------------------------
1 | # Makefile for GAlib 2.x - example programs
2 | # Copyright (c) 1994-1996 Massachusetts Institute of Technology
3 | # mbwall 17jan96 all rights reserved
4 |
5 | # You'll probably have to modify the XLIBS to include the right X libraries
6 | # for your system. For example, solaris typically need Xmu, some SUNs need PW,
7 | # and HP boxes are really messed up. On Athena's SUNs you must also add the
8 | # library -lgen when using MOTIF.
9 |
10 | # use these libs if you have MOTIF. You might need to add -lPW to XLIBS.
11 | MOTIF=-DUSE_MOTIF
12 | XLIBS= -lXm -lXt -lX11
13 |
14 | # use these if you're compiling with the athena widget set (no motif)
15 | #MOTIF=
16 | #XLIBS= -lXaw -lXt -lX11
17 |
18 | # the CC include directory is only for use by makedepend. linux needs the
19 | # /usr/X11R6/lib, but others might need it as well.
20 | CC_INC_DIR= -I/usr/include/CC
21 | INC_DIRS= -I../..
22 | LIB_DIRS= -L../../ga -L/usr/X11R6/lib
23 |
24 | # If you have SGI's DCC compiler...
25 | #C++C= DCC
26 | #CCFLAGS= -ptv +w +pp -O -g $(MOTIF) $(INC_DIRS)
27 |
28 | # If you're using the gnu compiler...
29 | C++C= g++
30 | CCFLAGS= -Wall -O -g $(MOTIF) $(INC_DIRS)
31 |
32 | .SUFFIXES: .o .C
33 | .C.o:
34 | $(C++C) $(CCFLAGS) -c $<
35 |
36 | all: gaview tspview
37 |
38 | gaview: gaview.o
39 | $(C++C) -o $@ $@.o $(LIB_DIRS) $(XLIBS) -lga -lm
40 |
41 | tspview: tspview.o
42 | $(C++C) -o $@ $@.o $(LIB_DIRS) $(XLIBS) -lga -lm
43 |
44 | clean:
45 | rm -rf *~ *.bak *.out *.pixie *.o core ii_files test* bog.dat
46 | rm -f gaview tspview
47 |
48 | depend:
49 | makedepend $(CC_INC_DIR) $(INC_DIRS) gaview.C tspview.C
50 |
51 | # DO NOT DELETE THIS LINE -- make depend depends on it.
52 |
--------------------------------------------------------------------------------
/doc/OtherSites.html:
--------------------------------------------------------------------------------
1 | GAlib: Evolutionary Algorithm Sites
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | GAlib
11 | Some sites with information about evolutionary algorithms...
12 |
13 |
14 | This list is by no means comprehensive, but it should get you started into some of the bigger genetic algorithm and other evolutionary algorithm sites.
15 |
16 |
17 |
18 | comp.ai.genetic newsgroup
19 |
20 | comp.ai.genetic Frequently Asked Questions
21 |
22 |
23 |
24 |
25 | Encore (The EvolutioNary COmputation REpository network)
26 |
27 | GA Rules of Thumb by Wendy Williams
28 |
29 | Illinois Genetic Algorithms Laboratory (IlliGAL)
30 |
31 | Michael Trick's Operations Research Page
32 |
33 | Navy Center for Applied Research in Artificial Intelligence (NCARAI)
34 |
35 | Yahoo has a small listing of GA topics
36 |
37 |
38 | Matthew Wall, 11 March 1996
39 |
40 |
41 |
--------------------------------------------------------------------------------
/ga/makefile.sources:
--------------------------------------------------------------------------------
1 | # -*- Mode: makefile -*-
2 |
3 | HDRS= ga.h gaconfig.h gatypes.h gaid.h garandom.h gaerror.h std_stream.h \
4 | GAEvalData.h GAParameter.h GAStatistics.h \
5 | GABaseGA.h GASStateGA.h GASimpleGA.h GAIncGA.h GADemeGA.h GADCrowdingGA.h \
6 | GASelector.h GAScaling.h GAPopulation.h GAGenome.h GAMask.h \
7 | GABinStr.h gabincvt.h GAAllele.h GAArray.h GANode.h \
8 | GA1DBinStrGenome.h GA2DBinStrGenome.h GA3DBinStrGenome.h GABin2DecGenome.h \
9 | GA1DArrayGenome.h GA2DArrayGenome.h GA3DArrayGenome.h \
10 | GAStringGenome.h GARealGenome.h \
11 | GATreeBASE.h GATree.h GATreeGenome.h GAListBASE.h GAList.h GAListGenome.h
12 | SRCS= garandom.C gaerror.C GAParameter.C GAStatistics.C \
13 | GABaseGA.C GASStateGA.C GASimpleGA.C GAIncGA.C GADemeGA.C GADCrowdingGA.C \
14 | GASelector.C GAScaling.C GAPopulation.C GAGenome.C \
15 | GABinStr.C gabincvt.C GAAllele.C GAStringGenome.C GARealGenome.C \
16 | GA1DBinStrGenome.C GA2DBinStrGenome.C GA3DBinStrGenome.C GABin2DecGenome.C \
17 | GA1DArrayGenome.C GA2DArrayGenome.C GA3DArrayGenome.C \
18 | GATreeBASE.C GATree.C GATreeGenome.C GAListBASE.C GAList.C GAListGenome.C
19 | OBJS= garandom.o gaerror.o GAParameter.o GAStatistics.o \
20 | GABaseGA.o GASStateGA.o GASimpleGA.o GAIncGA.o GADemeGA.o GADCrowdingGA.o \
21 | GASelector.o GAScaling.o GAPopulation.o GAGenome.o \
22 | GABinStr.o gabincvt.o GAAllele.o \
23 | GA1DBinStrGenome.o GA2DBinStrGenome.o GA3DBinStrGenome.o GABin2DecGenome.o \
24 | GA1DArrayGenome.o GA2DArrayGenome.o GA3DArrayGenome.o \
25 | GATreeBASE.o GATree.o GATreeGenome.o GAListBASE.o GAList.o GAListGenome.o
26 | TMPL_SRCS= GAAllele.C \
27 | GA1DArrayGenome.C GA2DArrayGenome.C GA3DArrayGenome.C \
28 | GATree.C GATreeGenome.C GAList.C GAListGenome.C \
29 | GAStringGenome.C GARealGenome.C
30 |
--------------------------------------------------------------------------------
/ga/gabincvt.h:
--------------------------------------------------------------------------------
1 | // $Header$
2 | /* ----------------------------------------------------------------------------
3 | bincvt.h
4 | mbwall 29jun95
5 | Copyright (c) 1995 Massachusetts Institute of Technology
6 | all rights reserved
7 |
8 | DESCRIPTION:
9 | Header for the binary to decimal conversion routines. The binary-to-decimal
10 | routines include encoders and decoders. We define a standard binary encoder/
11 | decoder set as well as one Gray encoder/decoder. You can define your own if
12 | you want a different Gray coding.
13 | ---------------------------------------------------------------------------- */
14 | #ifndef _ga_bincvt_h_
15 | #define _ga_bincvt_h_
16 |
17 | #include
18 |
19 | // The encoder converts a decimal value into a binary string. The decoder
20 | // converts a string of bits into a decimal value. Both types of functions
21 | // return an error code to indicate whether or not the conversion was
22 | // successful. The caller must make sure that sufficient space is available
23 | // for the arguments. The encoder will set the value to whatever it was able
24 | // to encode, so be sure to check the return status and make your value such
25 | // that you can check it if you get a non-zero return code.
26 | typedef int (*GABinaryEncoder)(float& value, GABit* bits,
27 | unsigned int nbits, float min, float max);
28 | typedef int (*GABinaryDecoder)(float& value, const GABit* bits,
29 | unsigned int nbits, float min, float max);
30 |
31 |
32 | int GABinaryEncode(float&, GABit* bits, unsigned int, float, float);
33 | int GABinaryDecode(float&, const GABit* bits, unsigned int, float, float);
34 |
35 | int GAGrayEncode(float&, GABit* bits, unsigned int, float, float);
36 | int GAGrayDecode(float&, const GABit* bits, unsigned int, float, float);
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/COPYRIGHT:
--------------------------------------------------------------------------------
1 | Copyright:
2 |
3 | Copyright (c) 1995-1996 Massachusetts Institute of Technology (MIT)
4 | Copyright (c) 1996-2005 Matthew Wall (the Author)
5 | All rights reserved.
6 |
7 | Distribution Conditions:
8 |
9 | Redistribution and use in source and binary forms, with or without
10 | modification, are permitted provided that the following conditions
11 | are met:
12 |
13 | Redistributions of source code must retain the above copyright
14 | notice, this list of conditions and the following disclaimer.
15 |
16 | Redistributions in binary form must reproduce the above copyright
17 | notice, this list of conditions and the following disclaimer in
18 | the documentation and/or other materials provided with the
19 | distribution.
20 |
21 | Neither the name Massachusetts Institute of Technology (MIT),
22 | Matthew Wall, nor the names of contributors may be used to
23 | endorse or promote products derived from this software without
24 | specific prior written permission.
25 |
26 | Disclaimer:
27 |
28 | This software is provided "as is". Any express or implied warranties,
29 | including, but not limited to, the implied warranties of merchantability
30 | and fitness for a particular purpose are disclaimed. In no event shall
31 | MIT, Matthew Wall, or the contributors to GAlib be liable for any direct,
32 | indirect, incidental, special, exemplary, or consequential damages
33 | (including, but not limited to, procurement of substitute goods or
34 | services; loss of use, data, or profits; or business interruption)
35 | however caused and on any theory of liability, whether in contract,
36 | strict liability, or tort (including negligence or otherwise) arising
37 | in any way out of the use of this software, even if advised of the
38 | possibility of such damage.
39 |
--------------------------------------------------------------------------------
/examples/gnu/README:
--------------------------------------------------------------------------------
1 | GNU BitString object and GAlib
2 | mbwall 19sep95
3 |
4 | This directory contains some objects from the GNU library (libg++) that can be
5 | used with GAlib. In particular, I have implemented a set of GAlib operators
6 | for use with the GNU BitString object. See the makefile for specifics, but
7 | basically you can compile a mini-library using the code in this directory then
8 | link to that as well as GAlib when you compile your program.
9 |
10 | The GAlib-specific files are bitstr.C, bitstr.h, and gnuex.C. bitstr.C and
11 | bitstr.h define the new genome class, and gnuex.C contains the main program
12 | that runs the GA.
13 |
14 | I had to modify the GNU files a bit in order to make them work cross-platform.
15 | No major changes, just tweaks to the includes and removal of libg++
16 | dependencies that I don't need for this example.
17 |
18 | This code has been tested on various UNIX machines. I do not know if or how
19 | well it work on DOS and/or Mac platforms. At this point I do not have time to
20 | try to compile GNU code on those machines (especially when the code does such
21 | lowlevel bit operations).
22 |
23 | COPYRIGHT and LICENSING ISSUES
24 |
25 | The code in this directory is protected under the terms of the GNU public
26 | license (see the file COPYING for details). Under the terms of that agreement,
27 | all of the code in this directory is free for any use. It is included with
28 | GAlib as an example of how to integrate GAlib with other data structures.
29 |
30 | Please see the copyright notices in each file for specific ownership.
31 |
32 | As works that use the GNU library (or parts thereof), the GAlib-specific files
33 | are Copyright MIT, but they are available for copying and distribution under
34 | the terms of the GNU public license agreement, not the terms of the general
35 | GAlib licensing agreement.
36 |
--------------------------------------------------------------------------------
/examples/gnu/bitand.c:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 1994 Free Software Foundation
2 |
3 | This file is part of the GNU BitString Library. This library is free
4 | software; you can redistribute it and/or modify it under the
5 | terms of the GNU General Public License as published by the
6 | Free Software Foundation; either version 2, or (at your option)
7 | any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this library; see the file COPYING. If not, write to the Free
16 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 |
18 | As a special exception, if you link this library with files
19 | compiled with a GNU compiler to produce an executable, this does not cause
20 | the resulting executable to be covered by the GNU General Public License.
21 | This exception does not however invalidate any other reasons why
22 | the executable file might be covered by the GNU General Public License. */
23 |
24 | /* Written by Per Bothner (bothner@cygnus.com). */
25 |
26 | #include "bitprims.h"
27 |
28 | /* Copy LENGTH bits from (starting at SRCBIT) into pdst starting at DSTBIT.
29 | This will work even if psrc & pdst overlap. */
30 |
31 | void
32 | /*
33 | _BS_and (pdst, dstbit, psrc, srcbit, length)
34 | register _BS_word* pdst;
35 | int dstbit;
36 | register const _BS_word* psrc;
37 | int srcbit;
38 | _BS_size_t length;
39 | */
40 | _BS_and (register _BS_word* pdst,
41 | int dstbit,
42 | register const _BS_word* psrc,
43 | int srcbit,
44 | _BS_size_t length)
45 | {
46 | #define COMBINE(dst, src) (dst) & (src)
47 | #include "bitdo2.h"
48 | }
49 |
--------------------------------------------------------------------------------
/examples/gnu/bitcopy.c:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 1994 Free Software Foundation
2 |
3 | This file is part of the GNU BitString Library. This library is free
4 | software; you can redistribute it and/or modify it under the
5 | terms of the GNU General Public License as published by the
6 | Free Software Foundation; either version 2, or (at your option)
7 | any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this library; see the file COPYING. If not, write to the Free
16 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 |
18 | As a special exception, if you link this library with files
19 | compiled with a GNU compiler to produce an executable, this does not cause
20 | the resulting executable to be covered by the GNU General Public License.
21 | This exception does not however invalidate any other reasons why
22 | the executable file might be covered by the GNU General Public License. */
23 |
24 | /* Written by Per Bothner (bothner@cygnus.com). */
25 |
26 | #include "bitprims.h"
27 |
28 | /* Copy LENGTH bits from (starting at SRCBIT) into pdst starting at DSTBIT.
29 | This will work even if psrc & pdst overlap. */
30 |
31 | void
32 | /*
33 | _BS_copy (pdst, dstbit, psrc, srcbit, length)
34 | register _BS_word* pdst;
35 | int dstbit;
36 | register const _BS_word* psrc;
37 | int srcbit;
38 | _BS_size_t length;
39 | */
40 | _BS_copy (register _BS_word* pdst,
41 | int dstbit,
42 | register const _BS_word* psrc,
43 | int srcbit,
44 | _BS_size_t length)
45 | {
46 | #define COMBINE(dst, src) (src)
47 | #include "bitdo2.h"
48 | }
49 |
--------------------------------------------------------------------------------
/examples/gnu/bitxor.c:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 1994 Free Software Foundation
2 |
3 | This file is part of the GNU BitString Library. This library is free
4 | software; you can redistribute it and/or modify it under the
5 | terms of the GNU General Public License as published by the
6 | Free Software Foundation; either version 2, or (at your option)
7 | any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this library; see the file COPYING. If not, write to the Free
16 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 |
18 | As a special exception, if you link this library with files
19 | compiled with a GNU compiler to produce an executable, this does not cause
20 | the resulting executable to be covered by the GNU General Public License.
21 | This exception does not however invalidate any other reasons why
22 | the executable file might be covered by the GNU General Public License. */
23 |
24 | /* Written by Per Bothner (bothner@cygnus.com). */
25 |
26 | #include "bitprims.h"
27 |
28 | /* Copy LENGTH bits from (starting at SRCBIT) into pdst starting at DSTBIT.
29 | This will work even if psrc & pdst overlap. */
30 |
31 | void
32 | /*
33 | _BS_xor (pdst, dstbit, psrc, srcbit, length)
34 | register _BS_word* pdst;
35 | int dstbit;
36 | register const _BS_word* psrc;
37 | int srcbit;
38 | _BS_size_t length;
39 | */
40 | _BS_xor (register _BS_word* pdst,
41 | int dstbit,
42 | register const _BS_word* psrc,
43 | int srcbit,
44 | _BS_size_t length)
45 | {
46 | #define COMBINE(dst, src) (dst) ^ (src)
47 | #include "bitdo2.h"
48 | }
49 |
--------------------------------------------------------------------------------
/examples/makefile.vcpp:
--------------------------------------------------------------------------------
1 | # -*- Mode: makefile -*-
2 | # Copyright (c) 1999-2005 Matthew Wall, all rights reserved
3 | # -----------------------------------------------------------------------------
4 | # To make all of the examples, do 'make'. You can compile any one of
5 | # the examples by typing 'make exN' where N is the number of the example you
6 | # want to compile. See the README for a description of what each example does.
7 | # -----------------------------------------------------------------------------
8 |
9 | !include ../makevars.vcpp
10 | GA_LIB=$(LIB_NAME).lib
11 |
12 | # Set these paths to the location of the GA library and headers.
13 | #GA_INC_DIR= /usr/local/include
14 | #GA_LIB_DIR= /usr/local/lib
15 | GA_INC_DIR= ..
16 | GA_LIB_DIR= ..\ga
17 |
18 | INC_DIRS= /I$(GA_INC_DIR)
19 | LIB_DIRS= /LIBPATH:$(GA_LIB_DIR)
20 |
21 | CXXFLAGS= $(CXXFLAGS) $(INC_DIRS)
22 |
23 | EXECS=randtest.exe\
24 | ex1.exe ex2.exe ex3.exe ex4.exe ex5.exe ex6.exe ex7.exe ex8.exe ex9.exe\
25 | ex10.exe ex11.exe ex12.exe ex13.exe ex14.exe ex15.exe ex16.exe ex17.exe ex18.exe\
26 | ex19.exe ex20.exe ex21.exe ex22.exe ex23.exe ex24.exe ex25.exe ex26.exe ex27.exe
27 |
28 | all: $(EXECS)
29 |
30 | $(EXECS): $*.o
31 | $(LD) $(LDFLAGS) $*.o /out:$*.exe $(LIB_DIRS) $(GA_LIB)
32 |
33 | clean:
34 | $(RM) test_results.txt test_stats.txt
35 | $(RM) *.dat
36 | $(RM) *.exe
37 | $(RM) *.pdb
38 | $(RM) *.o
39 | $(RM) vc*
40 |
41 | DATESTAMP=echo exit | cmd /q /k prompt $$D $$T
42 | test: $(EXECS)
43 | @echo running tests. this could take up to 1/2 hour, depending on
44 | @echo the speed of your computer. monitor test_results.txt and
45 | @echo test_stats.txt to see what is happening.
46 | @echo results > test_results.txt
47 | @echo stats > test_stats.txt
48 | @for %%x in ( $(EXECS) ) do \
49 | @echo %%x && echo %%x >> test_stats.txt && $(DATESTAMP) >> test_stats.txt && %%x seed 555 >> test_results.txt && $(DATESTAMP) >> test_stats.txt
50 |
--------------------------------------------------------------------------------
/examples/makefile.bcc:
--------------------------------------------------------------------------------
1 | # -*- Mode: makefile -*-
2 | # Copyright (c) 1999-2005 Matthew Wall, all rights reserved
3 | # -----------------------------------------------------------------------------
4 | # To make all of the examples, do 'make'. You can compile any one of
5 | # the examples by typing 'make exN' where N is the number of the example you
6 | # want to compile. See the README for a description of what each example does.
7 | # -----------------------------------------------------------------------------
8 |
9 | !include ../makevars.bcc
10 | GA_LIB=$(LIB_NAME).lib
11 |
12 | # Set these paths to the location of the GA library and headers.
13 | #GA_INC_DIR= /usr/local/include
14 | #GA_LIB_DIR= /usr/local/lib
15 | GA_INC_DIR= ..
16 | GA_LIB_DIR= ..\ga
17 |
18 | INC_DIRS= -I$(GA_INC_DIR)
19 | LIB_DIRS= -L$(GA_LIB_DIR) -L$(CXX_LIB_DIR)
20 |
21 | CXXFLAGS= $(CXXFLAGS) $(INC_DIRS)
22 |
23 | EXECS=randtest.exe\
24 | ex1.exe ex2.exe ex3.exe ex4.exe ex5.exe ex6.exe ex7.exe ex8.exe ex9.exe\
25 | ex10.exe ex11.exe ex12.exe ex13.exe ex14.exe ex15.exe ex16.exe ex17.exe ex18.exe\
26 | ex19.exe ex20.exe ex21.exe ex22.exe ex23.exe ex24.exe ex25.exe ex26.exe ex27.exe
27 |
28 | all: $(EXECS)
29 |
30 | .SUFFIXES:
31 | .SUFFIXES: .obj
32 | .obj.exe:
33 | $(CXX) -q $(LIB_DIRS) $*.obj $(GA_LIB)
34 |
35 | clean:
36 | $(RM) test_results.txt test_stats.txt
37 | $(RM) *.dat
38 | $(RM) *.exe
39 | $(RM) *.tds
40 | $(RM) *.obj
41 |
42 | DATESTAMP=echo exit | cmd /q /k prompt $$D $$T
43 | test: $(EXECS)
44 | @echo running tests. this could take up to 1/2 hour, depending on
45 | @echo the speed of your computer. monitor test_results.txt and
46 | @echo test_stats.txt to see what is happening.
47 | @echo results > test_results.txt
48 | @echo stats > test_stats.txt
49 | @for %x in ( $(EXECS) ) do \
50 | @echo %x & echo %x >> test_stats.txt & $(DATESTAMP) >> test_stats.txt & %x seed 555 >> test_results.txt & $(DATESTAMP) >> test_stats.txt
51 |
52 |
--------------------------------------------------------------------------------
/examples/gnu/AllocRing.h:
--------------------------------------------------------------------------------
1 | // This may look like C code, but it is really -*- C++ -*-
2 | /*
3 | Copyright (C) 1989 Free Software Foundation
4 | written by Doug Lea (dl@rocky.oswego.edu)
5 |
6 | This file is part of the GNU C++ Library. This library is free
7 | software; you can redistribute it and/or modify it under the terms of
8 | the GNU Library General Public License as published by the Free
9 | Software Foundation; either version 2 of the License, or (at your
10 | option) any later version. This library is distributed in the hope
11 | that it will be useful, but WITHOUT ANY WARRANTY; without even the
12 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 | PURPOSE. See the GNU Library General Public License for more details.
14 | You should have received a copy of the GNU Library General Public
15 | License along with this library; if not, write to the Free Software
16 | Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 | */
18 |
19 |
20 | #ifndef _AllocRing_h
21 | #ifdef __GNUG__
22 | #pragma interface
23 | #endif
24 | #define _AllocRing_h 1
25 |
26 |
27 | /*
28 | An AllocRing holds the last n malloc'ed strings, reallocating/reusing
29 | one only when the queue wraps around. It thus guarantees that the
30 | last n allocations are intact. It is useful for things like I/O
31 | formatting where reasonable restrictions may be made about the
32 | number of allowable live allocations before auto-deletion.
33 | */
34 |
35 | class AllocRing
36 | {
37 |
38 | struct AllocQNode
39 | {
40 | void* ptr;
41 | int sz;
42 | };
43 |
44 | AllocQNode* nodes;
45 | int n;
46 | int current;
47 |
48 | int find(void* p);
49 |
50 | public:
51 |
52 | AllocRing(int max);
53 | ~AllocRing();
54 |
55 | void* alloc(int size);
56 | int contains(void* ptr);
57 | void clear();
58 | void free(void* p);
59 | };
60 |
61 |
62 | #endif
63 |
--------------------------------------------------------------------------------
/examples/gnu/error.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 1990 Free Software Foundation
3 | written by Doug Lea (dl@rocky.oswego.edu)
4 |
5 | This file is part of the GNU C++ Library. This library is free
6 | software; you can redistribute it and/or modify it under the terms of
7 | the GNU Library General Public License as published by the Free
8 | Software Foundation; either version 2 of the License, or (at your
9 | option) any later version. This library is distributed in the hope
10 | that it will be useful, but WITHOUT ANY WARRANTY; without even the
11 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 | PURPOSE. See the GNU Library General Public License for more details.
13 | You should have received a copy of the GNU Library General Public
14 | License along with this library; if not, write to the Free Software
15 | Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 | */
17 |
18 | #include
19 | #include
20 |
21 | #ifdef __GNUG__
22 | #pragma implementation
23 | #endif
24 | #include
25 |
26 | #ifdef __GNUC__
27 | typedef _VOLATILE_VOID (*NoReturnFunc)(void);
28 | /* Cast abort to a _VOLATILE_VOID function, even if differs.
29 | This is to avoid a warning from g++ that a `volatile' function does return. */
30 | #define ABORT() ((NoReturnFunc)abort)()
31 | #else
32 | #define ABORT() abort()
33 | #endif
34 |
35 | _VOLATILE_VOID default_one_arg_error_handler(const char* msg)
36 | {
37 | fputs("Error: ", stderr);
38 | fputs(msg, stderr);
39 | fputs("\n", stderr);
40 | ABORT();
41 | }
42 |
43 |
44 | _VOLATILE_VOID default_two_arg_error_handler(const char* kind, const char* msg)
45 | {
46 | fputs(kind, stderr);
47 | fputs(" Error: ", stderr);
48 | fputs(msg, stderr);
49 | fputs("\n", stderr);
50 | ABORT();
51 | }
52 |
53 | two_arg_error_handler_t lib_error_handler = default_two_arg_error_handler;
54 |
55 | two_arg_error_handler_t set_lib_error_handler(two_arg_error_handler_t f)
56 | {
57 | two_arg_error_handler_t old = lib_error_handler;
58 | lib_error_handler = f;
59 | return old;
60 | }
61 |
62 |
--------------------------------------------------------------------------------
/examples/graphic/bitmaps/gaview.xbm:
--------------------------------------------------------------------------------
1 | /* microscope-on-chromosomes bitmap */
2 | /* Copyright (c) 1996 matthew wall, all rights reserved */
3 |
4 | #define gaview_width 48
5 | #define gaview_height 48
6 | static unsigned char gaview_bits[] = {
7 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0x00, 0x00, 0x00,
8 | 0x00, 0xfc, 0x1f, 0x00, 0x00, 0x00, 0x00, 0x3f, 0x7e, 0x00, 0x00, 0x00,
9 | 0x80, 0x07, 0xf0, 0x00, 0x00, 0x00, 0xc0, 0x11, 0xc6, 0x01, 0x00, 0x00,
10 | 0x60, 0x18, 0x01, 0x03, 0x40, 0x00, 0x70, 0x10, 0x03, 0x07, 0x48, 0x00,
11 | 0x30, 0x20, 0x22, 0x06, 0x88, 0x00, 0x38, 0x60, 0x23, 0x8e, 0x88, 0x00,
12 | 0x18, 0xc0, 0xa1, 0x4d, 0x51, 0x00, 0x1c, 0x42, 0x21, 0x5d, 0x51, 0x00,
13 | 0x1c, 0x42, 0x41, 0x9d, 0x20, 0x00, 0x6c, 0x61, 0x81, 0x5d, 0x51, 0x00,
14 | 0x4c, 0x41, 0x81, 0x58, 0x92, 0x00, 0x4c, 0x41, 0x83, 0x98, 0x92, 0x00,
15 | 0x5c, 0x41, 0x83, 0x9c, 0x92, 0x00, 0xdc, 0x40, 0x42, 0x9c, 0x52, 0x00,
16 | 0x98, 0x41, 0x42, 0x8c, 0x50, 0x00, 0x38, 0x61, 0x42, 0x0e, 0x00, 0x00,
17 | 0x30, 0x21, 0x06, 0x06, 0x00, 0x00, 0x70, 0x20, 0x06, 0x07, 0x00, 0x00,
18 | 0x60, 0x60, 0x04, 0x03, 0x00, 0x00, 0xc0, 0x41, 0xc0, 0x01, 0x00, 0x00,
19 | 0x80, 0x07, 0xf0, 0x03, 0x00, 0x00, 0x00, 0x3f, 0x7e, 0x07, 0x00, 0x00,
20 | 0x00, 0xfc, 0x1f, 0x3e, 0x00, 0x00, 0x00, 0xf0, 0x07, 0x7c, 0x00, 0x00,
21 | 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x01, 0x00,
22 | 0x00, 0x00, 0x00, 0xf8, 0x43, 0x00, 0x00, 0x00, 0x00, 0xf0, 0x4f, 0x00,
23 | 0x00, 0x00, 0x12, 0xe0, 0x8f, 0x00, 0x00, 0x00, 0x12, 0xc9, 0x9f, 0x00,
24 | 0x00, 0x00, 0x14, 0xc5, 0x7f, 0x00, 0x00, 0x50, 0x14, 0x45, 0x7f, 0x00,
25 | 0x40, 0x51, 0x08, 0x82, 0xfe, 0x00, 0x80, 0x20, 0x14, 0x45, 0xfd, 0x01,
26 | 0x40, 0x51, 0x24, 0x4a, 0xfa, 0x03, 0x40, 0xa2, 0x24, 0x89, 0xf2, 0x07,
27 | 0x40, 0x92, 0x28, 0x89, 0xf2, 0x0f, 0x00, 0x90, 0x28, 0x85, 0xd2, 0x1f,
28 | 0x00, 0x00, 0x24, 0x85, 0xd0, 0x1f, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x1f,
29 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
30 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
31 |
--------------------------------------------------------------------------------
/examples/pvmind/Makefile.aimk:
--------------------------------------------------------------------------------
1 | # makefile for compiling the PVM example for GAlib
2 | # Copyright (c) 1995-1996 Massachusetts Institute of Technology
3 | # mbwall 5dec95
4 | #
5 | # This makefile is designed to be used with aimk (that comes with pvm3). You
6 | # should set the PVM_ROOT and PVM_ARCH environment variables as described in
7 | # the PVM documentation. For our configuration, I have set them like this:
8 | #
9 | # setenv PVM_ROOT= /usr/local/pvm3
10 | # setenv PVM_ARCH= `$PVM_ROOT/lib/pvmgetarch`
11 | #
12 | # (I do this in my .cshrc file) Your mileage may vary. You can 'hardcode'
13 | # the directories here in the makefile if you like, but then you won't be able
14 | # to compile on different architectures without changing this file. XDIR is
15 | # the location of your PVM binaries. Do a simple 'aimk' first, then, if
16 | # everything went OK, do 'aimk install' and that will move the binaries to your
17 | # PVM executables directory. When you use aimk it will create a subdirectory
18 | # in the current directory for each architecture on which you try to compile.
19 |
20 | SDIR= ..
21 | BDIR= $(HOME)/pvm3/bin
22 | XDIR= $(BDIR)/$(PVM_ARCH)
23 | VPATH= $(SDIR)
24 |
25 | GA_INC_DIR=$(SDIR)/../..
26 | GA_LIB_DIR=$(SDIR)/../../ga
27 |
28 | INC_DIRS= -I$(SDIR)/. -I$(GA_INC_DIR) -I${PVM_ROOT}/include
29 | LIB_DIRS= -L$(SDIR)/. -L$(GA_LIB_DIR) -L${PVM_ROOT}/lib/${PVM_ARCH}
30 | LIBS= -lpvm3 -lga -lm
31 |
32 | CCFLAGS= +w +pp -O -g $(INC_DIRS)
33 | C++C= DCC
34 |
35 | SRCS= master.C slave.C genome.C
36 |
37 | all: master slave
38 |
39 | master.o: $(SDIR)/master.C
40 | $(C++C) $(CCFLAGS) -c $(SDIR)/master.C
41 | slave.o: $(SDIR)/slave.C
42 | $(C++C) $(CCFLAGS) -c $(SDIR)/slave.C
43 | genome.o: $(SDIR)/genome.C
44 | $(C++C) $(CCFLAGS) -c $(SDIR)/genome.C
45 |
46 | master: $$@.o genome.o
47 | $(C++C) $@.o genome.o -o $@ $(LIB_DIRS) $(LIBS)
48 |
49 | slave: $$@.o genome.o
50 | $(C++C) $@.o genome.o -o $@ $(LIB_DIRS) $(LIBS)
51 |
52 | install: master slave $(XDIR)
53 | mv master slave $(XDIR)
54 |
55 | $(XDIR):
56 | - mkdir $(BDIR) $(XDIR)
57 |
58 | clean:
59 |
60 | rm -rf *~ *.bak *.out *.o core master slave ii_files
61 |
--------------------------------------------------------------------------------
/examples/makefile:
--------------------------------------------------------------------------------
1 | # -*- Mode: makefile -*-
2 | # Copyright (c) 1999 Matthew Wall, all rights reserved
3 | # -----------------------------------------------------------------------------
4 | # To make all of the examples, do 'make'. You can compile any one of
5 | # the examples by typing 'make exN' where N is the number of the example you
6 | # want to compile. See the README for a description of what each example does.
7 | # -----------------------------------------------------------------------------
8 |
9 | include ../makevars
10 |
11 | # Set these paths to the location of the GA library and headers.
12 | #GA_INC_DIR= /usr/local/include
13 | #GA_LIB_DIR= /usr/local/lib
14 | GA_INC_DIR= ..
15 | GA_LIB_DIR= ../ga
16 |
17 | INC_DIRS= -I$(GA_INC_DIR)
18 | LIB_DIRS= -L$(GA_LIB_DIR)
19 |
20 | EXS=randtest\
21 | ex1 ex2 ex3 ex4 ex5 ex6 ex7 ex8 ex9\
22 | ex10 ex11 ex12 ex13 ex14 ex15 ex16 ex17 ex18\
23 | ex19 ex20 ex21 ex22 ex23 ex24 ex25 ex26 ex27
24 |
25 | .SUFFIXES: .C
26 | .C.o:
27 | $(CXX) $(CXXFLAGS) $(INC_DIRS) -c $<
28 |
29 | all: $(EXS)
30 |
31 | # Use this for non-gnu make
32 | #$(EXS): $$@.o
33 | # $(CXX) $@.o -o $@ $(LIB_DIRS) -lga -lm $(CXX_LIBS)
34 |
35 | # Use this for gnu make
36 | $(EXS): %: %.o
37 | $(CXX) $@.o -o $@ $(LIB_DIRS) -lga -lm $(CXX_LIBS)
38 |
39 | clean:
40 | $(RM) $(EXS)
41 | $(RM) *.o *~ *.bak *.pixie core
42 | $(RM) test_results.txt test_stats.txt
43 | $(RM) *.dat
44 | $(RM) *.out *.exe vc* *.pdb
45 |
46 | test: $(EXS)
47 | $(RM) test_results.txt test_stats.txt
48 | @echo "running tests. this could take up to 1/2 hour, depending on"
49 | @echo "the speed of your computer. monitor test_results.txt and"
50 | @echo "test_stats.txt to see what is happening."
51 | @echo ""
52 | @rm -f test_results.txt
53 | @echo `uname -a` > test_stats.txt
54 | @echo "" >> test_stats.txt
55 | for x in $(EXS); do \
56 | echo "$$x... "; \
57 | echo "$$x" >> test_stats.txt; \
58 | echo "start: " `date` >> test_stats.txt; \
59 | ./$$x seed 555 >> test_results.txt; \
60 | echo "finish: " `date` >> test_stats.txt; \
61 | echo "" >> test_stats.txt; \
62 | done
63 |
--------------------------------------------------------------------------------
/examples/ex25.C:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | ex25.C
3 | mbwall jan96
4 | Copyright (c) 1995-1996 Massachusetts Institute of Technology
5 |
6 | DESCRIPTION:
7 | This example shows how to do multiple populations on a single CPU.
8 | ---------------------------------------------------------------------------- */
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 | #define cout STD_COUT
15 | #define endl STD_ENDL
16 |
17 | float Objective(GAGenome &);
18 |
19 | int
20 | main(int argc, char** argv) {
21 | cout << "Example 25\n\n";
22 | cout << "This example uses a genetic algorithm with multiple populations.\n";
23 | cout << endl;
24 |
25 | // See if we've been given a seed to use (for testing purposes). When you
26 | // specify a random seed, the evolution will be exactly the same each time
27 | // you use that seed number.
28 |
29 | unsigned int seed = 0;
30 | for(int ii=1; ii
11 | #include
12 | #include
13 | #include
14 | #include
15 |
16 |
17 | /* ----------------------------------------------------------------------------
18 | BinaryStringGenome
19 | ---------------------------------------------------------------------------- */
20 | // Copy the contents of the bitstream. We don't care what format it is in -
21 | // we resize to make sure we have adequate space then we just copy all of the
22 | // data.
23 | // If the original is actually this, then we don't do anything. If the
24 | // original is not the same class as this, then we post an error and return.
25 | void
26 | GABinaryString::copy(const GABinaryString& orig)
27 | {
28 | if(&orig == this) return;
29 | resize(orig.sz);
30 | memcpy(data, orig.data, SZ*sizeof(GABit));
31 | }
32 |
33 |
34 | // Resize the bitstream to the specified number of bits. We return the number
35 | // of bits actually allocated. For now there is no error checking or memory
36 | // management - we assume that we'll always get all of the memory we ask for.
37 | // If we resize, we copy the previous bits into the new space. The memory
38 | // will never overlap (new should see to that) so we use memcpy not memmove.
39 | // If we're making more space, we set the contents of the new space to zeros.
40 | int
41 | GABinaryString::resize(unsigned int x)
42 | {
43 | if(sz == x) return sz;
44 | if(SZ < x){
45 | while(SZ < x) SZ += csz;
46 | if(!data){
47 | data = new GABit [SZ];
48 | memset(data, 0, SZ*sizeof(GABit));
49 | }
50 | else{
51 | GABit * tmp = data;
52 | data = new GABit [SZ];
53 | memcpy(data, tmp, sz * sizeof(GABit));
54 | memset(&(data[sz]), 0, (SZ-sz)*sizeof(GABit));
55 | delete [] tmp;
56 | }
57 | }
58 | return(sz = x);
59 | }
60 |
--------------------------------------------------------------------------------
/examples/pvmpop/Makefile.aimk:
--------------------------------------------------------------------------------
1 | # makefile for compiling the PVM example for GAlib
2 | # Copyright (c) 1995-1996 Massachusetts Institute of Technology
3 | # mbwall 5dec95
4 | #
5 | # This makefile is designed to be used with aimk (that comes with pvm3). You
6 | # should set the PVM_ROOT and PVM_ARCH environment variables as described in
7 | # the PVM documentation. For our configuration, I have set them like this:
8 | #
9 | # setenv PVM_ROOT= /usr/local/pvm3
10 | # setenv PVM_ARCH= `$PVM_ROOT/lib/pvmgetarch`
11 | #
12 | # (I do this in my .cshrc file) Your mileage may vary. You can 'hardcode'
13 | # the directories here in the makefile if you like, but then you won't be able
14 | # to compile on different architectures without changing this file. XDIR is
15 | # the location of your PVM binaries. Do a simple 'aimk' first, then, if
16 | # everything went OK, do 'aimk install' and that will move the binaries to your
17 | # PVM executables directory. When you use aimk it will create a subdirectory
18 | # in the current directory for each architecture on which you try to compile.
19 |
20 | SDIR= ..
21 | BDIR= $(HOME)/pvm3/bin
22 | XDIR= $(BDIR)/$(PVM_ARCH)
23 | VPATH= $(SDIR)
24 |
25 | CC_INC_DIR=/usr/include/CC
26 | INC_DIRS= -I$(SDIR)/. -I$(SDIR)/../.. -I${PVM_ROOT}/include
27 | LIB_DIRS= -L$(SDIR)/. -L$(SDIR)/../../ga -L${PVM_ROOT}/lib/${PVM_ARCH}
28 | LIBS= -lpvm3 -lga -lm
29 |
30 | CCFLAGS= +w +pp -O -g $(INC_DIRS)
31 | C++C= DCC
32 |
33 | SRCS= master.C slave.C genome.C
34 |
35 | all: master slave
36 |
37 | master.o: $(SDIR)/master.C
38 | $(C++C) $(CCFLAGS) -c $(SDIR)/master.C
39 | slave.o: $(SDIR)/slave.C
40 | $(C++C) $(CCFLAGS) -c $(SDIR)/slave.C
41 | genome.o: $(SDIR)/genome.C
42 | $(C++C) $(CCFLAGS) -c $(SDIR)/genome.C
43 | PVMDemeGA.o: $(SDIR)/PVMDemeGA.C
44 | $(C++C) $(CCFLAGS) -c $(SDIR)/PVMDemeGA.C
45 |
46 | master: $$@.o genome.o PVMDemeGA.o
47 | $(C++C) $@.o genome.o PVMDemeGA.o -o $@ $(LIB_DIRS) $(LIBS)
48 |
49 | slave: $$@.o genome.o
50 | $(C++C) $@.o genome.o -o $@ $(LIB_DIRS) $(LIBS)
51 |
52 | install: master slave $(XDIR)
53 | mv master slave $(XDIR)
54 |
55 | $(XDIR):
56 | - mkdir $(BDIR) $(XDIR)
57 |
58 | clean:
59 | rm -rf *~ *.bak *.out *.o core master slave ii_files
60 |
--------------------------------------------------------------------------------
/doc/Copyright.html:
--------------------------------------------------------------------------------
1 | GAlib: Copyright
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | Copyright:
12 |
13 | Copyright (c) 1995-1996 Massachusetts Institute of Technology (MIT)
14 | Copyright (c) 1996-2005 Matthew Wall (the Author)
15 | All rights reserved.
16 |
17 | Distribution Conditions:
18 |
19 | Redistribution and use in source and binary forms, with or without
20 | modification, are permitted provided that the following conditions
21 | are met:
22 |
23 | Redistributions of source code must retain the above copyright
24 | notice, this list of conditions and the following disclaimer.
25 |
26 | Redistributions in binary form must reproduce the above copyright
27 | notice, this list of conditions and the following disclaimer in
28 | the documentation and/or other materials provided with the
29 | distribution.
30 |
31 | Neither the name Massachusetts Institute of Technology (MIT),
32 | Matthew Wall, nor the names of contributors may be used to
33 | endorse or promote products derived from this software without
34 | specific prior written permission.
35 |
36 | Disclaimer:
37 |
38 | This software is provided "as is". Any express or implied warranties,
39 | including, but not limited to, the implied warranties of merchantability
40 | and fitness for a particular purpose are disclaimed. In no event shall
41 | MIT, Matthew Wall, or the contributors to GAlib be liable for any direct,
42 | indirect, incidental, special, exemplary, or consequential damages
43 | (including, but not limited to, procurement of substitute goods or
44 | services; loss of use, data, or profits; or business interruption)
45 | however caused and on any theory of liability, whether in contract,
46 | strict liability, or tort (including negligence or otherwise) arising
47 | in any way out of the use of this software, even if advised of the
48 | possibility of such damage.
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/examples/results/test_stats-win2k.txt:
--------------------------------------------------------------------------------
1 | 900MHz athlon win2k sp4
2 |
3 | stats
4 | randtest.exe
5 |
6 | Tue 12/28/2004 20:10:48.98
7 | Tue 12/28/2004 20:10:50.23 ex1.exe
8 |
9 | Tue 12/28/2004 20:10:50.47
10 | Tue 12/28/2004 20:10:51.42 ex2.exe
11 |
12 | Tue 12/28/2004 20:10:51.66
13 | Tue 12/28/2004 20:10:52.28 ex3.exe
14 |
15 | Tue 12/28/2004 20:10:52.59
16 | Tue 12/28/2004 20:10:54.33 ex4.exe
17 |
18 | Tue 12/28/2004 20:10:54.66
19 | Tue 12/28/2004 20:10:55.99 ex5.exe
20 |
21 | Tue 12/28/2004 20:10:56.41
22 | Tue 12/28/2004 20:10:58.68 ex6.exe
23 |
24 | Tue 12/28/2004 20:10:58.74
25 | Tue 12/28/2004 20:11:47.97 ex7.exe
26 |
27 | Tue 12/28/2004 20:11:48.04
28 | Tue 12/28/2004 20:11:48.71 ex8.exe
29 |
30 | Tue 12/28/2004 20:11:48.77
31 | Tue 12/28/2004 20:11:48.99 ex9.exe
32 |
33 | Tue 12/28/2004 20:11:49.05
34 | Tue 12/28/2004 20:11:49.28 ex10.exe
35 |
36 | Tue 12/28/2004 20:11:49.34
37 | Tue 12/28/2004 20:11:52.71 ex11.exe
38 |
39 | Tue 12/28/2004 20:11:52.77
40 | Tue 12/28/2004 20:11:54.32 ex12.exe
41 |
42 | Tue 12/28/2004 20:11:54.38
43 | Tue 12/28/2004 20:11:55.85 ex13.exe
44 |
45 | Tue 12/28/2004 20:11:55.91
46 | Tue 12/28/2004 20:11:56.37 ex14.exe
47 |
48 | Tue 12/28/2004 20:11:56.42
49 | Tue 12/28/2004 20:11:58.02 ex15.exe
50 |
51 | Tue 12/28/2004 20:11:58.07
52 | Tue 12/28/2004 20:11:58.26 ex16.exe
53 |
54 | Tue 12/28/2004 20:11:58.31
55 | Tue 12/28/2004 20:11:58.47 ex17.exe
56 |
57 | Tue 12/28/2004 20:11:58.52
58 | Tue 12/28/2004 20:12:17.14 ex18.exe
59 |
60 | Tue 12/28/2004 20:12:17.19
61 | Tue 12/28/2004 20:12:18.53 ex19.exe
62 |
63 | Tue 12/28/2004 20:12:18.59
64 | Tue 12/28/2004 20:12:18.83 ex20.exe
65 |
66 | Tue 12/28/2004 20:12:18.89
67 | Tue 12/28/2004 20:16:32.43 ex21.exe
68 |
69 | Tue 12/28/2004 20:16:32.48
70 | Tue 12/28/2004 20:16:34.46 ex22.exe
71 |
72 | Tue 12/28/2004 20:16:34.51
73 | Tue 12/28/2004 20:16:39.48 ex23.exe
74 |
75 | Tue 12/28/2004 20:16:39.53
76 | Tue 12/28/2004 20:16:39.76 ex24.exe
77 |
78 | Tue 12/28/2004 20:16:39.82
79 | Tue 12/28/2004 20:16:40.14 ex25.exe
80 |
81 | Tue 12/28/2004 20:16:40.19
82 | Tue 12/28/2004 20:16:40.63 ex26.exe
83 |
84 | Tue 12/28/2004 20:16:40.68
85 | Tue 12/28/2004 20:17:02.82 ex27.exe
86 |
87 | Tue 12/28/2004 20:17:02.87
88 | Tue 12/28/2004 20:17:03.11
89 |
--------------------------------------------------------------------------------
/examples/gnu/bitcount.c:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 1994 Free Software Foundation
2 |
3 | This file is part of the GNU BitString Library. This library is free
4 | software; you can redistribute it and/or modify it under the
5 | terms of the GNU General Public License as published by the
6 | Free Software Foundation; either version 2, or (at your option)
7 | any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this library; see the file COPYING. If not, write to the Free
16 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 |
18 | As a special exception, if you link this library with files
19 | compiled with a GNU compiler to produce an executable, this does not cause
20 | the resulting executable to be covered by the GNU General Public License.
21 | This exception does not however invalidate any other reasons why
22 | the executable file might be covered by the GNU General Public License. */
23 |
24 | /* Written by Per Bothner (bothner@cygnus.com) */
25 |
26 | #include "bitprims.h"
27 |
28 | /* bit_count[I] is number of '1' bits in I. */
29 | static const unsigned char
30 | four_bit_count[16] = {
31 | 0, 1, 1, 2,
32 | 1, 2, 2, 3,
33 | 1, 2, 2, 3,
34 | 2, 3, 3, 4};
35 |
36 | #if !defined(inline) && !defined(__GNUC__) && !defined(__cplusplus)
37 | #define inline
38 | #endif
39 |
40 | static inline int
41 | /*
42 | _BS_count_word (word)
43 | register _BS_word word;
44 | */
45 | _BS_count_word (register _BS_word word)
46 | {
47 | register int count = 0;
48 | while (word > 0)
49 | {
50 | count += four_bit_count[word & 15];
51 | word >>= 4;
52 | }
53 | return count;
54 | }
55 |
56 | int
57 | /*
58 | _BS_count (ptr, offset, length)
59 | register const _BS_word *ptr;
60 | int offset;
61 | _BS_size_t length;
62 | */
63 | _BS_count (register const _BS_word *ptr,
64 | int offset,
65 | _BS_size_t length)
66 | {
67 | register int count = 0;
68 | #undef DOIT
69 | #define DOIT(WORD, MASK) count += _BS_count_word ((WORD) & (MASK));
70 | #include "bitdo1.h"
71 | return count;
72 | }
73 |
--------------------------------------------------------------------------------
/makevars.vcpp:
--------------------------------------------------------------------------------
1 | # -*- Mode: makefile -*-
2 | # Copyright (c) 1999-2005 Matthew Wall, all rights reserved
3 | # makefile variables for compiling on windows
4 | # -----------------------------------------------------------------------------
5 |
6 | LIB_NAME= ga
7 |
8 | ### Set these directories to whatever is appropriate for your system. These
9 | ### used only if you do a 'make install'. They specify where the library and
10 | ### header files should be installed.
11 | DESTDIR=c:\temp
12 | HDR_DEST_DIR=$(DESTDIR)\include
13 | LIB_DEST_DIR=$(DESTDIR)\lib
14 |
15 |
16 | MKDEPEND = echo
17 | MKDIR = mkdir
18 | CP = xcopy
19 | RM = del /f
20 |
21 | CXX = cl.exe
22 | LD = link.exe
23 | AR = lib.exe
24 | INSTALL = copy
25 |
26 |
27 | # Here is a quick summary of the switches that cause much grief. These are
28 | # for the microsoft visual c++ compilers.
29 | #
30 | # switch thread dll/exe library
31 | # /MD multi DLL MSCVRT.LIB
32 | # /ML single EXE LIBC.LIB
33 | # /MT multi EXE LIBCMT.LIB
34 | #
35 | # /GR enable RTTI
36 | # /GX enable synchronous exception handling
37 | # /YX automate precompiled header
38 | # /FD generate file dependencies
39 |
40 | CFLAGS = /nologo /D_WINDOWS /DWIN32 /D_MBCS /W3 /GR /GX /TP
41 | LFLAGS = /nologo /subsystem:console /incremental:no
42 |
43 | !ifdef RELEASE_BUILD
44 | CXXDLLFLAGS = $(CFLAGS) /DNDEBUG /MD /O2
45 | CXXLIBFLAGS = $(CFLAGS) /DNDEBUG /MT /O2
46 | CXXEXEFLAGS = $(CFLAGS) /DNDEBUG /MT /O2
47 | LINKFLAGS = $(LFLAGS)
48 | !else
49 | CXXDLLFLAGS = $(CFLAGS) /D_DEBUG /MDd /Od /Zi
50 | CXXLIBFLAGS = $(CFLAGS) /D_DEBUG /MTd /Od /Zi
51 | CXXEXEFLAGS = $(CFLAGS) /D_DEBUG /MTd /Od /Zi
52 | LINKFLAGS = $(LFLAGS) /debug
53 | !endif
54 |
55 | !ifdef SHARED_BUILD
56 | !ifdef LIBRARY_BUILD
57 | CXXFLAGS = $(CXXDLLFLAGS) /DCOMPILE_GALIB_AS_DLL /D_USRDLL
58 | LINKFLAGS = $(LINKFLAGS) /dll
59 | !else
60 | CXXFLAGS = $(CXXEXEFLAGS) /DUSE_GALIB_AS_DLL
61 | LINKFLAGS = $(LINKFLAGS)
62 | !endif
63 | !else
64 | !ifdef LIBRARY_BUILD
65 | CXXFLAGS = $(CXXLIBFLAGS) /DCOMPILE_GALIB_AS_LIB /D_LIB
66 | LINKFLAGS = $(LINKFLAGS)
67 | !else
68 | CXXFLAGS = $(CXXEXEFLAGS) /DUSE_GALIB_AS_LIB
69 | LINKFLAGS = $(LINKFLAGS)
70 | !endif
71 | !endif
72 |
73 | LDFLAGS = $(LINKFLAGS)
74 | ARFLAGS = /nologo
75 |
76 | .SUFFIXES:
77 | .SUFFIXES: .C
78 | .C.o:
79 | $(CXX) $(CXXFLAGS) /c $< /Fo$*.o
80 |
--------------------------------------------------------------------------------
/ga/GADCrowdingGA.C:
--------------------------------------------------------------------------------
1 | // $Header$
2 | /* ----------------------------------------------------------------------------
3 | gadcrowdingga.C
4 | mbwall 29mar99
5 | Copyright (c) 1999 Matthew Wall, all rights reserved
6 | ---------------------------------------------------------------------------- */
7 | #include "GADCrowdingGA.h"
8 | #include "GAList.h"
9 | #include "garandom.h"
10 |
11 | // this assumes that all of the genomes in the population are the same class
12 | void
13 | GADCrowdingGA::initialize(unsigned int seed)
14 | {
15 | GARandomSeed(seed);
16 |
17 | pop->initialize();
18 | pop->evaluate(gaTrue);
19 |
20 | stats.reset(*pop);
21 |
22 | if(!scross)
23 | GAErr(GA_LOC, className(), "initialize", gaErrNoSexualMating);
24 | }
25 |
26 | void
27 | GADCrowdingGA::step() {
28 | if(pop->size() == 0) return;
29 |
30 | GAGenome *child = pop->individual(0).clone();
31 |
32 | GAList indpool;
33 |
34 | for (int i=0; isize(); i++)
35 | indpool.insert(i);
36 |
37 | do {
38 | int *ip;
39 | indpool.warp(GARandomInt(0,indpool.size()-1)); // select mom
40 | ip=indpool.remove();
41 | GAGenome *mom = &pop->individual(*ip);
42 | delete ip;
43 |
44 | indpool.warp(GARandomInt(0,indpool.size()-1)); // select dad
45 | ip=indpool.remove();
46 | GAGenome *dad = &pop->individual(*ip);
47 | delete ip;
48 |
49 | stats.numsel += 2; // create child
50 | stats.numcro += (*scross)(*mom, *dad, child, 0);
51 | stats.nummut += child->mutate(pMutation());
52 | stats.numeval += 1;
53 |
54 | float d1 = child->compare(*mom); // replace closest parent
55 | float d2 = child->compare(*dad);
56 | if (d1 < d2) {
57 | if (minmax == MINIMIZE) {
58 | if (child->score() < mom->score()) {
59 | mom->copy(*child);
60 | stats.numrep += 1;
61 | }
62 | }
63 | else {
64 | if (child->score() > mom->score()) {
65 | mom->copy(*child);
66 | stats.numrep += 1;
67 | }
68 | }
69 | }
70 | else {
71 | if (minmax == MINIMIZE) {
72 | if (child->score() < dad->score()) {
73 | dad->copy(*child);
74 | stats.numrep += 1;
75 | }
76 | }
77 | else {
78 | if (child->score() > dad->score()) {
79 | dad->copy(*child);
80 | stats.numrep += 1;
81 | }
82 | }
83 | }
84 | } while (indpool.size()>1);
85 |
86 | pop->evaluate(gaTrue);
87 | stats.update(*pop);
88 |
89 | delete child;
90 | }
91 |
--------------------------------------------------------------------------------
/doc/References.html:
--------------------------------------------------------------------------------
1 | GAlib: References
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | Some genetic algorithm references...
11 |
12 |
13 | These are some of the more common references for those interested in genetic algorithms and genetic algorithms implementations.
14 |
15 |
16 |
17 | - Evolutionary Algorithms in Theory and Practice
18 |
19 | - T. Baeck, Oxford, NY, 1996
20 |
21 |
22 |
23 |
24 | - Handbook of Genetic Algorithms
25 |
26 | - Lawrence Davis (editor), Van Nostrand Reinholt, NY, 1991
27 |
28 |
29 |
30 |
31 | - Evolutionary Computation
32 |
33 | - D.B. Fogel, IEEE Press, NY, 1995
34 |
35 |
36 |
37 |
38 | - Genetic Algorithms in Search and Optimization
39 |
40 | - David Edward Goldberg, Addison-Wesley Pub. Co., 1989
41 |
- ISBN 0-201-15767-5
42 |
43 |
44 |
45 |
46 | - Adaptation in Natural and Artificial Systems, 2nd. Edition
47 |
48 | - J.H. Holland, MIT Press, Cambridge, MA, 1992
49 |
50 |
51 |
52 |
53 | - Genetic Programming
54 |
55 | - J. Koza, MIT Press, Cambridge, MA, 1992
56 |
57 |
58 |
59 |
60 | - Genetic Algorithms + Data Structures = Evolution Programs
61 |
62 | - Zbginew Michalewicz, Springer, Berlin, 1994
63 |
64 |
65 |
66 |
67 | - An Introduction to Genetic Algorithms
68 |
69 | - Melanie Mitchell, MIT Press, Cambridge, MA, 1996
70 |
71 |
72 |
73 |
74 | - Evolution and Optimum Seeking
75 |
76 | - H.-P. Schwefel, Wiley, NY, 1994
77 |
78 |
79 |
80 |
81 | - Numerical Recipes in C: The Art of Scientific Computing
82 |
83 | - Cambridge University Press, (c) 1988-1992
84 |
- ISBN 0-521-43108-5
85 |
86 |
87 |
88 |
89 | Matthew Wall, 20 March 1996
90 |
91 |
92 |
--------------------------------------------------------------------------------
/ga/GASimpleGA.h:
--------------------------------------------------------------------------------
1 | // $Header$
2 | /* ----------------------------------------------------------------------------
3 | gasimple.h
4 | mbwall 28jul94
5 | Copyright (c) 1995 Massachusetts Institute of Technology
6 | all rights reserved
7 |
8 | Header file for the simple genetic algorithm class.
9 | ---------------------------------------------------------------------------- */
10 | #ifndef _ga_gasimple_h_
11 | #define _ga_gasimple_h_
12 |
13 | #include
14 |
15 | class GASimpleGA : public GAGeneticAlgorithm {
16 | public:
17 | GADefineIdentity("GASimpleGA", GAID::SimpleGA);
18 |
19 | static GAParameterList& registerDefaultParameters(GAParameterList&);
20 |
21 | public:
22 | GASimpleGA(const GAGenome&);
23 | GASimpleGA(const GAPopulation&);
24 | GASimpleGA(const GASimpleGA&);
25 | GASimpleGA& operator=(const GASimpleGA&);
26 | virtual ~GASimpleGA();
27 | virtual void copy(const GAGeneticAlgorithm&);
28 |
29 | virtual void initialize(unsigned int seed=0);
30 | virtual void step();
31 | GASimpleGA & operator++() { step(); return *this; }
32 |
33 | virtual int setptr(const char* name, const void* value);
34 | virtual int get(const char* name, void* value) const;
35 |
36 | GABoolean elitist() const {return el;}
37 | GABoolean elitist(GABoolean flag)
38 | {params.set(gaNelitism, (int)flag); return el=flag;}
39 |
40 | virtual int minimaxi() const {return minmax;}
41 | virtual int minimaxi(int m);
42 |
43 | virtual const GAPopulation& population() const {return *pop;}
44 | virtual const GAPopulation& population(const GAPopulation&);
45 | virtual int populationSize() const {return pop->size();}
46 | virtual int populationSize(unsigned int n);
47 | virtual GAScalingScheme& scaling() const {return pop->scaling();}
48 | virtual GAScalingScheme& scaling(const GAScalingScheme & s)
49 | {oldPop->scaling(s); return GAGeneticAlgorithm::scaling(s);}
50 | virtual GASelectionScheme& selector() const {return pop->selector(); }
51 | virtual GASelectionScheme& selector(const GASelectionScheme& s)
52 | {oldPop->selector(s); return GAGeneticAlgorithm::selector(s);}
53 | virtual void objectiveFunction(GAGenome::Evaluator f);
54 | virtual void objectiveData(const GAEvalData& v);
55 |
56 | protected:
57 | GAPopulation *oldPop; // current and old populations
58 | GABoolean el; // are we elitist?
59 | };
60 |
61 |
62 |
63 | #ifdef GALIB_USE_STREAMS
64 | inline STD_OSTREAM & operator<< (STD_OSTREAM & os, GASimpleGA & arg)
65 | { arg.write(os); return(os); }
66 | inline STD_ISTREAM & operator>> (STD_ISTREAM & is, GASimpleGA & arg)
67 | { arg.read(is); return(is); }
68 | #endif
69 |
70 | #endif
71 |
--------------------------------------------------------------------------------
/README:
--------------------------------------------------------------------------------
1 | GAlib: A C++ Genetic Algorithm Library
2 | Copyright (c) 1994-1996 MIT, 1996-2005 Matthew Wall
3 |
4 | GAlib is a C++ library of genetic algorithm objects. With GAlib you can add
5 | evolutionary algorithm optimization to almost any program using any data
6 | representation and standard or custom selection, crossover, mutation,
7 | scaling, and termination methods.
8 |
9 | The library requires reasonable C++ compiler. I have tested GAlib on MacOS
10 | using Metrowerks and Symantec development environments, MacOSX using gcc2/3,
11 | DOS/Windows using Borland C++ and MS VC++, and various UNIX platforms using
12 | g++, egcs, CC, DCC, xlC, and aCC.
13 |
14 | Graphic examples (XWindows/Motif and MS Windows) are available, as are
15 | parallel, distributed implementations using PVM. There are about 30 examples
16 | that illustrate various ways to use GAlib on a variety of problems.
17 |
18 | WHERE TO GET IT ---------------------------------------------------------------
19 |
20 | http://lancet.mit.edu/ga
21 | ftp://lancet.mit.edu/pub/ga/
22 |
23 | COMPILATION -------------------------------------------------------------------
24 |
25 | There are two things to build: the library and the examples. Here is the
26 | short version of how to build and test everything:
27 |
28 | On unix,
29 |
30 | % make test
31 |
32 | On windows, with MS VC++,
33 |
34 | > nmake /f makefile.vcpp test
35 |
36 | On windows, with Borland,
37 |
38 | > make -f makefile.bcc test
39 |
40 | If that does not work, then here are the files you might have to modify:
41 |
42 | - ga/gaconfig.h - this contains the macros that control library options
43 | - makevars - compiler and linker options for each compilier/os
44 | - makefile - the actual build rules for putting everything together
45 |
46 | If you still have problems, look at Installation.html in the doc directory.
47 |
48 | DOCUMENTATION and MAILING LIST ------------------------------------------------
49 |
50 | Complete documentation in html format is available in the doc directory. The
51 | distribution site contains PDF and PostScript(tm) versions.
52 |
53 | A current list of bugs is at http://lancet.mit.edu/ga/Bugs.html
54 |
55 | There are two GAlib mailing lists: galib@mit.edu and galib-announce@mit.edu
56 | The first list is an unmoderated list intended as a forum for galib users to
57 | help each other. The second is only for announcements about GAlib updates.
58 | To subscribe, send email to galib-request@mit.edu (or galib-announce-request)
59 | with the word 'subscribe' as the subject and nothing in the body of the email.
60 | To unsubscribe, send email with the word 'unsubscribe' as the subject.
61 |
--------------------------------------------------------------------------------
/examples/pvmind/slave.C:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | slave.C
3 | mbwall 5dec95
4 | Copyright (c) 1995-1996 Massachusetts Institute of Technology
5 |
6 | DESCRIPTION:
7 | Example program to illustrate use of GAlib with PVM. This example uses a
8 | master-slave configuration to parallelize the genetic algorithm. In this case,
9 | the master controls the evolution and farms out the task of evaluating single
10 | genomes to each of the slaves.
11 | This is the slave component. We wait for messages from the master then act
12 | on the content. We expect two kinds of messages: initialize and evaluate.
13 | When we get an initialize request, we initialize our genome then send the data
14 | to the master process. When we get an evaluate request, we grab the data from
15 | the master then invoke the genome's evaluator on the new data, then send only
16 | the score to the master process. We can also receive a 'finished' message
17 | that tells us to shut down and exit.
18 | ---------------------------------------------------------------------------- */
19 | #include
20 | #include "genome.h"
21 |
22 | int
23 | main(int argc, char** argv) {
24 | if(argc > 1) {
25 | cerr << "\n" << argv[0] << ": This program takes no arguments.\n";
26 | exit(1);
27 | }
28 |
29 | int mytid = pvm_mytid();
30 | int masterid = pvm_parent();
31 | if(mytid < 0 || masterid < 0) {
32 | cerr << "\n" << argv[0] << ": Couldn't get slave/master IDs. Aborting.\n";
33 | exit(1);
34 | }
35 |
36 | // create the genome (we'll resize it later on)
37 | GARandomSeed();
38 | GA1DBinaryStringGenome genome(1);
39 | genome.evaluator(GenomeEvaluator);
40 | genome.initializer(GenomeInitializer);
41 |
42 | // send an "I'm ready" message then wait for instructions from the master
43 | SendReady(masterid);
44 |
45 | int done = 0;
46 | int status, bufid, bytes, msgtag, tid;
47 | while(!done){
48 | bufid = pvm_recv(masterid, -1);
49 | if(bufid >= 0) {
50 | status = pvm_bufinfo(bufid, &bytes, &msgtag, &tid);
51 | if(msgtag == MSG_DONE) {
52 | done = 1;
53 | }
54 | else if(msgtag == MSG_GENOME_DATA) {
55 | RecvGenomeData(genome);
56 | SendGenomeScore(genome, masterid);
57 | SendReady(masterid);
58 | }
59 | else if(msgtag == MSG_GENOME_INITIALIZE) {
60 | RecvGenomeInitialize(genome);
61 | SendGenomeData(genome, masterid);
62 | SendReady(masterid);
63 | }
64 | else {
65 | cerr << argv[0] << ": unknown msgtag: " << msgtag << "\n";
66 | }
67 | }
68 | else {
69 | cerr << argv[0] << ": error from pvm_recv: " << bufid << "\n";
70 | }
71 | }
72 |
73 | pvm_exit();
74 | return 0;
75 | }
76 |
--------------------------------------------------------------------------------
/ga/GAGenome.C:
--------------------------------------------------------------------------------
1 | // $Header$
2 | /* ----------------------------------------------------------------------------
3 | genome.C
4 | mbwall 19apr95
5 | Copyright (c) 1995 Massachusetts Institute of Technology
6 | all rights reserved
7 |
8 | DESCRIPTION:
9 | Definitions for genome base class. See the header file for complete
10 | documentation for deriving new classes. Comments here are implementation-
11 | specific details about base class member functions.
12 | ---------------------------------------------------------------------------- */
13 | #include
14 |
15 | // These are the default genome operators.
16 | // None does anything - they just post an error message to let you know that no
17 | // method has been defined. These are for the base class (which has no
18 | // function by itself).
19 | void
20 | GAGenome::NoInitializer(GAGenome & c){
21 | GAErr(GA_LOC, c.className(), "initializer", gaErrOpUndef);
22 | }
23 | int
24 | GAGenome::NoMutator(GAGenome & c, float){
25 | GAErr(GA_LOC, c.className(), "mutator", gaErrOpUndef); return 0;
26 | }
27 | float
28 | GAGenome::NoComparator(const GAGenome& c, const GAGenome&){
29 | GAErr(GA_LOC, c.className(), "comparator", gaErrOpUndef); return -1.0;
30 | }
31 |
32 |
33 |
34 | GAGenome::
35 | GAGenome(Initializer i, Mutator m, Comparator c){
36 | if(i==0) i=NoInitializer;
37 | if(m==0) m=NoMutator;
38 | if(c==0) c=NoComparator;
39 | _score=_fitness=0.0; _evaluated=gaFalse; _neval=0;
40 | ga=0; ud=0; eval=0; evd=0;
41 | init=i; mutr=m; cmp=c;
42 | sexcross = 0;
43 | asexcross = 0;
44 | }
45 |
46 | GAGenome::GAGenome(const GAGenome & orig){
47 | evd=0; _neval=0;
48 | GAGenome::copy(orig);
49 | }
50 |
51 | GAGenome::~GAGenome(){
52 | delete evd;
53 | }
54 |
55 | GAGenome*
56 | GAGenome::clone(CloneMethod) const {
57 | GAErr(GA_LOC, className(), "clone", gaErrOpUndef);
58 | return new GAGenome(*this);
59 | }
60 |
61 | // The eval count is not copied from the other genome - that would inflate the
62 | // count.
63 | void
64 | GAGenome::copy(const GAGenome & orig){
65 | if(&orig == this) return;
66 | _score=orig._score; _fitness=orig._fitness; _evaluated=orig._evaluated;
67 | ga=orig.ga; ud=orig.ud; eval=orig.eval;
68 | init=orig.init; mutr=orig.mutr; cmp=orig.cmp;
69 | sexcross=orig.sexcross; asexcross=orig.asexcross;
70 | _neval = 0;
71 |
72 | if(orig.evd){
73 | if(evd) evd->copy(*orig.evd);
74 | else evd = orig.evd->clone();
75 | } // don't delete if c doesn't have one
76 | }
77 |
78 |
79 | float
80 | GAGenome::evaluate(GABoolean flag) const {
81 | if(_evaluated == gaFalse || flag == gaTrue){
82 | GAGenome *This = (GAGenome*)this;
83 | if(eval){ This->_neval++; This->_score = (*eval)(*This); }
84 | This->_evaluated = gaTrue;
85 | }
86 | return _score;
87 | }
88 |
--------------------------------------------------------------------------------
/ga/GAStringGenome.h:
--------------------------------------------------------------------------------
1 | // $Header$
2 | /* ----------------------------------------------------------------------------
3 | string.h
4 | mbwall 25feb95
5 | Copyright (c) 1995 Massachusetts Institute of Technology
6 |
7 | DESCRIPTION:
8 | This header defines the interface for the string genome.
9 | ---------------------------------------------------------------------------- */
10 | #ifndef _ga_string_h_
11 | #define _ga_string_h_
12 |
13 | #include
14 | #include
15 |
16 | typedef GAAlleleSet GAStringAlleleSet;
17 | typedef GAAlleleSet GACharacterAlleleSet;
18 | typedef GAAlleleSetArray GAStringAlleleSetArray;
19 |
20 | typedef GA1DArrayAlleleGenome GAStringGenome;
21 |
22 | // in one (and only one) place in the code that uses the string genome, you
23 | // should define INSTANTIATE_STRING_GENOME in order to force the specialization
24 | // for this genome.
25 | #if defined(INSTANTIATE_STRING_GENOME)
26 | #include
27 | #endif
28 |
29 | inline void GAStringUniformInitializer(GAGenome& g){
30 | GA1DArrayAlleleGenome::UniformInitializer(g);
31 | }
32 | inline void GAStringOrderedInitializer(GAGenome& g){
33 | GA1DArrayAlleleGenome::OrderedInitializer(g);
34 | }
35 |
36 | inline int GAStringFlipMutator(GAGenome& g, float pmut){
37 | return GA1DArrayAlleleGenome::FlipMutator(g, pmut);
38 | }
39 | inline int GAStringSwapMutator(GAGenome& g, float pmut){
40 | return GA1DArrayGenome::SwapMutator(g, pmut);
41 | }
42 |
43 | inline int GAStringUniformCrossover(const GAGenome& a, const GAGenome& b,
44 | GAGenome* c, GAGenome* d) {
45 | return GA1DArrayGenome::UniformCrossover(a,b,c,d);
46 | }
47 | inline int GAStringEvenOddCrossover(const GAGenome& a, const GAGenome& b,
48 | GAGenome* c, GAGenome* d) {
49 | return GA1DArrayGenome::EvenOddCrossover(a,b,c,d);
50 | }
51 | inline int GAStringOnePointCrossover(const GAGenome& a, const GAGenome& b,
52 | GAGenome* c, GAGenome* d) {
53 | return GA1DArrayGenome::OnePointCrossover(a,b,c,d);
54 | }
55 | inline int GAStringTwoPointCrossover(const GAGenome& a, const GAGenome& b,
56 | GAGenome* c, GAGenome* d) {
57 | return GA1DArrayGenome::TwoPointCrossover(a,b,c,d);
58 | }
59 | inline int GAStringPartialMatchCrossover(const GAGenome& a, const GAGenome& b,
60 | GAGenome* c, GAGenome* d) {
61 | return GA1DArrayGenome::PartialMatchCrossover(a,b,c,d);
62 | }
63 | inline int GAStringOrderCrossover(const GAGenome& a, const GAGenome& b,
64 | GAGenome* c, GAGenome* d) {
65 | return GA1DArrayGenome::OrderCrossover(a,b,c,d);
66 | }
67 | inline int GAStringCycleCrossover(const GAGenome& a, const GAGenome& b,
68 | GAGenome* c, GAGenome* d) {
69 | return GA1DArrayGenome::CycleCrossover(a,b,c,d);
70 | }
71 |
72 | #endif
73 |
--------------------------------------------------------------------------------
/examples/gnu/bitstr.h:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | bitstr.h
3 | mbwall 13sep95
4 | Copyright 1995 Massachusetts Institute of Technology
5 |
6 | This code can be freely distributed and modified under the terms of the GNU
7 | public license. See the COPYING file for details.
8 |
9 | DESCRIPTION:
10 | Header file for the bitstring example. This code uses the BitString object
11 | from the GNU class library for the derivation of a new class of genomes. Here
12 | we define the genome and all of the basic operators that it needs to function.
13 | ---------------------------------------------------------------------------- */
14 | #ifndef _bitstr_h_
15 | #define _bitstr_h_
16 |
17 | #include
18 | #include "BitString.h"
19 |
20 | // This is the class definition for the BitString genome. It is derived from
21 | // the Genome class and the GNU BitString class. We define here only the
22 | // additional methods that we'll need in order to use it a genome in GAlib.
23 | // The identity definition is to take care of the polymorphic nature of
24 | // GAlib genomes. You can use any number above 200 when defining your own
25 | // genome type. Anything under 200 is reserved for use in GAlib internals.
26 | // I have defined a 'gene' method here as a convenience routine. It simply
27 | // calls the BitString's bit access member function to determine if a bit is
28 | // set or not. When you call 'gene' with a second argument, it sets the
29 | // specified bit in the bitstring.
30 | // Unlike the binary string genomes included in GAlib, this genome is not
31 | // resizable.
32 |
33 | class BitStringGenome : public GAGenome, public BitString {
34 | public:
35 | GADefineIdentity("BitStringGenome", 201);
36 | static void UniformInitializer(GAGenome&);
37 | static int UniformMutator(GAGenome&, float);
38 | static float Comparator(const GAGenome&, const GAGenome&);
39 | static int UniformCrossover(const GAGenome&, const GAGenome&,
40 | GAGenome*, GAGenome*);
41 | public:
42 | BitStringGenome(unsigned int x, GAGenome::Evaluator f=0, void * u=0);
43 | BitStringGenome(const BitStringGenome& orig) { copy(orig); }
44 | BitStringGenome& operator=(const GAGenome& orig)
45 | { copy(orig); return *this; }
46 | virtual ~BitStringGenome() {}
47 | virtual GAGenome *clone(GAGenome::CloneMethod) const;
48 | virtual void copy(const GAGenome&);
49 |
50 | int write (ostream& os) const { printon(os); return os.fail() ? 1 : 0; }
51 | int equal(const GAGenome & c) const {
52 | BitStringGenome & b = (BitStringGenome&)c;
53 | return ((BitString&)*this == (BitString&)b ? 1 : 0);
54 | }
55 |
56 | int gene(unsigned int x) const { return test(x); }
57 | int gene(unsigned int x, int b)
58 | { _evaluated = gaFalse; assign(x,b); return test(x); }
59 | };
60 |
61 |
62 | #endif
63 |
--------------------------------------------------------------------------------
/ga/GAListGenome.h:
--------------------------------------------------------------------------------
1 | // $Header$
2 | /* ----------------------------------------------------------------------------
3 | list.h
4 | mbwall 25feb95
5 | Copyright (c) 1995 Massachusetts Institute of Technology
6 | all rights reserved
7 |
8 | DESCRIPTION:
9 | This header defines the interface for the list genome.
10 | ---------------------------------------------------------------------------- */
11 | #ifndef _ga_list_h_
12 | #define _ga_list_h_
13 |
14 | #include
15 | #include
16 |
17 |
18 | /* ----------------------------------------------------------------------------
19 | ListGenome
20 | -------------------------------------------------------------------------------
21 | ---------------------------------------------------------------------------- */
22 | template
23 | class GAListGenome : public GAList, public GAGenome {
24 | public:
25 | GADeclareIdentity();
26 |
27 | static int DestructiveMutator(GAGenome &, float);
28 | static int SwapMutator(GAGenome &, float);
29 | static float NodeComparator(const GAGenome&, const GAGenome&);
30 | static int OnePointCrossover(const GAGenome&, const GAGenome&,
31 | GAGenome*, GAGenome*);
32 | static int PartialMatchCrossover(const GAGenome&, const GAGenome&,
33 | GAGenome*, GAGenome*);
34 | static int OrderCrossover(const GAGenome&, const GAGenome&,
35 | GAGenome*, GAGenome*);
36 | static int CycleCrossover(const GAGenome&, const GAGenome&,
37 | GAGenome*, GAGenome*);
38 |
39 | public:
40 | GAListGenome(GAGenome::Evaluator f=0, void * u=(void *)0);
41 | GAListGenome(const GAListGenome &);
42 | GAListGenome & operator=(const GAGenome & orig)
43 | {copy(orig); return *this;}
44 | virtual ~GAListGenome();
45 | virtual GAGenome *clone(GAGenome::CloneMethod flag=CONTENTS) const;
46 | virtual void copy(const GAGenome &);
47 |
48 | #ifdef GALIB_USE_STREAMS
49 | virtual int write (STD_OSTREAM &) const;
50 | #endif
51 |
52 | virtual int equal(const GAGenome & c) const;
53 |
54 | // Here we do inlined versions of the access members of the super class. We
55 | // do our own here so that we can set/unset the _evaluated flag appropriately.
56 |
57 | int destroy() { _evaluated = gaFalse; return GAList::destroy(); }
58 | int swap(unsigned int i, unsigned int j)
59 | { _evaluated = gaFalse; return GAList::swap(i,j); }
60 | T * remove() { _evaluated = gaFalse; return GAList::remove(); }
61 | int insert(GAList * t, GAListBASE::Location where=GAListBASE::AFTER)
62 | { _evaluated = gaFalse; return GAList::insert(t, where); }
63 | int insert(const T & t, GAListBASE::Location where=GAListBASE::AFTER)
64 | { _evaluated = gaFalse; return GAList::insert(t, where); }
65 | };
66 |
67 | #ifdef GALIB_USE_BORLAND_INST
68 | #include
69 | #endif
70 |
71 | #endif
72 |
--------------------------------------------------------------------------------
/examples/pvmpop/PVMDemeGA.h:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | PVMDemeGA.h
3 | mbwall jan96
4 | Copyright (c) 1995-1996 Massachusetts Institute of Technology
5 | all rights reserved
6 |
7 | Header for the deme (parallel population) genetic algorithm class.
8 | This genetic algorithm lets you specify a number of individuals to migrate
9 | from one population to another at the end of each generation. You can specify
10 | how many populations to maintain. Each population evolves using a steady-state
11 | genetic algorithm. At the end of each generation, the specified number of
12 | individuals migrate from one population to the next (we use the loop migration
13 | topology in this implementation).
14 | You can modify the migration method by deriving a new class from this one and
15 | redefine the migration method. If you want to use a different kind of genetic
16 | algorithm for each population then you'll have to modify the mechanics of the
17 | step method.
18 | ---------------------------------------------------------------------------- */
19 | #ifndef _PVMDemeGA_h_
20 | #define _PVMDemeGA_h_
21 |
22 | #include
23 | #include
24 |
25 | class PVMDemeGA : public GADemeGA {
26 | public:
27 | GADefineIdentity("PVMDemeGA", 238);
28 |
29 | PVMDemeGA(const GAGenome&);
30 | PVMDemeGA(const GAPopulation&);
31 | PVMDemeGA(const PVMDemeGA&);
32 | PVMDemeGA& operator=(const PVMDemeGA&);
33 | virtual ~PVMDemeGA();
34 | virtual void copy(const GAGeneticAlgorithm&);
35 |
36 | virtual void initialize(unsigned int seed=0);
37 | virtual void step();
38 | virtual void migrate();
39 | PVMDemeGA & operator++() { step(); return *this; }
40 |
41 | const GAPopulation& population(unsigned int i) const;
42 | const GAStatistics& statistics() const {return stats;}
43 | const GAStatistics& statistics(unsigned int i) const {return pstats[i];}
44 |
45 | public:
46 | int spawn(const char*);
47 | void reap();
48 | int status() const { return _status; }
49 |
50 | protected:
51 | int _mid; // id of the master task
52 | int *_tid; // id of each slave task
53 | int _ntid, _Ntid; // how many we have, how many we requested
54 | int _status; // status of last pvm function called
55 | int _nhosts; // number of hosts we can see
56 | int _narch; // number of architectures we can see
57 |
58 | int tid2idx(int) const;
59 | int ntasks() const { return _ntid; }
60 | int nreq() const { return _Ntid; }
61 | int collect();
62 | };
63 |
64 | #ifndef NO_STREAMS
65 | inline ostream & operator<< (ostream & os, PVMDemeGA & arg)
66 | {arg.write(os); return(os);}
67 | inline istream & operator>> (istream & is, PVMDemeGA & arg)
68 | {arg.read(is); return(is);}
69 | #endif
70 |
71 | #endif
72 |
--------------------------------------------------------------------------------
/ga/GABinStr.h:
--------------------------------------------------------------------------------
1 | // $Header$
2 | /* ----------------------------------------------------------------------------
3 | binstr.h
4 | mbwall 30jun95
5 | Copyright (c) 1995 Massachusetts Institute of Technology
6 |
7 | DESCRIPTION:
8 | This header defines the interface for the binary string. This is a crude
9 | version of a real bitstring object. We don't do real bitstring in the
10 | interest of speed and ease of coding this mess up.
11 |
12 | TO DO:
13 | we can get major improvements to speed by inlining functions and getting rid
14 | of the error checking... for example, inlining genome and removing the
15 | conditional makes it go from 7.5 seconds to 3.2 seconds (bm bl cs 1024 c 0.9)
16 | ---------------------------------------------------------------------------- */
17 | #ifndef _ga_binstr_h_
18 | #define _ga_binstr_h_
19 |
20 | #include
21 | #include
22 | #include
23 |
24 | #define GA_BINSTR_CHUNKSIZE 32 // size of the chunks of bits we allocate
25 |
26 |
27 | class GABinaryString {
28 | public:
29 | GABinaryString(unsigned int s){
30 | csz=GA_BINSTR_CHUNKSIZE; sz=0; SZ=0; data=(GABit *)0;
31 | resize(s);
32 | }
33 | GABinaryString(const GABinaryString& orig){
34 | sz=0; SZ=0; data=(GABit *)0;
35 | copy(orig);
36 | }
37 | virtual ~GABinaryString(){delete [] data;}
38 | void copy(const GABinaryString&);
39 | int resize(unsigned int); // pass desired size, in bits
40 | int size() const {return sz;}
41 |
42 | short bit(unsigned int a) const {
43 | return(data[a]);
44 | }
45 | short bit(unsigned int a, short val) { // set/unset the bit
46 | return(data[a] = (val ? 1 : 0));
47 | }
48 | int equal(const GABinaryString & b,
49 | unsigned int r, unsigned int x, unsigned int l) const {
50 | return(memcmp(&(data[r]),&(b.data[x]),l*sizeof(GABit))?0:1);
51 | }
52 | void copy(const GABinaryString & orig,
53 | unsigned int r, unsigned int x, unsigned int l){
54 | memcpy(&(data[r]), &(orig.data[x]), l*sizeof(GABit));
55 | }
56 | void move(unsigned int r, unsigned int x, unsigned int l){
57 | memmove(&(data[r]), &(data[x]), l*sizeof(GABit));
58 | }
59 | void set(unsigned int a, unsigned int l){
60 | memset(&(data[a]), 1, l*sizeof(GABit));
61 | }
62 | void unset(unsigned int a, unsigned int l){
63 | memset(&(data[a]), 0, l*sizeof(GABit));
64 | }
65 | void randomize(unsigned int a, unsigned int l){
66 | for(unsigned int i=0; i
14 |
15 | class GASteadyStateGA : public GAGeneticAlgorithm {
16 | public:
17 | GADefineIdentity("GASteadyStateGA", GAID::SteadyStateGA);
18 |
19 | static GAParameterList& registerDefaultParameters(GAParameterList&);
20 |
21 | public:
22 | GASteadyStateGA(const GAGenome&);
23 | GASteadyStateGA(const GAPopulation&);
24 | GASteadyStateGA(const GASteadyStateGA&);
25 | GASteadyStateGA& operator=(const GASteadyStateGA&);
26 | virtual ~GASteadyStateGA();
27 | virtual void copy(const GAGeneticAlgorithm&);
28 |
29 | virtual void initialize(unsigned int seed=0);
30 | virtual void step();
31 | GASteadyStateGA & operator++() { step(); return *this; }
32 |
33 | virtual int setptr(const char* name, const void* value);
34 | virtual int get(const char* name, void* value) const;
35 |
36 | virtual int minimaxi() const {return minmax;}
37 | virtual int minimaxi(int m);
38 |
39 | virtual const GAPopulation& population() const {return *pop;}
40 | virtual const GAPopulation& population(const GAPopulation&);
41 | virtual int populationSize() const {return pop->size();}
42 | virtual int populationSize(unsigned int n);
43 | virtual GAScalingScheme& scaling() const {return pop->scaling();}
44 | virtual GAScalingScheme& scaling(const GAScalingScheme & s)
45 | { /* tmpPop->scaling(s); */ return GAGeneticAlgorithm::scaling(s); }
46 | virtual GASelectionScheme& selector() const {return pop->selector(); }
47 | virtual GASelectionScheme& selector(const GASelectionScheme& s)
48 | { /* tmpPop->selector(s); */ return GAGeneticAlgorithm::selector(s); }
49 | virtual void objectiveFunction(GAGenome::Evaluator f);
50 | virtual void objectiveData(const GAEvalData& v);
51 |
52 | float pReplacement() const { return pRepl; }
53 | float pReplacement(float p);
54 | int nReplacement() const { return nRepl; }
55 | int nReplacement(unsigned int n);
56 |
57 | protected:
58 | GAPopulation *tmpPop; // temporary population for replacements
59 | float pRepl; // percentage of population to replace each gen
60 | unsigned int nRepl; // how many of each population to replace
61 | short which; // 0 if prepl, 1 if nrepl
62 | };
63 |
64 |
65 |
66 | #ifdef GALIB_USE_STREAMS
67 | inline STD_OSTREAM & operator<< (STD_OSTREAM & os, GASteadyStateGA & arg)
68 | { arg.write(os); return(os); }
69 | inline STD_ISTREAM & operator>> (STD_ISTREAM & is, GASteadyStateGA & arg)
70 | { arg.read(is); return(is); }
71 | #endif
72 |
73 | #endif
74 |
--------------------------------------------------------------------------------
/examples/gnu/AllocRing.cc:
--------------------------------------------------------------------------------
1 | // This may look like C code, but it is really -*- C++ -*-
2 | /*
3 | Copyright (C) 1989 Free Software Foundation
4 | written by Doug Lea (dl@rocky.oswego.edu)
5 |
6 | This file is part of the GNU C++ Library. This library is free
7 | software; you can redistribute it and/or modify it under the terms of
8 | the GNU Library General Public License as published by the Free
9 | Software Foundation; either version 2 of the License, or (at your
10 | option) any later version. This library is distributed in the hope
11 | that it will be useful, but WITHOUT ANY WARRANTY; without even the
12 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13 | PURPOSE. See the GNU Library General Public License for more details.
14 | You should have received a copy of the GNU Library General Public
15 | License along with this library; if not, write to the Free Software
16 | Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 | */
18 |
19 | #ifdef __GNUG__
20 | #pragma implementation
21 | #endif
22 | #include
23 | #include
24 | #include
25 |
26 | AllocRing::AllocRing(int max)
27 | :n(max), current(0), nodes(new AllocQNode[max])
28 | {
29 | for (int i = 0; i < n; ++i)
30 | {
31 | nodes[i].ptr = 0;
32 | nodes[i].sz = 0;
33 | }
34 | }
35 |
36 | int AllocRing::find(void* p)
37 | {
38 | if (p == 0) return -1;
39 |
40 | for (int i = 0; i < n; ++i)
41 | if (nodes[i].ptr == p)
42 | return i;
43 |
44 | return -1;
45 | }
46 |
47 |
48 | void AllocRing::clear()
49 | {
50 | for (int i = 0; i < n; ++i)
51 | {
52 | if (nodes[i].ptr != 0)
53 | {
54 | delete(nodes[i].ptr);
55 | nodes[i].ptr = 0;
56 | }
57 | nodes[i].sz = 0;
58 | }
59 | current = 0;
60 | }
61 |
62 |
63 | void AllocRing::free(void* p)
64 | {
65 | int idx = find(p);
66 | if (idx >= 0)
67 | {
68 | delete nodes[idx].ptr;
69 | nodes[idx].ptr = 0;
70 | }
71 | }
72 |
73 | AllocRing::~AllocRing()
74 | {
75 | clear();
76 | }
77 |
78 | int AllocRing::contains(void* p)
79 | {
80 | return find(p) >= 0;
81 | }
82 |
83 | static inline unsigned int good_size(unsigned int s)
84 | {
85 | unsigned int req = s + 4;
86 | unsigned int good = 8;
87 | while (good < req) good <<= 1;
88 | return good - 4;
89 | }
90 |
91 | void* AllocRing::alloc(int s)
92 | {
93 | unsigned int size = good_size(s);
94 |
95 | void* p;
96 | if (nodes[current].ptr != 0 &&
97 | nodes[current].sz >= int(size) &&
98 | nodes[current].sz < int(4 * size))
99 | p = nodes[current].ptr;
100 | else
101 | {
102 | if (nodes[current].ptr != 0) operator delete (nodes[current].ptr);
103 | p = operator new (size);
104 | nodes[current].ptr = p;
105 | nodes[current].sz = size;
106 | }
107 | ++current;
108 | if (current >= n) current = 0;
109 | return p;
110 | }
111 |
--------------------------------------------------------------------------------
/examples/results/test_stats-irix.txt:
--------------------------------------------------------------------------------
1 | IRIX64 sirene 6.5 10120733 IP30
2 |
3 | randtest
4 | start: Tue Dec 28 21:07:58 EST 2004
5 | finish: Tue Dec 28 21:07:59 EST 2004
6 |
7 | ex1
8 | start: Tue Dec 28 21:07:59 EST 2004
9 | finish: Tue Dec 28 21:08:01 EST 2004
10 |
11 | ex2
12 | start: Tue Dec 28 21:08:01 EST 2004
13 | finish: Tue Dec 28 21:08:01 EST 2004
14 |
15 | ex3
16 | start: Tue Dec 28 21:08:01 EST 2004
17 | finish: Tue Dec 28 21:08:05 EST 2004
18 |
19 | ex4
20 | start: Tue Dec 28 21:08:05 EST 2004
21 | finish: Tue Dec 28 21:08:08 EST 2004
22 |
23 | ex5
24 | start: Tue Dec 28 21:08:08 EST 2004
25 | finish: Tue Dec 28 21:08:14 EST 2004
26 |
27 | ex6
28 | start: Tue Dec 28 21:08:14 EST 2004
29 | finish: Tue Dec 28 21:08:53 EST 2004
30 |
31 | ex7
32 | start: Tue Dec 28 21:08:53 EST 2004
33 | finish: Tue Dec 28 21:08:55 EST 2004
34 |
35 | ex8
36 | start: Tue Dec 28 21:08:55 EST 2004
37 | finish: Tue Dec 28 21:08:55 EST 2004
38 |
39 | ex9
40 | start: Tue Dec 28 21:08:55 EST 2004
41 | finish: Tue Dec 28 21:08:55 EST 2004
42 |
43 | ex10
44 | start: Tue Dec 28 21:08:55 EST 2004
45 | finish: Tue Dec 28 21:09:07 EST 2004
46 |
47 | ex11
48 | start: Tue Dec 28 21:09:07 EST 2004
49 | finish: Tue Dec 28 21:09:10 EST 2004
50 |
51 | ex12
52 | start: Tue Dec 28 21:09:10 EST 2004
53 | finish: Tue Dec 28 21:09:15 EST 2004
54 |
55 | ex13
56 | start: Tue Dec 28 21:09:15 EST 2004
57 | finish: Tue Dec 28 21:09:16 EST 2004
58 |
59 | ex14
60 | start: Tue Dec 28 21:09:16 EST 2004
61 | finish: Tue Dec 28 21:09:18 EST 2004
62 |
63 | ex15
64 | start: Tue Dec 28 21:09:18 EST 2004
65 | finish: Tue Dec 28 21:09:18 EST 2004
66 |
67 | ex16
68 | start: Tue Dec 28 21:09:18 EST 2004
69 | finish: Tue Dec 28 21:09:19 EST 2004
70 |
71 | ex17
72 | start: Tue Dec 28 21:09:19 EST 2004
73 | finish: Tue Dec 28 21:10:25 EST 2004
74 |
75 | ex18
76 | start: Tue Dec 28 21:10:25 EST 2004
77 | finish: Tue Dec 28 21:10:30 EST 2004
78 |
79 | ex19
80 | start: Tue Dec 28 21:10:30 EST 2004
81 | finish: Tue Dec 28 21:10:30 EST 2004
82 |
83 | ex20
84 | start: Tue Dec 28 21:10:30 EST 2004
85 | finish: Tue Dec 28 21:24:53 EST 2004
86 |
87 | ex21
88 | start: Tue Dec 28 21:24:53 EST 2004
89 | finish: Tue Dec 28 21:25:00 EST 2004
90 |
91 | ex22
92 | start: Tue Dec 28 21:25:00 EST 2004
93 | finish: Tue Dec 28 21:25:13 EST 2004
94 |
95 | ex23
96 | start: Tue Dec 28 21:25:13 EST 2004
97 | finish: Tue Dec 28 21:25:13 EST 2004
98 |
99 | ex24
100 | start: Tue Dec 28 21:25:13 EST 2004
101 | finish: Tue Dec 28 21:25:13 EST 2004
102 |
103 | ex25
104 | start: Tue Dec 28 21:25:13 EST 2004
105 | finish: Tue Dec 28 21:25:14 EST 2004
106 |
107 | ex26
108 | start: Tue Dec 28 21:25:14 EST 2004
109 | finish: Tue Dec 28 21:25:58 EST 2004
110 |
111 | ex27
112 | start: Tue Dec 28 21:25:58 EST 2004
113 | finish: Tue Dec 28 21:25:58 EST 2004
114 |
115 |
--------------------------------------------------------------------------------
/examples/results/test_stats-hpux11.txt:
--------------------------------------------------------------------------------
1 | hp visualize c240
2 |
3 | HP-UX testouri B.11.00 A 9000/782 2008476391 two-user license
4 |
5 | randtest
6 | start: Tue Dec 28 17:36:31 EST 2004
7 | finish: Tue Dec 28 17:36:35 EST 2004
8 |
9 | ex1
10 | start: Tue Dec 28 17:36:35 EST 2004
11 | finish: Tue Dec 28 17:36:38 EST 2004
12 |
13 | ex2
14 | start: Tue Dec 28 17:36:38 EST 2004
15 | finish: Tue Dec 28 17:36:38 EST 2004
16 |
17 | ex3
18 | start: Tue Dec 28 17:36:38 EST 2004
19 | finish: Tue Dec 28 17:36:49 EST 2004
20 |
21 | ex4
22 | start: Tue Dec 28 17:36:49 EST 2004
23 | finish: Tue Dec 28 17:36:56 EST 2004
24 |
25 | ex5
26 | start: Tue Dec 28 17:36:56 EST 2004
27 | finish: Tue Dec 28 17:37:05 EST 2004
28 |
29 | ex6
30 | start: Tue Dec 28 17:37:05 EST 2004
31 | finish: Tue Dec 28 17:37:58 EST 2004
32 |
33 | ex7
34 | start: Tue Dec 28 17:37:58 EST 2004
35 | finish: Tue Dec 28 17:38:03 EST 2004
36 |
37 | ex8
38 | start: Tue Dec 28 17:38:03 EST 2004
39 | finish: Tue Dec 28 17:38:03 EST 2004
40 |
41 | ex9
42 | start: Tue Dec 28 17:38:03 EST 2004
43 | finish: Tue Dec 28 17:38:04 EST 2004
44 |
45 | ex10
46 | start: Tue Dec 28 17:38:04 EST 2004
47 | finish: Tue Dec 28 17:38:16 EST 2004
48 |
49 | ex11
50 | start: Tue Dec 28 17:38:16 EST 2004
51 | finish: Tue Dec 28 17:38:20 EST 2004
52 |
53 | ex12
54 | start: Tue Dec 28 17:38:20 EST 2004
55 | finish: Tue Dec 28 17:38:27 EST 2004
56 |
57 | ex13
58 | start: Tue Dec 28 17:38:27 EST 2004
59 | finish: Tue Dec 28 17:38:28 EST 2004
60 |
61 | ex14
62 | start: Tue Dec 28 17:38:28 EST 2004
63 | finish: Tue Dec 28 17:38:32 EST 2004
64 |
65 | ex15
66 | start: Tue Dec 28 17:38:32 EST 2004
67 | finish: Tue Dec 28 17:38:32 EST 2004
68 |
69 | ex16
70 | start: Tue Dec 28 17:38:33 EST 2004
71 | finish: Tue Dec 28 17:38:33 EST 2004
72 |
73 | ex17
74 | start: Tue Dec 28 17:38:33 EST 2004
75 | finish: Tue Dec 28 17:41:14 EST 2004
76 |
77 | ex18
78 | start: Tue Dec 28 17:41:14 EST 2004
79 | finish: Tue Dec 28 17:41:25 EST 2004
80 |
81 | ex19
82 | start: Tue Dec 28 17:41:25 EST 2004
83 | finish: Tue Dec 28 17:41:26 EST 2004
84 |
85 | ex20
86 | start: Tue Dec 28 17:41:26 EST 2004
87 | finish: Tue Dec 28 18:18:34 EST 2004
88 |
89 | ex21
90 | start: Tue Dec 28 18:18:34 EST 2004
91 | finish: Tue Dec 28 18:18:44 EST 2004
92 |
93 | ex22
94 | start: Tue Dec 28 18:18:44 EST 2004
95 | finish: Tue Dec 28 18:19:09 EST 2004
96 |
97 | ex23
98 | start: Tue Dec 28 18:19:09 EST 2004
99 | finish: Tue Dec 28 18:19:09 EST 2004
100 |
101 | ex24
102 | start: Tue Dec 28 18:19:09 EST 2004
103 | finish: Tue Dec 28 18:19:10 EST 2004
104 |
105 | ex25
106 | start: Tue Dec 28 18:19:10 EST 2004
107 | finish: Tue Dec 28 18:19:12 EST 2004
108 |
109 | ex26
110 | start: Tue Dec 28 18:19:12 EST 2004
111 | finish: Tue Dec 28 18:20:17 EST 2004
112 |
113 | ex27
114 | start: Tue Dec 28 18:20:17 EST 2004
115 | finish: Tue Dec 28 18:20:17 EST 2004
116 |
117 |
--------------------------------------------------------------------------------
/examples/results/test_stats-cygwin-x86.txt:
--------------------------------------------------------------------------------
1 | 900MHz athlon win2k
2 |
3 | CYGWIN_NT-5.0 panela 1.5.12(0.116/4/2) 2004-11-10 08:34 i686 unknown unknown Cygwin
4 |
5 | randtest
6 | start: Tue Dec 28 19:14:16 EST 2004
7 | finish: Tue Dec 28 19:14:18 EST 2004
8 |
9 | ex1
10 | start: Tue Dec 28 19:14:18 EST 2004
11 | finish: Tue Dec 28 19:14:19 EST 2004
12 |
13 | ex2
14 | start: Tue Dec 28 19:14:19 EST 2004
15 | finish: Tue Dec 28 19:14:20 EST 2004
16 |
17 | ex3
18 | start: Tue Dec 28 19:14:20 EST 2004
19 | finish: Tue Dec 28 19:14:22 EST 2004
20 |
21 | ex4
22 | start: Tue Dec 28 19:14:22 EST 2004
23 | finish: Tue Dec 28 19:14:23 EST 2004
24 |
25 | ex5
26 | start: Tue Dec 28 19:14:23 EST 2004
27 | finish: Tue Dec 28 19:14:25 EST 2004
28 |
29 | ex6
30 | start: Tue Dec 28 19:14:25 EST 2004
31 | finish: Tue Dec 28 19:14:53 EST 2004
32 |
33 | ex7
34 | start: Tue Dec 28 19:14:53 EST 2004
35 | finish: Tue Dec 28 19:14:53 EST 2004
36 |
37 | ex8
38 | start: Tue Dec 28 19:14:53 EST 2004
39 | finish: Tue Dec 28 19:14:54 EST 2004
40 |
41 | ex9
42 | start: Tue Dec 28 19:14:54 EST 2004
43 | finish: Tue Dec 28 19:14:54 EST 2004
44 |
45 | ex10
46 | start: Tue Dec 28 19:14:54 EST 2004
47 | finish: Tue Dec 28 19:14:57 EST 2004
48 |
49 | ex11
50 | start: Tue Dec 28 19:14:57 EST 2004
51 | finish: Tue Dec 28 19:14:59 EST 2004
52 |
53 | ex12
54 | start: Tue Dec 28 19:14:59 EST 2004
55 | finish: Tue Dec 28 19:15:00 EST 2004
56 |
57 | ex13
58 | start: Tue Dec 28 19:15:00 EST 2004
59 | finish: Tue Dec 28 19:15:01 EST 2004
60 |
61 | ex14
62 | start: Tue Dec 28 19:15:01 EST 2004
63 | finish: Tue Dec 28 19:15:02 EST 2004
64 |
65 | ex15
66 | start: Tue Dec 28 19:15:02 EST 2004
67 | finish: Tue Dec 28 19:15:03 EST 2004
68 |
69 | ex16
70 | start: Tue Dec 28 19:15:03 EST 2004
71 | finish: Tue Dec 28 19:15:03 EST 2004
72 |
73 | ex17
74 | start: Tue Dec 28 19:15:03 EST 2004
75 | finish: Tue Dec 28 19:15:16 EST 2004
76 |
77 | ex18
78 | start: Tue Dec 28 19:15:16 EST 2004
79 | finish: Tue Dec 28 19:15:17 EST 2004
80 |
81 | ex19
82 | start: Tue Dec 28 19:15:17 EST 2004
83 | finish: Tue Dec 28 19:15:18 EST 2004
84 |
85 | ex20
86 | start: Tue Dec 28 19:15:18 EST 2004
87 | finish: Tue Dec 28 19:18:08 EST 2004
88 |
89 | ex21
90 | start: Tue Dec 28 19:18:08 EST 2004
91 | finish: Tue Dec 28 19:18:10 EST 2004
92 |
93 | ex22
94 | start: Tue Dec 28 19:18:10 EST 2004
95 | finish: Tue Dec 28 19:18:15 EST 2004
96 |
97 | ex23
98 | start: Tue Dec 28 19:18:15 EST 2004
99 | finish: Tue Dec 28 19:18:15 EST 2004
100 |
101 | ex24
102 | start: Tue Dec 28 19:18:15 EST 2004
103 | finish: Tue Dec 28 19:18:16 EST 2004
104 |
105 | ex25
106 | start: Tue Dec 28 19:18:16 EST 2004
107 | finish: Tue Dec 28 19:18:16 EST 2004
108 |
109 | ex26
110 | start: Tue Dec 28 19:18:16 EST 2004
111 | finish: Tue Dec 28 19:18:52 EST 2004
112 |
113 | ex27
114 | start: Tue Dec 28 19:18:52 EST 2004
115 | finish: Tue Dec 28 19:18:53 EST 2004
116 |
117 |
--------------------------------------------------------------------------------
/examples/results/test_stats-linux-x86.txt:
--------------------------------------------------------------------------------
1 | intel dual 800MHz P3
2 |
3 | Linux manur 2.6.5-1.358smp #1 SMP Sat May 8 09:25:36 EDT 2004 i686 i686 i386 GNU/Linux
4 |
5 | randtest
6 | start: Tue Dec 28 18:35:53 EST 2004
7 | finish: Tue Dec 28 18:35:54 EST 2004
8 |
9 | ex1
10 | start: Tue Dec 28 18:35:54 EST 2004
11 | finish: Tue Dec 28 18:35:55 EST 2004
12 |
13 | ex2
14 | start: Tue Dec 28 18:35:55 EST 2004
15 | finish: Tue Dec 28 18:35:55 EST 2004
16 |
17 | ex3
18 | start: Tue Dec 28 18:35:55 EST 2004
19 | finish: Tue Dec 28 18:35:56 EST 2004
20 |
21 | ex4
22 | start: Tue Dec 28 18:35:56 EST 2004
23 | finish: Tue Dec 28 18:35:57 EST 2004
24 |
25 | ex5
26 | start: Tue Dec 28 18:35:57 EST 2004
27 | finish: Tue Dec 28 18:35:58 EST 2004
28 |
29 | ex6
30 | start: Tue Dec 28 18:35:58 EST 2004
31 | finish: Tue Dec 28 18:36:10 EST 2004
32 |
33 | ex7
34 | start: Tue Dec 28 18:36:10 EST 2004
35 | finish: Tue Dec 28 18:36:11 EST 2004
36 |
37 | ex8
38 | start: Tue Dec 28 18:36:11 EST 2004
39 | finish: Tue Dec 28 18:36:11 EST 2004
40 |
41 | ex9
42 | start: Tue Dec 28 18:36:11 EST 2004
43 | finish: Tue Dec 28 18:36:11 EST 2004
44 |
45 | ex10
46 | start: Tue Dec 28 18:36:11 EST 2004
47 | finish: Tue Dec 28 18:36:14 EST 2004
48 |
49 | ex11
50 | start: Tue Dec 28 18:36:14 EST 2004
51 | finish: Tue Dec 28 18:36:14 EST 2004
52 |
53 | ex12
54 | start: Tue Dec 28 18:36:14 EST 2004
55 | finish: Tue Dec 28 18:36:16 EST 2004
56 |
57 | ex13
58 | start: Tue Dec 28 18:36:16 EST 2004
59 | finish: Tue Dec 28 18:36:16 EST 2004
60 |
61 | ex14
62 | start: Tue Dec 28 18:36:16 EST 2004
63 | finish: Tue Dec 28 18:36:17 EST 2004
64 |
65 | ex15
66 | start: Tue Dec 28 18:36:17 EST 2004
67 | finish: Tue Dec 28 18:36:17 EST 2004
68 |
69 | ex16
70 | start: Tue Dec 28 18:36:17 EST 2004
71 | finish: Tue Dec 28 18:36:17 EST 2004
72 |
73 | ex17
74 | start: Tue Dec 28 18:36:17 EST 2004
75 | finish: Tue Dec 28 18:36:33 EST 2004
76 |
77 | ex18
78 | start: Tue Dec 28 18:36:33 EST 2004
79 | finish: Tue Dec 28 18:36:34 EST 2004
80 |
81 | ex19
82 | start: Tue Dec 28 18:36:34 EST 2004
83 | finish: Tue Dec 28 18:36:34 EST 2004
84 |
85 | ex20
86 | start: Tue Dec 28 18:36:34 EST 2004
87 | finish: Tue Dec 28 18:40:23 EST 2004
88 |
89 | ex21
90 | start: Tue Dec 28 18:40:23 EST 2004
91 | finish: Tue Dec 28 18:40:24 EST 2004
92 |
93 | ex22
94 | start: Tue Dec 28 18:40:24 EST 2004
95 | finish: Tue Dec 28 18:40:28 EST 2004
96 |
97 | ex23
98 | start: Tue Dec 28 18:40:28 EST 2004
99 | finish: Tue Dec 28 18:40:29 EST 2004
100 |
101 | ex24
102 | start: Tue Dec 28 18:40:29 EST 2004
103 | finish: Tue Dec 28 18:40:29 EST 2004
104 |
105 | ex25
106 | start: Tue Dec 28 18:40:29 EST 2004
107 | finish: Tue Dec 28 18:40:29 EST 2004
108 |
109 | ex26
110 | start: Tue Dec 28 18:40:29 EST 2004
111 | finish: Tue Dec 28 18:40:40 EST 2004
112 |
113 | ex27
114 | start: Tue Dec 28 18:40:40 EST 2004
115 | finish: Tue Dec 28 18:40:40 EST 2004
116 |
117 |
--------------------------------------------------------------------------------
/examples/results/test_stats-linux-ppc.txt:
--------------------------------------------------------------------------------
1 | powermac g3 400MHz yellow dog linux 3
2 |
3 | Linux gammelost 2.4.22-2f #1 Sun Nov 9 16:49:49 EST 2003 ppc ppc ppc GNU/Linux
4 |
5 | randtest
6 | start: Tue Dec 28 22:52:17 EST 2004
7 | finish: Tue Dec 28 22:52:18 EST 2004
8 |
9 | ex1
10 | start: Tue Dec 28 22:52:18 EST 2004
11 | finish: Tue Dec 28 22:52:19 EST 2004
12 |
13 | ex2
14 | start: Tue Dec 28 22:52:19 EST 2004
15 | finish: Tue Dec 28 22:52:19 EST 2004
16 |
17 | ex3
18 | start: Tue Dec 28 22:52:19 EST 2004
19 | finish: Tue Dec 28 22:52:21 EST 2004
20 |
21 | ex4
22 | start: Tue Dec 28 22:52:21 EST 2004
23 | finish: Tue Dec 28 22:52:23 EST 2004
24 |
25 | ex5
26 | start: Tue Dec 28 22:52:23 EST 2004
27 | finish: Tue Dec 28 22:52:26 EST 2004
28 |
29 | ex6
30 | start: Tue Dec 28 22:52:26 EST 2004
31 | finish: Tue Dec 28 22:52:54 EST 2004
32 |
33 | ex7
34 | start: Tue Dec 28 22:52:54 EST 2004
35 | finish: Tue Dec 28 22:52:55 EST 2004
36 |
37 | ex8
38 | start: Tue Dec 28 22:52:55 EST 2004
39 | finish: Tue Dec 28 22:52:55 EST 2004
40 |
41 | ex9
42 | start: Tue Dec 28 22:52:55 EST 2004
43 | finish: Tue Dec 28 22:52:56 EST 2004
44 |
45 | ex10
46 | start: Tue Dec 28 22:52:56 EST 2004
47 | finish: Tue Dec 28 22:53:03 EST 2004
48 |
49 | ex11
50 | start: Tue Dec 28 22:53:03 EST 2004
51 | finish: Tue Dec 28 22:53:05 EST 2004
52 |
53 | ex12
54 | start: Tue Dec 28 22:53:05 EST 2004
55 | finish: Tue Dec 28 22:53:07 EST 2004
56 |
57 | ex13
58 | start: Tue Dec 28 22:53:07 EST 2004
59 | finish: Tue Dec 28 22:53:08 EST 2004
60 |
61 | ex14
62 | start: Tue Dec 28 22:53:08 EST 2004
63 | finish: Tue Dec 28 22:53:09 EST 2004
64 |
65 | ex15
66 | start: Tue Dec 28 22:53:09 EST 2004
67 | finish: Tue Dec 28 22:53:10 EST 2004
68 |
69 | ex16
70 | start: Tue Dec 28 22:53:10 EST 2004
71 | finish: Tue Dec 28 22:53:10 EST 2004
72 |
73 | ex17
74 | start: Tue Dec 28 22:53:10 EST 2004
75 | finish: Tue Dec 28 22:53:43 EST 2004
76 |
77 | ex18
78 | start: Tue Dec 28 22:53:43 EST 2004
79 | finish: Tue Dec 28 22:53:45 EST 2004
80 |
81 | ex19
82 | start: Tue Dec 28 22:53:45 EST 2004
83 | finish: Tue Dec 28 22:53:46 EST 2004
84 |
85 | ex20
86 | start: Tue Dec 28 22:53:46 EST 2004
87 | finish: Tue Dec 28 23:01:15 EST 2004
88 |
89 | ex21
90 | start: Tue Dec 28 23:01:15 EST 2004
91 | finish: Tue Dec 28 23:01:19 EST 2004
92 |
93 | ex22
94 | start: Tue Dec 28 23:01:19 EST 2004
95 | finish: Tue Dec 28 23:01:29 EST 2004
96 |
97 | ex23
98 | start: Tue Dec 28 23:01:29 EST 2004
99 | finish: Tue Dec 28 23:01:29 EST 2004
100 |
101 | ex24
102 | start: Tue Dec 28 23:01:29 EST 2004
103 | finish: Tue Dec 28 23:01:29 EST 2004
104 |
105 | ex25
106 | start: Tue Dec 28 23:01:29 EST 2004
107 | finish: Tue Dec 28 23:01:30 EST 2004
108 |
109 | ex26
110 | start: Tue Dec 28 23:01:30 EST 2004
111 | finish: Tue Dec 28 23:01:54 EST 2004
112 |
113 | ex27
114 | start: Tue Dec 28 23:01:54 EST 2004
115 | finish: Tue Dec 28 23:01:55 EST 2004
116 |
117 |
--------------------------------------------------------------------------------
/doc/GAlib.html:
--------------------------------------------------------------------------------
1 | GAlib: Matthew's C++ Genetic Algorithms Library
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 | GAlib Documentation
11 | version 2.4
12 |
13 |
14 | GAlib is a set of C++ genetic algorithm objects. The library includes tools for using genetic algorithms to do optimization in any C++ program. This documentation includes:
15 |
16 | installation instructions
17 | overview of the GAlib implementation and programming techniques
18 | class hierarchy of GAlib objects
19 | programming interface for using GAlib classes
20 | instructions for deriving new classes and genetic operators
21 | descriptions of the examples
22 | list of features
23 | other genetic algorithm sites
24 |
25 |
26 |
27 |
28 |
29 | For the most recent GAlib developments, please refer to http://lancet.mit.edu/ga/
30 |
31 | change history
32 | bug list
33 | frequently asked questions
34 | mailing list archive
35 |
36 |
37 |
38 |
39 |
40 | There are two mailing lists to which you may subscribe:
41 |
42 |
43 | - galib@mit.edu
44 |
- This is an unmoderated mailing list for GAlib users. If you have found use for GAlib and would like to let other users know about it, or if you're having problems with GAlib, post it to this mailing list and one of the other subscribers just might be able to help you out. I read all messages that are posted to this list, but I cannot respond to every one.
45 |
46 |
47 | - galib-announce@mit.edu
48 |
- This mailing list is for announcements about updates to GAlib. The only messages sent to recipients of this list are announcements from me about revisions to GAlib. This typically amounts to about one or two emails per year.
49 |
50 |
51 | To subscribe, send email to galib-request@mit.edu with the word subscribe as the subject. To unsubscribe, send email with the word unsubscribe as the subject.
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | Copyright (c) Massachusetts Institute of Technology and Matthew Wall. All rights reserved.
61 |
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/ga/GATreeGenome.h:
--------------------------------------------------------------------------------
1 | // $Header$
2 | /* ----------------------------------------------------------------------------
3 | tree.h
4 | mbwall 25feb95
5 | Copyright (c) 1995 Massachusetts Institute of Technology
6 | all rights reserved
7 |
8 | DESCRIPTION:
9 | This header defines the interface for the tree genome.
10 | ---------------------------------------------------------------------------- */
11 | #ifndef _ga_tree_h_
12 | #define _ga_tree_h_
13 |
14 | #include
15 | #include
16 |
17 |
18 | /* ----------------------------------------------------------------------------
19 | TreeGenome
20 | -------------------------------------------------------------------------------
21 | Beware that the tree genome can grow unbounded - there is no size limit
22 | on the tree, so if you have an objective function that encourages size the tree
23 | will grow until you run out of memory.
24 | ---------------------------------------------------------------------------- */
25 | template
26 | class GATreeGenome : public GATree, public GAGenome {
27 | public:
28 | GADeclareIdentity();
29 |
30 | static int DestructiveMutator(GAGenome &, float);
31 | static int SwapNodeMutator(GAGenome &, float);
32 | static int SwapSubtreeMutator(GAGenome &, float);
33 | static int OnePointCrossover(const GAGenome&, const GAGenome&,
34 | GAGenome*, GAGenome*);
35 | static float TopologyComparator(const GAGenome&, const GAGenome&);
36 | // static float NodeComparator(const GAGenome&, const GAGenome&);
37 |
38 | public:
39 | GATreeGenome(GAGenome::Evaluator f=NULL, void * u=NULL);
40 | GATreeGenome(const GATreeGenome &);
41 | GATreeGenome & operator=(const GAGenome & orig)
42 | {copy(orig); return *this;}
43 | virtual ~GATreeGenome();
44 | virtual GAGenome *clone(GAGenome::CloneMethod flag=CONTENTS) const;
45 | virtual void copy(const GAGenome &);
46 |
47 | #ifdef GALIB_USE_STREAMS
48 | virtual int write (STD_OSTREAM &) const;
49 | #endif
50 |
51 | virtual int equal(const GAGenome & c) const;
52 |
53 | // Here we do inlined versions of the access members of the super class. We
54 | // do our own here so that we can set/unset the _evaluated flag appropriately.
55 |
56 | int destroy() { _evaluated = gaFalse; return GATree::destroy(); }
57 | int swaptree(GATree * t)
58 | { _evaluated = gaFalse; return GATree::swaptree(t); }
59 | int swaptree(unsigned int i, unsigned int j)
60 | { _evaluated = gaFalse; return GATree::swaptree(i,j); }
61 | int swap(unsigned int i, unsigned int j)
62 | { _evaluated = gaFalse; return GATree::swap(i,j); }
63 | GATree * remove() { _evaluated = gaFalse; return GATree::remove(); }
64 | int insert(GATree * t, GATreeBASE::Location where=GATreeBASE::BELOW)
65 | { _evaluated = gaFalse; return GATree::insert(t, where); }
66 | int insert(const T & t, GATreeBASE::Location where=GATreeBASE::BELOW)
67 | { _evaluated = gaFalse; return GATree::insert(t, where); }
68 | };
69 |
70 | #ifdef GALIB_USE_BORLAND_INST
71 | #include
72 | #endif
73 |
74 | #endif
75 |
--------------------------------------------------------------------------------
/examples/results/test_stats-macosx-gcc2.txt:
--------------------------------------------------------------------------------
1 | powerbook g4 1.3GHz 1.3G ram
2 |
3 | Darwin gouda.local 7.7.0 Darwin Kernel Version 7.7.0: Sun Nov 7 16:06:51 PST 2004; root:xnu/xnu-517.9.5.obj~1/RELEASE_PPC Power Macintosh powerpc
4 |
5 | randtest
6 | start: Tue Dec 28 17:47:40 EST 2004
7 | finish: Tue Dec 28 17:47:41 EST 2004
8 |
9 | ex1
10 | start: Tue Dec 28 17:47:41 EST 2004
11 | finish: Tue Dec 28 17:47:41 EST 2004
12 |
13 | ex2
14 | start: Tue Dec 28 17:47:41 EST 2004
15 | finish: Tue Dec 28 17:47:41 EST 2004
16 |
17 | ex3
18 | start: Tue Dec 28 17:47:41 EST 2004
19 | finish: Tue Dec 28 17:47:43 EST 2004
20 |
21 | ex4
22 | start: Tue Dec 28 17:47:43 EST 2004
23 | finish: Tue Dec 28 17:47:43 EST 2004
24 |
25 | ex5
26 | start: Tue Dec 28 17:47:43 EST 2004
27 | finish: Tue Dec 28 17:47:45 EST 2004
28 |
29 | ex6
30 | start: Tue Dec 28 17:47:45 EST 2004
31 | finish: Tue Dec 28 17:47:58 EST 2004
32 |
33 | ex7
34 | start: Tue Dec 28 17:47:58 EST 2004
35 | finish: Tue Dec 28 17:47:58 EST 2004
36 |
37 | ex8
38 | start: Tue Dec 28 17:47:58 EST 2004
39 | finish: Tue Dec 28 17:47:58 EST 2004
40 |
41 | ex9
42 | start: Tue Dec 28 17:47:58 EST 2004
43 | finish: Tue Dec 28 17:47:59 EST 2004
44 |
45 | ex10
46 | start: Tue Dec 28 17:47:59 EST 2004
47 | finish: Tue Dec 28 17:48:02 EST 2004
48 |
49 | ex11
50 | start: Tue Dec 28 17:48:02 EST 2004
51 | finish: Tue Dec 28 17:48:03 EST 2004
52 |
53 | ex12
54 | start: Tue Dec 28 17:48:03 EST 2004
55 | finish: Tue Dec 28 17:48:04 EST 2004
56 |
57 | ex13
58 | start: Tue Dec 28 17:48:04 EST 2004
59 | finish: Tue Dec 28 17:48:04 EST 2004
60 |
61 | ex14
62 | start: Tue Dec 28 17:48:04 EST 2004
63 | finish: Tue Dec 28 17:48:05 EST 2004
64 |
65 | ex15
66 | start: Tue Dec 28 17:48:05 EST 2004
67 | finish: Tue Dec 28 17:48:05 EST 2004
68 |
69 | ex16
70 | start: Tue Dec 28 17:48:05 EST 2004
71 | finish: Tue Dec 28 17:48:05 EST 2004
72 |
73 | ex17
74 | start: Tue Dec 28 17:48:05 EST 2004
75 | finish: Tue Dec 28 17:48:17 EST 2004
76 |
77 | ex18
78 | start: Tue Dec 28 17:48:17 EST 2004
79 | finish: Tue Dec 28 17:48:19 EST 2004
80 |
81 | ex19
82 | start: Tue Dec 28 17:48:19 EST 2004
83 | finish: Tue Dec 28 17:48:19 EST 2004
84 |
85 | ex20
86 | start: Tue Dec 28 17:48:19 EST 2004
87 | finish: Tue Dec 28 17:56:04 EST 2004
88 |
89 | ex21
90 | start: Tue Dec 28 17:56:04 EST 2004
91 | finish: Tue Dec 28 17:56:06 EST 2004
92 |
93 | ex22
94 | start: Tue Dec 28 17:56:06 EST 2004
95 | finish: Tue Dec 28 17:56:09 EST 2004
96 |
97 | ex23
98 | start: Tue Dec 28 17:56:09 EST 2004
99 | finish: Tue Dec 28 17:56:09 EST 2004
100 |
101 | ex24
102 | start: Tue Dec 28 17:56:09 EST 2004
103 | finish: Tue Dec 28 17:56:10 EST 2004
104 |
105 | ex25
106 | start: Tue Dec 28 17:56:10 EST 2004
107 | finish: Tue Dec 28 17:56:10 EST 2004
108 |
109 | ex26
110 | start: Tue Dec 28 17:56:10 EST 2004
111 | finish: Tue Dec 28 17:56:21 EST 2004
112 |
113 | ex27
114 | start: Tue Dec 28 17:56:21 EST 2004
115 | finish: Tue Dec 28 17:56:21 EST 2004
116 |
117 |
--------------------------------------------------------------------------------
/examples/results/test_stats-macosx-gcc3.txt:
--------------------------------------------------------------------------------
1 | powerbook g4 1.3GHz 1.3G ram
2 |
3 | Darwin gouda.local 7.7.0 Darwin Kernel Version 7.7.0: Sun Nov 7 16:06:51 PST 2004; root:xnu/xnu-517.9.5.obj~1/RELEASE_PPC Power Macintosh powerpc
4 |
5 | randtest
6 | start: Tue Dec 28 18:01:41 EST 2004
7 | finish: Tue Dec 28 18:01:42 EST 2004
8 |
9 | ex1
10 | start: Tue Dec 28 18:01:42 EST 2004
11 | finish: Tue Dec 28 18:01:43 EST 2004
12 |
13 | ex2
14 | start: Tue Dec 28 18:01:43 EST 2004
15 | finish: Tue Dec 28 18:01:43 EST 2004
16 |
17 | ex3
18 | start: Tue Dec 28 18:01:43 EST 2004
19 | finish: Tue Dec 28 18:01:45 EST 2004
20 |
21 | ex4
22 | start: Tue Dec 28 18:01:45 EST 2004
23 | finish: Tue Dec 28 18:01:46 EST 2004
24 |
25 | ex5
26 | start: Tue Dec 28 18:01:46 EST 2004
27 | finish: Tue Dec 28 18:01:48 EST 2004
28 |
29 | ex6
30 | start: Tue Dec 28 18:01:48 EST 2004
31 | finish: Tue Dec 28 18:02:02 EST 2004
32 |
33 | ex7
34 | start: Tue Dec 28 18:02:02 EST 2004
35 | finish: Tue Dec 28 18:02:02 EST 2004
36 |
37 | ex8
38 | start: Tue Dec 28 18:02:02 EST 2004
39 | finish: Tue Dec 28 18:02:03 EST 2004
40 |
41 | ex9
42 | start: Tue Dec 28 18:02:03 EST 2004
43 | finish: Tue Dec 28 18:02:03 EST 2004
44 |
45 | ex10
46 | start: Tue Dec 28 18:02:03 EST 2004
47 | finish: Tue Dec 28 18:02:07 EST 2004
48 |
49 | ex11
50 | start: Tue Dec 28 18:02:07 EST 2004
51 | finish: Tue Dec 28 18:02:08 EST 2004
52 |
53 | ex12
54 | start: Tue Dec 28 18:02:08 EST 2004
55 | finish: Tue Dec 28 18:02:09 EST 2004
56 |
57 | ex13
58 | start: Tue Dec 28 18:02:09 EST 2004
59 | finish: Tue Dec 28 18:02:10 EST 2004
60 |
61 | ex14
62 | start: Tue Dec 28 18:02:10 EST 2004
63 | finish: Tue Dec 28 18:02:11 EST 2004
64 |
65 | ex15
66 | start: Tue Dec 28 18:02:11 EST 2004
67 | finish: Tue Dec 28 18:02:11 EST 2004
68 |
69 | ex16
70 | start: Tue Dec 28 18:02:11 EST 2004
71 | finish: Tue Dec 28 18:02:12 EST 2004
72 |
73 | ex17
74 | start: Tue Dec 28 18:02:12 EST 2004
75 | finish: Tue Dec 28 18:02:26 EST 2004
76 |
77 | ex18
78 | start: Tue Dec 28 18:02:26 EST 2004
79 | finish: Tue Dec 28 18:02:27 EST 2004
80 |
81 | ex19
82 | start: Tue Dec 28 18:02:27 EST 2004
83 | finish: Tue Dec 28 18:02:27 EST 2004
84 |
85 | ex20
86 | start: Tue Dec 28 18:02:27 EST 2004
87 | finish: Tue Dec 28 18:05:32 EST 2004
88 |
89 | ex21
90 | start: Tue Dec 28 18:05:32 EST 2004
91 | finish: Tue Dec 28 18:05:34 EST 2004
92 |
93 | ex22
94 | start: Tue Dec 28 18:05:34 EST 2004
95 | finish: Tue Dec 28 18:05:38 EST 2004
96 |
97 | ex23
98 | start: Tue Dec 28 18:05:38 EST 2004
99 | finish: Tue Dec 28 18:05:39 EST 2004
100 |
101 | ex24
102 | start: Tue Dec 28 18:05:39 EST 2004
103 | finish: Tue Dec 28 18:05:39 EST 2004
104 |
105 | ex25
106 | start: Tue Dec 28 18:05:39 EST 2004
107 | finish: Tue Dec 28 18:05:40 EST 2004
108 |
109 | ex26
110 | start: Tue Dec 28 18:05:40 EST 2004
111 | finish: Tue Dec 28 18:05:53 EST 2004
112 |
113 | ex27
114 | start: Tue Dec 28 18:05:53 EST 2004
115 | finish: Tue Dec 28 18:05:53 EST 2004
116 |
117 |
--------------------------------------------------------------------------------
/ga/GARealGenome.h:
--------------------------------------------------------------------------------
1 | // $Header$
2 | /* ----------------------------------------------------------------------------
3 | real.h
4 | mbwall 25feb95
5 | Copyright (c) 1995 Massachusetts Institute of Technology
6 | all rights reserved
7 |
8 | DESCRIPTION:
9 | This header defines the specialization of the array genome of type float
10 | for the real number genome.
11 | ---------------------------------------------------------------------------- */
12 | #ifndef _ga_real_h_
13 | #define _ga_real_h_
14 |
15 | #include
16 | #include
17 |
18 | typedef GAAlleleSet GARealAlleleSet;
19 | typedef GAAlleleSetArray GARealAlleleSetArray;
20 |
21 | typedef GA1DArrayAlleleGenome GARealGenome;
22 |
23 | int GARealGaussianMutator(GAGenome &, float);
24 |
25 | // in one (and only one) place in the code that uses the string genome, you
26 | // should define INSTANTIATE_STRING_GENOME in order to force the specialization
27 | // for this genome.
28 | #if defined(INSTANTIATE_REAL_GENOME)
29 | #include
30 | #endif
31 |
32 | inline void GARealUniformInitializer(GAGenome& g){
33 | GA1DArrayAlleleGenome::UniformInitializer(g);
34 | }
35 | inline void GARealOrderedInitializer(GAGenome& g){
36 | GA1DArrayAlleleGenome::OrderedInitializer(g);
37 | }
38 |
39 | inline int GARealUniformMutator(GAGenome& g, float pmut){
40 | return GA1DArrayAlleleGenome::FlipMutator(g, pmut);
41 | }
42 | inline int GARealSwapMutator(GAGenome& g, float pmut){
43 | return GA1DArrayGenome::SwapMutator(g, pmut);
44 | }
45 |
46 |
47 | inline int GARealUniformCrossover(const GAGenome& a, const GAGenome& b,
48 | GAGenome* c, GAGenome* d) {
49 | return GA1DArrayGenome::UniformCrossover(a,b,c,d);
50 | }
51 | inline int GARealEvenOddCrossover(const GAGenome& a, const GAGenome& b,
52 | GAGenome* c, GAGenome* d) {
53 | return GA1DArrayGenome::EvenOddCrossover(a,b,c,d);
54 | }
55 | inline int GARealOnePointCrossover(const GAGenome& a, const GAGenome& b,
56 | GAGenome* c, GAGenome* d) {
57 | return GA1DArrayGenome::OnePointCrossover(a,b,c,d);
58 | }
59 | inline int GARealTwoPointCrossover(const GAGenome& a, const GAGenome& b,
60 | GAGenome* c, GAGenome* d) {
61 | return GA1DArrayGenome::TwoPointCrossover(a,b,c,d);
62 | }
63 | inline int GARealPartialMatchCrossover(const GAGenome& a, const GAGenome& b,
64 | GAGenome* c, GAGenome* d) {
65 | return GA1DArrayGenome::PartialMatchCrossover(a,b,c,d);
66 | }
67 | inline int GARealOrderCrossover(const GAGenome& a, const GAGenome& b,
68 | GAGenome* c, GAGenome* d) {
69 | return GA1DArrayGenome::OrderCrossover(a,b,c,d);
70 | }
71 | inline int GARealCycleCrossover(const GAGenome& a, const GAGenome& b,
72 | GAGenome* c, GAGenome* d) {
73 | return GA1DArrayGenome::CycleCrossover(a,b,c,d);
74 | }
75 | int GARealArithmeticCrossover(const GAGenome& a, const GAGenome& b,
76 | GAGenome* c, GAGenome* d);
77 | int GARealBlendCrossover(const GAGenome& a, const GAGenome& b,
78 | GAGenome* c, GAGenome* d);
79 |
80 | #endif
81 |
--------------------------------------------------------------------------------
/examples/gnu/bitlcomp.c:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 1994 Free Software Foundation
2 |
3 | This file is part of the GNU BitString Library. This library is free
4 | software; you can redistribute it and/or modify it under the
5 | terms of the GNU General Public License as published by the
6 | Free Software Foundation; either version 2, or (at your option)
7 | any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this library; see the file COPYING. If not, write to the Free
16 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 |
18 | As a special exception, if you link this library with files
19 | compiled with a GNU compiler to produce an executable, this does not cause
20 | the resulting executable to be covered by the GNU General Public License.
21 | This exception does not however invalidate any other reasons why
22 | the executable file might be covered by the GNU General Public License. */
23 |
24 | /* Written by Per Bothner (bothner@cygnus.com) */
25 |
26 | #include "bitprims.h"
27 | #include
28 |
29 | /* Return -1, 0, 1 depending on whether (ptr0, len0) is
30 | lexicographically less than, equal, or greater than (ptr1, len1).
31 | Both bitstrings must be left-aligned. */
32 |
33 | int
34 | /*
35 | _BS_lcompare_0 (ptr0, len0, ptr1, len1)
36 | register _BS_word *ptr0;
37 | _BS_size_t len0;
38 | register _BS_word *ptr1;
39 | _BS_size_t len1;
40 | */
41 | _BS_lcompare_0 (register _BS_word *ptr0,
42 | _BS_size_t len0,
43 | register _BS_word *ptr1,
44 | _BS_size_t len1)
45 | {
46 | _BS_size_t nwords0 = len0 / _BS_BITS_PER_WORD;
47 | _BS_size_t nwords1 = len1 / _BS_BITS_PER_WORD;
48 | register _BS_word word0, word1, mask;
49 | _BS_size_t nwords = nwords0 > nwords1 ? nwords1 : nwords0;
50 | for (; nwords != 0; nwords--)
51 | {
52 | word0 = *ptr0++;
53 | word1 = *ptr1++;
54 | if (word0 != word1)
55 | {
56 | #if _BS_BIGENDIAN
57 | return (word0 < word1) ? -1 : 1;
58 | #else
59 | mask = 1;
60 | for (;;)
61 | {
62 | int bit0 = word0 & 1;
63 | int bit1 = word1 & 1;
64 | int diff = bit0 - bit1;
65 | if (diff)
66 | return diff;
67 | word0 >>= 1;
68 | word1 >>= 1;
69 | }
70 | #endif
71 | }
72 | }
73 | len0 -= nwords0 * _BS_BITS_PER_WORD;
74 | len1 -= nwords1 * _BS_BITS_PER_WORD;
75 | if (len0 == 0 || len1 == 0)
76 | return len0 == 0 - len1 == 0;
77 | len0 &= _BS_BITS_PER_WORD - 1;
78 | len1 &= _BS_BITS_PER_WORD - 1;
79 | word0 = *ptr0++ & ~((_BS_word)(~0) _BS_RIGHT len0);
80 | word1 = *ptr1++ & ~((_BS_word)(~0) _BS_RIGHT len1);
81 | if (word0 == word1)
82 | return len0 == len1 ? 0 : len0 < len1 ? -1 : 1;
83 | #if _BS_BIGENDIAN
84 | return (word0 < word1) ? -1 : 1;
85 | #else
86 | for (;;)
87 | {
88 | int bit0 = word0 & 1;
89 | int bit1 = word1 & 1;
90 | int diff = bit0 - bit1;
91 | if (diff)
92 | return diff;
93 | word0 >>= 1;
94 | word1 >>= 1;
95 | }
96 | #endif
97 | }
98 |
99 |
--------------------------------------------------------------------------------
/examples/pvmpop/slave.C:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | slave.C
3 | mbwall 5dec95
4 | Copyright (c) 1995-1996 Massachusetts Institute of Technology
5 |
6 | DESCRIPTION:
7 | Each slave evolves its own population. Between steps it checks to see if
8 | any messages have appeared for it. After each step it sends a message that
9 | says that it has completed a generation. A slave can receive two kinds of
10 | messages, one to send individuals (and where to send them), and another to
11 | receive them (and from where to receive them). The master controls the
12 | migrations by telling the slaves when and where to migrate individuals.
13 | To control the actual migration algorithm, you can modify the section of
14 | code that merges the received individuals into the population. You can also
15 | determine which individuals will be selected to migrate to another population.
16 | ---------------------------------------------------------------------------- */
17 | #include
18 | #include
19 | #include "genome.h"
20 |
21 | int
22 | main(int, char** argv) {
23 | int status = 0;
24 | int mytid = pvm_mytid();
25 | int masterid = pvm_parent();
26 | if(mytid < 0 || masterid < 0) {
27 | cerr << "\n" << argv[0] << ": Couldn't get slave/master IDs. Aborting.\n";
28 | exit(1);
29 | }
30 |
31 | GA1DBinaryStringGenome genome(GENOME_LENGTH,GenomeEvaluator);
32 | GASteadyStateGA ga(genome);
33 |
34 | status = pvm_initsend(PvmDataDefault);
35 | status = pvm_send(masterid, MSG_READY);
36 |
37 | int done = 0;
38 | while(!done){
39 | int bufid = pvm_recv(-1, -1);
40 | int ival;
41 | if(bufid >= 0) {
42 | int bytes, msgtag, tid;
43 | status = pvm_bufinfo(bufid, &bytes, &msgtag, &tid);
44 | switch(msgtag) {
45 | case MSG_DONE:
46 | done = 1;
47 | break;
48 |
49 | case MSG_SET_POPULATION_SIZE:
50 | ival = gaDefPopSize;
51 | status = pvm_upkint(&ival, 1, 1);
52 | ga.populationSize(ival);
53 | break;
54 |
55 | case MSG_INITIALIZE:
56 | ga.initialize();
57 | break;
58 |
59 | case MSG_STEP:
60 | ival = 0;
61 | status = pvm_upkint(&ival, 1, 1);
62 | for(int i=0; i
12 | #include
13 | #include
14 |
15 | #define cout STD_COUT
16 |
17 | float objective(GAGenome &);
18 |
19 | int
20 | main(int argc, char **argv)
21 | {
22 | cout << "Example 9\n\n";
23 | cout << "This program finds the maximum value in the function\n";
24 | cout << " y = - x1^2 - x2^2\n";
25 | cout << "with the constraints\n";
26 | cout << " -5 <= x1 <= 5\n";
27 | cout << " -5 <= x2 <= 5\n";
28 | cout << "\n\n"; cout.flush();
29 |
30 | // See if we've been given a seed to use (for testing purposes). When you
31 | // specify a random seed, the evolution will be exactly the same each time
32 | // you use that seed number.
33 |
34 | unsigned int seed = 0;
35 | for(int i=1; i
31 | class GAArray {
32 | public:
33 | GAArray(unsigned int s) : sz(s), a(sz ? new T[sz] : 0)
34 | {for(unsigned int i=0; i & orig){sz=0; a=(T *)0; copy(orig);}
36 | GAArray & operator=(const GAArray & orig){copy(orig); return *this;}
37 | GAArray & operator=(const T array []) // no err checks!
38 | {for(unsigned int i=0; i * clone(){return new GAArray(*this);}
42 | operator const T * () const {return a;}
43 | operator T * () {return a;}
44 | const T & operator[](unsigned int i) const {return a[i];}
45 | T & operator[](unsigned int i) {return a[i];}
46 | void copy(const GAArray & orig){
47 | size(orig.sz);
48 | for(unsigned int i=0; i & orig, unsigned int dest,
52 | unsigned int src, unsigned int length){
53 | for(unsigned int i=0; i dest)
57 | for(unsigned int i=0; i=0; i--) tmp[i] = a[i];
67 | delete [] a;
68 | a = tmp;
69 | return sz=n;
70 | }
71 | int equal(const GAArray & b,
72 | unsigned int dest, unsigned int src, unsigned int length) const {
73 | for(unsigned int i=0; i int
85 | operator==(const GAArray & a, const GAArray & b){
86 | if(a.size() != b.size()) return 0;
87 | return a.equal(b,0,0,a.sz);
88 | }
89 | template int
90 | operator!=(const GAArray & a, const GAArray & b){
91 | if(a.size() != b.size()) return 1;
92 | return a.equal(b,0,0,a.sz) ? 0 : 1;
93 | }
94 |
95 | #endif
96 |
--------------------------------------------------------------------------------
/makevars:
--------------------------------------------------------------------------------
1 | # -*- Mode: makefile -*-
2 | # Copyright (c) 2005 Matthew Wall, all rights reserved
3 | # makefile variables for compiling on unix environments
4 | # -----------------------------------------------------------------------------
5 |
6 | LIB =libga.a
7 |
8 | ### Set these directories to whatever is appropriate for your system. These
9 | ### are used only if you do a 'make install'. They specify where the library
10 | ### and header files should be installed.
11 | DESTDIR=/usr/local
12 | HDR_DEST_DIR=$(DESTDIR)/include
13 | LIB_DEST_DIR=$(DESTDIR)/lib
14 |
15 |
16 | ### Make sure that these are ok for your operating system.
17 | MKDEPEND = makedepend
18 | MKDIR = mkdir -p
19 | CP = cp
20 | RM = rm -rf
21 |
22 |
23 | ### Uncomment a block from the list below appropriate for the compiler and
24 | ### operating system on which you are compiling.
25 |
26 | # gcc3, gcc4
27 | # verified 28dec04 on linux-x86 (fedora core 2 with gcc 3.3.3)
28 | # verified 28dec04 on linux-ppc (yellow dog 3 with gcc 3.2.2)
29 | # verified 28dec04 on win2k-x86 (cygwin-win2k with gcc 3.3.3)
30 | # verified 10jan05 on linux-x86 (fedora core 3 with gcc 3.4.2)
31 | # verified 06mar07 on linux-x86 (debian with gcc 3.3.5)
32 | # verified 06mar07 on linux-x86 (ubuntu with gcc 4.0.3)
33 | # verified 06mar07 on macosx-ppc (macosx 10.4.8 with gcc 4.0.1)
34 | CXX = g++
35 | CXXFLAGS = -g -Wall
36 | LD = g++ -w
37 | AR = ar rv
38 | INSTALL = install -c
39 | RANLIB = echo no ranlib
40 |
41 | # gcc2
42 | # verified 28dec04 on linux-x86 (redhat 6.2 with gcc 2.95.2)
43 | # verified 28dec04 on sol7-x86 (solaris 7 with gcc 2.95.2)
44 | # verified 28dec04 on sol6-sparc (solaris 6 with gcc 2.95.2)
45 | #CXX = g++
46 | #CXXFLAGS = -g -Wall -O -fexceptions -O0
47 | #LD = g++ -w
48 | #AR = ar rv
49 | #INSTALL = install -c
50 | #RANLIB = echo no ranlib
51 |
52 | # macosx using gcc2
53 | # verified 28dec04 macosx-ppc (macosx 10.3.7 with gcc 2.95.2)
54 | #CXX = gcc2
55 | #CXXFLAGS = -g -Wall -fexceptions
56 | #LD = gcc2 -w
57 | #AR = ar rv
58 | #INSTALL = install
59 | #RANLIB = ranlib
60 | #CXX_LIBS = -lstdc++
61 |
62 | # macosx using gcc3
63 | # verified 28dec04 macosx-ppc (macosx 10.3.7 with gcc 3.3)
64 | #CXX = g++
65 | #CXXFLAGS = -g -Wall -O -O0
66 | #LD = gcc3 -w
67 | #AR = ar rv
68 | #INSTALL = install
69 | #RANLIB = ranlib
70 |
71 | # HPUX11 with aCC
72 | # verified 28dec04 hpux11-hppa (hpux 11 with aCC A.03.31)
73 | #CXX = aCC
74 | #CXXFLAGS = -g
75 | #LD = aCC
76 | #AR = ar rv
77 | #INSTALL = bsdinst -c
78 | #RANLIB = ranlib
79 |
80 | # AIX 4.3 with xlC
81 | # verified 28dec04 aix-ppc (aix 4.3.3 with xlC 6.0.0.5)
82 | #CXX = xlC
83 | #CXXFLAGS = -g -O -qrtti=all
84 | #LD = xlC
85 | #AR = ar rv
86 | #INSTALL = bsdinst -c
87 | #RANLIB = ranlib
88 |
89 | # IRIX 6.x with new 32-bit libraries
90 | # verified 28dec04 irix65-mips (irix 6.5 with CC 7.3.1.2m)
91 | #CXX = CC
92 | #CXXFLAGS = -g -fullwarn -n32
93 | #LD = ld
94 | #AR = ar rv
95 | #INSTALL = bsdinst -c
96 | #RANLIB = echo no ranlib
97 |
98 | # IRIX 6.x with old 32-bit libraries
99 | # verified 28dec04 irix65-mips (irix 6.5 with CC 7.3.1.2m)
100 | #CXX = CC
101 | #CXXFLAGS = -g -fullwarn
102 | #LD = ld
103 | #AR = ar rv
104 | #INSTALL = bsdinst -c
105 | #RANLIB = echo no ranlib
106 |
--------------------------------------------------------------------------------
/examples/gnu/bitblt.c:
--------------------------------------------------------------------------------
1 | /* Copyright (C) 1994 Free Software Foundation
2 |
3 | This file is part of the GNU BitString Library. This library is free
4 | software; you can redistribute it and/or modify it under the
5 | terms of the GNU General Public License as published by the
6 | Free Software Foundation; either version 2, or (at your option)
7 | any later version.
8 |
9 | This library is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 |
14 | You should have received a copy of the GNU General Public License
15 | along with this library; see the file COPYING. If not, write to the Free
16 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 |
18 | As a special exception, if you link this library with files
19 | compiled with a GNU compiler to produce an executable, this does not cause
20 | the resulting executable to be covered by the GNU General Public License.
21 | This exception does not however invalidate any other reasons why
22 | the executable file might be covered by the GNU General Public License. */
23 |
24 | /* Written by Per Bothner (bothner@cygnus.com).
25 | Based on ideas in the X11 MFB server. */
26 |
27 | #include "bitprims.h"
28 | #define ONES ((_BS_word)(~0))
29 |
30 | /* Copy LENGTH bits from (starting at SRCBIT) into pdst starting at DSTBIT.
31 | This will work even if psrc & pdst overlap. */
32 |
33 | void
34 | /*
35 | _BS_blt (op, pdst, dstbit, psrc, srcbit, length)
36 | enum _BS_alu op;
37 | register _BS_word* pdst;
38 | int dstbit;
39 | register const _BS_word* psrc;
40 | int srcbit;
41 | _BS_size_t length;
42 | */
43 | _BS_blt (enum _BS_alu op,
44 | register _BS_word* pdst,
45 | int dstbit,
46 | register const _BS_word* psrc,
47 | int srcbit,
48 | _BS_size_t length)
49 | {
50 | _BS_word ca1, cx1, ca2, cx2;
51 | switch (op)
52 | {
53 | case _BS_alu_clear:
54 | _BS_clear (pdst, dstbit, length);
55 | return;
56 | case _BS_alu_and:
57 | _BS_and (pdst, dstbit, psrc, srcbit, length);
58 | return;
59 | case _BS_alu_andReverse:
60 | ca1 = ONES; cx1 = 0; ca2 = ONES; cx2 = 0;
61 | break;
62 | case _BS_alu_copy:
63 | _BS_copy (pdst, dstbit, psrc, srcbit, length);
64 | return;
65 | case _BS_alu_andInverted:
66 | ca1 = ONES; cx1 = ONES; ca2 = 0; cx2 = 0;
67 | break;
68 | case _BS_alu_noop:
69 | return;
70 | case _BS_alu_xor:
71 | _BS_xor (pdst, dstbit, psrc, srcbit, length);
72 | return;
73 | case _BS_alu_or:
74 | ca1 = ONES; cx1 = ONES; ca2 = ONES; cx2 = 0;
75 | break;
76 | case _BS_alu_nor:
77 | ca1 = ONES; cx1 = ONES; ca2 = ONES; cx2 = ONES;
78 | break;
79 | case_BS_alu_equiv:
80 | ca1 = 0; cx1 = ONES; ca2 = ONES; cx2 = ONES;
81 | break;
82 | case _BS_alu_invert:
83 | _BS_invert (pdst, dstbit, length);
84 | return;
85 | case _BS_alu_orReverse:
86 | ca1 = ONES; cx1 = ONES; ca2 = 0; cx2 = ONES;
87 | break;
88 | case _BS_alu_copyInverted:
89 | ca1 = 0; cx1 = 0; ca2 = ONES; cx2 = ONES;
90 | break;
91 | case _BS_alu_orInverted:
92 | ca1 = ONES; cx1 = 0; ca2 = ONES; cx2 = ONES;
93 | break;
94 | case _BS_alu_nand:
95 | ca1 = ONES; cx1 = 0; ca2 = 0; cx2 = ONES;
96 | break;
97 | case _BS_alu_set:
98 | _BS_set (pdst, dstbit, length);
99 | return;
100 | }
101 | {
102 | #define COMBINE(dst, src) ((dst) & ((src) & ca1 ^ cx1) ^ ((src) & ca2 ^ cx2))
103 | #include "bitdo2.h"
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/examples/gnu/builtin.h:
--------------------------------------------------------------------------------
1 | // This may look like C code, but it is really -*- C++ -*-
2 |
3 | /*
4 | Copyright (C) 1988, 1992 Free Software Foundation
5 | written by Doug Lea (dl@rocky.oswego.edu)
6 |
7 | This file is part of the GNU C++ Library. This library is free
8 | software; you can redistribute it and/or modify it under the terms of
9 | the GNU Library General Public License as published by the Free
10 | Software Foundation; either version 2 of the License, or (at your
11 | option) any later version. This library is distributed in the hope
12 | that it will be useful, but WITHOUT ANY WARRANTY; without even the
13 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 | PURPOSE. See the GNU Library General Public License for more details.
15 | You should have received a copy of the GNU Library General Public
16 | License along with this library; if not, write to the Free Software
17 | Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 | */
19 |
20 | /*
21 | arithmetic, etc. functions on built in types
22 | */
23 |
24 |
25 | #ifndef _builtin_h
26 | #ifdef __GNUG__
27 | #pragma interface
28 | #endif
29 | #define _builtin_h 1
30 |
31 | #include
32 | #include
33 | #include
34 |
35 | #ifdef __GNUG__
36 | #define _VOLATILE_VOID volatile void
37 | #else
38 | #define _VOLATILE_VOID void
39 | #endif
40 |
41 | typedef void (*one_arg_error_handler_t)(const char*);
42 | typedef void (*two_arg_error_handler_t)(const char*, const char*);
43 |
44 | long gcd(long, long);
45 | long lg(unsigned long);
46 | double pow(double, long);
47 | long pow(long, long);
48 |
49 | extern "C" double start_timer();
50 | extern "C" double return_elapsed_time(double last_time = 0.0);
51 |
52 | char* dtoa(double x, char cvt = 'g', int width = 0, int prec = 6);
53 |
54 | unsigned int hashpjw(const char*);
55 | unsigned int multiplicativehash(int);
56 | unsigned int foldhash(double);
57 |
58 | extern _VOLATILE_VOID default_one_arg_error_handler(const char*);
59 | extern _VOLATILE_VOID default_two_arg_error_handler(const char*, const char*);
60 |
61 | extern two_arg_error_handler_t lib_error_handler;
62 |
63 | extern two_arg_error_handler_t
64 | set_lib_error_handler(two_arg_error_handler_t f);
65 |
66 |
67 | #if !defined(IV)
68 |
69 | #if ! _G_MATH_H_INLINES /* hpux and SCO define this in math.h */
70 | inline double abs(double arg)
71 | {
72 | return (arg < 0.0)? -arg : arg;
73 | }
74 | #endif
75 |
76 | inline float abs(float arg)
77 | {
78 | return (arg < 0.0)? -arg : arg;
79 | }
80 |
81 | inline short abs(short arg)
82 | {
83 | return (arg < 0)? -arg : arg;
84 | }
85 |
86 | inline long abs(long arg)
87 | {
88 | return (arg < 0)? -arg : arg;
89 | }
90 |
91 | inline int sign(long arg)
92 | {
93 | return (arg == 0) ? 0 : ( (arg > 0) ? 1 : -1 );
94 | }
95 |
96 | inline int sign(double arg)
97 | {
98 | return (arg == 0.0) ? 0 : ( (arg > 0.0) ? 1 : -1 );
99 | }
100 |
101 | inline long sqr(long arg)
102 | {
103 | return arg * arg;
104 | }
105 |
106 | #if ! _G_MATH_H_INLINES /* hpux and SCO define this in math.h */
107 | inline double sqr(double arg)
108 | {
109 | return arg * arg;
110 | }
111 | #endif
112 |
113 | inline int even(long arg)
114 | {
115 | return !(arg & 1);
116 | }
117 |
118 | inline int odd(long arg)
119 | {
120 | return (arg & 1);
121 | }
122 |
123 | inline long lcm(long x, long y)
124 | {
125 | return x / gcd(x, y) * y;
126 | }
127 |
128 | inline void (setbit)(long& x, long b)
129 | {
130 | x |= (1 << b);
131 | }
132 |
133 | inline void clearbit(long& x, long b)
134 | {
135 | x &= ~(1 << b);
136 | }
137 |
138 | inline int testbit(long x, long b)
139 | {
140 | return ((x & (1 << b)) != 0);
141 | }
142 |
143 | #endif
144 | #endif
145 |
--------------------------------------------------------------------------------
/ga/GAStringGenome.C:
--------------------------------------------------------------------------------
1 | // $Header$
2 | /* ----------------------------------------------------------------------------
3 | string.C
4 | mbwall 21mar95
5 | Copyright (c) 1995-1996 Massachusetts Institute of Technology
6 | all rights reserved
7 |
8 | DESCRIPTION:
9 | Source file for the string specialization of the array genome.
10 | ---------------------------------------------------------------------------- */
11 | #include
12 |
13 | template <> const char *
14 | GA1DArrayAlleleGenome::className() const {return "GAStringGenome";}
15 | template <> int
16 | GA1DArrayAlleleGenome::classID() const {return GAID::StringGenome;}
17 |
18 | template <> GA1DArrayAlleleGenome::
19 | GA1DArrayAlleleGenome(unsigned int length, const GAAlleleSet & s,
20 | GAGenome::Evaluator f, void * u) :
21 | GA1DArrayGenome(length, f, u){
22 | naset = 1;
23 | aset = new GAAlleleSet[1];
24 | aset[0] = s;
25 |
26 | initializer(DEFAULT_STRING_INITIALIZER);
27 | mutator(DEFAULT_STRING_MUTATOR);
28 | comparator(DEFAULT_STRING_COMPARATOR);
29 | crossover(DEFAULT_STRING_CROSSOVER);
30 | }
31 |
32 | template <> GA1DArrayAlleleGenome::
33 | GA1DArrayAlleleGenome(const GAAlleleSetArray & sa,
34 | GAGenome::Evaluator f, void * u) :
35 | GA1DArrayGenome(sa.size(), f, u){
36 | naset = sa.size();
37 | aset = new GAAlleleSet[naset];
38 | for(int i=0; i
48 | GA1DArrayAlleleGenome::~GA1DArrayAlleleGenome(){
49 | delete [] aset;
50 | }
51 |
52 |
53 | #ifdef GALIB_USE_STREAMS
54 | // The read specialization takes in each character whether it is whitespace or
55 | // not and stuffs it into the genome. This is unlike the default array read.
56 | template <> int
57 | GA1DArrayAlleleGenome::read(STD_ISTREAM & is)
58 | {
59 | unsigned int i=0;
60 | char c;
61 | do{
62 | is.get(c);
63 | if(!is.fail()) gene(i++, c);
64 | } while(!is.fail() && !is.eof() && i < nx);
65 |
66 | if(is.eof() && i < nx){
67 | GAErr(GA_LOC, className(), "read", gaErrUnexpectedEOF);
68 | is.clear(STD_IOS_BADBIT | is.rdstate());
69 | return 1;
70 | }
71 | return 0;
72 | }
73 |
74 | // Unlike the base array genome, here when we write out we don't put any
75 | // whitespace between genes. No newline at end of it all.
76 | template <> int
77 | GA1DArrayAlleleGenome::write(STD_OSTREAM & os) const
78 | {
79 | for(unsigned int i=0; i
95 | #include
96 |
97 | #if defined(__BORLANDC__)
98 | #define GALIB_STRINGGENOME_TEMPLATE_PREFACE
99 | #else
100 | #define GALIB_STRINGGENOME_TEMPLATE_PREFACE template class
101 | #endif
102 |
103 | GALIB_STRINGGENOME_TEMPLATE_PREFACE GAAlleleSet;
104 | GALIB_STRINGGENOME_TEMPLATE_PREFACE GAAlleleSetCore;
105 | GALIB_STRINGGENOME_TEMPLATE_PREFACE GAAlleleSetArray;
106 |
107 | GALIB_STRINGGENOME_TEMPLATE_PREFACE GAArray;
108 | GALIB_STRINGGENOME_TEMPLATE_PREFACE GA1DArrayGenome;
109 | GALIB_STRINGGENOME_TEMPLATE_PREFACE GA1DArrayAlleleGenome;
110 |
111 | #endif
112 |
--------------------------------------------------------------------------------
/examples/ex1.C:
--------------------------------------------------------------------------------
1 | /* ----------------------------------------------------------------------------
2 | ex1.C
3 | mbwall 28jul94
4 | Copyright (c) 1995-1996 Massachusetts Institute of Technology
5 |
6 | DESCRIPTION:
7 | Example program for the SimpleGA class and 2DBinaryStringGenome class.
8 | This program tries to fill the 2Dgenome with alternating 1s and 0s.
9 | This example uses the default crossover (single point), default mutator
10 | (uniform random bit flip), and default initializer (uniform random) for the
11 | 2D genome.
12 | Notice that one-point crossover is not necessarily the best kind of crossover
13 | to use if you want to generate a 'good' genome with this kind of objective
14 | function. But it does work.
15 | ---------------------------------------------------------------------------- */
16 | #include // we're going to use the simple GA
17 | #include // and the 2D binary string genome
18 | #include
19 |
20 | #define cout STD_COUT
21 |
22 | float Objective(GAGenome &); // This is the declaration of our obj function.
23 | // The definition comes later in the file.
24 |
25 | int
26 | main(int argc, char **argv)
27 | {
28 | cout << "Example 1\n\n";
29 | cout << "This program tries to fill a 2DBinaryStringGenome with\n";
30 | cout << "alternating 1s and 0s using a SimpleGA\n\n"; cout.flush();
31 |
32 | // See if we've been given a seed to use (for testing purposes). When you
33 | // specify a random seed, the evolution will be exactly the same each time
34 | // you use that seed number.
35 |
36 | for(int ii=1; ii // we're going to use the simple GA
17 | #include // and the 2D binary string genome
18 | #include
19 |
20 | #define cout STD_COUT
21 |
22 | float Objective(GAGenome &); // This is the declaration of our obj function.
23 | // The definition comes later in the file.
24 |
25 | int
26 | main(int argc, char **argv)
27 | {
28 | cout << "Example 1\n\n";
29 | cout << "This program tries to fill a 2DBinaryStringGenome with\n";
30 | cout << "alternating 1s and 0s using a SimpleGA\n\n"; cout.flush();
31 |
32 | // See if we've been given a seed to use (for testing purposes). When you
33 | // specify a random seed, the evolution will be exactly the same each time
34 | // you use that seed number.
35 |
36 | for(int ii=1; ii
36 |
37 | class GAIncrementalGA : public GAGeneticAlgorithm {
38 | public:
39 | GADefineIdentity("GAIncrementalGA", GAID::IncrementalGA);
40 |
41 | typedef GAGenome & (*ReplacementFunction)(GAGenome&, GAPopulation&);
42 |
43 | enum ReplacementScheme {
44 | RANDOM = GAPopulation::RANDOM,
45 | BEST = GAPopulation::BEST,
46 | WORST = GAPopulation::WORST,
47 | CUSTOM = -30,
48 | CROWDING = -30,
49 | PARENT = -10
50 | };
51 |
52 | static GAParameterList& registerDefaultParameters(GAParameterList&);
53 |
54 | public:
55 | GAIncrementalGA(const GAGenome&);
56 | GAIncrementalGA(const GAPopulation&);
57 | GAIncrementalGA(const GAIncrementalGA&);
58 | GAIncrementalGA& operator=(const GAIncrementalGA&);
59 | virtual ~GAIncrementalGA();
60 | virtual void copy(const GAGeneticAlgorithm &);
61 |
62 | virtual void initialize(unsigned int seed=0);
63 | virtual void step();
64 | GAIncrementalGA & operator++() { step(); return *this; }
65 |
66 | virtual int setptr(const char* name, const void* value);
67 | virtual int get(const char* name, void* value) const;
68 |
69 | virtual void objectiveFunction(GAGenome::Evaluator f);
70 | virtual void objectiveData(const GAEvalData& v);
71 |
72 | int nOffspring() const {return noffspr;}
73 | int nOffspring(unsigned int);
74 |
75 | ReplacementScheme replacement() const {return rs;}
76 | ReplacementScheme replacement(ReplacementScheme, ReplacementFunction f=0);
77 |
78 | protected:
79 | GAGenome *child1, *child2; // children that will be generated each gen
80 | ReplacementScheme rs; // replacement strategy
81 | ReplacementFunction rf; // (optional) replacement function
82 | unsigned int noffspr; // number of children to generate in crossover
83 | };
84 |
85 |
86 |
87 | #ifdef GALIB_USE_STREAMS
88 | inline STD_OSTREAM & operator<< (STD_OSTREAM & os, GAIncrementalGA & arg)
89 | { arg.write(os); return(os); }
90 | inline STD_ISTREAM & operator>> (STD_ISTREAM & is, GAIncrementalGA & arg)
91 | { arg.read(is); return(is); }
92 | #endif
93 |
94 | #endif
95 |
--------------------------------------------------------------------------------
/ga/GANode.h:
--------------------------------------------------------------------------------
1 | // $Header$
2 | /* ----------------------------------------------------------------------------
3 | node.h
4 | mbwall 25nov94
5 | Copyright 1995 Massachusetts Institute of Technology
6 |
7 | DESCRIPTION:
8 | This defines the node objects.
9 | ---------------------------------------------------------------------------- */
10 | #ifndef _ga_node_h_
11 | #define _ga_node_h_
12 |
13 | #include
14 | #include
15 |
16 | /* ----------------------------------------------------------------------------
17 | GANodeBASE
18 | -------------------------------------------------------------------------------
19 | This is the basic node object. In its basic form it should be useful for
20 | trees, lists, and some graphs. I debated whether to make two different objects
21 | for tree and list nodes, but decided for now to make them the same.
22 | ---------------------------------------------------------------------------- */
23 | struct GANodeBASE {
24 | GANodeBASE *next, *prev, *parent, *child;
25 | GANodeBASE()
26 | {next=0; prev=0; parent=0; child=0;}
27 | GANodeBASE(GANodeBASE *n, GANodeBASE *p, GANodeBASE *par, GANodeBASE *chi)
28 | {next=n; prev=p; parent=par; child=chi;}
29 | virtual ~GANodeBASE() {}
30 | };
31 |
32 |
33 | #ifdef GALIB_USE_STREAMS
34 | inline STD_OSTREAM & operator<<(STD_OSTREAM & os, GANodeBASE & arg){
35 | os << " node: " << &arg << "\n";
36 | os << " next: " << arg.next << "\n";
37 | os << " prev: " << arg.prev << "\n";
38 | os << " child: " << arg.child << "\n";
39 | os << " parent: " << arg.parent << "\n";
40 | return(os);
41 | }
42 | #endif
43 |
44 |
45 |
46 | /* ----------------------------------------------------------------------------
47 | GANode
48 | -------------------------------------------------------------------------------
49 | This node is a container for any kind of object you want to put into a list.
50 | Since it is a sub-class of the BASE node object, it inherits all of the next,
51 | prev, etc members of that class. All we add here is support for the type-
52 | specific contents.
53 | Beware of what you put in for the type. Remember that it
54 | can be expensive to use an object rather than a pointer (if you have big
55 | objects, for example). We define this template using the object rather than
56 | a pointer so that it can be use for ints, chars, or other small objects. If
57 | you are going to contain a large object, you should instantiate it as a pointer
58 | to the object, not the object itself.
59 | Note also that we use the copy constructor to intialize the object rather
60 | than doing an assignment! This assumes that the object you put into this
61 | container has a properly functioning copy initializer and avoids the default
62 | construction followed by assignment that you'd get with operator=.
63 | You must have a copy creator defined for any object that goes into the nodes.
64 | The operator= must defined as well (it is used when the node contents get
65 | reassigned). We do not allow the nodes to be created without any arguments.
66 | Summary of methods your object must have:
67 | copy initializer
68 | operator=
69 | The node always owns its contents; when the node is destroyed, the contents
70 | of the node get destroyed as well.
71 | ---------------------------------------------------------------------------- */
72 | template
73 | struct GANode : public GANodeBASE {
74 | T contents;
75 | // GANode() : GANodeBASE(), contents() {}
76 | GANode(const T & t) : GANodeBASE(), contents(t) {}
77 | virtual ~GANode() {}
78 | T & operator()(const T & t){contents = t; return contents;}
79 | };
80 |
81 | #ifdef GALIB_USE_STREAMS
82 | template STD_OSTREAM & operator<<(STD_OSTREAM & os, GANode & arg){
83 | os << " node: " << &arg << "\n";
84 | os << " next: " << arg.next << "\n";
85 | os << " prev: " << arg.prev << "\n";
86 | os << " child: " << arg.child << "\n";
87 | os << " parent: " << arg.parent << "\n";
88 | return(os);
89 | }
90 | #endif
91 |
92 | #endif
93 |
--------------------------------------------------------------------------------
/examples/gnu/Obstack.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (C) 1988 Free Software Foundation
3 | written by Doug Lea (dl@rocky.oswego.edu)
4 |
5 | This file is part of the GNU C++ Library. This library is free
6 | software; you can redistribute it and/or modify it under the terms of
7 | the GNU Library General Public License as published by the Free
8 | Software Foundation; either version 2 of the License, or (at your
9 | option) any later version. This library is distributed in the hope
10 | that it will be useful, but WITHOUT ANY WARRANTY; without even the
11 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 | PURPOSE. See the GNU Library General Public License for more details.
13 | You should have received a copy of the GNU Library General Public
14 | License along with this library; if not, write to the Free Software
15 | Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 | */
17 |
18 | #ifdef __GNUG__
19 | #pragma implementation
20 | #endif
21 | #include
22 | #include
23 | #include
24 | #include
25 |
26 | /* We use subtraction of (char *)0 instead of casting to int
27 | because on word-addressable machines a simple cast to int
28 | may ignore the byte-within-word field of the pointer. */
29 |
30 | #ifndef __PTR_TO_INT
31 | #define __PTR_TO_INT(P) ((P) - (char *)0)
32 | #endif
33 |
34 | #ifndef __INT_TO_PTR
35 | #define __INT_TO_PTR(P) ((P) + (char *)0)
36 | #endif
37 |
38 | Obstack::Obstack(int size, int alignment)
39 | {
40 | alignmentmask = alignment - 1;
41 | chunksize = size;
42 | chunk = 0;
43 | nextfree = objectbase = 0;
44 | chunklimit = 0;
45 | }
46 |
47 | void Obstack::_free(void* obj)
48 | {
49 | _obstack_chunk* lp;
50 | _obstack_chunk* plp;
51 |
52 | lp = chunk;
53 | while (lp != 0 && ((void*)lp > obj || (void*)(lp)->limit < obj))
54 | {
55 | plp = lp -> prev;
56 | delete [] (char*)lp;
57 | lp = plp;
58 | }
59 | if (lp)
60 | {
61 | objectbase = nextfree = (char *)(obj);
62 | chunklimit = lp->limit;
63 | chunk = lp;
64 | }
65 | else if (obj != 0)
66 | (*lib_error_handler)("Obstack", "deletion of nonexistent obj");
67 | }
68 |
69 | void Obstack::newchunk(int size)
70 | {
71 | _obstack_chunk* old_chunk = chunk;
72 | _obstack_chunk* new_chunk;
73 | long new_size;
74 | int obj_size = nextfree - objectbase;
75 |
76 | new_size = (obj_size + size) << 1;
77 | if (new_size < chunksize)
78 | new_size = chunksize;
79 |
80 | new_chunk = chunk = new (operator new (new_size)) _obstack_chunk;
81 | new_chunk->prev = old_chunk;
82 | new_chunk->limit = chunklimit = (char *) new_chunk + new_size;
83 |
84 | memcpy((void*)new_chunk->contents, (void*)objectbase, obj_size);
85 | objectbase = new_chunk->contents;
86 | nextfree = objectbase + obj_size;
87 | }
88 |
89 | void* Obstack::finish()
90 | {
91 | void* value = (void*) objectbase;
92 | nextfree = __INT_TO_PTR (__PTR_TO_INT (nextfree + alignmentmask)
93 | & ~alignmentmask);
94 | if (nextfree - (char*)chunk > chunklimit - (char*)chunk)
95 | nextfree = chunklimit;
96 | objectbase = nextfree;
97 | return value;
98 | }
99 |
100 | int Obstack::contains(void* obj) // true if obj somewhere in Obstack
101 | {
102 | _obstack_chunk* ch;
103 | for (ch = chunk;
104 | ch != 0 && (obj < (void*)ch || obj >= (void*)(ch->limit));
105 | ch = ch->prev);
106 |
107 | return ch != 0;
108 | }
109 |
110 | int Obstack::OK()
111 | {
112 | int v = chunksize > 0; // valid size
113 | v &= alignmentmask != 0; // and alignment
114 | v &= chunk != 0;
115 | v &= objectbase >= chunk->contents;
116 | v &= nextfree >= objectbase;
117 | v &= nextfree <= chunklimit;
118 | v &= chunklimit == chunk->limit;
119 | _obstack_chunk* p = chunk;
120 | // allow lots of chances to find bottom!
121 | long x = LONG_MAX;
122 | while (p != 0 && x != 0) { --x; p = p->prev; }
123 | v &= x > 0;
124 | if (!v)
125 | (*lib_error_handler)("Obstack", "invariant failure");
126 | return v;
127 | }
128 |
--------------------------------------------------------------------------------
/examples/pvmind/README:
--------------------------------------------------------------------------------
1 | mbw 5dec95
2 |
3 | To build the programs in this directory, use aimk (part of the PVM package).
4 | You should be able to simply type 'aimk' to build the programs or
5 | 'aimk install' to build the programs then put them into your PVM bin
6 | directories. Be sure you edit the Makefile first to work with your compiler
7 | and to specify the location of the GAlib headers and library. You can use
8 | 'aimk clean' just as you would use 'make clean'.
9 |
10 | This example shows how to use GAlib with pvm to do parallel processing of your
11 | genetic algorithms. In this example we use a master-slave configuration. The
12 | master controls the overall evolution and the slaves chug away. Using PVM you
13 | can specify on which machines the slaves should run (see the PVM documentation
14 | for more details about that).
15 |
16 | Note that this configuration is particularly useful for problems in which the
17 | objective function takes a long time to run relative to the time it takes to
18 | transfer a single genome from the master to the slave (or vice versa).
19 |
20 | Before you run this example, you must install PVM3 (I have tested with version
21 | 3.3.10 - you'll have to check the PVM documentation for PVM incompatibilities).
22 | The makefile in this directory assumes that you have your environment properly
23 | configured as described in the PVM documentation (see the makefile for details)
24 |
25 | For more details about PVM, see
26 | http://www.netlib.org/pvm3/index.html
27 | http://www.epm.ornl.gov/pvm/pvm_home.html
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | OK, so you don't want to chug through the PVM documentation? Here's the
36 | quick and dirty PVM config (assuming that PVM is on your system already):
37 |
38 | 1) add this to your .cshrc file (you may have to change the value of
39 | PVM_ROOT to match your system's configuration)
40 |
41 | # -----------------------------------------------------------------------------
42 | # pvm additions for .cshrc file (mbw dec95)
43 | #
44 | # These are for using the parallel virtual machine codes. The first tells
45 | # where PVM is located, the second tells where XPVM is located.
46 | setenv PVM_ROOT /nfs/lancet/local/pvm3
47 | setenv XPVM_ROOT /nfs/lancet/local/pvm3/xpvm
48 |
49 | # These set up the environment so we can find the pvm man pages and run pvm
50 | # programs without typing in the explicit path to each executable.
51 | setenv PVM_ARCH `$PVM_ROOT/lib/pvmgetarch`
52 | set path=($path $PVM_ROOT/lib)
53 | set path=($path $PVM_ROOT/bin/$PVM_ARCH $HOME/pvm3/bin/$PVM_ARCH)
54 |
55 | # The MANPATH variable must be defined already for this to work.
56 | setenv MANPATH ${MANPATH}:$PVM_ROOT/man
57 | # -----------------------------------------------------------------------------
58 |
59 |
60 | 2) create a pvm directory for your programs
61 |
62 | cd
63 | mkdir pvm3 pvm3/bin
64 |
65 |
66 | 3) create a hosts file that defines your virtual machine - just put the
67 | hostnames of all the machines you'll be using into a file, then when you
68 | start pvm, pass the name of the hosts file and pvm will use those hosts
69 | to set up the PVM. I keep a file called ~/pvm3/hosts with my default
70 | host configuration.
71 |
72 |
73 | 4) start pvm
74 |
75 | pvm ~/pvm3/hosts
76 |
77 |
78 | 5) run your program in a separate shell (do not type this at the pvm prompt)
79 |
80 | master ngen 100 nslaves 25
81 |
82 |
83 | 6) to shut down pvm, type 'halt' at the pvm prompt (if you just type 'quit'
84 | then you'll leave the pvm prompt but pvmd will still be running)
85 |
86 |
87 |
88 |
89 |
90 | IMPORTANT NOTES
91 | To shut down all of the processes spawned in your PVM, type 'reset' at the
92 | pvm prompt. If you just control-C the master then it will die but the slaves
93 | will continue to run (unless you do some signal handling in the master). Don't
94 | forget to 'halt' the PVM when you are finished running everything. For help
95 | with PVM commands, type 'help' at the PVM prompt.
96 | To see the cout/cerr messages from your spawned (slave) processes, look in
97 | the file /var/tmp/pvml.XXXXXX where XXXXXX is your uid. On some systems the
98 | pvm log file may be located in /tmp/pvml.XXXXXX
99 |
--------------------------------------------------------------------------------
/examples/pvmpop/README:
--------------------------------------------------------------------------------
1 | mbw 5dec95
2 |
3 | To build the programs in this directory, use aimk (part of the PVM package).
4 | You should be able to simply type 'aimk' to build the programs or
5 | 'aimk install' to build the programs then put them into your PVM bin
6 | directories. Be sure you edit the Makefile first to work with your compiler
7 | and to specify the location of the GAlib headers and library. You can use
8 | 'aimk clean' just as you would use 'make clean'.
9 |
10 | This example shows how to use GAlib with pvm to do parallel processing of your
11 | genetic algorithms. In this example we use a master-slave configuration. The
12 | master controls the overall evolution and the slaves chug away. Using PVM you
13 | can specify on which machines the slaves should run (see the PVM documentation
14 | for more details about that).
15 |
16 | Note that this configuration is particularly useful for problems in which the
17 | objective function takes a long time to run relative to the time it takes to
18 | transfer a single genome from the master to the slave (or vice versa).
19 |
20 | Before you run this example, you must install PVM3 (I have tested with version
21 | 3.3.10 - you'll have to check the PVM documentation for PVM incompatibilities).
22 | The makefile in this directory assumes that you have your environment properly
23 | configured as described in the PVM documentation (see the makefile for details)
24 |
25 | For more details about PVM, see
26 | http://www.netlib.org/pvm3/index.html
27 | http://www.epm.ornl.gov/pvm/pvm_home.html
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 | OK, so you don't want to chug through the PVM documentation? Here's the
36 | quick and dirty PVM config (assuming that PVM is on your system already):
37 |
38 | 1) add this to your .cshrc file (you may have to change the value of
39 | PVM_ROOT to match your system's configuration)
40 |
41 | # -----------------------------------------------------------------------------
42 | # pvm additions for .cshrc file (mbw dec95)
43 | #
44 | # These are for using the parallel virtual machine codes. The first tells
45 | # where PVM is located, the second tells where XPVM is located.
46 | setenv PVM_ROOT /nfs/lancet/local/pvm3
47 | setenv XPVM_ROOT /nfs/lancet/local/pvm3/xpvm
48 |
49 | # These set up the environment so we can find the pvm man pages and run pvm
50 | # programs without typing in the explicit path to each executable.
51 | setenv PVM_ARCH `$PVM_ROOT/lib/pvmgetarch`
52 | set path=($path $PVM_ROOT/lib)
53 | set path=($path $PVM_ROOT/bin/$PVM_ARCH $HOME/pvm3/bin/$PVM_ARCH)
54 |
55 | # The MANPATH variable must be defined already for this to work.
56 | setenv MANPATH ${MANPATH}:$PVM_ROOT/man
57 | # -----------------------------------------------------------------------------
58 |
59 |
60 | 2) create a pvm directory for your programs
61 |
62 | cd
63 | mkdir pvm3 pvm3/bin
64 |
65 |
66 | 3) create a hosts file that defines your virtual machine - just put the
67 | hostnames of all the machines you'll be using into a file, then when you
68 | start pvm, pass the name of the hosts file and pvm will use those hosts
69 | to set up the PVM. I keep a file called ~/pvm3/hosts with my default
70 | host configuration.
71 |
72 |
73 | 4) start pvm
74 |
75 | pvm ~/pvm3/hosts
76 |
77 |
78 | 5) run your program in a separate shell (do not type this at the pvm prompt)
79 |
80 | master ngen 100 nslaves 25
81 |
82 |
83 | 6) to shut down pvm, type 'halt' at the pvm prompt (if you just type 'quit'
84 | then you'll leave the pvm prompt but pvmd will still be running)
85 |
86 |
87 |
88 |
89 |
90 | IMPORTANT NOTES
91 | To shut down all of the processes spawned in your PVM, type 'reset' at the
92 | pvm prompt. If you just control-C the master then it will die but the slaves
93 | will continue to run (unless you do some signal handling in the master). Don't
94 | forget to 'halt' the PVM when you are finished running everything. For help
95 | with PVM commands, type 'help' at the PVM prompt.
96 | To see the cout/cerr messages from your spawned (slave) processes, look in
97 | the file /var/tmp/pvml.XXXXXX where XXXXXX is your uid. On some systems the
98 | pvm log file may be located in /tmp/pvml.XXXXXX
99 |
--------------------------------------------------------------------------------
/ga/gaerror.h:
--------------------------------------------------------------------------------
1 | // $Header$
2 | /* ----------------------------------------------------------------------------
3 | error.h
4 | mbwall 7may95
5 | Copyright (c) 1995 Massachusetts Institute of Technology
6 | all rights reserved
7 |
8 | DESCRIPTION:
9 | This defines the error routines for handling errors.
10 | ---------------------------------------------------------------------------- */
11 | #ifndef _ga_error_h_
12 | #define _ga_error_h_
13 |
14 | #include
15 | #include
16 | #include
17 |
18 | // This object is for telling us where in the source code an error occurs.
19 | class GASourceLocator {
20 | public:
21 | GASourceLocator(const char* f, long l) : file(f), line(l) {}
22 | const char* file;
23 | long line;
24 | };
25 |
26 | #define GA_LOC GASourceLocator(__FILE__, __LINE__)
27 |
28 |
29 |
30 | // These are the indices for all of the error messages used in the library.
31 | enum GAErrorIndex {
32 | // general errors
33 | gaErrReadError=0,
34 | gaErrWriteError,
35 | gaErrUnexpectedEOF,
36 | gaErrBadProbValue,
37 | gaErrObjectTypeMismatch,
38 | gaErrOpUndef,
39 | gaErrRefsRemain,
40 |
41 | // errors for the GA objects
42 | gaErrNeedRS,
43 | gaErrBadRS,
44 | gaErrBadCS,
45 | gaErrBadPRepl,
46 | gaErrBadNRepl,
47 | gaErrBadPopIndex,
48 | gaErrNoIndividuals,
49 | gaErrBadPopSize,
50 | gaErrNoSexualMating,
51 | gaErrNoAsexualMating,
52 |
53 | // errors for the genome and crossover objects
54 | gaErrSameBehavReqd,
55 | gaErrSameLengthReqd,
56 | gaErrBadParentLength,
57 | gaErrBadResizeBehaviour,
58 | gaErrBadPhenotypeID,
59 | gaErrBadPhenotypeValue,
60 | gaErrBadBndsDim,
61 |
62 | // scaling scheme error messages
63 | gaErrBadLinearScalingMult,
64 | gaErrBadSigmaTruncationMult,
65 | gaErrNegFitness,
66 | gaErrPowerNegFitness,
67 | gaErrBadSharingCutoff,
68 |
69 | // miscellaneous error messages from various data objects
70 | gaErrNoAlleleIndex,
71 | gaErrBinStrTooLong,
72 | gaErrDataLost,
73 | gaErrBadWhereIndicator,
74 | gaErrBadTypeIndicator,
75 | gaErrBadTreeLinks,
76 | gaErrCannotSwapAncestors,
77 | gaErrCannotInsertIntoSelf,
78 | gaErrCannotInsertOnNilNode,
79 | gaErrCannotInsertWithSiblings,
80 | gaErrCannotInsertBeforeRoot,
81 | gaErrCannotInsertAfterRoot
82 | };
83 |
84 |
85 |
86 | // Error messages will look like this: (assuming that you use streams)
87 | //
88 | // GASimpleGA::function:
89 | // this is the error message
90 | // /usr/people/jimmyboy/doughhead.C : XXX
91 | //
92 | // GAGenome::function:
93 | // primary error message
94 | // additional error messages go here
95 | // /usr/people/algore/distribute_your_intelligence.C : XXX
96 | //
97 | // MyOwnFunction:
98 | // primary error message
99 | // additional error messages go here
100 | // /usr/people/algore/distribute_your_intelligence.C : XXX
101 | //
102 |
103 | void GAErr(const GASourceLocator loc,
104 | const char *clss, const char *function_name,
105 | GAErrorIndex i, const char *msg2=0, const char *msg3=0);
106 | void GAErr(const GASourceLocator loc,
107 | const char *clss, const char *function_name,
108 | const char *msg1, const char *msg2=0, const char *msg3=0);
109 | void GAErr(const GASourceLocator loc,
110 | const char *function_name,
111 | GAErrorIndex i, const char *msg2=0, const char *msg3=0);
112 |
113 | // Use this function to turn on/off the error reporting. If you turn off the
114 | // error reporting, the messages will still get stuck into the global error
115 | // message string, but they will not be sent to the error stream.
116 |
117 | void GAReportErrors(GABoolean flag);
118 |
119 | // Provide a mechanism for redirecting the error messages.
120 |
121 | #ifdef GALIB_USE_STREAMS
122 | void GASetErrorStream(STD_OSTREAM &);
123 | #else
124 | inline void GASetErrorStream(){} // dummy function
125 | #endif
126 |
127 | // This error string contains the text of the most recent error message. If a
128 | // GAlib function returns an error code, this string will contain the text of
129 | // the explanation for the error.
130 | extern char gaErrMsg[];
131 |
132 | #endif
133 |
--------------------------------------------------------------------------------