質問編集履歴
4
データを含むcsvファイルの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,6 +30,10 @@
|
|
30
30
|
|
31
31
|
明らかに、余分に時間のかかる道を通っている。
|
32
32
|
|
33
|
+
⇒待ち時間は固定されている(時間帯による混雑具合の変化を考慮していない)
|
34
|
+
|
35
|
+
にも関わらず、道が交差している。
|
36
|
+
|
33
37
|
```
|
34
38
|
|
35
39
|
![イメージ説明](31de9e12cf3e0d3a4796885a98898f62.jpeg)
|
@@ -426,6 +430,102 @@
|
|
426
430
|
|
427
431
|
|
428
432
|
|
433
|
+
```python
|
434
|
+
|
435
|
+
#data1.csv
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
x,y,atraction,u,wait,ride
|
440
|
+
|
441
|
+
0,0,0,0,0,0
|
442
|
+
|
443
|
+
178.744977,-411.6189186,1,100,12.5,11
|
444
|
+
|
445
|
+
405.4401112,-312.2808575,2,95,60.7,4
|
446
|
+
|
447
|
+
-22.70930008,-564.4792691,3,90,69.9,10
|
448
|
+
|
449
|
+
357.8210161,-525.665818,4,85,75.9,10
|
450
|
+
|
451
|
+
273.1456584,-463.0388498,5,80,31.4,15
|
452
|
+
|
453
|
+
172.4910395,-508.2196069,6,75,18.4,10
|
454
|
+
|
455
|
+
97.21253517,-524.7490879,7,70,56.7,5
|
456
|
+
|
457
|
+
348.8892339,-403.770249,8,65,11.5,12
|
458
|
+
|
459
|
+
41.15260526,-502.6122195,9,60,30,10
|
460
|
+
|
461
|
+
2.332562611,-276.7307541,10,55,50.6,4
|
462
|
+
|
463
|
+
176.8174996,-365.3482959,11,50,20,10
|
464
|
+
|
465
|
+
297.2690795,-174.6022427,12,45,15.9,15
|
466
|
+
|
467
|
+
501.2385967,-343.8873111,13,40,36.6,10
|
468
|
+
|
469
|
+
286.4826814,-163.0686191,14,35,17.2,10
|
470
|
+
|
471
|
+
-1.89344419,-578.5751364,15,30,9.3,10
|
472
|
+
|
473
|
+
187.3186156,-455.4562819,16,25,9.7,2
|
474
|
+
|
475
|
+
444.250322,-472.5915338,17,20,15.8,10
|
476
|
+
|
477
|
+
-20.76762671,-420.1353009,18,15,30,2
|
478
|
+
|
479
|
+
0,0,19,0,0,0
|
480
|
+
|
481
|
+
-88.01231104,-295.1343085,19,10,54,3
|
482
|
+
|
483
|
+
-77.66354913,-207.5716535,20,5,23.3,5
|
484
|
+
|
485
|
+
384.2804108,-295.1652853,21,100,7.6,10
|
486
|
+
|
487
|
+
51.72024722,-142.7772925,22,95,0,10
|
488
|
+
|
489
|
+
88.4746779,-611.9902531,23,90,24.7,4
|
490
|
+
|
491
|
+
288.6467783,-327.1411494,24,85,4.9,15
|
492
|
+
|
493
|
+
150.8913633,-115.0186422,25,80,13.3,15
|
494
|
+
|
495
|
+
-39.47286352,-175.8517677,26,75,59.7,4
|
496
|
+
|
497
|
+
-32.6778722,-526.8200045,27,70,14.8,1
|
498
|
+
|
499
|
+
-74.98752337,-454.4261077,28,65,30,8
|
500
|
+
|
501
|
+
280.8704375,-350.3917632,29,60,32.9,3
|
502
|
+
|
503
|
+
191.6029157,-443.0583631,30,55,11.1,2
|
504
|
+
|
505
|
+
-8.011026911,-533.3133665,31,50,20,10
|
506
|
+
|
507
|
+
422.962446,-365.2849465,32,45,4.9,3
|
508
|
+
|
509
|
+
234.2239144,-217.6443543,33,40,5,10
|
510
|
+
|
511
|
+
239.6768402,-424.4387339,34,35,30.5,2
|
512
|
+
|
513
|
+
37.0970462,-526.6317192,35,30,0,10
|
514
|
+
|
515
|
+
291.4600076,-238.6206014,36,25,4.7,9
|
516
|
+
|
517
|
+
-2.391548601,-302.5799912,37,20,14.3,12
|
518
|
+
|
519
|
+
-26.98081197,-544.1594307,38,15,15,10
|
520
|
+
|
521
|
+
60.64059017,-252.8263049,39,10,7.2,6
|
522
|
+
|
523
|
+
136.2315839,-477.4127281,40,5,12.9,2
|
524
|
+
|
525
|
+
```
|
526
|
+
|
527
|
+
|
528
|
+
|
429
529
|
### 試したこと
|
430
530
|
|
431
531
|
|
3
画像添付
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,402 +30,402 @@
|
|
30
30
|
|
31
31
|
明らかに、余分に時間のかかる道を通っている。
|
32
32
|
|
33
|
+
```
|
34
|
+
|
33
35
|
![イメージ説明](31de9e12cf3e0d3a4796885a98898f62.jpeg)
|
34
36
|
|
37
|
+
|
38
|
+
|
39
|
+
### 該当のソースコード
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
```python
|
44
|
+
|
45
|
+
# ライブラリのロード
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
import numpy as np
|
50
|
+
|
51
|
+
import pandas as pd
|
52
|
+
|
53
|
+
import matplotlib.pyplot as plt
|
54
|
+
|
55
|
+
from IPython.display import display
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
df = pd.read_csv("C:/Users/data1.csv")
|
60
|
+
|
61
|
+
display(df.head())
|
62
|
+
|
63
|
+
print('size = ', df.values.shape)
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
# 対象項目数
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
N = 20
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
# データを用いて、初期化と散布図表示
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
data = df[:N]
|
80
|
+
|
81
|
+
print(data)
|
82
|
+
|
83
|
+
data_np = np.array(data)
|
84
|
+
|
85
|
+
plt.figure(figsize=(6,6))
|
86
|
+
|
87
|
+
plt.scatter(data_np[:,0], data_np[:,1])
|
88
|
+
|
89
|
+
plt.grid()
|
90
|
+
|
91
|
+
plt.show()
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
# 距離関数の定義
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
def distance(i, j):
|
100
|
+
|
101
|
+
return np.sqrt(np.sum((data_np[i,0:2] - data_np[j,0:2])** 2))
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
# 移動時間の定義
|
106
|
+
|
107
|
+
d = np.zeros((N,N))
|
108
|
+
|
109
|
+
dis = np.zeros((N,N))
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
for i in range(N):
|
114
|
+
|
115
|
+
for j in range(N):
|
116
|
+
|
117
|
+
dis[i, j] = distance(i, j)
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
for i in range(N):
|
122
|
+
|
123
|
+
for j in range(N):
|
124
|
+
|
125
|
+
d[i][j] = dis[i][j] / 80.0
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
# 満足度の定義
|
130
|
+
|
131
|
+
u = data_np[:,3]
|
132
|
+
|
133
|
+
print(u)
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
# 待ち時間の定義
|
138
|
+
|
139
|
+
w = data_np[:,4]
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
# 乗車時間の定義
|
144
|
+
|
145
|
+
r = data_np[:,5]
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
# 制限時間の定義
|
150
|
+
|
151
|
+
t = 60 * 12
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
# CPLEX環境の確認
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
from docplex.mp.environment import Environment
|
160
|
+
|
161
|
+
env = Environment()
|
162
|
+
|
163
|
+
# env.print_information()
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
# モデルの宣言
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
from docplex.mp.model import Model
|
172
|
+
|
173
|
+
mdl = Model(name="TDL")
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
# モデルのパラメータ定義
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
# スレッド数: 2
|
182
|
+
|
183
|
+
mdl.parameters.threads = 2
|
184
|
+
|
185
|
+
# 最大時間数: 600秒
|
186
|
+
|
187
|
+
mdl.parameters.timelimit = 600
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
# 決定変数の宣言
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
# x : 移動matrix
|
196
|
+
|
197
|
+
# i番目のノードからj番目のノードに移動する時 x_ij = 1
|
198
|
+
|
199
|
+
# それ以外の場合 x_ij = 0
|
200
|
+
|
201
|
+
x = mdl.integer_var_matrix(N, N)
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
# q: 順序変数
|
206
|
+
|
207
|
+
# 0番目のノードの次に移動するノードがiの場合
|
208
|
+
|
209
|
+
# q[i] = 1
|
210
|
+
|
211
|
+
# その次に移動するノードがjの場合
|
212
|
+
|
213
|
+
# q[j] = 2
|
214
|
+
|
215
|
+
# .. のように定義する
|
216
|
+
|
217
|
+
q = mdl.integer_var_list(N)
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
# q(順序変数)の制約
|
222
|
+
|
223
|
+
# 最初のノードは0番目 : q[0] = 0
|
224
|
+
|
225
|
+
# それ以外の順序変数は1以上 N-1以下
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
mdl.add_constraint(q[0] == 0)
|
230
|
+
|
231
|
+
for i in range(1, N):
|
232
|
+
|
233
|
+
mdl.add_constraint(q[i] >= 1)
|
234
|
+
|
235
|
+
mdl.add_constraint(q[i] <= N-1)
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
# 自分から自分への移動はないので、x_ii = 0
|
240
|
+
|
241
|
+
# それ以外の場合は x_ij は0か1
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
for i in range(N):
|
246
|
+
|
247
|
+
for j in range(N):
|
248
|
+
|
249
|
+
if i == j:
|
250
|
+
|
251
|
+
mdl.add_constraint(x[i, j] == 0)
|
252
|
+
|
253
|
+
else:
|
254
|
+
|
255
|
+
mdl.add_constraint(x[i, j] >= 0)
|
256
|
+
|
257
|
+
mdl.add_constraint(x[i, j] <= 1)
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
#スタート地点
|
262
|
+
|
263
|
+
mdl.add_constraint(mdl.sum(x[0, j] for j in range(N-1)) == 1)
|
264
|
+
|
265
|
+
mdl.add_constraint(mdl.sum(x[i, 0] for i in range(N-1)) == 0)
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
# x(移動matirx)に関する縦の制約
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
for i in range(N):
|
274
|
+
|
275
|
+
mdl.add_constraint(mdl.sum(x[i, j] for j in range(N)) <= 1)
|
276
|
+
|
277
|
+
|
278
|
+
|
279
|
+
# x(移動matirx)に関する横の制約
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
for j in range(N):
|
284
|
+
|
285
|
+
mdl.add_constraint(mdl.sum(x[i, j] for i in range(N)) <= 1)
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
# 制限時間
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
mdl.add_constraint(mdl.sum((d[i][j] + w[j] + r[j]) * x[i,j] for j in range(N) for i in range(N)) <= t)
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
# in out の本数が同じ
|
300
|
+
|
301
|
+
|
302
|
+
|
303
|
+
for s in range(N):
|
304
|
+
|
305
|
+
mdl.add_constraint(mdl.sum(x[i, s] for i in range(N)) - mdl.sum(x[s, j] for j in range(N)) == 0)
|
306
|
+
|
307
|
+
#mdl.add_constraint(mdl.sum(x[i, s] for i in range(N)) - mdl.sum(x[s, j] for j in range(N)) == 0)
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
# 部分路制約
|
312
|
+
|
313
|
+
# ループが全体で1つであるための条件
|
314
|
+
|
315
|
+
# 参考リンク http://satemochi.blog.fc2.com/blog-entry-24.html
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
for i in range(1, N):
|
320
|
+
|
321
|
+
for j in range(1, N):
|
322
|
+
|
323
|
+
mdl.add_constraint(q[i]-q[j] + N*x[i,j] <= N-1)
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
#ゴール地点
|
328
|
+
|
329
|
+
mdl.add_constraint(mdl.sum(x[N-1, j] for j in range(1,N-1)) == 0)
|
330
|
+
|
331
|
+
mdl.add_constraint(mdl.sum(x[i, N-1] for i in range(1,N-1)) == 1)
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
# 総合満足度
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
total_satisfaction = mdl.sum(u[j] * x[i,j] for i in range(N) for j in range(N))
|
340
|
+
|
341
|
+
mdl.minimize(mdl.sum((d[i][j]+ w[j] + r[j]) * x[i,j] for i in range(N) for j in range(N)))
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
# 最適化の定義
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
mdl.maximize(total_satisfaction)
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
# 制約設定の確認
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
mdl.print_information()
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
# 問題を解く
|
362
|
+
|
363
|
+
# ログ出力をONにして、詳細情報も表示します
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
mdl.solve(log_output = False)
|
368
|
+
|
369
|
+
# mdl.report()
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
# 詳細情報の表示
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
print(mdl.get_solve_status())
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
#結果の取得
|
382
|
+
|
383
|
+
|
384
|
+
|
385
|
+
#indexes = [q[i].solution_value for i in range(N)]
|
386
|
+
|
387
|
+
matrix = [[x[i, j].solution_value for j in range(N)] for i in range(N)]
|
388
|
+
|
389
|
+
ar = np.array(matrix)
|
390
|
+
|
391
|
+
|
392
|
+
|
393
|
+
print("総満足度:",np.sum(np.dot(u,ar)))
|
394
|
+
|
395
|
+
|
396
|
+
|
397
|
+
# 結果の散布図上での表示
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
sum = 0
|
402
|
+
|
403
|
+
data_np = np.array(data)
|
404
|
+
|
405
|
+
plt.figure(figsize=(6,6))
|
406
|
+
|
407
|
+
plt.scatter(data_np[:,0], data_np[:,1])
|
408
|
+
|
409
|
+
for i in range(N):
|
410
|
+
|
411
|
+
for j in range(N):
|
412
|
+
|
413
|
+
if ar[i, j] == 1:
|
414
|
+
|
415
|
+
plt.plot(data_np[[i,j],0], data_np[[i,j],1])
|
416
|
+
|
417
|
+
sum += d[i][j] + w[j] + r[j]
|
418
|
+
|
419
|
+
print("総時間:",sum)
|
420
|
+
|
421
|
+
plt.grid()
|
422
|
+
|
423
|
+
plt.show()
|
424
|
+
|
35
425
|
```
|
36
426
|
|
37
427
|
|
38
428
|
|
39
|
-
### 該当のソースコード
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
```python
|
44
|
-
|
45
|
-
# ライブラリのロード
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
import numpy as np
|
50
|
-
|
51
|
-
import pandas as pd
|
52
|
-
|
53
|
-
import matplotlib.pyplot as plt
|
54
|
-
|
55
|
-
from IPython.display import display
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
df = pd.read_csv("C:/Users/data1.csv")
|
60
|
-
|
61
|
-
display(df.head())
|
62
|
-
|
63
|
-
print('size = ', df.values.shape)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
# 対象項目数
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
N = 20
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
# データを用いて、初期化と散布図表示
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
data = df[:N]
|
80
|
-
|
81
|
-
print(data)
|
82
|
-
|
83
|
-
data_np = np.array(data)
|
84
|
-
|
85
|
-
plt.figure(figsize=(6,6))
|
86
|
-
|
87
|
-
plt.scatter(data_np[:,0], data_np[:,1])
|
88
|
-
|
89
|
-
plt.grid()
|
90
|
-
|
91
|
-
plt.show()
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
# 距離関数の定義
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
def distance(i, j):
|
100
|
-
|
101
|
-
return np.sqrt(np.sum((data_np[i,0:2] - data_np[j,0:2])** 2))
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
# 移動時間の定義
|
106
|
-
|
107
|
-
d = np.zeros((N,N))
|
108
|
-
|
109
|
-
dis = np.zeros((N,N))
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
for i in range(N):
|
114
|
-
|
115
|
-
for j in range(N):
|
116
|
-
|
117
|
-
dis[i, j] = distance(i, j)
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
for i in range(N):
|
122
|
-
|
123
|
-
for j in range(N):
|
124
|
-
|
125
|
-
d[i][j] = dis[i][j] / 80.0
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
# 満足度の定義
|
130
|
-
|
131
|
-
u = data_np[:,3]
|
132
|
-
|
133
|
-
print(u)
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
# 待ち時間の定義
|
138
|
-
|
139
|
-
w = data_np[:,4]
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
# 乗車時間の定義
|
144
|
-
|
145
|
-
r = data_np[:,5]
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
# 制限時間の定義
|
150
|
-
|
151
|
-
t = 60 * 12
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
# CPLEX環境の確認
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
from docplex.mp.environment import Environment
|
160
|
-
|
161
|
-
env = Environment()
|
162
|
-
|
163
|
-
# env.print_information()
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
# モデルの宣言
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
from docplex.mp.model import Model
|
172
|
-
|
173
|
-
mdl = Model(name="TDL")
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
# モデルのパラメータ定義
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
# スレッド数: 2
|
182
|
-
|
183
|
-
mdl.parameters.threads = 2
|
184
|
-
|
185
|
-
# 最大時間数: 600秒
|
186
|
-
|
187
|
-
mdl.parameters.timelimit = 600
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
# 決定変数の宣言
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
# x : 移動matrix
|
196
|
-
|
197
|
-
# i番目のノードからj番目のノードに移動する時 x_ij = 1
|
198
|
-
|
199
|
-
# それ以外の場合 x_ij = 0
|
200
|
-
|
201
|
-
x = mdl.integer_var_matrix(N, N)
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
# q: 順序変数
|
206
|
-
|
207
|
-
# 0番目のノードの次に移動するノードがiの場合
|
208
|
-
|
209
|
-
# q[i] = 1
|
210
|
-
|
211
|
-
# その次に移動するノードがjの場合
|
212
|
-
|
213
|
-
# q[j] = 2
|
214
|
-
|
215
|
-
# .. のように定義する
|
216
|
-
|
217
|
-
q = mdl.integer_var_list(N)
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
# q(順序変数)の制約
|
222
|
-
|
223
|
-
# 最初のノードは0番目 : q[0] = 0
|
224
|
-
|
225
|
-
# それ以外の順序変数は1以上 N-1以下
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
mdl.add_constraint(q[0] == 0)
|
230
|
-
|
231
|
-
for i in range(1, N):
|
232
|
-
|
233
|
-
mdl.add_constraint(q[i] >= 1)
|
234
|
-
|
235
|
-
mdl.add_constraint(q[i] <= N-1)
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
# 自分から自分への移動はないので、x_ii = 0
|
240
|
-
|
241
|
-
# それ以外の場合は x_ij は0か1
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
for i in range(N):
|
246
|
-
|
247
|
-
for j in range(N):
|
248
|
-
|
249
|
-
if i == j:
|
250
|
-
|
251
|
-
mdl.add_constraint(x[i, j] == 0)
|
252
|
-
|
253
|
-
else:
|
254
|
-
|
255
|
-
mdl.add_constraint(x[i, j] >= 0)
|
256
|
-
|
257
|
-
mdl.add_constraint(x[i, j] <= 1)
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
#スタート地点
|
262
|
-
|
263
|
-
mdl.add_constraint(mdl.sum(x[0, j] for j in range(N-1)) == 1)
|
264
|
-
|
265
|
-
mdl.add_constraint(mdl.sum(x[i, 0] for i in range(N-1)) == 0)
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
# x(移動matirx)に関する縦の制約
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
for i in range(N):
|
274
|
-
|
275
|
-
mdl.add_constraint(mdl.sum(x[i, j] for j in range(N)) <= 1)
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
# x(移動matirx)に関する横の制約
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
for j in range(N):
|
284
|
-
|
285
|
-
mdl.add_constraint(mdl.sum(x[i, j] for i in range(N)) <= 1)
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
# 制限時間
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
mdl.add_constraint(mdl.sum((d[i][j] + w[j] + r[j]) * x[i,j] for j in range(N) for i in range(N)) <= t)
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
# in out の本数が同じ
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
for s in range(N):
|
304
|
-
|
305
|
-
mdl.add_constraint(mdl.sum(x[i, s] for i in range(N)) - mdl.sum(x[s, j] for j in range(N)) == 0)
|
306
|
-
|
307
|
-
#mdl.add_constraint(mdl.sum(x[i, s] for i in range(N)) - mdl.sum(x[s, j] for j in range(N)) == 0)
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
# 部分路制約
|
312
|
-
|
313
|
-
# ループが全体で1つであるための条件
|
314
|
-
|
315
|
-
# 参考リンク http://satemochi.blog.fc2.com/blog-entry-24.html
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
for i in range(1, N):
|
320
|
-
|
321
|
-
for j in range(1, N):
|
322
|
-
|
323
|
-
mdl.add_constraint(q[i]-q[j] + N*x[i,j] <= N-1)
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
#ゴール地点
|
328
|
-
|
329
|
-
mdl.add_constraint(mdl.sum(x[N-1, j] for j in range(1,N-1)) == 0)
|
330
|
-
|
331
|
-
mdl.add_constraint(mdl.sum(x[i, N-1] for i in range(1,N-1)) == 1)
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
# 総合満足度
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
total_satisfaction = mdl.sum(u[j] * x[i,j] for i in range(N) for j in range(N))
|
340
|
-
|
341
|
-
mdl.minimize(mdl.sum((d[i][j]+ w[j] + r[j]) * x[i,j] for i in range(N) for j in range(N)))
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
# 最適化の定義
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
mdl.maximize(total_satisfaction)
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
# 制約設定の確認
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
mdl.print_information()
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
# 問題を解く
|
362
|
-
|
363
|
-
# ログ出力をONにして、詳細情報も表示します
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
mdl.solve(log_output = False)
|
368
|
-
|
369
|
-
# mdl.report()
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
# 詳細情報の表示
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
print(mdl.get_solve_status())
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
#結果の取得
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
#indexes = [q[i].solution_value for i in range(N)]
|
386
|
-
|
387
|
-
matrix = [[x[i, j].solution_value for j in range(N)] for i in range(N)]
|
388
|
-
|
389
|
-
ar = np.array(matrix)
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
print("総満足度:",np.sum(np.dot(u,ar)))
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
# 結果の散布図上での表示
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
sum = 0
|
402
|
-
|
403
|
-
data_np = np.array(data)
|
404
|
-
|
405
|
-
plt.figure(figsize=(6,6))
|
406
|
-
|
407
|
-
plt.scatter(data_np[:,0], data_np[:,1])
|
408
|
-
|
409
|
-
for i in range(N):
|
410
|
-
|
411
|
-
for j in range(N):
|
412
|
-
|
413
|
-
if ar[i, j] == 1:
|
414
|
-
|
415
|
-
plt.plot(data_np[[i,j],0], data_np[[i,j],1])
|
416
|
-
|
417
|
-
sum += d[i][j] + w[j] + r[j]
|
418
|
-
|
419
|
-
print("総時間:",sum)
|
420
|
-
|
421
|
-
plt.grid()
|
422
|
-
|
423
|
-
plt.show()
|
424
|
-
|
425
|
-
```
|
426
|
-
|
427
|
-
|
428
|
-
|
429
429
|
### 試したこと
|
430
430
|
|
431
431
|
|
2
画像
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
|
31
31
|
明らかに、余分に時間のかかる道を通っている。
|
32
32
|
|
33
|
-
![イメージ説明](9
|
33
|
+
![イメージ説明](31de9e12cf3e0d3a4796885a98898f62.jpeg)
|
34
34
|
|
35
35
|
```
|
36
36
|
|
1
画像の添付
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
|
31
31
|
明らかに、余分に時間のかかる道を通っている。
|
32
32
|
|
33
|
-
![イメージ説明](
|
33
|
+
![イメージ説明](99c677943c1bed75c36e79b96d169819.png)
|
34
34
|
|
35
35
|
```
|
36
36
|
|