質問編集履歴
5
.csvファイルのスクショも追加しました.
title
CHANGED
File without changes
|
body
CHANGED
@@ -309,4 +309,4 @@
|
|
309
309
|
コンパイラ環境はEmacsです
|
310
310
|
|
311
311
|

|
312
|
-
.csv
|
312
|
+

|
4
使用しているsampledataを追加しました.
title
CHANGED
File without changes
|
body
CHANGED
@@ -306,4 +306,7 @@
|
|
306
306
|
|
307
307
|
環境は
|
308
308
|
macbook pro macOS BigSur ver.11.4
|
309
|
-
コンパイラ環境はEmacsです
|
309
|
+
コンパイラ環境はEmacsです
|
310
|
+
|
311
|
+

|
312
|
+
.csvも用意しています.
|
3
エラー内容を変更しました.
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,65 +3,17 @@
|
|
3
3
|
### 発生している問題・エラーメッセージ
|
4
4
|
|
5
5
|
```
|
6
|
-
|
6
|
+
g++ -o bee sample04.cpp
|
7
|
-
.
|
7
|
+
sample04.cpp:10:25: warning: conversion from string literal to 'char *' is deprecated [-Wc++11-compat-deprecated-writable-strings]
|
8
|
-
|
8
|
+
fSet = new FlowerSet("sampledata.csv");
|
9
|
-
|
9
|
+
^
|
10
|
-
//
|
11
|
-
In file included from flowerset.cpp:1:
|
12
|
-
In file included from ./FlowerSet.h:3:
|
13
|
-
./Flower.h:5:23: warning: extra tokens at end of #include directive [-Wextra-tokens]
|
14
|
-
#include "FlowerSet.h"<U+0013>
|
15
|
-
^
|
16
|
-
//
|
17
|
-
In file included from flowerset.cpp:1:
|
18
|
-
In file included from ./FlowerSet.h:3:
|
19
|
-
In file included from ./Flower.h:5:
|
20
|
-
.
|
10
|
+
sample04.cpp:16:17: warning: illegal character encoding in string literal [-Winvalid-source-encoding]
|
11
|
+
printf("%d<89><F1><96>ځF<8D>ŗǕ]<89><BF><92>l%f\n", i, fSet->bestValue);
|
21
|
-
|
12
|
+
^~~~~~~~~~~~ ~~~~ ~~~~~~~~~~~~
|
22
|
-
^
|
23
|
-
//
|
24
|
-
.
|
13
|
+
sample04.cpp:16:7: error: use of undeclared identifier 'printf'
|
25
|
-
Flower **flower;//食糧源の集合のメンバ
|
26
|
-
^
|
27
|
-
./FlowerSet.h:24:3: error: unknown type name 'Flower'
|
28
|
-
Flower *newFlower; //新しい食糧源
|
29
|
-
^
|
30
|
-
In file included from flowerset.cpp:1:
|
31
|
-
|
14
|
+
printf("%d<89><F1><96>ځF<8D>ŗǕ]<89><BF><92>l%f\n", i, fSet->bestValue);
|
32
|
-
class FlowerSet
|
33
15
|
^
|
34
|
-
./Flower.h:5:10: note: './FlowerSet.h' included multiple times, additional include site here
|
35
|
-
#include "FlowerSet.h"<U+0013>
|
36
|
-
^
|
37
|
-
flowerset.cpp:1:10: note: './FlowerSet.h' included multiple times, additional include site here
|
38
|
-
#include "FlowerSet.h"
|
39
|
-
^
|
40
|
-
flowerset.cpp:2:9: warning: #pragma once in main file [-Wpragma-once-outside-header]
|
41
|
-
#pragma once
|
42
|
-
^
|
43
|
-
flowerset.cpp:43:5: error: function definition is not allowed here
|
44
|
-
{
|
45
|
-
^
|
46
|
-
flowerset.cpp:59:5: error: function definition is not allowed here
|
47
|
-
{
|
48
|
-
^
|
49
|
-
flowerset.cpp:105:5: error: function definition is not allowed here
|
50
|
-
{
|
51
|
-
^
|
52
|
-
flowerset.cpp:116:5: error: function definition is not allowed here
|
53
|
-
{
|
54
|
-
^
|
55
|
-
flowerset.cpp:134:5: error: function definition is not allowed here
|
56
|
-
{
|
57
|
-
^
|
58
|
-
flowerset.cpp:139:3: error: expected '}'
|
59
|
-
|
60
|
-
^
|
61
|
-
flowerset.cpp:29:24: note: to match this '{'
|
62
|
-
FlowerSet::~FlowerSet(){
|
63
|
-
^
|
64
|
-
|
16
|
+
2 warnings and 1 error generated.
|
65
17
|
```
|
66
18
|
|
67
19
|
### 該当のソースコード
|
2
現在発生しているエラーです.
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,67 +3,65 @@
|
|
3
3
|
### 発生している問題・エラーメッセージ
|
4
4
|
|
5
5
|
```
|
6
|
+
In file included from flowerset.cpp:1:
|
7
|
+
./FlowerSet.h:3:20: warning: extra tokens at end of #include directive [-Wextra-tokens]
|
8
|
+
#include "Flower.h"<U+0013>
|
9
|
+
^
|
10
|
+
//
|
11
|
+
In file included from flowerset.cpp:1:
|
12
|
+
In file included from ./FlowerSet.h:3:
|
13
|
+
./Flower.h:5:23: warning: extra tokens at end of #include directive [-Wextra-tokens]
|
14
|
+
#include "FlowerSet.h"<U+0013>
|
15
|
+
^
|
16
|
+
//
|
17
|
+
In file included from flowerset.cpp:1:
|
18
|
+
In file included from ./FlowerSet.h:3:
|
19
|
+
In file included from ./Flower.h:5:
|
20
|
+
./FlowerSet.h:3:20: warning: extra tokens at end of #include directive [-Wextra-tokens]
|
21
|
+
#include "Flower.h"<U+0013>
|
22
|
+
^
|
23
|
+
//
|
24
|
+
./FlowerSet.h:19:3: error: unknown type name 'Flower'
|
25
|
+
Flower **flower;//食糧源の集合のメンバ
|
26
|
+
^
|
27
|
+
./FlowerSet.h:24:3: error: unknown type name 'Flower'
|
28
|
+
Flower *newFlower; //新しい食糧源
|
29
|
+
^
|
30
|
+
In file included from flowerset.cpp:1:
|
6
|
-
error: redefinition of 'FlowerSet'
|
31
|
+
./FlowerSet.h:7:7: error: redefinition of 'FlowerSet'
|
7
32
|
class FlowerSet
|
8
33
|
^
|
9
|
-
flowerset.cpp:7:12: error: C++ requires a type specifier for all declarations
|
10
|
-
FlowerSet::Flower(char *filename){
|
11
|
-
|
34
|
+
./Flower.h:5:10: note: './FlowerSet.h' included multiple times, additional include site here
|
12
|
-
|
35
|
+
#include "FlowerSet.h"<U+0013>
|
13
|
-
|
36
|
+
^
|
14
|
-
class
|
15
|
-
flowerset.cpp:
|
37
|
+
flowerset.cpp:1:10: note: './FlowerSet.h' included multiple times, additional include site here
|
16
|
-
|
38
|
+
#include "FlowerSet.h"
|
17
|
-
|
39
|
+
^
|
18
|
-
flowerset.cpp:
|
40
|
+
flowerset.cpp:2:9: warning: #pragma once in main file [-Wpragma-once-outside-header]
|
19
|
-
|
41
|
+
#pragma once
|
20
|
-
|
42
|
+
^
|
21
|
-
class
|
22
|
-
flowerset.cpp:
|
43
|
+
flowerset.cpp:43:5: error: function definition is not allowed here
|
23
|
-
|
44
|
+
{
|
24
|
-
|
45
|
+
^
|
25
|
-
flowerset.cpp:22:30: error: no member named 'post' in 'Flower'; did you mean 'pos'?
|
26
|
-
bestPos[i]=flower[best]->post[i];
|
27
|
-
^~~~
|
28
|
-
pos
|
29
|
-
.
|
46
|
+
flowerset.cpp:59:5: error: function definition is not allowed here
|
30
|
-
|
47
|
+
{
|
31
|
-
|
48
|
+
^
|
32
|
-
flowerset.cpp:
|
49
|
+
flowerset.cpp:105:5: error: function definition is not allowed here
|
33
|
-
|
50
|
+
{
|
34
|
-
|
51
|
+
^
|
35
|
-
class
|
36
|
-
flowerset.cpp:
|
52
|
+
flowerset.cpp:116:5: error: function definition is not allowed here
|
37
|
-
|
53
|
+
{
|
38
|
-
|
54
|
+
^
|
39
|
-
flowerset.cpp:26:3: error: use of undeclared identifier 'trvlue'; did you mean 'trValue'?
|
40
|
-
trvlue=new double[EBEE_NUM];
|
41
|
-
^~~~~~
|
42
|
-
trValue
|
43
|
-
.
|
55
|
+
flowerset.cpp:134:5: error: function definition is not allowed here
|
44
|
-
|
56
|
+
{
|
45
|
-
|
57
|
+
^
|
46
|
-
flowerset.cpp:43:37: error: function definition is not allowed here
|
47
|
-
void FlowerSet::employedBeePhase(){
|
48
|
-
^
|
49
|
-
flowerset.cpp:58:37: error: function definition is not allowed here
|
50
|
-
void FlowerSet::onlookerBeePhase(){
|
51
|
-
^
|
52
|
-
flowerset.cpp:103:34: error: function definition is not allowed here
|
53
|
-
void FlowerSet::scoutBeePhase(){
|
54
|
-
^
|
55
|
-
flowerset.cpp:113:32: error: function definition is not allowed here
|
56
|
-
void FlowerSet::saveBestPos(){
|
57
|
-
^
|
58
|
-
flowerset.cpp:130:32: error: function definition is not allowed here
|
59
|
-
void FlowerSet::printResult(){
|
60
|
-
^
|
61
|
-
flowerset.cpp:
|
58
|
+
flowerset.cpp:139:3: error: expected '}'
|
62
59
|
|
63
60
|
^
|
64
|
-
.
|
61
|
+
flowerset.cpp:29:24: note: to match this '{'
|
65
|
-
|
62
|
+
FlowerSet::~FlowerSet(){
|
66
|
-
|
63
|
+
^
|
64
|
+
4 warnings and 9 errors generated.
|
67
65
|
```
|
68
66
|
|
69
67
|
### 該当のソースコード
|
1
FlowerSet.h Flower.h Flower.cppを追加しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -211,6 +211,143 @@
|
|
211
211
|
|
212
212
|
```
|
213
213
|
|
214
|
+
```Flower
|
215
|
+
//Flower.h
|
216
|
+
#ifndef INCLUDED_FLOWER
|
217
|
+
#define INCLUDED_FLOWER
|
218
|
+
#include "DataSet.h"
|
219
|
+
#include "FlowerSet.h"
|
220
|
+
#pragma once
|
221
|
+
class FlowerSet;
|
222
|
+
|
223
|
+
//定数の定義
|
224
|
+
#define REPEAT_NUM 1000 //繰り返し数
|
225
|
+
#define EBEE_NUM 100 //収穫蜂の数
|
226
|
+
#define OBEE_NUM 10 //追従蜂の数
|
227
|
+
#define VISIT_MAX 10 //蜜の採取可能回数
|
228
|
+
#define COEF_MIN -1 //標準偏回帰係数の最小値
|
229
|
+
#define COEF_MAX 1 //標準偏回帰係数の最大値
|
230
|
+
|
231
|
+
//0以上1以下の実数乱数
|
232
|
+
#define RAND_01 ((double)rand() / RAND_MAX)
|
233
|
+
|
234
|
+
class Flower{
|
235
|
+
public:
|
236
|
+
Flower(FlowerSet *argFSet);
|
237
|
+
~Flower();
|
238
|
+
void change(int base); //近くの食糧源に変更する
|
239
|
+
void renew();//新しい食糧源に変更する.
|
240
|
+
|
241
|
+
FlowerSet *fSet; //属している食糧源集合
|
242
|
+
double *pos; //位置
|
243
|
+
double value;//評価値
|
244
|
+
int visitNum;//蜜の採取回数
|
245
|
+
|
246
|
+
private:
|
247
|
+
void evaluate();//評価値を算出する
|
248
|
+
};
|
249
|
+
#endif
|
250
|
+
```
|
251
|
+
|
252
|
+
```Flower
|
253
|
+
//Flower.cpp
|
254
|
+
#include "Flower.h"
|
255
|
+
#pragma once
|
256
|
+
|
257
|
+
//コントラスた
|
258
|
+
//argFSet:属している食糧源集合
|
259
|
+
|
260
|
+
Flower::Flower(FlowerSet *argFSet){
|
261
|
+
int i;
|
262
|
+
|
263
|
+
fSet=argFSet;
|
264
|
+
pos=new double[fSet->dataset->exVarNum];
|
265
|
+
for(i=0;i<fSet->dataset->exVarNum;i++){
|
266
|
+
pos[i]=COEF_MIN+(COEF_MAX-COEF_MIN)*RAND_01;
|
267
|
+
}
|
268
|
+
visitNum=0;
|
269
|
+
evaluate();
|
270
|
+
}
|
271
|
+
|
272
|
+
//デストラクタ
|
273
|
+
Flower::~Flower(){
|
274
|
+
delete[]pos;
|
275
|
+
}
|
276
|
+
//baseの近くの食糧源に変更する
|
277
|
+
//base:元にする食糧源の添字
|
278
|
+
void Flower::change(int base){
|
279
|
+
int i,j;
|
280
|
+
|
281
|
+
for(i=0;i<fSet->dataset->exVarNum;i++){
|
282
|
+
pos[i]=fSet->flower[base]->pos[i];
|
283
|
+
}
|
284
|
+
i=rand() % fSet->dataset->exVarNum;
|
285
|
+
j=(base+(rand() % (EBEE_NUM-1)+1)) % EBEE_NUM;
|
286
|
+
pos[i]=pos[i]+(rand() / (RAND_MAX/2.0)-1)*(pos[i]-fSet->flower[j]->pos[i]);
|
287
|
+
visitNum=0;
|
288
|
+
evaluate();
|
289
|
+
}
|
290
|
+
|
291
|
+
//新しい食糧源に変更する
|
292
|
+
void Flower::renew(){
|
293
|
+
int i;
|
294
|
+
for(i=0;i<fSet->dataset->exVarNum;i++){
|
295
|
+
pos[i]=COEF_MIN+(COEF_MAX - COEF_MIN)*RAND_01;
|
296
|
+
}
|
297
|
+
visitNum=0;
|
298
|
+
evaluate();
|
299
|
+
}
|
300
|
+
|
301
|
+
//評価値を算出する
|
302
|
+
void Flower::evaluate(){
|
303
|
+
int i,j;
|
304
|
+
double diff;
|
305
|
+
|
306
|
+
value=0.0;
|
307
|
+
for(i=0;i<fSet->dataset->dataNum;i++){
|
308
|
+
diff=fSet->dataset->resSData[i];
|
309
|
+
for(j=0;j<fSet->dataset->exSData[i][j];j++){
|
310
|
+
diff -= pos[j]*fSet->dataset->exSData[i][j];
|
311
|
+
}
|
312
|
+
value += pow(diff,2.0);
|
313
|
+
}
|
314
|
+
}
|
315
|
+
|
316
|
+
```
|
317
|
+
|
318
|
+
```FlowerSet
|
319
|
+
//FlowerSet.h
|
320
|
+
#ifndef INCLUDED_FLOWERSET
|
321
|
+
#define INCLUDE_FLOWERSET
|
322
|
+
#include "Flower.h"
|
323
|
+
#pragma once
|
324
|
+
class Flower;
|
325
|
+
|
326
|
+
class FlowerSet
|
327
|
+
{
|
328
|
+
public:
|
329
|
+
FlowerSet(char *filename);
|
330
|
+
~FlowerSet();
|
331
|
+
void employedBeePhase(); //収穫蜂フェーズを実行する
|
332
|
+
void onlockerBeePhase();//追従蜂フェーズを実行する
|
333
|
+
void scoutBeePhase();//偵察蜂フェーズを実行する.
|
334
|
+
void saveBestPos();//最良食糧源を記録する.
|
335
|
+
void printResult();//結果を表示する.
|
336
|
+
|
337
|
+
Dataset *dataset;//データセット
|
338
|
+
Flower **flower;//食糧源の集合のメンバ
|
339
|
+
double *bestPos;//最良食糧源の位置
|
340
|
+
double bestValue;//最良食糧源の評価値
|
341
|
+
|
342
|
+
private:
|
343
|
+
Flower *newFlower; //新しい食糧源
|
344
|
+
double *trValue; //格食糧源の変換後の評価値
|
345
|
+
};
|
346
|
+
|
347
|
+
#endif
|
348
|
+
|
349
|
+
|
350
|
+
```
|
214
351
|
### 試したこと
|
215
352
|
|
216
353
|
著書には載っていませんでしたがインクルードガードなどは行いました
|