-
Notifications
You must be signed in to change notification settings - Fork 0
/
23.06.12 1200 class5에 대해 저장.txt
1464 lines (1285 loc) · 82.7 KB
/
23.06.12 1200 class5에 대해 저장.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
from itertools import chain, repeat
import itertools
import scipy
from scipy import stats
from mpl_toolkits.mplot3d import Axes3D
# def first_in_folder(x, a1, a2, a3, a4, a5, rho, t0, C):
# t = t0 * (a1 + a2 * rho) * (1 + a3 * (1 + rho) ** a4 * (x / C) ** a5)
# return t
# def second_in_folder(x, a1, a2, a3, a4, a5, rho, N, t0, C):
# t = t0 * (a1 + a2 * N) * (1 + a3 * (1 + rho) ** a4 * (x / C)** a5)
# return t
# def third_in_folder(x, a1, a2, a3, a4, a5, a6, rho, N, t0, C):
# t = t0 * (a1 + a2 * N) * (1 + a3 * (1 + N) ** a4 * (1 + rho) ** a5 * (x / C) ** a6)
# return t
# def forth_in_folder(x, a1, a2, a3, a4, a5, a6, a7, a8, rho, N, t0, C):
# t = t0 * (a1 + a2 * N) * (a3 + a4 * rho) * (1 + a5 * (1 + N) ** a6 * (1 + rho) ** a7 * (x / C) ** a8)
# return t
# def fifth_in_folder(x, a1, a2, a3, a4, a5, a6, a7, a8, a9, rho, N, t0, C):
# t = t0 * (a1 + a2 * N) * (a3 + a4 * rho) * (1 + (a5 * (1 + N) ** a6 + a7 * (1 + rho) ** a8 ) * (x / C) ** a9)
# return t
class Fitting:
def __init__(self, beta=0):
# global variables
self.C = 0
self.t0 = 0
self.C_list = []
self.t0_list = []
self.V = []
self.t = []
self.newV = []
self.newt = []
self.t_estimated = []
self.val_result = []
self.averaged_V = [] # capacity 구할때 필요함
self.averaged_t = [] # capacity 구할때 필요함
self.file_name_list = []
self.x_list = []
self.y_list = []
self.V_list = []
self.t_list = []
self.V_list_averaged = [] # 초기화
self.t_estimated_averaged = [] # 초기화
self.file_name_list_averaged = [] # 초기화
self.rho_list = []
self.r_squared = 0
self.N_list = []
self.off_list = []
self.on_list = []
self.averaged_t_list = []
self.averaged_V_list = []
self.averaged_rho_list = []
## params ##
self.alpha = 0
self.beta = beta
self.limit = 0
self.rho = 0
## x,y ##
self.cur_x = 0
self.cur_y = 0
self.pre_x = 0
self.pre_y = 0
self.next_x = 0
self.next_y = 0
## flag and count ##
self.cnt = 0
## info ##
self.fitted_func = 'None'
# 폴더에 들어있는 파일 모두 볼때
def bpr_function(self, x, a1, a2):
t = self.t0_list * (1 + a1 * (x / self.C_list) ** a2)
return t
def Lu_1(self, x, a1, a2, a3):
t = self.t0_list * (1 + a1 * (1 + self.rho_list) ** a2 * (x / self.C_list) ** a3)
return t
def Lu_2(self, x, a1, a2):
t = self.t0_list * (1 + a1 * (x / self.C_list) ** a2)
return t
def Lu_3(self, x, a1, a2):
t = self.t0_list * (1 + a1 * (x / self.C_list) ** a2)
return t
def Lu_4(self, x, a1, a2):
t = self.t0_list * (1 + a1 * (x / self.C_list) ** a2)
return t
def TRUCK1(self, x, a1, a2, a3, a4, a5): # t0, rho, V, C, N, off, on 순서로 넣어라
t = self.t0_list * (a1 + a2 * self.rho_list) * (1 + a3 * (1 + self.rho_list) ** a4 * (x / self.C_list) ** a5)
return t
def TRUCK2(self, x, a1, a2, a3, a4, a5): # t0, rho, V, C, N, off, on 순서로 넣어라
t = self.t0_list * (a1 + a2 * self.rho_list) * (1 + self.rho_list) ** a3 * (x / self.C_list) ** a4
return t
def TRUCK3(self, x, a1, a2, a3, a4): # t0, rho, V, C, N , off, on 순서로 넣어라
t = self.t0_list * (1 + a1 * (x * (1-self.rho_list))/self.C_list) ** a2 * (1 + a3 * (x * self.rho_list)/self.C_list) ** a4
return t
def TRUCK4(self, x, a1, a2, a3, a4): # t0, rho, V, C, N, off, on 순서로 넣어라
t = self.t0_list * a1 * self.rho_list + a2 * (1 + self.rho_list) ** a3 * (x / self.C_list) ** a4
return t
def TRUCK5(self, x, a1, a2, a3, a4, a5): # t0, rho, V, C, N , off, on 순서로 넣어라
t = self.t0_list * (a1 * (2 - self.rho_list) ** a2 + a3 * (1 + self.rho_list) ** a4 ) * (x / self.C_list) ** a5
return t
def TRUCK6(self, x, a1, a2, a3, a4): # t0, rho, V, C, N, off, on 순서로 넣어라
t = self.t0_list * (a1 * (2 - self.rho_list) ** a2 * (1 + self.rho_list) ** a3 ) * (x / self.C_list) ** a4
return t
def TRUCK7(self, x, a1, a2, a3, a4): # t0, rho, V, C, N , off, on 순서로 넣어라
t = self.t0_list * (1 + a1 * (2 - self.rho_list) ** a2 * (1 + self.rho_list) ** a3 * (x / self.C_list) ** a4)
return t
def TRUCK8(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N, off, on 순서로 넣어라
t = self.t0_list * (a1 + a2 * self.rho_list) * (1 + a3 * (2 - self.rho_list) ** a4 * (1 + self.rho_list) ** a5 * (x / self.C_list) ** a6)
return t
def TRUCK9(self, x, a1, a2, a3, a4, a5): # t0, rho, V, C, N , off, on 순서로 넣어라
t = self.t0_list * (a1 * (2 - self.rho_list) ** a2 + a3 * (1 + self.rho_list) ** a4 ) * (x / self.C_list) ** a5
return t
def TRUCK10(self, x, a1, a2, a3, a4, a5, a6, a7, a8): # t0, rho, V, C, N, off, on 순서로 넣어라
t = (a1 + a2 * self.rho_list) * (a3 + a4 * (1 - self.rho_list)) * (1 + a5 * (2 - self.rho_list) ** a6 * (1 + self.rho_list) ** a7 * (x / self.C_list) ** a8)
return t
def TRUCK11(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N, off, on 순서로 넣어라
t = (a1 + a2 * self.rho_list) * (1 + a3 * (2 - self.rho_list) ** a4 * (1 + self.rho_list) ** a5 * (x / self.C_list) ** a6)
return t
def TRUCK12(self, x, a1, a2, a3, a4, a5): # t0, rho, V, C, N, off, on 순서로 넣어라
t = (a1 + a2 * self.rho_list) * (1 + a3 * (1 + self.rho_list) ** a4 * (x / self.C_list) ** a5)
return t
def N1(self, x, a1, a2, a3, a4, a5): # t0, rho, V, C, N, off, on 순서로 넣어라
t = self.t0_list * (a1 + a2 * self.N_list) * (1 + a3 * (1 + self.rho_list) ** a4 * (x / self.C_list) ** a5)
return t
def N2(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N, off, on 순서로 넣어라
t = self.t0_list * (1 + a1 * (a2 + a3 * self.N_list) ** a4 * (1 + self.rho_list) ** a5 * (x / self.C_list) ** a6)
return t
def N3(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N, off, on 순서로 넣어라
t = self.t0_list * (a1 + a2 * self.N_list) * (1 + a3 * (1 + self.N_list) ** a4 * (1 + self.rho_list) ** a5 * (x / self.C_list) ** a6)
return t
def N4(self, x, a1, a2, a3, a4, a5, a6, a7): # t0, rho, V, C, N, off, on 순서로 넣어라
t = self.t0_list * (a1 + a2 * self.N_list) * (1 + a3 * (1 + self.N_list) ** a4 * (2 - self.rho_list) ** a5 * (1 + self.rho_list) ** a6 *(x / self.C_list) ** a7)
return t
def N5(self, x, a1, a2, a3, a4, a5, a6, a7, a8, a9): # t0, rho, V, C, N, off, on 순서로 넣어라
t = self.t0_list * (a1 + a2 * self.N_list) * (a3 + a4 * self.rho_list) * (1 + a5 * (1 + self.N_list) ** a6 * (2 - self.rho_list) ** a7 * (1 + self.rho_list) ** a8 *(x / self.C_list) ** a9)
return t
def N6(self, x, a1, a2, a3, a4, a5, a6, a7): # t0, rho, V, C, N, off, on 순서로 넣어라
t = self.t0_list * (a1 + a2 * self.rho_list) * (1 + a3 * (1 + self.N_list) ** a4 * (2 - self.rho_list) ** a5 * (1 + self.rho_list) ** a6 *(x / self.C_list) ** a7)
return t
def R1(self, x, a1, a2, a3, a4, a5): # t0, rho, V, C, N, off, on 순서로 넣어라
t = self.t0_list * (1 + a1 * ( 1 + self.off_list ) ** a2 * (1 + self.on_list) ** a3 * (1 + self.rho_list) ** a4 * (x / self.C_list) ** a5)
return t
def R2(self, x, a1, a2, a3, a4, a5, a6, a7): # t0, rho, V, C, N, off, on 순서로 넣어라
t = self.t0_list * (a1 + a2 * self.off_list) * (a3 + a4 * self.on_list)* (1 + a5 * (1 + self.rho_list)** a6 * (x / self.C_list) ** a7 )
return t
def R3(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N, off, on 순서로 넣어라
t = self.t0_list * (1 + a1 * ( 1 + self.off_list ) ** a2 * (1 + self.on_list) ** a3 * (2 - self.rho_list) ** a4 *(1 + self.rho_list) ** a5 * (x / self.C_list) ** a6)
return t
def R4(self, x, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10): # t0, rho, V, C, N , off, on 순서로 넣어라
t = self.t0_list * (a1 + a2 * self.off_list) * (a3 + a4 * self.on_list) * (1 + a5 * ( 1 + self.off_list ) ** a6 * (1 + self.on_list) ** a7 * (2 - self.rho_list) ** a8 *(1 + self.rho_list) ** a9 * (x / self.C_list) ** a10)
return t
def R5(self, x, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12): # t0, rho, V, C, N , off, on 순서로 넣어라
t = self.t0_list * (a1 + a2 * self.off_list) * (a3 + a4 * self.on_list) * (a5 + a6 * self.rho_list) * (1 + a7 * ( 1 + self.off_list ) ** a8 * (1 + self.on_list) ** a9 * (2 - self.rho_list) ** a10 *(1 + self.rho_list) ** a11 * (x / self.C_list) ** a12)
return t
def C1(self, x, a1, a2, a3, a4, a5, a6, a7, a8): # t0, rho, V, C, N , off, on 순서로 넣어라
t = self.t0_list * (a1 + a2 * self.rho_list) * (1 + a3 * ( 1 + self.off_list ) ** a4 * (1 + self.on_list) ** a5 * (2 - self.rho_list) ** a6 *(1 + self.rho_list) ** a7 * (x / self.C_list) ** a8)
return t
def C1_no(self, x, a1, a2, a3, a4, a5, a6, a7, a8): # t0, rho, V, C, N , off, on 순서로 넣어라
t = (a1 + a2 * self.rho_list) * (1 + a3 * ( 1 + self.off_list ) ** a4 * (1 + self.on_list) ** a5 * (2 - self.rho_list) ** a6 *(1 + self.rho_list) ** a7 * (x / self.C_list) ** a8)
return t
def C2(self, x, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10): # t0, rho, V, C, N , off, on 순서로 넣어라
t = (a1 + a2 * self.rho_list) * (a3 + a4 * (1 - self.rho_list)) * (1 + a5 * ( 1 + self.off_list ) ** a6 * (1 + self.on_list) ** a7 * (2 - self.rho_list) ** a8 *(1 + self.rho_list) ** a9 * (x / self.C_list) ** a10)
return t
def C3(self, x, a1, a2, a3, a4, a5, a6, a7, a8): # t0, rho, V, C, N , off, on 순서로 넣어라
t = (a1 + a2 * self.rho_list) * (1 + a3 * ( 1 + self.off_list ) ** a4 * (1 + self.on_list) ** a5 * (self.rho_list) ** a6 *(1 + self.rho_list) ** a7 * (x / self.C_list) ** a8)
return t
def C4(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N , off, on 순서로 넣어라
t = self.t0_list * (1 + a1 * ( 1 + self.off_list ) ** a2 * (1 + self.on_list) ** a3 * (self.rho_list) ** a4 *(1 + self.rho_list) ** a5 * (x / self.C_list) ** a6)
return t
def C5(self, x, a1, a2, a3, a4, a5, a6, a7): # t0, rho, V, C, N , off, on 순서로 넣어라
t = self.t0_list * (a1 + a2 * self.rho_list) * (1 + a3 * (1 + self.off_list) ** a4 * (2 - self.rho_list) ** a5 *(1 + self.rho_list) ** a6 * (x / self.C_list) ** a7)
return t
def C6(self, x, a1, a2, a3, a4, a5, a6, a7): # t0, rho, V, C, N , off, on 순서로 넣어라
t = self.t0_list * (a1 + a2 * self.rho_list) * (1 + a3 * (1 + self.on_list) ** a4 * (2 - self.rho_list) ** a5 *(1 + self.rho_list) ** a6 * (x / self.C_list) ** a7)
return t
def C7(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N , off, on 순서로 넣어라
t = self.t0_list * (a1 + a2 * self.rho_list) * (1 + a3 * (1 + (2 - self.rho_list) ** a4 * (1 + self.rho_list) ** a5 * (x / self.C_list) ** a6))
return t
def C8(self, x, a1, a2, a3, a4, a5, a6, a7): # t0, rho, V, C, N , off, on 순서로 넣어라
t = self.t0_list * (a1 + a2 * self.rho_list) * (1 + ( 1 + self.off_list ) ** a3 * (1 + self.on_list) ** a4 * (2 - self.rho_list) ** a5 *(1 + self.rho_list) ** a6 * (x / self.C_list) ** a7)
return t
def C9(self, x, a1, a2, a3, a4, a5, a6, a7): # t0, rho, V, C, N , off, on 순서로 넣어라
t = (a1 + a2 * self.rho_list) * (1 + a3 * ( 1 + self.off_list ) * (1 + self.on_list) ** a4 * (2 - self.rho_list) ** a5 *(1 + self.rho_list) ** a6 * (x / self.C_list) ** a7)
return t
def C10(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N , off, on 순서로 넣어라
t = self.t0_list * (1 + a1 * ( 1 + self.off_list ) ** a2 * (1 + self.on_list) ** a3 * (2 - self.rho_list) ** a4 *(1 + self.rho_list) ** a5 * (x / self.C_list) ** a6)
return t
def C11(self, x, a1, a2, a3, a4, a5): # t0, rho, V, C, N , off, on 순서로 넣어라
t = self.t0_list * (1 + a1 * ( 1 + self.off_list ) * (1 + self.on_list) ** a2 * (2 - self.rho_list) ** a3 *(1 + self.rho_list) ** a4 * (x / self.C_list) ** a5)
return t
def C12(self, x, a1, a2, a3, a4): # t0, rho, V, C, N , off, on 순서로 넣어라
t = self.t0_list * (1 + a1 * ( 1 + self.off_list ) * (1 + self.on_list) ** a2 *(1 + self.rho_list) ** a3 * (x / self.C_list) ** a4)
return t
def C13(self, x, a1, a2, a3): # t0, rho, V, C, N , off, on 순서로 넣어라
t = self.t0_list * (1 + a1 * ( 1 + self.off_list ) * (1 + self.on_list) ** a2 * (x / self.C_list) ** a3)
return t
def C14(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N , off, on 순서로 넣어라
t = (a1 + a2 * self.rho_list) * (1 + a3 * ( 1 + self.off_list ) * (1 + self.on_list) ** a4 *(1 + self.rho_list) ** a5 * (x / self.C_list) ** a6)
return t
def C15(self, x, a1, a2, a3, a4, a5): # t0, rho, V, C, N , off, on 순서로 넣어라
t = (a1 + a2 * self.rho_list) * (1 + a3 * ( 1 + self.off_list ) * (1 + self.on_list) ** a4 * (x / self.C_list) ** a5)
return t
def C16(self, x, a1, a2, a3, a4, a5, a6, a7, a8, a9): # t0, rho, V, C, N , off, on 순서로 넣어라
t = (a1 + a2 * self.rho_list) * (a3 + a4 *(1 - self.rho_list)) * (1 + a5 * ( 1 + self.off_list ) * (1 + self.on_list) ** a6 * (2 - self.rho_list) ** a7 *(1 + self.rho_list) ** a8 * (x / self.C_list) ** a9)
return t
def C17(self, x, a1, a2, a3, a4, a5, a6, a7, a8): # t0, rho, V, C, N , off, on 순서로 넣어라
t = (a1 + a2 * self.rho_list) * (a3 + a4 *(1 - self.rho_list)) * (1 + a5 * ( 1 + self.off_list ) * (1 + self.on_list) ** a6 *(1 + self.rho_list) ** a7 * (x / self.C_list) ** a8)
return t
def C18(self, x, a1, a2, a3, a4): # t0, rho, V, C, N , off, on 순서로 넣어라
t = self.t0_list * (1 + a1 * ( 1 + self.off_list ) * (1 + self.on_list) ** a2 * (2 - self.rho_list) *(1 + self.rho_list) ** a3 * (x / self.C_list) ** a4)
return t
def C19(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N , off, on 순서로 넣어라
t = (a1 + a2 * self.rho_list) * (1 + a3 * ( 1 + self.off_list ) * (1 + self.on_list) ** a4 * (2 - self.rho_list) *(1 + self.rho_list) ** a5 * (x / self.C_list) ** a6)
return t
def bpr_function_in_folder(self, x, a1, a2): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (1 + a1 * (x[2] / x[3]) ** a2)
return t
def Lu_1_in_folder(self, x, a1, a2, a3): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (1 + a1 * (1 + x[1]) ** a2 * (x[2] / x[3]) ** a3)
return t
def Lu_2_in_folder(self, x, a1, a2): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (1 + a1 * (x[2] / x[3]) ** a2)
return t
def Lu_3_in_folder(self, x, a1, a2): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (1 + a1 * (x[2] / x[3]) ** a2)
return t
def Lu_4_in_folder(self, x, a1, a2): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (1 + a1 * (x[2] / x[3]) ** a2)
return t
def TRUCK1_in_folder(self, x, a1, a2, a3, a4, a5): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (a1 + a2 * x[1]) * (1 + a3 * (1 + x[1]) ** a4 * (x[2] / x[3]) ** a5)
return t
def TRUCK2_in_folder(self, x, a1, a2, a3, a4, a5): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (a1 + a2 * x[1]) * (1 + x[1]) ** a3 * (x[2] / x[3]) ** a4
return t
def TRUCK3_in_folder(self, x, a1, a2, a3, a4): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (1 + a1 * (x[2] * (1-x[1]))/self.C_list) ** a2 * (1 + a3 * (x[2] * x[1])/x[3]) ** a4
return t
def TRUCK4_in_folder(self, x, a1, a2, a3, a4): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * a1 * x[1] + a2 * (1 + x[1]) ** a3 * (x[2] / x[3]) ** a4
return t
def TRUCK5_in_folder(self, x, a1, a2, a3, a4, a5): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (a1 * (2 - x[1]) ** a2 + a3 * (1 + x[1]) ** a4 ) * (x[2] / x[3]) ** a5
return t
def TRUCK6_in_folder(self, x, a1, a2, a3, a4): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (a1 * (2 - x[1]) ** a2 * (1 + x[1]) ** a3 ) * (x[2] / x[3]) ** a4
return t
def TRUCK7_in_folder(self, x, a1, a2, a3, a4): # t0, rho, V, C, N , off, on 순서로 넣어라
t = x[0] * (1 + a1 * (2 - x[1]) ** a2 * (1 + x[1]) ** a3 * (x[2] / x[3]) ** a4 )
return t
def TRUCK8_in_folder(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (a1 + a2 * x[1]) * (1 + a3 * (2 - x[1]) ** a4 * (1 + x[1]) ** a5 * (x[2] / x[3]) ** a6 )
return t
def TRUCK9_in_folder(self, x, a1, a2, a3, a4, a5): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (a1* (2 - x[1]) ** a2 + a3 * (1 + x[1]) ** a4 ) * (x[2] / x[3]) ** a5
return t
def TRUCK10_in_folder(self, x, a1, a2, a3, a4, a5, a6, a7, a8): # t0, rho, V, C, N, off, on 순서로 넣어라
t = (a1 + a2 * x[1]) * (a3 + a4 * (1 - x[1])) * (1 + a5 * (2 - x[1]) ** a6 * (1 + x[1]) ** a7 * (x[2] / x[3]) ** a8)
return t
def TRUCK11_in_folder(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N, off, on 순서로 넣어라
t = (a1 + a2 * x[1]) * (1 + a3 * (2 - x[1]) ** a4 * (1 + x[1]) ** a5 * (x[2] / x[3]) ** a6 )
return t
def TRUCK12_in_folder(self, x, a1, a2, a3, a4, a5): # t0, rho, V, C, N, off, on 순서로 넣어라
t = (a1 + a2 * x[1]) * (1 + a3 * (1 + x[1]) ** a4 * (x[2] / x[3]) ** a5 )
return t
def N1_in_folder(self, x, a1, a2, a3, a4, a5): # t0, rho, V, C, N , off, on 순서로 넣어라
t = x[0] * (a1 + a2 * x[4]) * (1 + a3 * (1 + x[1]) ** a4 * (x[2] / x[3]) ** a5)
return t
def N2_in_folder(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (1 + a1 * (a2 + a3 * x[4]) ** a4 * (1 + x[1]) ** a5 * (x[2] / x[3]) ** a6)
return t
def N3_in_folder(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (a1 + a2 * x[4]) * (1 + a3 * (1 + x[4]) ** a4 * (1 + x[1]) ** a5 * (x[2] / x[3]) ** a6)
return t
def N4_in_folder(self, x, a1, a2, a3, a4, a5, a6, a7): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (a1 + a2 * x[4]) * (1 + a3 * (1 + x[4]) ** a4 * (2 - x[1]) ** a5 * (1 + x[1]) ** a6 *(x[2] / x[3]) ** a7)
return t
def N5_in_folder(self, x, a1, a2, a3, a4, a5, a6, a7, a8, a9): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (a1 + a2 * x[4]) * (a3 + a4 * x[1]) * (1 + a5 * (1 + x[4]) ** a6 * (2 - x[1]) ** a7 * (1 + x[1]) ** a8 *(x[2] / x[3]) ** a9)
return t
def N6_in_folder(self, x, a1, a2, a3, a4, a5, a6, a7): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (a1 + a2 * x[1]) * (1 + a3 * (1 + x[4]) ** a4 * (2 - x[1]) ** a5 * (1 + x[1]) ** a6 *(x[2] / x[3]) ** a7)
return t
def R1_in_folder(self, x, a1, a2, a3, a4, a5): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (1 + a1 * ( 1 + x[5] ) ** a2 * (1 + x[6]) ** a3 * (1 + x[1]) ** a4 * (x[2] / x[3]) ** a5)
return t
def R2_in_folder(self, x, a1, a2, a3, a4, a5, a6, a7): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (a1 + a2 * x[5]) * (a3 + a4 * x[6])* (1 + a5 * (1 + x[1])** a6 * (x[2] / x[3]) ** a7 )
return t
def R3_in_folder(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (1 + a1 * ( 1 + x[5]) ** a2 * (1 + x[6]) ** a3 * (2 - x[1]) ** a4 *(1 + x[1]) ** a5 * (x[2] / x[3]) ** a6)
return t
def R4_in_folder(self, x, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10): # t0, rho, V, C, N, off, on 순서로 넣어라
t = x[0] * (a1 + a2 * x[5]) * (a3 + a4 * x[6]) * (1 + a5 * (1 + x[5]) ** a6 * (1 + x[6]) ** a7 * (2 - x[1]) ** a8 *(1 + x[1]) ** a9 * (x[2] / x[3]) ** a10)
return t
def R5_in_folder(self, x, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12): # t0, rho, V, C, N , off, on 순서로 넣어라
t = x[0] * (a1 + a2 * x[5]) * (a3 + a4 * x[6]) * (a5 + a6 * x[1]) * (1 + a7 * ( 1 + x[5]) ** a8 * (1 + x[6]) ** a9 * (2 - x[1]) ** a10 *(1 + x[1]) ** a11 * (x[2] / x[3]) ** a12)
return t
def C1_in_folder(self, x, a1, a2, a3, a4, a5, a6, a7, a8): # t0, rho, V, C, N , off, on 순서로 넣어라
t = x[0] * (a1 + a2 * x[1]) * (1 + a3 * ( 1 + x[5]) ** a4 * (1 + x[6]) ** a5 * (2 - x[1]) ** a6 *(1 + x[1]) ** a7 * (x[2] / x[3]) ** a8)
return t
def C1_no_in_folder(self, x, a1, a2, a3, a4, a5, a6, a7, a8): # t0, rho, V, C, N , off, on 순서로 넣어라
t = (a1 + a2 * x[1]) * (1 + a3 * ( 1 + x[5]) ** a4 * (1 + x[6]) ** a5 * (2 - x[1]) ** a6 *(1 + x[1]) ** a7 * (x[2] / x[3]) ** a8)
return t
def C2_in_folder(self, x, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10): # t0, rho, V, C, N , off, on 순서로 넣어라
t = (a1 + a2 * x[1]) * (a3 + a4 *(1 - x[1])) * (1 + a5 * ( 1 + x[5]) ** a6 * (1 + x[6]) ** a7 * (2 - x[1]) ** a8 *(1 + x[1]) ** a9 * (x[2] / x[3]) ** a10)
return t
def C3_in_folder(self, x, a1, a2, a3, a4, a5, a6, a7, a8): # t0, rho, V, C, N , off, on 순서로 넣어라
t = (a1 + a2 * x[1]) * (1 + a3 * ( 1 + x[5]) ** a4 * (1 + x[6]) ** a5 * (x[1]) ** a6 *(1 + x[1]) ** a7 * (x[2] / x[3]) ** a8)
return t
def C4_in_folder(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N , off, on 순서로 넣어라
t = x[0] * (1 + a1 * ( 1 + x[5]) ** a2 * (1 + x[6]) ** a3 * (x[1]) ** a4 *(1 + x[1]) ** a5 * (x[2] / x[3]) ** a6)
return t
def C5_in_folder(self, x, a1, a2, a3, a4, a5, a6, a7): # t0, rho, V, C, N , off, on 순서로 넣어라
t = x[0] * (a1 + a2 * x[1]) * (1 + a3 * ( 1 + x[5]) ** a4 * (2 - x[1]) ** a5 *(1 + x[1]) ** a6 * (x[2] / x[3]) ** a7)
return t
def C6_in_folder(self, x, a1, a2, a3, a4, a5, a6, a7): # t0, rho, V, C, N , off, on 순서로 넣어라
t = x[0] * (a1 + a2 * x[1]) * (1 + a3 * (1 + x[6]) ** a4 * (2 - x[1]) ** a5 *(1 + x[1]) ** a6 * (x[2] / x[3]) ** a7)
return t
def C7_in_folder(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N , off, on 순서로 넣어라
t = x[0] * (a1 + a2 * x[1]) * (1 + a3 * (2 - x[1]) ** a4 *(1 + x[1]) ** a5 * (x[2] / x[3]) ** a6)
return t
def C8_in_folder(self, x, a1, a2, a3, a4, a5, a6, a7): # t0, rho, V, C, N , off, on 순서로 넣어라
t = x[0] * (a1 + a2 * x[1]) * (1 + ( 1 + x[5]) ** a3 * (1 + x[6]) ** a4 * (2 - x[1]) ** a5 *(1 + x[1]) ** a6 * (x[2] / x[3]) ** a7)
return t
def C9_in_folder(self, x, a1, a2, a3, a4, a5, a6, a7): # t0, rho, V, C, N , off, on 순서로 넣어라
t = (a1 + a2 * x[1]) * (1 + a3 * ( 1 + x[5]) * (1 + x[6]) ** a4 * (2 - x[1]) ** a5 *(1 + x[1]) ** a6 * (x[2] / x[3]) ** a7)
return t
def C10_in_folder(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N , off, on 순서로 넣어라
t = x[0] * (1 + a1 * ( 1 + x[5]) ** a2 * (1 + x[6]) ** a3 * (2 - x[1]) ** a4 *(1 + x[1]) ** a5 * (x[2] / x[3]) ** a6)
return t
def C11_in_folder(self, x, a1, a2, a3, a4, a5): # t0, rho, V, C, N , off, on 순서로 넣어라
t = x[0] * (1 + a1 * ( 1 + x[5]) * (1 + x[6]) ** a2 * (2 - x[1]) ** a3 *(1 + x[1]) ** a4 * (x[2] / x[3]) ** a5)
return t
def C12_in_folder(self, x, a1, a2, a3, a4): # t0, rho, V, C, N , off, on 순서로 넣어라
t = x[0] * (1 + a1 * ( 1 + x[5]) * (1 + x[6]) ** a2 * (1 + x[1]) ** a3 * (x[2] / x[3]) ** a4)
return t
def C13_in_folder(self, x, a1, a2, a3): # t0, rho, V, C, N , off, on 순서로 넣어라
t = x[0] * (1 + a1 * ( 1 + x[5]) * (1 + x[6]) ** a2 * (x[2] / x[3]) ** a3)
return t
def C14_in_folder(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N , off, on 순서로 넣어라
t = (a1 + a2 * x[1]) * (1 + a3 * ( 1 + x[5]) * (1 + x[6]) ** a4 *(1 + x[1]) ** a5 * (x[2] / x[3]) ** a6)
return t
def C15_in_folder(self, x, a1, a2, a3, a4, a5): # t0, rho, V, C, N , off, on 순서로 넣어라
t = (a1 + a2 * x[1]) * (1 + a3 * ( 1 + x[5]) * (1 + x[6]) ** a4 * (x[2] / x[3]) ** a5)
return t
def C16_in_folder(self, x, a1, a2, a3, a4, a5, a6, a7, a8, a9): # t0, rho, V, C, N , off, on 순서로 넣어라
t = (a1 + a2 * x[1]) * (a3 + a4 *(1 - x[1])) *(1 + a5 * ( 1 + x[5]) * (1 + x[6]) ** a6 * (2 - x[1]) ** a7 *(1 + x[1]) ** a8 * (x[2] / x[3]) ** a9)
return t
def C17_in_folder(self, x, a1, a2, a3, a4, a5, a6, a7, a8): # t0, rho, V, C, N , off, on 순서로 넣어라
t = (a1 + a2 * x[1]) * (a3 + a4 *(1 - x[1])) *(1 + a5 * ( 1 + x[5]) * (1 + x[6]) ** a6 * (1 + x[1]) ** a7 * (x[2] / x[3]) ** a8)
return t
def C18_in_folder(self, x, a1, a2, a3, a4): # t0, rho, V, C, N , off, on 순서로 넣어라
t = x[0] * (1 + a1 * ( 1 + x[5]) * (1 + x[6]) ** a2 * (2 - x[1]) *(1 + x[1]) ** a3 * (x[2] / x[3]) ** a4)
return t
def C19_in_folder(self, x, a1, a2, a3, a4, a5, a6): # t0, rho, V, C, N , off, on 순서로 넣어라
t = (a1 + a2 * x[1]) * (1 + a3 * ( 1 + x[5]) * (1 + x[6]) ** a4 * (2 - x[1]) *(1 + x[1]) ** a5 * (x[2] / x[3]) ** a6)
return t
# 파일 하나씩 볼때
def bpr_function_one(self, x, a1, a2):
t = self.t0 * (1 + a1 * (x / self.C) ** a2)
return t
def Lu_1_one(self, x, a1, a2, a3):
t = self.t0 * (1 + a1 * (1 + self.rho) ** a2 * (x / self.C) ** a3)
return t
def Lu_2_one(self, x, a1, a2):
t = self.t0 * (1 + a1 * (x / self.C) ** a2)
return t
def Lu_3_one(self, x, a1, a2):
t = self.t0 * (1 + a1 * (x / self.C) ** a2)
return t
def Lu_4_one(self, x, a1, a2):
t = self.t0 * (1 + a1 * (x / self.C) ** a2)
return t
# 각 cycle의 시작 인덱스를 찾는 함수
def find_cycle_start_indices(self, arr):
cycle_start_indices = []
prev_value = arr[0]
for i, value in enumerate(arr):
if value <= prev_value:
cycle_start_indices.append(i)
prev_value = value
return cycle_start_indices
def calculate_C(self, A): # capacity가 외부에서 주어지지 않은 상황에서 써먹는 함수임.
result = 0
max_diff = 0
for i in range(len(self.averaged_V)): # 20이라고 한다면, 0~19까지 접근가능
if self.averaged_V[i] > 2000:
if i < len(self.averaged_V)-1: #17까지만
self.cur_x = self.averaged_V[i]
self.cur_y = self.averaged_t[i]
self.pre_x = self.averaged_V[i-1]
self.pre_y = self.averaged_t[i-1]
self.next_x = self.averaged_V[i+1]
self.next_y = self.averaged_t[i+1]
first_incl = (abs(self.cur_y-self.pre_y)/abs(self.cur_x-self.pre_x)) * 10000
second_incl = (abs(self.next_y-self.cur_y)/abs(self.next_x-self.cur_x)) * 10000
diff = first_incl - second_incl
if diff > max_diff:
max_diff = diff
result = self.cur_x
print("[capacity] 꺾이는 점으로 capacity를 설정합니다.")####################################################
if max_diff == 0:
result = (A // 10) * 2200
print('[capacity] 꺾이는 지점이 없어, 기본값으로 설정합니다. ')####################################################
return result
def calculate_t0(self, XXX, B): # B는 int값
# x = 68.8
x = 69.16
y = 99.45
if XXX == "LOV":
return x
elif XXX == "HGV":
return y
elif XXX == "AVG":
result = (B/10*y + (10-B/10)*x)/10
print("free flow travel time:", result)
return result
else:
print("에러!!")
return 0 # 기본값 0으로 변경
def calculate_r_squared(self, y_true, y_pred):
print("Calculate R-squared (coefficient of determination)")
ss_total = np.sum((y_true - np.mean(y_true))**2)
ss_residual = np.sum((y_true - y_pred)**2)
print('y값의 평균:', np.mean(y_true))
print('SSR(예측값과의 편차 값):', ss_residual)
print('SST(평균과의 편차 값):', ss_total)
r_squared = 1 - (ss_residual / ss_total)
print('r^2:', r_squared)
return r_squared
def empty_lists(self):
self.C_list = []
self.t0_list = []
self.V_list = []
self.t_list = []
self.rho_list = []
self.file_name_list = []
self.newt = []
self.newV = []
self.t_estimated = []
self.x_list = []
self.y_list = []
self.N_list = []
self.off_list = []
self.on_list = []
self.averaged_t_list = []
self.averaged_V_list = []
self.averaged_rho_list = []
def estimate_parameters(self, func_name, folder_path, limits=None):
for file_name, limit in zip(os.listdir(folder_path), limits):
if file_name.endswith(".csv"):
print('-------------------------------------------------------------------------------------------------')
print('-------------------------------------------------------------------------------------------------')
#### 비우고 시작 ####
self.averaged_V = []
self.averaged_t = []
self.V = []
self.t = []
file_path = os.path.join(folder_path, file_name)
##### 1. 파일 이름 분석하기 #####
parts = file_name.split("_")
A = int(parts[0])
B = int(parts[1])
XXX = parts[3].split(".")[0]
# 할 필요 없는 상황 없애기
if (B==0 and XXX=='HGV') or (B==100 and XXX=='LOV'):
continue
##### 2. 데이터 읽어들이기 #####
data = pd.read_csv(file_path)
self.V = data["index"].values
self.t = data[f"{A}_{B}%_{XXX}"].values
print("file_name : ", file_name)
##### 3. 5개의 점 Averaging #####
self.averaged_V = [] # 비우고 시작
self.averaged_t = []
for i in range(0, len(self.V), 5): # 한줄에 다섯개씩이니까 이렇게 됨
average = np.average(self.V[i:i+5])
self.averaged_V.append(average)
for i in range(0, len(self.t), 5): # 한줄에 다섯개씩이니까 이렇게 됨
average = np.average(self.t[i:i+5])
self.averaged_t.append(average)
##### 4. Capacity 설정하기 ######
if limit != 0:
self.C = limit
print('[capacity] 주어진 값으로 capacity 설정 완료')
else: # limit = 0일 경우
self.C = self.calculate_C(A)
self.t0 = self.calculate_t0(XXX, B)
if self.calculate_t0(XXX, B) is None:
continue
####### 5. curve fitting 및 그래프 그리기 ######
plt.scatter(self.V, self.t, label="All Data Points")
##### 6. 사전에 설정된 capacity에 따라 데이터 자르기 #####
if len(self.V) > 0:
print("self.C:", self.C)
indices = np.where(self.V > self.C)[0]
if len(indices) != 0:
self.newV = self.V[:indices[0]]
self.newt = self.t[:indices[0]]
if np.max(self.newV)!=0:
print('max V:', np.max(self.newV))
else:
print("No data points in the valid range.")
# Curve Fitting
if func_name == 'BPR':
popt, pcov = curve_fit(self.bpr_function, self.newV, self.newt)
self.t_estimated = self.bpr_function(self.newV, *popt)
self.fitted_func = 'standard BPR'
# elif ~~ :
# Drawing
plt.scatter(self.newV, self.newt, label="Valid Data Points")
plt.scatter(self.averaged_V, self.averaged_t, label="Average Data Points")
plt.plot(self.newV, self.t_estimated, 'r-', label=self.fitted_func)
plt.xlabel("Volume[veh]")
plt.ylabel("Travel Time[s]")
plt.title(f"A: {A}, B: {B}, XXX: {XXX}")
plt.legend()
plt.show()
# Display parameters
print('popt:', popt)
# Calculate r^2 and Add R-squared value to the plot
self.r_squared = self.calculate_r_squared(self.newt, self.t_estimated)
plt.text(0.95, 0.05, f'R-squared = {self.r_squared:.2f}', transform=plt.gca().transAxes, ha='right')
self.val_result.append(self.r_squared)
def estimate_parameters_in_folder(self, func_name, folder_path, limits=None, none_zero=1, p_0 = None):
# 주어진 데이터를, 주어진 함수로 fitting해보기
#### 비우고 시작 ####
self.empty_lists()
self.cnt = 0
for file_name in os.listdir(folder_path):
if file_name.endswith(".csv"):
#### 비우고 시작 ####
self.averaged_V = [] # 비우고 시작
self.averaged_t = []
self.rho = 0
file_path = os.path.join(folder_path, file_name)
##### 1. 파일 이름 분석하기 #####
parts = file_name.split("_")
A = int(parts[0])
B = int(parts[1])
C = parts[2]
both_numbers = C.split("-")
off_percent = int(both_numbers[0]) * 0.01
on_percent = int(both_numbers[1]) * 0.01
if A % 10 == 1:
on_percent = 0
# print('on_percent is zero')
elif A % 10 == 2:
off_percent = 0
# print('off_percent is zero')
XXX = parts[3].split(".")[0]
self.rho = B * 0.01
N = A//10 # 2, 3, 4
print('ssibal')
##### 2. 데이터 읽어들이기 #####
data = pd.read_csv(file_path)
self.V = data["index"].values
self.t = data[f"{A}_{B}%_{XXX}"].values
print('ssibal')
##### 3. 5개의 점 Averaging #####
for i in range(0, len(self.V), 5): # 한줄에 다섯개씩이니까 이렇게 됨
print('ssibal')
average = np.average(self.V[i:i+5])
self.averaged_V.append(average)
for i in range(0, len(self.t), 5): # 한줄에 다섯개씩이니까 이렇게 됨
average = np.average(self.t[i:i+5])
self.averaged_t.append(average)
# 향후 3D 그림을 위해서 저장
self.averaged_V_list.append(self.averaged_V)
self.averaged_t_list.append(self.averaged_t)
##### 4. Capacity, t0 설정하기 ######
if limits is not None:
limit = limits[self.cnt]
if limit != 0:
self.C = limit
# print('[capacity] 주어진 값으로 capacity 설정 완료')####################################################
else: # limit = 0일 경우
self.C = self.calculate_C(A)
self.cnt += 1
else:
self.C = self.calculate_C(A) # limits가 주어지지 않은 경우, limit=0으로 설정합니다.
self.t0 = self.calculate_t0(XXX, B)
if self.calculate_t0(XXX, B) is None:
continue
# 할 필요 없는 상황 없애기 -> fitting 할때 0의 데이터가 들어가 있으면 안된다.
if (B==0 and XXX=='HGV') or (B==100 and XXX=='LOV'):
# print('의미없는 상황제거완료')#####################################################
continue
##### 6. 사전에 설정된 capacity에 따라 데이터 자르기 #####
# print('-------------------------------------------------------------------------------------------------')
# print('-------------------------------------------------------------------------------------------------')
# print("file_name : ", file_name)####################################################
if len(self.V) > 0:
# print("self.C:", self.C)####################################################
indices = np.where(self.V > self.C)[0]
if len(indices) != 0:
self.newV = self.V[:indices[0]] # list
self.newt = self.t[:indices[0]]
# if np.max(self.newV)!=0:####################################################
# print('max V:', np.max(self.newV))####################################################
else:
print("No data points in the valid range.")
self.V_list.append(self.newV)
self.t_list.append(self.newt)
self.t0_list.append(repeat(self.t0, len(self.newV)))
self.C_list.append(repeat(self.C, len(self.newV)))
self.rho_list.append(repeat(self.rho, len(self.newV)))
self.N_list.append(repeat(N, len(self.newV)))
self.off_list.append(repeat(off_percent, len(self.newV)))
self.on_list.append(repeat(on_percent, len(self.newV)))
self.averaged_rho_list.append(repeat(self.rho, len(self.averaged_V)))
self.file_name_list.append(repeat(file_name, len(self.averaged_V))) ## 길이는 averaged_V의 갯수만큼만!!
self.XXX = XXX
### 1차원 배열로 변경 ###
self.V_list = list(itertools.chain(*self.V_list))
self.t_list = list(itertools.chain(*self.t_list))
self.t0_list = list(itertools.chain(*self.t0_list))
self.C_list = list(itertools.chain(*self.C_list))
self.rho_list = list(itertools.chain(*self.rho_list))
self.file_name_list = list(itertools.chain(*self.file_name_list))
self.N_list = list(itertools.chain(*self.N_list))
self.off_list = list(itertools.chain(*self.off_list))
self.on_list = list(itertools.chain(*self.on_list))
self.averaged_rho_list = list(itertools.chain(*self.averaged_rho_list))
################ t0, rho, V, C, N, off, on 순서로 넣어라 ###############
self.x_list.append(self.t0_list)
self.x_list.append(self.rho_list)
self.x_list.append(self.V_list)
self.x_list.append(self.C_list)
self.x_list.append(self.N_list)
self.x_list.append(self.off_list)
self.x_list.append(self.on_list)
# self.x_list.append(self.file_name_list) # 하면 안됨
self.x_list = np.array(self.x_list)
self.y_list = np.array(self.t_list)
# np array로 변환
self.V_list = np.array(self.V_list)
self.t0_list = np.array(self.t0_list)
self.C_list = np.array(self.C_list)
self.rho_list = np.array(self.rho_list)
self.N_list = np.array(self.N_list)
self.off_list = np.array(self.off_list)
self.on_list = np.array(self.on_list)
###############################################################
###################### Curve Fitting #########################
# Curve Fitting bpr_function_in_folder(self, x, a1, a2):
if func_name == 'BPR':
if none_zero == 1:
popt, pcov = curve_fit(self.bpr_function_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
formula = f"t = t_0 * (1 + {popt[0]} * (V / C) ** {popt[1]})"
else:
popt, pcov = curve_fit(self.bpr_function_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.bpr_function(self.V_list, *popt)
elif func_name == 'Lu_1': # def Lu_1_in_folder(x, a1, a2, a3):
if none_zero == 1:
popt, pcov = curve_fit(self.Lu_1_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.Lu_1_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.Lu_1(self.V_list, *popt)
elif func_name == 'Lu_2': # def Lu_2_in_folder(x, a1, a2):
if none_zero == 1:
popt, pcov = curve_fit(self.Lu_2_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.Lu_2_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.Lu_2(self.V_list, *popt)
elif func_name == 'Lu_3': # def Lu_3_in_folder(x, a1, a2):
if none_zero == 1:
popt, pcov = curve_fit(self.Lu_3_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.Lu_3_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.Lu_3(self.V_list, *popt)
elif func_name == 'Lu_4': # def Lu_4_in_folder(x, a1, a2):
if none_zero == 1:
popt, pcov = curve_fit(self.Lu_4_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.Lu_4_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.Lu_4(self.V_list, *popt)
elif func_name == 'TRUCK1': #
if none_zero == 1:
popt, pcov = curve_fit(self.TRUCK1_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.TRUCK1_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.TRUCK1(self.V_list, *popt)
elif func_name == 'TRUCK2': #
if none_zero == 1:
popt, pcov = curve_fit(self.TRUCK2_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.TRUCK2_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.TRUCK2(self.V_list, *popt)
elif func_name == 'TRUCK3':
if none_zero == 1:
popt, pcov = curve_fit(self.TRUCK3_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.TRUCK3_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.TRUCK3(self.V_list, *popt)
elif func_name == 'TRUCK4':
if none_zero == 1:
popt, pcov = curve_fit(self.TRUCK4_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.TRUCK4_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.TRUCK4(self.V_list, *popt)
elif func_name == 'TRUCK5':
if none_zero == 1:
popt, pcov = curve_fit(self.TRUCK5_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.TRUCK5_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.TRUCK5(self.V_list, *popt)
elif func_name == 'TRUCK6':
if none_zero == 1:
popt, pcov = curve_fit(self.TRUCK6_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.TRUCK6_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.TRUCK6(self.V_list, *popt)
elif func_name == 'TRUCK7':
if none_zero == 1:
popt, pcov = curve_fit(self.TRUCK7_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.TRUCK7_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.TRUCK7(self.V_list, *popt)
elif func_name == 'TRUCK8':
if none_zero == 1:
popt, pcov = curve_fit(self.TRUCK8_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.TRUCK8_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.TRUCK8(self.V_list, *popt)
elif func_name == 'TRUCK9':
if none_zero == 1:
popt, pcov = curve_fit(self.TRUCK9_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.TRUCK9_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.TRUCK9(self.V_list, *popt)
elif func_name == 'TRUCK10':
if none_zero == 1:
popt, pcov = curve_fit(self.TRUCK10_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.TRUCK10_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.TRUCK10(self.V_list, *popt)
elif func_name == 'TRUCK11':
if none_zero == 1:
popt, pcov = curve_fit(self.TRUCK11_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.TRUCK11_in_folder, self.x_list, self.y_list, bounds=([0,0,0,-np.inf,-np.inf,0],np.inf), maxfev=5000) #, bounds=(0,np.inf))
print('4-5 음수')
self.t_estimated = self.TRUCK11(self.V_list, *popt)
elif func_name == 'TRUCK12':
if none_zero == 1:
popt, pcov = curve_fit(self.TRUCK12_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.TRUCK12_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.TRUCK12(self.V_list, *popt)
elif func_name == 'N1':
if none_zero == 1:
popt, pcov = curve_fit(self.N1_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.N1_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.N1(self.V_list, *popt)
elif func_name == 'N2':
if none_zero == 1:
popt, pcov = curve_fit(self.N2_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.N2_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.N2(self.V_list, *popt)
elif func_name == 'N3':
if none_zero == 1:
popt, pcov = curve_fit(self.N3_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.N3_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.N3(self.V_list, *popt)
elif func_name == 'N4':
if none_zero == 1:
popt, pcov = curve_fit(self.N4_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.N4_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.N4(self.V_list, *popt)
elif func_name == 'N5':
if none_zero == 1:
popt, pcov = curve_fit(self.N5_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.N5_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.N5(self.V_list, *popt)
elif func_name == 'N6':
if none_zero == 1:
popt, pcov = curve_fit(self.N6_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.N6_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.N6(self.V_list, *popt)
elif func_name == 'R1':
if none_zero == 1:
popt, pcov = curve_fit(self.R1_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.R1_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.R1(self.V_list, *popt)
elif func_name == 'R2':
if none_zero == 1:
popt, pcov = curve_fit(self.R2_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.R2_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.R2(self.V_list, *popt)
elif func_name == 'R3':
if none_zero == 1:
popt, pcov = curve_fit(self.R3_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.R3_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.R3(self.V_list, *popt)
elif func_name == 'R4':
if none_zero == 1:
popt, pcov = curve_fit(self.R4_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.R4_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.R4(self.V_list, *popt)
elif func_name == 'R5':
if none_zero == 1:
popt, pcov = curve_fit(self.R5_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.R5_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.R5(self.V_list, *popt)
elif func_name == 'C1':
if none_zero == 1:
popt, pcov = curve_fit(self.C1_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
formula = fr"$t = t_0 * ({round(popt[0], 2)} + {round(popt[1], 2)} * R_t) * (1 + {round(popt[2], 2)} * (1 + Rₒₕₕ) ** {round(popt[3], 2)} * (1 + Rₒₙₕₙ) ** {round(popt[4], 2)} * (1 + R_c) ** {round(popt[5], 2)} * (1 + R_t) ** {round(popt[6], 2)} * (V / C) ** {round(popt[7], 2)})$"
else:
if p_0 != None:
popt, pcov = curve_fit(self.C1_in_folder, self.x_list, self.y_list, bounds=([0,0,0,0,0,-np.inf,-np.inf,0],np.inf), maxfev=5000, p0 = p_0) #, bounds=(0,np.inf))
else:
popt, pcov = curve_fit(self.C1_in_folder, self.x_list, self.y_list,bounds=([0,0,0,0,0,-np.inf,-np.inf,0],np.inf), maxfev=5000) #, bounds=(0,np.inf))
print('5~6 값 음수')
formula = fr"$t = t_0 * ({round(popt[0], 2)} + {round(popt[1], 2)} * R_t) * (1 + {round(popt[2], 2)} * (1 + Rₒₕₕ) ** {round(popt[3], 2)} * (1 + Rₒₙₕₙ) ** {round(popt[4], 2)} * (1 + R_c) ** {round(popt[5], 2)} * (1 + R_t) ** {round(popt[6], 2)} * (V / C) ** {round(popt[7], 2)})$"
self.t_estimated = self.C1(self.V_list, *popt)
elif func_name == 'C1_no':
if none_zero == 1:
popt, pcov = curve_fit(self.C1_no_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
formula = fr"$t = ({round(popt[0], 2)} + {round(popt[1], 2)} * R_t) * (1 + {round(popt[2], 2)} * (1 + Rₒₕₕ) ** {round(popt[3], 2)} * (1 + Rₒₙₕₙ) ** {round(popt[4], 2)} * (1 + R_c) ** {round(popt[5], 2)} * (1 + R_t) ** {round(popt[6], 2)} * (V / C) ** {round(popt[7], 2)})$"
else:
popt, pcov = curve_fit(self.C1_no_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
formula = fr"$t = ({round(popt[0], 2)} + {round(popt[1], 2)} * R_t) * (1 + {round(popt[2], 2)} * (1 + Rₒₕₕ) ** {round(popt[3], 2)} * (1 + Rₒₙₕₙ) ** {round(popt[4], 2)} * (1 + R_c) ** {round(popt[5], 2)} * (1 + R_t) ** {round(popt[6], 2)} * (V / C) ** {round(popt[7], 2)})$"
self.t_estimated = self.C1_no(self.V_list, *popt)
elif func_name == 'C2':
if none_zero == 1:
popt, pcov = curve_fit(self.C2_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.C2_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.C2(self.V_list, *popt)
elif func_name == 'C3':
if none_zero == 1:
popt, pcov = curve_fit(self.C3_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.C3_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.C3(self.V_list, *popt)
elif func_name == 'C4':
if none_zero == 1:
popt, pcov = curve_fit(self.C4_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.C4_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.C4(self.V_list, *popt)
elif func_name == 'C5':
if none_zero == 1:
popt, pcov = curve_fit(self.C5_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.C5_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.C5(self.V_list, *popt)
elif func_name == 'C6':
if none_zero == 1:
popt, pcov = curve_fit(self.C6_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.C6_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.C6(self.V_list, *popt)
elif func_name == 'C7':
if none_zero == 1:
popt, pcov = curve_fit(self.C7_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
popt, pcov = curve_fit(self.C7_in_folder, self.x_list, self.y_list, maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.C7(self.V_list, *popt)
elif func_name == 'C8':
if none_zero == 1:
popt, pcov = curve_fit(self.C8_in_folder, self.x_list, self.y_list, bounds=([0,0,-np.inf,-np.inf,-np.inf,-np.inf,0],np.inf), maxfev=5000)
else:
if p_0 != None:
popt, pcov = curve_fit(self.C8_in_folder, self.x_list, self.y_list, bounds=([0,0,-np.inf,-np.inf,-np.inf,-np.inf,0],np.inf), maxfev=5000, p0 = p_0) #, bounds=(0,np.inf))
else:
popt, pcov = curve_fit(self.C8_in_folder, self.x_list, self.y_list,bounds=([0,0,-np.inf,-np.inf,-np.inf,-np.inf,0],np.inf), maxfev=5000) #, bounds=(0,np.inf))
self.t_estimated = self.C8(self.V_list, *popt)
elif func_name == 'C9':
if none_zero == 1:
popt, pcov = curve_fit(self.C9_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
if p_0 != None:
popt, pcov = curve_fit(self.C9_in_folder, self.x_list, self.y_list, bounds=([0,0,0,-np.inf,-np.inf,-np.inf,0],np.inf), maxfev=5000, p0 = p_0) #, bounds=(0,np.inf))
else:
popt, pcov = curve_fit(self.C9_in_folder, self.x_list, self.y_list,bounds=([0,0,0,-np.inf,-np.inf,-np.inf,0],np.inf), maxfev=5000) #, bounds=(0,np.inf))
print(' 4~6 음수')
self.t_estimated = self.C9(self.V_list, *popt)
elif func_name == 'C10':
if none_zero == 1:
popt, pcov = curve_fit(self.C10_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
if p_0 != None:
popt, pcov = curve_fit(self.C10_in_folder, self.x_list, self.y_list, bounds=([0,0,0,-np.inf,-np.inf,0],np.inf), maxfev=5000, p0 = p_0) #, bounds=(0,np.inf))
else:
popt, pcov = curve_fit(self.C10_in_folder, self.x_list, self.y_list,bounds=([0,0,0,-np.inf,-np.inf,0],np.inf), maxfev=5000) #, bounds=(0,np.inf))
print(' 4~5 음수')
self.t_estimated = self.C10(self.V_list, *popt)
elif func_name == 'C11':
if none_zero == 1:
popt, pcov = curve_fit(self.C11_in_folder, self.x_list, self.y_list, bounds=(0,np.inf), maxfev=5000)
else:
if p_0 != None:
popt, pcov = curve_fit(self.C11_in_folder, self.x_list, self.y_list, bounds=([0,0,-np.inf,-np.inf,0],np.inf), maxfev=5000, p0 = p_0) #, bounds=(0,np.inf))
else:
popt, pcov = curve_fit(self.C11_in_folder, self.x_list, self.y_list,bounds=([0,0,-np.inf,-np.inf,0],np.inf), maxfev=5000) #, bounds=(0,np.inf))
print(' 3-4 음수')
self.t_estimated = self.C11(self.V_list, *popt)
elif func_name == 'C12':
if none_zero == 1: