質問編集履歴

1

実際に制作しているソースコードを添付しました。

2018/11/26 08:30

投稿

totogawa
totogawa

スコア18

test CHANGED
File without changes
test CHANGED
@@ -30,105 +30,525 @@
30
30
 
31
31
 
32
32
 
33
- ### 該当のソースコード
33
+ ### 製作しているソースコード(問題が発生しているもの)
34
+
35
+ ```java
36
+
37
+ private static final long serialVersionUID = 1L;
38
+
39
+
40
+
41
+ public Imput_Action() {
42
+
43
+ super();
44
+
45
+ }
46
+
47
+
48
+
49
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
50
+
51
+
52
+
53
+ }
54
+
55
+
56
+
57
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
58
+
59
+ // 各種必要な変数等の定義
60
+
61
+ String bf_gender;
62
+
63
+ String bf_age;
64
+
65
+ String bf_day;
66
+
67
+
68
+
69
+ bf_gender = request.getParameter("num_Gender");
70
+
71
+ bf_age = request.getParameter("num_Age");
72
+
73
+ bf_day = request.getParameter("Day_data");
74
+
75
+
76
+
77
+ num_Gender = Integer.parseInt(bf_gender);
78
+
79
+ num_Age = Integer.parseInt(bf_age);
80
+
81
+ num_Day = Integer.parseInt(bf_day);
82
+
83
+
84
+
85
+ // GA自体の実行部分
86
+
87
+ ALL_FileRead();
88
+
89
+ Firast_Population();
90
+
91
+ Satisfaction();
92
+
93
+
94
+
95
+ for(int generation = 0 ; generation < GENERATION_SIZE ; generation++) {
96
+
97
+ strat();
98
+
99
+ elite_SRST = Collections.max(SRST);
100
+
101
+ Generation_Elite.add(elite_SRST);
102
+
103
+
104
+
105
+ // 各世代で最大満足度個体を保存
106
+
107
+ for(int i = 0 ; i < SRST.size() ; i++) {
108
+
109
+ double a = SRST.get(i);
110
+
111
+ if(elite_SRST == a) {
112
+
113
+ ArrayList<Integer> ESRN = new ArrayList<>(SNRList.get(i));
114
+
115
+ ArrayList<Integer> EPRN = new ArrayList<>();
116
+
117
+ Generation_EliteS.add(ESRN);
118
+
119
+
120
+
121
+ // 競技Noを会場Noに変換
122
+
123
+ for(int y = 0 ; y < ESRN.size() ; y++) {
124
+
125
+ for(int x = 0 ; x < noExchange.length ; x++) {
126
+
127
+ if(noExchange[ESRN.get(y)][x] == 1) {
128
+
129
+ EPRN.add(x);
130
+
131
+ }
132
+
133
+ }
134
+
135
+ }
136
+
137
+ // 会場ルートの先頭にNo,0…JR東京駅を追加
138
+
139
+ EPRN.add(0 , 0);
140
+
141
+ Generation_EliteP.add(EPRN);
142
+
143
+ break;
144
+
145
+ }
146
+
147
+ }
148
+
149
+ }
150
+
151
+
152
+
153
+ // 全世代間で最大満足度の個体を探索。
154
+
155
+ double TOP_ELITE = 0.0;
156
+
157
+ ArrayList<Integer> TOP_ELITE_PROOT = new ArrayList<>();
158
+
159
+ ArrayList<Integer> TOP_ELITE_SROOT = new ArrayList<>();
160
+
161
+ int TOP_ELITE_NO = 0;
162
+
163
+
164
+
165
+ TOP_ELITE = Collections.max(Generation_Elite);
166
+
167
+ TOP_ELITE_NO = Generation_Elite.indexOf(TOP_ELITE);
168
+
169
+ TOP_ELITE_SROOT = Generation_EliteS.get(TOP_ELITE_NO);
170
+
171
+ TOP_ELITE_PROOT = Generation_EliteP.get(TOP_ELITE_NO);
172
+
173
+
174
+
175
+ // output.jspに送る際に先頭にダミーを置く。
176
+
177
+ TOP_ELITE_SROOT.add(0 , 1000);
178
+
179
+ TOP_ELITE_PROOT.add(0 , 1000);
180
+
181
+
182
+
183
+ // 競技・会場Noから名前への変換と配列への保存
184
+
185
+ ArrayList<String> result_SNroot = new ArrayList<>();
186
+
187
+ ArrayList<String> result_PNroot = new ArrayList<>();
188
+
189
+
190
+
191
+ for(int i = 1 ; i < TOP_ELITE_SROOT.size() ; i++) {
192
+
193
+ String numS = Sname.get(TOP_ELITE_SROOT.get(i));
194
+
195
+ result_SNroot.add(numS);
196
+
197
+ }
198
+
199
+
200
+
201
+ for(int i = 1 ; i < TOP_ELITE_PROOT.size() ; i++) {
202
+
203
+ String numP = Pname.get(TOP_ELITE_PROOT.get(i));
204
+
205
+ result_PNroot.add(numP);
206
+
207
+ }
208
+
209
+
210
+
211
+ // output.jspに送る際に先頭と最後尾にダミーを置く。
212
+
213
+ result_SNroot.add(0 , "ダミー");
214
+
215
+ result_PNroot.add(0 , "ダミー");
216
+
217
+ result_SNroot.add(result_SNroot.size() , "ダミー");
218
+
219
+ result_PNroot.add(result_PNroot.size() , "ダミー");
220
+
221
+
222
+
223
+ // output.jspに各種数値等を送る
224
+
225
+ request.setAttribute("result_Sroot" , TOP_ELITE_SROOT);
226
+
227
+ request.setAttribute("result_Proot" , TOP_ELITE_PROOT);
228
+
229
+ request.setAttribute("result_SNroot" , result_SNroot);
230
+
231
+ request.setAttribute("result_PNroot" , result_PNroot);
232
+
233
+ request.setAttribute("result_Satisfaction" , TOP_ELITE);
234
+
235
+
236
+
237
+ getServletConfig().getServletContext().
238
+
239
+ getRequestDispatcher("/output-action.jsp").forward(request , response);
240
+
241
+ }
242
+
243
+
244
+
245
+ // GAの流れを構成(フローチャートでいう繰り返しの部分)
246
+
247
+ public void strat() {
248
+
249
+ Selection_R();
250
+
251
+ crossover2();
252
+
253
+ mutation();
254
+
255
+ time_limit();
256
+
257
+ Satisfaction();
258
+
259
+ **上記のコードは文字数の関係上省略しました。**
260
+
261
+ }
262
+
263
+
264
+
265
+ // HTMLからの使用者の性別年代情報の入力
266
+
267
+ public void User_Choice() {
268
+
269
+
270
+
271
+ // 性別の選択
272
+
273
+ int Gender_data = num_Gender;
274
+
275
+
276
+
277
+ // 男女別の満足度表取り込み
278
+
279
+ switch (Gender_data) {
280
+
281
+ case 0:
282
+
283
+ for (int y = 0; y < 38; y++) {
284
+
285
+ for (int x = 0; x < 6; x++) {
286
+
287
+ GENDER[y][x] = womanSatisfaction[y][x];
288
+
289
+ }
290
+
291
+ }
292
+
293
+ break;
294
+
295
+
296
+
297
+ case 1:
298
+
299
+ for (int y = 0; y < 38; y++) {
300
+
301
+ for (int x = 0; x < 6; x++) {
302
+
303
+ GENDER[y][x] = manSatisfaction[y][x];
304
+
305
+ }
306
+
307
+ }
308
+
309
+ break;
310
+
311
+ }
312
+
313
+
314
+
315
+ // 年代を選択
316
+
317
+ int Age_data = num_Age;
318
+
319
+ age = Age_data - 1;
320
+
321
+ for(int x = 0 ; x < GENDER.length ; x++) {
322
+
323
+ AGE[x] = GENDER[x][Age_data];
324
+
325
+ }
326
+
327
+
328
+
329
+ // 年代の表示
330
+
331
+ switch (num_Age) {
332
+
333
+ case 0:
334
+
335
+ PAge = ("20代");
336
+
337
+ break;
338
+
339
+ case 1:
340
+
341
+ PAge = ("30代");
342
+
343
+ break;
344
+
345
+ case 2:
346
+
347
+ PAge = ("40代");
348
+
349
+ break;
350
+
351
+ case 3:
352
+
353
+ PAge = ("50代");
354
+
355
+ break;
356
+
357
+ case 4:
358
+
359
+ PAge = ("60代");
360
+
361
+ break;
362
+
363
+ case 5:
364
+
365
+ PAge = ("70代以上");
366
+
367
+ break;
368
+
369
+ }
370
+
371
+
372
+
373
+ // 性別の表示
374
+
375
+ switch (num_Gender) {
376
+
377
+ case 0:
378
+
379
+ PGender = ("女性");
380
+
381
+ break;
382
+
383
+ case 1:
384
+
385
+ PGender = ("男性");
386
+
387
+ break;
388
+
389
+ }
390
+
391
+
392
+
393
+ // 対象の日程情報を取り出し
394
+
395
+ int Day = num_Day;
396
+
397
+ //各日程の開催競技Noの読み込み
398
+
399
+ for(int x = 0 ; x < dayHolding.length ; x++) {
400
+
401
+ if(dayHolding[Day][x] == 1) {
402
+
403
+ DH.add(x);
404
+
405
+ }
406
+
407
+ }
408
+
409
+ }
410
+
411
+ }
412
+
413
+ ```
34
414
 
35
415
 
36
416
 
37
417
  ```html
38
418
 
39
- <!DOCTYPE html>
40
-
41
- <html>
42
-
43
- <head>
44
-
45
- <meta charset="UTF-8">
46
-
47
- <title>テスト</title>
48
-
49
- </head>
50
-
51
- <body>
52
-
53
- <br>
54
-
55
- <form method = "post" action = "../test/HelloWorld" onSubmit = "return check()">
56
-
57
- <select name="number1" style="font-size:100% ; border:0.5px">
58
-
59
- <option value="1">1</option>
60
-
61
- <option value="2">2</option>
62
-
63
- <option value="3">3</option>
64
-
65
- <option value="4">4</option>
66
-
67
- <option value="5">5</option>
68
-
69
- <option value="6">6</option>
70
-
71
- <option value="7">7</option>
72
-
73
- <option value="8">8</option>
74
-
75
- <option value="9">9</option>
76
-
77
- <option value="10">10</option>
78
-
79
- <option value="11">11</option>
80
-
81
- <option value="12">12</option>
82
-
83
- <option value="13">13</option>
84
-
85
- <option value="14">14</option>
86
-
87
- <option value="15">15</option>
88
-
89
- <option value="16">16</option>
90
-
91
- <option value="17">17</option>
419
+ **form部分のみ掲載します**
420
+
421
+ <form method = "post" action = "/imput-test/Imput_Action" onSubmit = "return check()">
422
+
423
+
424
+
425
+ <h2><label for="GENDER">~~性別を教えてください~~</label></h2>
426
+
427
+
428
+
429
+ <div class="table">
430
+
431
+ <table border="1" align="center">
432
+
433
+ <tr>
434
+
435
+ <th id="man-table">男性</th>
436
+
437
+
438
+
439
+ <th id="woman-table">女性</th>
440
+
441
+ </tr>
442
+
443
+
444
+
445
+ <tr>
446
+
447
+ <td id="man-table">
448
+
449
+ <div class="select-gender" >
450
+
451
+ <input id="man" type="radio" name="num_Gender" value="1">
452
+
453
+ <label for="man">
454
+
455
+ <img src="img/man.jpg" width="150px" height="150px" alt="エラー">
456
+
457
+ </label>
458
+
459
+ </div>
460
+
461
+ </td>
462
+
463
+
464
+
465
+ <td id="woman-table">
466
+
467
+ <div class="select-gender">
468
+
469
+ <input id="woman" type="radio" name="num_Gender" value="0">
470
+
471
+ <label for="woman">
472
+
473
+ <img src="img/woman.jpg" width="150px" height="150px" alt="エラー">
474
+
475
+ </label>
476
+
477
+ </div>
478
+
479
+
480
+
481
+ </td>
482
+
483
+ </tr>
484
+
485
+ </table>
486
+
487
+ </div>
488
+
489
+
490
+
491
+ <h2><label for="AGE">~~年代を教えてください~~</label></h2>
492
+
493
+
494
+
495
+ <select name="num_Age" style="font-size:100% ; border:0.5px">
496
+
497
+ <option value="0">20代</option>
498
+
499
+ <option value="1">30代</option>
500
+
501
+ <option value="2">40代</option>
502
+
503
+ <option value="3">50代</option>
504
+
505
+ <option value="4">60代</option>
506
+
507
+ <option value="5">70代以上</option>
92
508
 
93
509
  </select>
94
510
 
95
511
 
96
512
 
513
+ <h2><label for="DAY">~~調べたい日程を教えてください~~</label></h2>
514
+
515
+
516
+
97
- <select name="number2" style="font-size:100% ; border:0.5px">
517
+ <select name="Day_data" style="font-size:100% ; border:0.5px">
98
-
518
+
99
- <option value="1">1</option>
519
+ <option value="0">1日目</option>
100
-
520
+
101
- <option value="2">2</option>
521
+ <option value="1">2日目</option>
102
-
522
+
103
- <option value="3">3</option>
523
+ <option value="2">3日目</option>
104
-
524
+
105
- <option value="4">4</option>
525
+ <option value="3">4日目</option>
106
-
526
+
107
- <option value="5">5</option>
527
+ <option value="4">5日目</option>
108
-
528
+
109
- <option value="6">6</option>
529
+ <option value="5">6日目</option>
110
-
530
+
111
- <option value="7">7</option>
531
+ <option value="6">7日目</option>
112
-
532
+
113
- <option value="8">8</option>
533
+ <option value="7">8日目</option>
114
-
534
+
115
- <option value="9">9</option>
535
+ <option value="8">9日目</option>
536
+
116
-
537
+ <option value="9">10日目</option>
538
+
117
- <option value="10">10</option>
539
+ <option value="10">11日目</option>
118
-
540
+
119
- <option value="11">11</option>
541
+ <option value="11">12日目</option>
120
-
542
+
121
- <option value="12">12</option>
543
+ <option value="12">13日目</option>
122
-
544
+
123
- <option value="13">13</option>
545
+ <option value="13">14日目</option>
124
-
546
+
125
- <option value="14">14</option>
547
+ <option value="14">15日目</option>
126
-
548
+
127
- <option value="15">15</option>
549
+ <option value="15">16日目</option>
128
-
550
+
129
- <option value="16">16</option>
551
+ <option value="16">17日目</option>
130
-
131
- <option value="17">17</option>
132
552
 
133
553
  </select>
134
554
 
@@ -140,188 +560,116 @@
140
560
 
141
561
  </p>
142
562
 
563
+
564
+
565
+ <script>function check(){
566
+
567
+ num_Gender = 0 ;
568
+
569
+ num_Age = 0 ;
570
+
571
+ Day_data = 0 ;
572
+
573
+ if(window.confirm("送信してよろしいですか?")){
574
+
575
+ return true;
576
+
577
+ }
578
+
579
+ else{
580
+
581
+ window.alert("キャンセルしました\n再度入力してください");
582
+
583
+ return false;
584
+
585
+ }
586
+
587
+ }</script>
588
+
143
589
  </form>
144
590
 
145
- <br>
146
-
147
- </body>
148
-
149
- </html>
150
-
151
591
  ```
152
592
 
153
- ```java
154
-
155
- package test;
156
-
157
-
158
-
159
- import java.io.IOException;
160
-
161
-
162
-
163
- import javax.servlet.ServletException;
164
-
165
- import javax.servlet.annotation.WebServlet;
166
-
167
- import javax.servlet.http.HttpServlet;
168
-
169
- import javax.servlet.http.HttpServletRequest;
170
-
171
- import javax.servlet.http.HttpServletResponse;
172
-
173
-
174
-
175
- @WebServlet("/HelloWorld")
176
-
177
- public class HelloWorld extends HttpServlet {
178
-
179
- private static final long serialVersionUID = 1L;
180
-
181
-
182
-
183
- int number1 = 0;
184
-
185
- int number2 = 0;
186
-
187
- int sum = 0;
188
-
189
-
190
-
191
- public HelloWorld() {
192
-
193
- super();
194
-
195
- }
196
-
197
-
198
-
199
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
200
-
201
-
202
-
203
- }
204
-
205
-
206
-
207
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
208
-
209
- String num1;
210
-
211
- String num2;
212
-
213
-
214
-
215
- num1 = request.getParameter("number1");
216
-
217
- num2 = request.getParameter("number2");
218
-
219
-
220
-
221
- number1 = Integer.parseInt(num1);
222
-
223
- number2 = Integer.parseInt(num2);
224
-
225
-
226
-
227
- test();
228
-
229
-
230
-
231
- request.setAttribute("number1", number1);
232
-
233
- request.setAttribute("number2", number2);
234
-
235
- request.setAttribute("sum", sum);
236
-
237
-
238
-
239
- getServletConfig().getServletContext().
240
-
241
- getRequestDispatcher("/test-output.jsp").forward(request , response);
242
-
243
- }
244
-
245
-
246
-
247
- public void test() {
248
-
249
- sum = number1 + number2;
250
-
251
- }
252
-
253
- }
254
-
255
-
593
+
594
+
595
+ ```jsp
596
+
597
+ **script部分のみ掲載します**
598
+
599
+ <script type="text/javascript">
600
+
601
+ SNnum = new Array;
602
+
603
+ Sport_Name_Root = new Array;
604
+
605
+ var SNroot = '<%=request.getAttribute("result_SNroot")%>';
606
+
607
+ SNnum = SNroot.split(",");
608
+
609
+ for(var i = 1 ; i < SNnum.length-1 ; i++){
610
+
611
+ Sport_Name_Root[i] = SNnum[i];
612
+
613
+ document.write(i + "番目…" + Sport_Name_Root[i] + "<br>");
614
+
615
+ }
616
+
617
+ document.write("~~finish~~");
618
+
619
+ </script>
620
+
621
+ </div>
622
+
623
+
624
+
625
+ <div class="public_root">
626
+
627
+ <h2>~~会場ルート~~</h2>
628
+
629
+ <script type="text/javascript">
630
+
631
+ Pnum = new Array;
632
+
633
+ Public_No_Root = new Array;
634
+
635
+ var Proot = '<%=request.getAttribute("result_Proot")%>';
636
+
637
+ Pnum = Proot.split(",");
638
+
639
+ for(var i = 1 ; i < Pnum.length ; i++){
640
+
641
+ Public_No_Root[i] = parseInt(Pnum[i]);
642
+
643
+ }
644
+
645
+ document.write("finish" + "<br>");
646
+
647
+
648
+
649
+ PNnum = new Array;
650
+
651
+ Public_Name_Root = new Array;
652
+
653
+ var PNroot = '<%=request.getAttribute("result_PNroot")%>';
654
+
655
+ PNnum = PNroot.split(",");
656
+
657
+ for(var i = 1 ; i < PNnum.length-1 ; i++){
658
+
659
+ Public_Name_Root[i] = PNnum[i];
660
+
661
+ document.write(i + "番目…" + Public_Name_Root[i]);
662
+
663
+ document.write('<center>');
664
+
665
+ document.write(point[ Public_No_Root[i] ]);
666
+
667
+ document.write('</center>');
668
+
669
+ }
670
+
671
+ document.write("~~finish~~");
672
+
673
+ </script>
256
674
 
257
675
  ```
258
-
259
- ```jsp
260
-
261
- <%@ page language="java" contentType="text/html; charset=UTF-8"
262
-
263
- pageEncoding="UTF-8"%>
264
-
265
- <!DOCTYPE html>
266
-
267
- <html>
268
-
269
- <head>
270
-
271
- <meta charset="UTF-8">
272
-
273
- <title>Insert title here</title>
274
-
275
- </head>
276
-
277
- <body>
278
-
279
- <script type="text/javascript">
280
-
281
- var number1 = '<%=request.getAttribute("number1")%>';
282
-
283
- document.write(number1);
284
-
285
- </script>
286
-
287
- <br>
288
-
289
-
290
-
291
- <script type="text/javascript">
292
-
293
- var number2 = '<%=request.getAttribute("number2")%>';
294
-
295
- document.write(number2);
296
-
297
- </script>
298
-
299
- <br>
300
-
301
-
302
-
303
- <script type="text/javascript">
304
-
305
- var sum = '<%=request.getAttribute("sum")%>';
306
-
307
- document.write(sum);
308
-
309
- </script>
310
-
311
- <br>
312
-
313
-
314
-
315
- <script type="text/javascript">
316
-
317
- document.write("~~finish~~");
318
-
319
- </script>
320
-
321
- <br>
322
-
323
- </body>
324
-
325
- </html>
326
-
327
- ```