6 |
OptInfoPso::OptInfoPso() |
OptInfoPso::OptInfoPso() |
7 |
: OptInfo(), goal(1e-5), psoiter(100000), c1(1.496), c2(1.496), |
: OptInfo(), goal(1e-5), psoiter(100000), c1(1.496), c2(1.496), |
8 |
w_max(PSO_INERTIA), w_min(0.3), clamp_pos(1), nhood_strategy(PSO_NHOOD_RING), |
w_max(PSO_INERTIA), w_min(0.3), clamp_pos(1), nhood_strategy(PSO_NHOOD_RING), |
9 |
nhood_size(5), w_strategy(PSO_W_LIN_DEC) |
nhood_size(5), w_strategy(PSO_W_LIN_DEC), scale(0) |
10 |
{ |
{ |
11 |
type = OPTPSO; |
type = OPTPSO; |
12 |
handle.logMessage(LOGMESSAGE, "Initialising PSO optimisation algorithm"); |
handle.logMessage(LOGMESSAGE, "Initialising PSO optimisation algorithm"); |
15 |
void OptInfoPso::read(CommentStream& infile, char* text) { |
void OptInfoPso::read(CommentStream& infile, char* text) { |
16 |
handle.logMessage(LOGMESSAGE, "Reading PSO optimisation parameters"); |
handle.logMessage(LOGMESSAGE, "Reading PSO optimisation parameters"); |
17 |
|
|
18 |
unsigned s1 = 0; |
// unsigned s1 = 0; |
19 |
unsigned s2 = 0; |
// unsigned s2 = 0; |
20 |
unsigned s3 = 0; |
// unsigned s3 = 0; |
21 |
|
|
22 |
int count = 0; |
int count = 0; |
23 |
while (!infile.eof() && strcasecmp(text, "[PSO]") && strcasecmp(text, "[simann]") && strcasecmp(text, "[hooke]") && strcasecmp(text, "[bfgs]")) { |
while (!infile.eof() && strcasecmp(text, "[PSO]") && strcasecmp(text, "[simann]") && strcasecmp(text, "[hooke]") && strcasecmp(text, "[bfgs]")) { |
25 |
if (strcasecmp(text, "seed") == 0) { |
if (strcasecmp(text, "seed") == 0) { |
26 |
int s = 0; |
int s = 0; |
27 |
infile >> s >> ws; |
infile >> s >> ws; |
28 |
s1 = s; |
// s1 = s; |
29 |
handle.logMessage(LOGMESSAGE, "Initialising random number generator with", s); |
handle.logMessage(LOGMESSAGE, "Initialising random number generator with", s); |
30 |
srand(s1); |
srand(s); |
31 |
} |
} |
32 |
else if (strcasecmp(text, "psoiter") == 0) { |
else if (strcasecmp(text, "psoiter") == 0) { |
33 |
infile >> psoiter; |
infile >> psoiter; |
71 |
infile >> size; |
infile >> size; |
72 |
count++; |
count++; |
73 |
|
|
74 |
|
} else if (strcasecmp(text, "scale") == 0) { |
75 |
|
infile >> scale; |
76 |
|
count++; |
77 |
|
|
78 |
} else { |
} else { |
79 |
handle.logMessage(LOGINFO, "Warning in optinfofile - unrecognised option", text); |
handle.logMessage(LOGINFO, "Warning in optinfofile - unrecognised option", text); |
80 |
infile >> text; //read and ignore the next entry |
infile >> text; //read and ignore the next entry |
98 |
handle.logMessage(LOGINFO, "Warning in optinfofile - Invalid w_strategy. Setting to default PSO_W_LIN_DEC"); |
handle.logMessage(LOGINFO, "Warning in optinfofile - Invalid w_strategy. Setting to default PSO_W_LIN_DEC"); |
99 |
w_strategy=PSO_W_LIN_DEC; |
w_strategy=PSO_W_LIN_DEC; |
100 |
} |
} |
101 |
|
|
102 |
|
if (scale != 0 && scale != 1) { |
103 |
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of scale outside bounds", scale); |
104 |
|
scale = 0; |
105 |
|
} |
106 |
} |
} |
107 |
|
|
108 |
void OptInfoPso::Print(ofstream& outfile, int prec) { |
void OptInfoPso::Print(ofstream& outfile, int prec) { |