teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

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

2018/11/26 08:30

投稿

totogawa
totogawa

スコア18

title CHANGED
File without changes
body CHANGED
@@ -14,151 +14,325 @@
14
14
 
15
15
  こうしたらいいのではないのか、これを試したらどうか等何でも構いませんので、ご回答のほどよろしくお願いします。
16
16
 
17
- ### 該当のソースコード
17
+ ### 製作しているソースコード(問題が発生しているもの)
18
+ ```java
19
+ private static final long serialVersionUID = 1L;
18
20
 
19
- ```html
20
- <!DOCTYPE html>
21
+ public Imput_Action() {
21
- <html>
22
- <head>
23
- <meta charset="UTF-8">
24
- <title>テスト</title>
25
- </head>
26
- <body>
27
- <br>
22
+ super();
28
- <form method = "post" action = "../test/HelloWorld" onSubmit = "return check()">
29
- <select name="number1" style="font-size:100% ; border:0.5px">
30
- <option value="1">1</option>
31
- <option value="2">2</option>
32
- <option value="3">3</option>
33
- <option value="4">4</option>
34
- <option value="5">5</option>
35
- <option value="6">6</option>
36
- <option value="7">7</option>
37
- <option value="8">8</option>
38
- <option value="9">9</option>
39
- <option value="10">10</option>
40
- <option value="11">11</option>
41
- <option value="12">12</option>
42
- <option value="13">13</option>
43
- <option value="14">14</option>
44
- <option value="15">15</option>
45
- <option value="16">16</option>
46
- <option value="17">17</option>
47
- </select>
23
+ }
48
24
 
49
- <select name="number2" style="font-size:100% ; border:0.5px">
25
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
50
- <option value="1">1</option>
51
- <option value="2">2</option>
52
- <option value="3">3</option>
53
- <option value="4">4</option>
54
- <option value="5">5</option>
55
- <option value="6">6</option>
56
- <option value="7">7</option>
57
- <option value="8">8</option>
58
- <option value="9">9</option>
59
- <option value="10">10</option>
60
- <option value="11">11</option>
61
- <option value="12">12</option>
62
- <option value="13">13</option>
63
- <option value="14">14</option>
64
- <option value="15">15</option>
65
- <option value="16">16</option>
66
- <option value="17">17</option>
67
- </select>
68
26
 
69
- <p><input type = "submit" value = "情報をサーブレットに送信">
70
- <input type = "reset" value = "入力した情報をリセットする">
71
- </p>
72
- </form>
73
- <br>
74
- </body>
75
- </html>
76
- ```
27
+ }
77
- ```java
78
- package test;
79
28
 
29
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
30
+ // 各種必要な変数等の定義
80
- import java.io.IOException;
31
+ String bf_gender;
32
+ String bf_age;
33
+ String bf_day;
81
34
 
82
- import javax.servlet.ServletException;
35
+ bf_gender = request.getParameter("num_Gender");
83
- import javax.servlet.annotation.WebServlet;
36
+ bf_age = request.getParameter("num_Age");
84
- import javax.servlet.http.HttpServlet;
85
- import javax.servlet.http.HttpServletRequest;
37
+ bf_day = request.getParameter("Day_data");
86
- import javax.servlet.http.HttpServletResponse;
87
38
 
88
- @WebServlet("/HelloWorld")
89
- public class HelloWorld extends HttpServlet {
39
+ num_Gender = Integer.parseInt(bf_gender);
90
- private static final long serialVersionUID = 1L;
40
+ num_Age = Integer.parseInt(bf_age);
41
+ num_Day = Integer.parseInt(bf_day);
91
42
 
43
+ // GA自体の実行部分
92
- int number1 = 0;
44
+ ALL_FileRead();
93
- int number2 = 0;
45
+ Firast_Population();
94
- int sum = 0;
46
+ Satisfaction();
95
47
 
96
- public HelloWorld() {
48
+ for(int generation = 0 ; generation < GENERATION_SIZE ; generation++) {
97
- super();
49
+ strat();
50
+ elite_SRST = Collections.max(SRST);
98
- }
51
+ Generation_Elite.add(elite_SRST);
99
52
 
53
+ // 各世代で最大満足度個体を保存
54
+ for(int i = 0 ; i < SRST.size() ; i++) {
55
+ double a = SRST.get(i);
56
+ if(elite_SRST == a) {
100
- protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
57
+ ArrayList<Integer> ESRN = new ArrayList<>(SNRList.get(i));
58
+ ArrayList<Integer> EPRN = new ArrayList<>();
59
+ Generation_EliteS.add(ESRN);
101
60
 
61
+ // 競技Noを会場Noに変換
62
+ for(int y = 0 ; y < ESRN.size() ; y++) {
63
+ for(int x = 0 ; x < noExchange.length ; x++) {
64
+ if(noExchange[ESRN.get(y)][x] == 1) {
65
+ EPRN.add(x);
102
- }
66
+ }
67
+ }
68
+ }
69
+ // 会場ルートの先頭にNo,0…JR東京駅を追加
70
+ EPRN.add(0 , 0);
71
+ Generation_EliteP.add(EPRN);
72
+ break;
73
+ }
74
+ }
75
+ }
103
76
 
77
+ // 全世代間で最大満足度の個体を探索。
78
+ double TOP_ELITE = 0.0;
104
- protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
79
+ ArrayList<Integer> TOP_ELITE_PROOT = new ArrayList<>();
80
+ ArrayList<Integer> TOP_ELITE_SROOT = new ArrayList<>();
105
- String num1;
81
+ int TOP_ELITE_NO = 0;
106
- String num2;
107
82
 
108
- num1 = request.getParameter("number1");
83
+ TOP_ELITE = Collections.max(Generation_Elite);
109
- num2 = request.getParameter("number2");
84
+ TOP_ELITE_NO = Generation_Elite.indexOf(TOP_ELITE);
85
+ TOP_ELITE_SROOT = Generation_EliteS.get(TOP_ELITE_NO);
86
+ TOP_ELITE_PROOT = Generation_EliteP.get(TOP_ELITE_NO);
110
87
 
88
+ // output.jspに送る際に先頭にダミーを置く。
111
- number1 = Integer.parseInt(num1);
89
+ TOP_ELITE_SROOT.add(0 , 1000);
112
- number2 = Integer.parseInt(num2);
90
+ TOP_ELITE_PROOT.add(0 , 1000);
113
91
 
92
+ // 競技・会場Noから名前への変換と配列への保存
114
- test();
93
+ ArrayList<String> result_SNroot = new ArrayList<>();
94
+ ArrayList<String> result_PNroot = new ArrayList<>();
115
95
 
116
- request.setAttribute("number1", number1);
96
+ for(int i = 1 ; i < TOP_ELITE_SROOT.size() ; i++) {
117
- request.setAttribute("number2", number2);
118
- request.setAttribute("sum", sum);
97
+ String numS = Sname.get(TOP_ELITE_SROOT.get(i));
98
+ result_SNroot.add(numS);
99
+ }
119
100
 
101
+ for(int i = 1 ; i < TOP_ELITE_PROOT.size() ; i++) {
102
+ String numP = Pname.get(TOP_ELITE_PROOT.get(i));
103
+ result_PNroot.add(numP);
104
+ }
105
+
106
+ // output.jspに送る際に先頭と最後尾にダミーを置く。
107
+ result_SNroot.add(0 , "ダミー");
108
+ result_PNroot.add(0 , "ダミー");
109
+ result_SNroot.add(result_SNroot.size() , "ダミー");
110
+ result_PNroot.add(result_PNroot.size() , "ダミー");
111
+
112
+ // output.jspに各種数値等を送る
113
+ request.setAttribute("result_Sroot" , TOP_ELITE_SROOT);
114
+ request.setAttribute("result_Proot" , TOP_ELITE_PROOT);
115
+ request.setAttribute("result_SNroot" , result_SNroot);
116
+ request.setAttribute("result_PNroot" , result_PNroot);
117
+ request.setAttribute("result_Satisfaction" , TOP_ELITE);
118
+
120
119
  getServletConfig().getServletContext().
121
- getRequestDispatcher("/test-output.jsp").forward(request , response);
120
+ getRequestDispatcher("/output-action.jsp").forward(request , response);
122
121
  }
123
122
 
123
+ // GAの流れを構成(フローチャートでいう繰り返しの部分)
124
- public void test() {
124
+ public void strat() {
125
+ Selection_R();
126
+ crossover2();
127
+ mutation();
128
+ time_limit();
129
+ Satisfaction();
125
- sum = number1 + number2;
130
+ **上記のコードは文字数の関係上省略しました。**
126
131
  }
132
+
133
+ // HTMLからの使用者の性別年代情報の入力
134
+ public void User_Choice() {
135
+
136
+ // 性別の選択
137
+ int Gender_data = num_Gender;
138
+
139
+ // 男女別の満足度表取り込み
140
+ switch (Gender_data) {
141
+ case 0:
142
+ for (int y = 0; y < 38; y++) {
143
+ for (int x = 0; x < 6; x++) {
144
+ GENDER[y][x] = womanSatisfaction[y][x];
145
+ }
146
+ }
147
+ break;
148
+
149
+ case 1:
150
+ for (int y = 0; y < 38; y++) {
151
+ for (int x = 0; x < 6; x++) {
152
+ GENDER[y][x] = manSatisfaction[y][x];
153
+ }
154
+ }
155
+ break;
156
+ }
157
+
158
+ // 年代を選択
159
+ int Age_data = num_Age;
160
+ age = Age_data - 1;
161
+ for(int x = 0 ; x < GENDER.length ; x++) {
162
+ AGE[x] = GENDER[x][Age_data];
163
+ }
164
+
165
+ // 年代の表示
166
+ switch (num_Age) {
167
+ case 0:
168
+ PAge = ("20代");
169
+ break;
170
+ case 1:
171
+ PAge = ("30代");
172
+ break;
173
+ case 2:
174
+ PAge = ("40代");
175
+ break;
176
+ case 3:
177
+ PAge = ("50代");
178
+ break;
179
+ case 4:
180
+ PAge = ("60代");
181
+ break;
182
+ case 5:
183
+ PAge = ("70代以上");
184
+ break;
185
+ }
186
+
187
+ // 性別の表示
188
+ switch (num_Gender) {
189
+ case 0:
190
+ PGender = ("女性");
191
+ break;
192
+ case 1:
193
+ PGender = ("男性");
194
+ break;
195
+ }
196
+
197
+ // 対象の日程情報を取り出し
198
+ int Day = num_Day;
199
+ //各日程の開催競技Noの読み込み
200
+ for(int x = 0 ; x < dayHolding.length ; x++) {
201
+ if(dayHolding[Day][x] == 1) {
202
+ DH.add(x);
203
+ }
204
+ }
205
+ }
127
206
  }
207
+ ```
128
208
 
209
+ ```html
210
+ **form部分のみ掲載します**
211
+ <form method = "post" action = "/imput-test/Imput_Action" onSubmit = "return check()">
212
+
213
+ <h2><label for="GENDER">~~性別を教えてください~~</label></h2>
214
+
215
+ <div class="table">
216
+ <table border="1" align="center">
217
+ <tr>
218
+ <th id="man-table">男性</th>
219
+
220
+ <th id="woman-table">女性</th>
221
+ </tr>
222
+
223
+ <tr>
224
+ <td id="man-table">
225
+ <div class="select-gender" >
226
+ <input id="man" type="radio" name="num_Gender" value="1">
227
+ <label for="man">
228
+ <img src="img/man.jpg" width="150px" height="150px" alt="エラー">
229
+ </label>
230
+ </div>
231
+ </td>
232
+
233
+ <td id="woman-table">
234
+ <div class="select-gender">
235
+ <input id="woman" type="radio" name="num_Gender" value="0">
236
+ <label for="woman">
237
+ <img src="img/woman.jpg" width="150px" height="150px" alt="エラー">
238
+ </label>
239
+ </div>
240
+
241
+ </td>
242
+ </tr>
243
+ </table>
244
+ </div>
245
+
246
+ <h2><label for="AGE">~~年代を教えてください~~</label></h2>
247
+
248
+ <select name="num_Age" style="font-size:100% ; border:0.5px">
249
+ <option value="0">20代</option>
250
+ <option value="1">30代</option>
251
+ <option value="2">40代</option>
252
+ <option value="3">50代</option>
253
+ <option value="4">60代</option>
254
+ <option value="5">70代以上</option>
255
+ </select>
256
+
257
+ <h2><label for="DAY">~~調べたい日程を教えてください~~</label></h2>
258
+
259
+ <select name="Day_data" style="font-size:100% ; border:0.5px">
260
+ <option value="0">1日目</option>
261
+ <option value="1">2日目</option>
262
+ <option value="2">3日目</option>
263
+ <option value="3">4日目</option>
264
+ <option value="4">5日目</option>
265
+ <option value="5">6日目</option>
266
+ <option value="6">7日目</option>
267
+ <option value="7">8日目</option>
268
+ <option value="8">9日目</option>
269
+ <option value="9">10日目</option>
270
+ <option value="10">11日目</option>
271
+ <option value="11">12日目</option>
272
+ <option value="12">13日目</option>
273
+ <option value="13">14日目</option>
274
+ <option value="14">15日目</option>
275
+ <option value="15">16日目</option>
276
+ <option value="16">17日目</option>
277
+ </select>
278
+
279
+ <p><input type = "submit" value = "情報をサーブレットに送信">
280
+ <input type = "reset" value = "入力した情報をリセットする">
281
+ </p>
282
+
283
+ <script>function check(){
284
+ num_Gender = 0 ;
285
+ num_Age = 0 ;
286
+ Day_data = 0 ;
287
+ if(window.confirm("送信してよろしいですか?")){
288
+ return true;
289
+ }
290
+ else{
291
+ window.alert("キャンセルしました\n再度入力してください");
292
+ return false;
293
+ }
294
+ }</script>
295
+ </form>
129
296
  ```
297
+
130
298
  ```jsp
131
- <%@ page language="java" contentType="text/html; charset=UTF-8"
132
- pageEncoding="UTF-8"%>
133
- <!DOCTYPE html>
134
- <html>
135
- <head>
136
- <meta charset="UTF-8">
137
- <title>Insert title here</title>
138
- </head>
299
+ **script部分のみ掲載します**
139
- <body>
140
- <script type="text/javascript">
300
+ <script type="text/javascript">
301
+ SNnum = new Array;
302
+ Sport_Name_Root = new Array;
141
- var number1 = '<%=request.getAttribute("number1")%>';
303
+ var SNroot = '<%=request.getAttribute("result_SNroot")%>';
304
+ SNnum = SNroot.split(",");
305
+ for(var i = 1 ; i < SNnum.length-1 ; i++){
306
+ Sport_Name_Root[i] = SNnum[i];
307
+ document.write(i + "番目…" + Sport_Name_Root[i] + "<br>");
308
+ }
142
- document.write(number1);
309
+ document.write("~~finish~~");
143
310
  </script>
144
- <br>
311
+ </div>
145
312
 
313
+ <div class="public_root">
314
+ <h2>~~会場ルート~~</h2>
146
- <script type="text/javascript">
315
+ <script type="text/javascript">
316
+ Pnum = new Array;
317
+ Public_No_Root = new Array;
147
- var number2 = '<%=request.getAttribute("number2")%>';
318
+ var Proot = '<%=request.getAttribute("result_Proot")%>';
148
- document.write(number2);
319
+ Pnum = Proot.split(",");
320
+ for(var i = 1 ; i < Pnum.length ; i++){
149
- </script>
321
+ Public_No_Root[i] = parseInt(Pnum[i]);
322
+ }
150
- <br>
323
+ document.write("finish" + "<br>");
151
324
 
325
+ PNnum = new Array;
152
- <script type="text/javascript">
326
+ Public_Name_Root = new Array;
153
- var sum = '<%=request.getAttribute("sum")%>';
327
+ var PNroot = '<%=request.getAttribute("result_PNroot")%>';
328
+ PNnum = PNroot.split(",");
329
+ for(var i = 1 ; i < PNnum.length-1 ; i++){
330
+ Public_Name_Root[i] = PNnum[i];
331
+ document.write(i + "番目…" + Public_Name_Root[i]);
332
+ document.write('<center>');
333
+ document.write(point[ Public_No_Root[i] ]);
334
+ document.write('</center>');
335
+ }
154
- document.write(sum);
336
+ document.write("~~finish~~");
155
- </script>
337
+ </script>
156
- <br>
157
-
158
- <script type="text/javascript">
159
- document.write("~~finish~~");
160
- </script>
161
- <br>
162
- </body>
163
- </html>
164
338
  ```