Next: Module: Parallel
Up: Source Code
Previous: Module: Definitions
  Contents
Subsections
1
2 /* Declaration of Sequential Features */
3
4 #ifndef SEQ_H
5 #define SEQ_H 1
6
7 #include "defs.h"
8
9 char *SeqOptStr();
10 char *SeqUsage();
11 char SeqParamStr[256];
12
13 int PopSize; /* size of actual population */
14
15 int MaxGen; /* Maximum no. of generations */
16 errtyp MaxErr; /* Maximum error for succes */
17
18 int SeedRand; /* random seed */
19
20 int handleSeqOpt(char opt,char* arg);
21 int initSeq();
22
23 void errorexit(char *msg);
24
25 #endif
1
2 /* Implementation of sequential features */
3
4 #include "defs.h"
5 #include "seq.h"
6
7 /* Parameter Handling */
8
9 #define DEFPOPSIZE 100
10 #define DEFMAXGEN 10000
11 #define DEFMAXERR 0.01
12 #define DEFSEED AUTO
13
14 char *SeqOptStr() {return "p:g:e:s:\0";}
15
16 char *SeqUsage() {return
17 "Simulation Parameters:\n"
18 "-p <population size>: 100\n"
19 "-g <max. no. of generations>: 10000\n"
20 "-e <max. error for succes>: 0.01\n"
21 "-s <random seed value>: time\n\0";}
22
23 /* set default values */
24
25 int PopSize =DEFPOPSIZE; /* size of actual population */
26 int MaxGen =DEFMAXGEN; /* Maximum no. of generations */
27 errtyp MaxErr =DEFMAXERR; /* Maximum error for succes */
28 int SeedRand =DEFSEED; /* random seed */
29
30 int handleSeqOpt(char opt,char* arg)
31 {
32 switch(opt)
33 {
34 case 'p': return (PopSize =getint(arg,2,1000000))<0;
35 case 'g': return (MaxGen =getint(arg,1,1000000000))<0;
36 case 'e': return getfloat(&MaxErr,arg,0,1000000);
37 case 's': return (SeedRand =getint(arg,0,MAXRANDOM))<0;
38 default: return 1;
39 };
40 }
41
42 void errorexit(char *msg)
43 {
44 printf(msg);
45 exit(1);
46 }
47
48 int initSeq()
49 {
50 if(SeedRand==AUTO) SeedRand=gettime();
51 seedrand(SeedRand);
52
53 sprintf(SeqParamStr,
54 "Simulation: serial, PopSize = %d, MaxGen = %d, "
55 "MaxErr = %7.4f\n RandomSeed = %d\n",
56 PopSize,MaxGen,MaxErr,SeedRand);
57 return 0;
58 }
(c) Bernhard Ömer - oemer@tph.tuwien.ac.at - http://tph.tuwien.ac.at/~oemer/