-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchanges.diff
More file actions
2329 lines (2155 loc) · 184 KB
/
changes.diff
File metadata and controls
2329 lines (2155 loc) · 184 KB
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
diff --git a/benchmarks/pressure_vessel/dependent_space/run.py b/benchmarks/pressure_vessel/dependent_space/run.py
index cf46eaf..b4f9fc7 100644
--- a/benchmarks/pressure_vessel/dependent_space/run.py
+++ b/benchmarks/pressure_vessel/dependent_space/run.py
@@ -139,20 +139,20 @@ def objective(harmony: Dict[str, Any]) -> Tuple[float, float]:
π·R²·L + (4/3)·π·R³ ≥ 1,296,000
→ −π·R²·L − (4/3)·π·R³ + 1,296,000 ≤ 0
"""
- R: float = harmony["R"]
- Ts: float = harmony["Ts"]
- Th: float = harmony["Th"]
- L: float = harmony["L"]
+ r: float = harmony["R"]
+ ts: float = harmony["Ts"]
+ th: float = harmony["Th"]
+ l: float = harmony["L"]
# --- Guard against degenerate designs ---
- if R <= 0.0 or Ts <= 0.0 or Th <= 0.0 or L <= 0.0:
+ if r <= 0.0 or ts <= 0.0 or th <= 0.0 or l <= 0.0:
return float("inf"), float("inf")
# --- Fabrication cost ---
- cost: float = 0.6224 * Ts * R * L + 1.7781 * Th * R**2 + 3.1661 * Ts**2 * L + 19.84 * Ts**2 * R
+ cost: float = 0.6224 * ts * r * l + 1.7781 * th * r**2 + 3.1661 * ts**2 * l + 19.84 * ts**2 * r
# --- Volume constraint (g3) ---
- volume: float = math.pi * R**2 * L + (4.0 / 3.0) * math.pi * R**3
+ volume: float = math.pi * r**2 * l + (4.0 / 3.0) * math.pi * r**3
g3: float = -volume + MIN_VOLUME
penalty: float = max(0.0, g3)
@@ -200,7 +200,7 @@ def main() -> None:
plotter = ConvergencePlotter(OUTPUT_DIR / "history_data.csv")
plotter.set_labels(title="Pressure Vessel ΓÇö Dependent Space")
plotter.add_info_box(
- f"Cost: {result.best_fitness:.2f}\n" f"Penalty: {result.best_penalty:.4f}\n" f"Time: {t_elapsed:.2f}s"
+ f"Cost: {result.best_fitness:.2f}\nPenalty: {result.best_penalty:.4f}\nTime: {t_elapsed:.2f}s"
)
plotter.plot(save_path=OUTPUT_DIR / "convergence.png")
diff --git a/benchmarks/pressure_vessel/full_parametric_extreme/run.py b/benchmarks/pressure_vessel/full_parametric_extreme/run.py
index aa91858..4fab98f 100644
--- a/benchmarks/pressure_vessel/full_parametric_extreme/run.py
+++ b/benchmarks/pressure_vessel/full_parametric_extreme/run.py
@@ -119,8 +119,8 @@ def _compute_r_min(
R_min to full machine precision.
"""
- def f(R: float) -> float:
- return math.pi * R**2 * (l_max + 4.0 * R / 3.0) - volume
+ def f(r: float) -> float:
+ return math.pi * r**2 * (l_max + 4.0 * r / 3.0) - volume
# Bracket: f(0) = -volume < 0; f(R_upper) >> 0 for any sane problem
lo, hi = 0.0, R_UPPER
@@ -135,7 +135,7 @@ def _compute_r_min(
return hi # conservative (slightly above true root)
-def _l_min_from_volume(R: float, volume: float) -> float:
+def _l_min_from_volume(r: float, volume: float) -> float:
"""
Invert the volume equation for the minimum cylindrical length.
@@ -156,11 +156,11 @@ def _l_min_from_volume(R: float, volume: float) -> float:
float
Lower bound for L.
"""
- head_volume: float = (4.0 / 3.0) * math.pi * R**3
+ head_volume: float = (4.0 / 3.0) * math.pi * r**3
remaining: float = volume - head_volume
if remaining <= 0.0:
return L_LOWER # heads alone satisfy volume
- return max(L_LOWER, remaining / (math.pi * R**2))
+ return max(L_LOWER, remaining / (math.pi * r**2))
# ---------------------------------------------------------------------------
@@ -233,12 +233,17 @@ def objective(harmony: Dict[str, Any]) -> Tuple[float, float]:
3.1661 ┬╖ Ts┬▓ ┬╖ L ΓÇö longitudinal shell forming
19.84 ┬╖ Ts┬▓ ┬╖ R ΓÇö circumferential shell forming
"""
- R: float = harmony["R"]
- Ts: float = harmony["Ts"]
- Th: float = harmony["Th"]
- L: float = harmony["L"]
-
- cost: float = 0.6224 * Ts * R * L + 1.7781 * Th * R**2 + 3.1661 * Ts**2 * L + 19.84 * Ts**2 * R
+ r: float = harmony["R"]
+ ts: float = harmony["Ts"]
+ th: float = harmony["Th"]
+ l: float = harmony["L"]
+
+ cost: float = (
+ 0.6224 * ts * r * l
+ + 1.7781 * th * r**2
+ + 3.1661 * ts**2 * l
+ + 19.84 * ts**2 * r
+ )
return cost, 0.0
@@ -287,10 +292,7 @@ def main() -> None:
plotter = ConvergencePlotter(OUTPUT_DIR / "history_data.csv")
plotter.set_labels(title="Pressure Vessel ΓÇö Full Parametric Extreme")
plotter.add_info_box(
- f"Cost: {result.best_fitness:.2f}\n"
- f"Penalty: {result.best_penalty:.4f}\n"
- f"R_min: {R_MIN:.2f} in\n"
- f"Time: {t_elapsed:.2f}s"
+ f"Cost: {result.best_fitness:.2f}\nPenalty: {result.best_penalty:.4f}\nR_min: {R_MIN:.2f} in\nTime: {t_elapsed:.2f}s"
)
plotter.plot(save_path=OUTPUT_DIR / "convergence.png")
diff --git a/benchmarks/pressure_vessel/semi_dependent/run.py b/benchmarks/pressure_vessel/semi_dependent/run.py
index 17d538d..4cc8252 100644
--- a/benchmarks/pressure_vessel/semi_dependent/run.py
+++ b/benchmarks/pressure_vessel/semi_dependent/run.py
@@ -73,7 +73,7 @@ HEAVY_PENALTY: float = 1e9 # Penalty for geometrically infeasible R
# ---------------------------------------------------------------------------
# Helper: volume-derived minimum L
# ---------------------------------------------------------------------------
-def _l_min_from_volume(R: float) -> float:
+def _l_min_from_volume(r: float) -> float:
"""
Invert the volume equation to find the minimum cylindrical length
that satisfies g3 for a given inner radius R.
@@ -85,11 +85,11 @@ def _l_min_from_volume(R: float) -> float:
sufficient volume, making L_min negative. The result is clamped
to a minimum of 10.0 (the benchmark lower bound for L).
"""
- head_volume: float = (4.0 / 3.0) * math.pi * R**3
+ head_volume: float = (4.0 / 3.0) * math.pi * r**3
remaining: float = MIN_VOLUME - head_volume
if remaining <= 0:
return 10.0 # heads alone satisfy volume
- return remaining / (math.pi * R**2)
+ return remaining / (math.pi * r**2)
# ---------------------------------------------------------------------------
@@ -160,22 +160,22 @@ def objective(harmony: Dict[str, Any]) -> Tuple[float, float]:
For all other designs the penalty is 0.0 because the space
guarantees g1ΓÇôg4 satisfaction.
"""
- R: float = harmony["R"]
- Ts: float = harmony["Ts"]
- Th: float = harmony["Th"]
- L: float = harmony["L"]
+ r: float = harmony["R"]
+ ts: float = harmony["Ts"]
+ th: float = harmony["Th"]
+ l: float = harmony["L"]
- if R <= 0.0 or Ts <= 0.0 or Th <= 0.0 or L <= 0.0:
+ if r <= 0.0 or ts <= 0.0 or th <= 0.0 or l <= 0.0:
return float("inf"), float("inf")
# --- Check geometric feasibility of R ---------------------------------
- l_min_required: float = _l_min_from_volume(R)
+ l_min_required: float = _l_min_from_volume(r)
if l_min_required > 240.0:
# This R is too small ΓÇö no valid L can satisfy the volume.
return HEAVY_PENALTY, HEAVY_PENALTY
# --- Fabrication cost --------------------------------------------------
- cost: float = 0.6224 * Ts * R * L + 1.7781 * Th * R**2 + 3.1661 * Ts**2 * L + 19.84 * Ts**2 * R
+ cost: float = 0.6224 * ts * r * l + 1.7781 * th * r**2 + 3.1661 * ts**2 * l + 19.84 * ts**2 * r
return cost, 0.0
@@ -220,7 +220,7 @@ def main() -> None:
plotter = ConvergencePlotter(OUTPUT_DIR / "history_data.csv")
plotter.set_labels(title="Pressure Vessel ΓÇö Semi-Dependent Space")
plotter.add_info_box(
- f"Cost: {result.best_fitness:.2f}\n" f"Penalty: {result.best_penalty:.4f}\n" f"Time: {t_elapsed:.2f}s"
+ f"Cost: {result.best_fitness:.2f}\nPenalty: {result.best_penalty:.4f}\nTime: {t_elapsed:.2f}s"
)
plotter.plot(save_path=OUTPUT_DIR / "convergence.png")
diff --git a/benchmarks/pressure_vessel/static_penalty/run.py b/benchmarks/pressure_vessel/static_penalty/run.py
index 4b9174d..4ff1990 100644
--- a/benchmarks/pressure_vessel/static_penalty/run.py
+++ b/benchmarks/pressure_vessel/static_penalty/run.py
@@ -82,23 +82,23 @@ def objective(harmony: Dict[str, Any]) -> Tuple[float, float]:
Term 3: 3.1661 ┬╖ Ts┬▓ ┬╖ L ΓÇö longitudinal shell forming
Term 4: 19.84 ┬╖ Ts┬▓ ┬╖ R ΓÇö circumferential shell forming
"""
- Ts: float = harmony["Ts"]
- Th: float = harmony["Th"]
- R: float = harmony["R"]
- L: float = harmony["L"]
+ ts: float = harmony["Ts"]
+ th: float = harmony["Th"]
+ r: float = harmony["R"]
+ l: float = harmony["L"]
# --- Guard against degenerate designs ---
- if Ts <= 0 or Th <= 0 or R <= 0 or L <= 0:
+ if ts <= 0 or th <= 0 or r <= 0 or l <= 0:
return float("inf"), float("inf")
# --- Fabrication cost ---
- cost: float = 0.6224 * Ts * R * L + 1.7781 * Th * R**2 + 3.1661 * Ts**2 * L + 19.84 * Ts**2 * R
+ cost: float = 0.6224 * ts * r * l + 1.7781 * th * r**2 + 3.1661 * ts**2 * l + 19.84 * ts**2 * r
# --- All 4 constraints ---
- g1 = -Ts + 0.0193 * R # shell hoop
- g2 = -Th + 0.00954 * R # head hoop
- g3 = -(math.pi * R**2 * L) - (4.0 / 3.0) * math.pi * R**3 + MIN_VOLUME # volume
- g4 = L - 240.0 # length
+ g1 = -ts + 0.0193 * r # shell hoop
+ g2 = -th + 0.00954 * r # head hoop
+ g3 = -(math.pi * r**2 * l) - (4.0 / 3.0) * math.pi * r**3 + MIN_VOLUME # volume
+ g4 = l - 240.0 # length
penalty: float = sum(max(0.0, g) for g in [g1, g2, g3, g4])
@@ -145,7 +145,7 @@ def main() -> None:
plotter = ConvergencePlotter(OUTPUT_DIR / "history_data.csv")
plotter.set_labels(title="Pressure Vessel ΓÇö Static Penalty")
plotter.add_info_box(
- f"Cost: {result.best_fitness:.2f}\n" f"Penalty: {result.best_penalty:.4f}\n" f"Time: {t_elapsed:.2f}s"
+ f"Cost: {result.best_fitness:.2f}\nPenalty: {result.best_penalty:.4f}\nTime: {t_elapsed:.2f}s"
)
plotter.plot(save_path=OUTPUT_DIR / "convergence.png")
diff --git a/benchmarks/retaining_wall/dependent_space/run.py b/benchmarks/retaining_wall/dependent_space/run.py
index c6a2613..50bf2ed 100644
--- a/benchmarks/retaining_wall/dependent_space/run.py
+++ b/benchmarks/retaining_wall/dependent_space/run.py
@@ -60,10 +60,10 @@ def _x3_min(ctx: Dict[str, float]) -> float:
fc = round(ctx["fc"] / 5.0) * 5.0
x4 = round(ctx["x4"] / 50.0) * 50.0
- Vu_stem = 1.6 * (0.5 * KA * GAMMA_SOIL * H_STEM**2) * 1000.0 # N
+ vu_stem = 1.6 * (0.5 * KA * GAMMA_SOIL * H_STEM**2) * 1000.0 # N
# phi * Vc = 0.75 * 0.17 * sqrt(f'c) * bw * d
shear_cap_per_mm = 0.75 * 0.17 * math.sqrt(fc) * WIDTH_B
- d_req = Vu_stem / shear_cap_per_mm
+ d_req = vu_stem / shear_cap_per_mm
return float(max(300.0, x4, math.ceil((d_req + COVER) / 50.0) * 50.0))
@@ -75,8 +75,8 @@ def check_geotech_stability(x1, x2, x3, x4, x5) -> bool:
if l_heel < 0:
return False
- Pa = 0.5 * KA * GAMMA_SOIL * (h_tot**2)
- Mo = Pa * (h_tot / 3.0)
+ pa = 0.5 * KA * GAMMA_SOIL * (h_tot**2)
+ mo = pa * (h_tot / 3.0)
w_base = (x1 / 1000.0) * t_base_m * GAMMA_CONC
w_base_x = (x1 / 1000.0) / 2.0
@@ -90,12 +90,12 @@ def check_geotech_stability(x1, x2, x3, x4, x5) -> bool:
w_soil = (l_heel / 1000.0) * H_STEM * GAMMA_SOIL
w_soil_x = (x1 - l_heel / 2.0) / 1000.0
- sum_W = w_base + w_stem_rect + w_stem_tri + w_soil
- Mr = (w_base * w_base_x) + (w_stem_rect * w_stem_rect_x) + (w_stem_tri * w_stem_tri_x) + (w_soil * w_soil_x)
+ sum_w = w_base + w_stem_rect + w_stem_tri + w_soil
+ mr = (w_base * w_base_x) + (w_stem_rect * w_stem_rect_x) + (w_stem_tri * w_stem_tri_x) + (w_soil * w_soil_x)
- fs_ov = Mr / Mo if Mo > 0 else 100.0
- fs_sl = (sum_W * math.tan(PHI_SOIL)) / Pa
- e = abs((x1 / 2000.0) - ((Mr - Mo) / sum_W))
+ fs_ov = mr / mo if mo > 0 else 100.0
+ fs_sl = (sum_w * math.tan(PHI_SOIL)) / pa
+ e = abs((x1 / 2000.0) - ((mr - mo) / sum_w))
return fs_ov >= 2.5 and fs_sl >= 2.5 and e <= (x1 / 6000.0)
@@ -171,18 +171,18 @@ def objective(config: Dict[str, Any]) -> Tuple[float, float]:
l_heel = x1 - x2 - x3
# Demands
- Pa_stem = 0.5 * KA * GAMMA_SOIL * (H_STEM**2)
- Mu_stem = 1.6 * Pa_stem * (H_STEM / 3.0)
+ pa_stem = 0.5 * KA * GAMMA_SOIL * (H_STEM**2)
+ mu_stem = 1.6 * pa_stem * (H_STEM / 3.0)
d_stem = x3 - COVER
w_heel_total = 1.2 * (GAMMA_SOIL * H_STEM + GAMMA_CONC * t_base_m)
- Vu_heel_N = w_heel_total * (l_heel / 1000.0) * 1000.0
- Mu_heel = w_heel_total * ((l_heel / 1000.0) ** 2 / 2.0)
+ vu_heel_n = w_heel_total * (l_heel / 1000.0) * 1000.0
+ mu_heel = w_heel_total * ((l_heel / 1000.0) ** 2 / 2.0)
d_base = x5 - COVER
# Embed shear check for heel (dynamically penalized if it fails because x5 wasn't pruned)
- phi_Vc_heel = 0.75 * 0.17 * math.sqrt(fc) * WIDTH_B * d_base
- shear_pen = max(0.0, Vu_heel_N - phi_Vc_heel) ** 2 * 1e4
+ phi_vc_heel = 0.75 * 0.17 * math.sqrt(fc) * WIDTH_B * d_base
+ shear_pen = max(0.0, vu_heel_n - phi_vc_heel) ** 2 * 1e4
code_stem = config["dc_stem"]
code_base = config["dc_base"]
@@ -190,21 +190,21 @@ def objective(config: Dict[str, Any]) -> Tuple[float, float]:
if code_stem is None or code_base is None or l_heel < 0:
return 1e12, 1e8 + space_penalty
- As_s = steel_area(code_stem)
- As_b = steel_area(code_base)
+ as_s = steel_area(code_stem)
+ as_b = steel_area(code_base)
# Check Flexure (Because ACIRebar handles rho & fit, but we must verify Moment limit)
- a_stem = (As_s * FY_MPA) / (0.85 * fc * WIDTH_B)
- phi_Mn_stem = 0.9 * As_s * FY_MPA * max(0.1, d_stem - a_stem / 2.0) * 1e-6
- mu_pen_stem = max(0.0, Mu_stem - phi_Mn_stem) ** 2 * 1e4
+ a_stem = (as_s * FY_MPA) / (0.85 * fc * WIDTH_B)
+ phi_mn_stem = 0.9 * as_s * FY_MPA * max(0.1, d_stem - a_stem / 2.0) * 1e-6
+ mu_pen_stem = max(0.0, mu_stem - phi_mn_stem) ** 2 * 1e4
- a_base = (As_b * FY_MPA) / (0.85 * fc * WIDTH_B)
- phi_Mn_base = 0.9 * As_b * FY_MPA * max(0.1, d_base - a_base / 2.0) * 1e-6
- mu_pen_base = max(0.0, Mu_heel - phi_Mn_base) ** 2 * 1e4
+ a_base = (as_b * FY_MPA) / (0.85 * fc * WIDTH_B)
+ phi_mn_base = 0.9 * as_b * FY_MPA * max(0.1, d_base - a_base / 2.0) * 1e-6
+ mu_pen_base = max(0.0, mu_heel - phi_mn_base) ** 2 * 1e4
vol_conc = (x1 / 1000.0) * t_base_m + 0.5 * (x3 + x4) / 1000.0 * H_STEM
cost_conc = (0.5 + 0.02 * fc) * vol_conc
- cost_steel = 50.0 * (As_s + As_b) / 1000.0
+ cost_steel = 50.0 * (as_s + as_b) / 1000.0
total_cost = cost_conc + cost_steel
return total_cost, space_penalty + shear_pen + mu_pen_stem + mu_pen_base
diff --git a/benchmarks/retaining_wall/static_penalty/run.py b/benchmarks/retaining_wall/static_penalty/run.py
index 084f4c6..9452418 100644
--- a/benchmarks/retaining_wall/static_penalty/run.py
+++ b/benchmarks/retaining_wall/static_penalty/run.py
@@ -83,8 +83,8 @@ def objective(config: Dict[str, Any]) -> Tuple[float, float]:
h_tot = H_STEM + t_base_m
# Active Earth Thrust
- Pa = 0.5 * KA * GAMMA_SOIL * (h_tot**2)
- Mo = Pa * (h_tot / 3.0)
+ pa = 0.5 * KA * GAMMA_SOIL * (h_tot**2)
+ mo = pa * (h_tot / 3.0)
# Weights and Centers
w_base = (x1 / 1000.0) * t_base_m * GAMMA_CONC
@@ -99,61 +99,61 @@ def objective(config: Dict[str, Any]) -> Tuple[float, float]:
w_soil = (l_heel / 1000.0) * H_STEM * GAMMA_SOIL
w_soil_x = (x1 - l_heel / 2.0) / 1000.0
- sum_W = w_base + w_stem_rect + w_stem_tri + w_soil
- Mr = (w_base * w_base_x) + (w_stem_rect * w_stem_rect_x) + (w_stem_tri * w_stem_tri_x) + (w_soil * w_soil_x)
+ sum_w = w_base + w_stem_rect + w_stem_tri + w_soil
+ mr = (w_base * w_base_x) + (w_stem_rect * w_stem_rect_x) + (w_stem_tri * w_stem_tri_x) + (w_soil * w_soil_x)
- fs_overturning = Mr / Mo if Mo > 0 else 100.0
- fs_sliding = (sum_W * math.tan(PHI_SOIL)) / Pa
+ fs_overturning = mr / mo if mo > 0 else 100.0
+ fs_sliding = (sum_w * math.tan(PHI_SOIL)) / pa
# Eccentricity
- e = (x1 / 2000.0) - ((Mr - Mo) / sum_W)
+ e = (x1 / 2000.0) - ((mr - mo) / sum_w)
# --- Structural ACI Demands ---
# Stem at base
- Pa_stem = 0.5 * KA * GAMMA_SOIL * (H_STEM**2)
- Vu_stem = 1.6 * Pa_stem
- Mu_stem = 1.6 * Pa_stem * (H_STEM / 3.0)
+ pa_stem = 0.5 * KA * GAMMA_SOIL * (H_STEM**2)
+ vu_stem = 1.6 * pa_stem
+ mu_stem = 1.6 * pa_stem * (H_STEM / 3.0)
d_stem = x3 - COVER
# Heel at back of stem
w_heel_total = 1.2 * (GAMMA_SOIL * H_STEM + GAMMA_CONC * t_base_m)
- Vu_heel = w_heel_total * (l_heel / 1000.0)
- Mu_heel = w_heel_total * ((l_heel / 1000.0) ** 2 / 2.0)
+ vu_heel = w_heel_total * (l_heel / 1000.0)
+ mu_heel = w_heel_total * ((l_heel / 1000.0) ** 2 / 2.0)
d_base = x5 - COVER
# Rebars
db_s = DIAMS[idx_stem_dia]
- As_s = float(n_s) * math.pi * (db_s**2) / 4.0
+ as_s = float(n_s) * math.pi * (db_s**2) / 4.0
db_b = DIAMS[idx_base_dia]
- As_b = float(n_b) * math.pi * (db_b**2) / 4.0
+ as_b = float(n_b) * math.pi * (db_b**2) / 4.0
# --- Structural Penalties (g_i <= 0) ---
beta1 = get_beta1(fc)
rho_min = max(0.25 * math.sqrt(fc) / FY_MPA, 1.4 / FY_MPA)
rho_max = 0.85 * beta1 * (fc / FY_MPA) * (3.0 / 8.0)
- def check_aci(M_u, V_u, d_eff, A_s, d_b, n):
- phi_Vc = 0.75 * 0.17 * math.sqrt(fc) * WIDTH_B * (d_eff / 1000.0)
- a = (A_s * FY_MPA) / (0.85 * fc * WIDTH_B)
- phi_Mn = 0.9 * A_s * FY_MPA * max(0.1, d_eff - a / 2.0) * 1e-6
- rho = A_s / (WIDTH_B * d_eff)
+ def check_aci(m_u, v_u, d_eff, a_s, d_b, n):
+ phi_vc = 0.75 * 0.17 * math.sqrt(fc) * WIDTH_B * (d_eff / 1000.0)
+ a = (a_s * FY_MPA) / (0.85 * fc * WIDTH_B)
+ phi_mn = 0.9 * a_s * FY_MPA * max(0.1, d_eff - a / 2.0) * 1e-6
+ rho = a_s / (WIDTH_B * d_eff)
# Spacing
s_available = (WIDTH_B - 2.0 * COVER - n * d_b) / max(1, n - 1)
s_min = max(25.0, d_b)
- return [M_u - phi_Mn, V_u - phi_Vc, rho_min - rho, rho - rho_max, s_min - s_available]
+ return [m_u - phi_mn, v_u - phi_vc, rho_min - rho, rho - rho_max, s_min - s_available]
g = [2.5 - fs_overturning, 2.5 - fs_sliding, abs(e) - (x1 / 6000.0)]
- g.extend(check_aci(Mu_stem, Vu_stem, d_stem, As_s, db_s, n_s))
- g.extend(check_aci(Mu_heel, Vu_heel, d_base, As_b, db_b, n_b))
+ g.extend(check_aci(mu_stem, vu_stem, d_stem, as_s, db_s, n_s))
+ g.extend(check_aci(mu_heel, vu_heel, d_base, as_b, db_b, n_b))
penalty_value = sum(max(0.0, limit) ** 2 for limit in g) * 1e6
# --- Cost Evaluation ---
vol_conc = (x1 / 1000.0) * t_base_m + 0.5 * (x3 + x4) / 1000.0 * H_STEM
cost_conc = (0.5 + 0.02 * fc) * vol_conc
- cost_steel = 50.0 * (As_s + As_b) / 1000.0
+ cost_steel = 50.0 * (as_s + as_b) / 1000.0
total_cost = cost_conc + cost_steel
return total_cost, penalty_value
diff --git a/benchmarks/spring_design/semi_dependent/run.py b/benchmarks/spring_design/semi_dependent/run.py
index d17918c..db61ef4 100644
--- a/benchmarks/spring_design/semi_dependent/run.py
+++ b/benchmarks/spring_design/semi_dependent/run.py
@@ -183,7 +183,7 @@ def main() -> None:
plotter = ConvergencePlotter(OUTPUT_DIR / "history_data.csv")
plotter.set_labels(title="Spring Design ΓÇö Semi-Dependent Space")
plotter.add_info_box(
- f"Cost: {result.best_fitness:.6f}\n" f"Penalty: {result.best_penalty:.6f}\n" f"Time: {t_elapsed:.2f}s"
+ f"Cost: {result.best_fitness:.6f}\nPenalty: {result.best_penalty:.6f}\nTime: {t_elapsed:.2f}s"
)
plotter.plot(save_path=OUTPUT_DIR / "convergence.png")
diff --git a/benchmarks/spring_design/static_penalty/run.py b/benchmarks/spring_design/static_penalty/run.py
index 6105d65..1a9a97c 100644
--- a/benchmarks/spring_design/static_penalty/run.py
+++ b/benchmarks/spring_design/static_penalty/run.py
@@ -141,7 +141,7 @@ def main() -> None:
plotter = ConvergencePlotter(OUTPUT_DIR / "history_data.csv")
plotter.set_labels(title="Spring Design ΓÇö Static Penalty")
plotter.add_info_box(
- f"Cost: {result.best_fitness:.6f}\n" f"Penalty: {result.best_penalty:.6f}\n" f"Time: {t_elapsed:.2f}s"
+ f"Cost: {result.best_fitness:.6f}\nPenalty: {result.best_penalty:.6f}\nTime: {t_elapsed:.2f}s"
)
plotter.plot(save_path=OUTPUT_DIR / "convergence.png")
diff --git a/benchmarks/utils/plotter.py b/benchmarks/utils/plotter.py
index cf3b658..59d2bae 100644
--- a/benchmarks/utils/plotter.py
+++ b/benchmarks/utils/plotter.py
@@ -225,30 +225,8 @@ class ConvergencePlotter:
return self
# --------------------------------------------------------------- render
- def plot(self, save_path: Optional[Union[str, Path]] = None) -> None:
- """
- Render the convergence plot.
-
- Three scenarios are handled automatically:
-
- 1. **All penalties zero** ΓÇö only the fitness curve is drawn.
- 2. **No feasible solution found** ΓÇö only the penalty curve is drawn.
- 3. **Mixed** ΓÇö penalty is drawn (shifted) up to the feasibility
- transition point, then fitness takes over.
-
- Parameters
- ----------
- save_path : str | Path | None
- If given, the figure is saved at 300 DPI. Otherwise ``plt.show()``
- is called.
- """
- _apply_academic_style()
-
- if not self.iterations_data:
- print("No data to plot!")
- return
-
- # --- Phase detection ------------------------------------------------
+ def _phase_detection(self) -> Tuple[int, float, bool]:
+ """Detect the first iteration where penalty reaches (close to) zero."""
first_zero_idx: int = -1
first_feasible_fitness: float = -1.0
@@ -259,128 +237,195 @@ class ConvergencePlotter:
break
all_zero: bool = all(np.isclose(r.penalty, 0.0) for r in self.iterations_data)
+ return first_zero_idx, first_feasible_fitness, all_zero
+ def _extract_series(
+ self,
+ ) -> Tuple[
+ List[int],
+ List[float],
+ List[float],
+ Optional[float],
+ Optional[float],
+ float,
+ Optional[float],
+ ]:
iterations = [r.iteration for r in self.iterations_data]
fitness_values = [r.fitness for r in self.iterations_data]
penalty_values = [r.penalty for r in self.iterations_data]
- # Pre-compute stats
min_fitness: Optional[float] = min(fitness_values) if fitness_values else None
last_fitness: Optional[float] = fitness_values[-1] if fitness_values else None
max_penalty: float = max(penalty_values) if penalty_values else 0.0
first_fitness: Optional[float] = fitness_values[0] if fitness_values else None
- # Physical y-values for reference lines
- y_pen_zero_phys: Optional[float] = 0.0
- y_pen_max_phys: Optional[float] = max_penalty
+ return (
+ iterations,
+ fitness_values,
+ penalty_values,
+ min_fitness,
+ last_fitness,
+ max_penalty,
+ first_fitness,
+ )
+
+ def _build_draw_series(
+ self,
+ *,
+ all_zero: bool,
+ first_zero_idx: int,
+ first_feasible_fitness: float,
+ fitness_values: List[float],
+ penalty_values: List[float],
+ min_fitness: Optional[float],
+ last_fitness: Optional[float],
+ max_penalty: float,
+ ) -> Tuple[List[Optional[float]], List[Optional[float]], Optional[float], Optional[float], Optional[float], Optional[float]]:
+ """
+ Build the two draw-series arrays (with None gaps) and update axis/reference stats.
- # --- Build draw series (penaltyΓÇôfitness alignment) ------------------
+ Returns:
+ penalties_draw, fitness_draw, min_fitness, last_fitness, y_pen_zero_phys, y_pen_max_phys
+ """
penalties_draw: List[Optional[float]] = []
fitness_draw: List[Optional[float]] = []
+ y_pen_zero_phys: Optional[float] = 0.0
+ y_pen_max_phys: Optional[float] = max_penalty
+
if all_zero:
- # Scenario 1: purely feasible run ΓÇö no penalty curve
penalties_draw = [None] * len(self.iterations_data)
fitness_draw = list(fitness_values)
y_pen_zero_phys = None
y_pen_max_phys = None
+ return penalties_draw, fitness_draw, min_fitness, last_fitness, y_pen_zero_phys, y_pen_max_phys
- elif first_zero_idx == -1:
- # Scenario 2: never reached feasibility ΓÇö no fitness curve
+ if first_zero_idx == -1:
penalties_draw = list(penalty_values)
fitness_draw = [None] * len(self.iterations_data)
- min_fitness = None
- last_fitness = None
y_pen_zero_phys = None
+ y_pen_max_phys = None
+ return penalties_draw, fitness_draw, None, None, y_pen_zero_phys, y_pen_max_phys
- else:
- # Scenario 3: transition ΓÇö shift penalties up by first feasible
- for i, rec in enumerate(self.iterations_data):
- if i <= first_zero_idx:
- penalties_draw.append(rec.penalty + first_feasible_fitness)
- fitness_draw.append(None)
- else:
- penalties_draw.append(None)
- fitness_draw.append(rec.fitness)
-
- y_pen_zero_phys = 0.0 + first_feasible_fitness
- y_pen_max_phys = max_penalty + first_feasible_fitness
- min_fitness = last_fitness
-
- # --- Figure ---------------------------------------------------------
- fig, ax1 = plt.subplots(figsize=(12, 6))
- ax1.set_xlabel(self.x_label)
+ for i, rec in enumerate(self.iterations_data):
+ if i <= first_zero_idx:
+ penalties_draw.append(rec.penalty + first_feasible_fitness)
+ fitness_draw.append(None)
+ else:
+ penalties_draw.append(None)
+ fitness_draw.append(rec.fitness)
- valid_fit_iters = [iterations[i] for i, v in enumerate(fitness_draw) if v is not None]
- valid_fit_vals = [v for v in fitness_draw if v is not None]
+ y_pen_zero_phys = 0.0 + first_feasible_fitness
+ y_pen_max_phys = max_penalty + first_feasible_fitness
+ min_fitness = last_fitness # match original plotting logic
+ return penalties_draw, fitness_draw, min_fitness, last_fitness, y_pen_zero_phys, y_pen_max_phys
- if valid_fit_vals:
- ax1.set_ylabel(self.y_fit_label, color="#2ca02c")
- ax1.tick_params(axis="y", labelcolor="#2ca02c")
- ax1.plot(
- valid_fit_iters,
- valid_fit_vals,
- color="#2ca02c",
- linestyle="-",
- label=self.y_fit_label,
- linewidth=2,
- )
- else:
+ def _plot_fitness_curve(
+ self,
+ *,
+ ax1: plt.Axes,
+ iterations: List[int],
+ fitness_draw: List[Optional[float]],
+ ) -> List[float]:
+ valid_fit_vals = [v for v in fitness_draw if v is not None]
+ if not valid_fit_vals:
ax1.set_ylabel("")
ax1.set_yticks([])
+ return []
- ax2 = ax1.twinx()
- if not valid_fit_vals:
- ax2.grid(True, linestyle="--", alpha=0.55)
+ valid_fit_iters = [iterations[i] for i, v in enumerate(fitness_draw) if v is not None]
+ ax1.set_ylabel(self.y_fit_label, color="#2ca02c")
+ ax1.tick_params(axis="y", labelcolor="#2ca02c")
+ ax1.plot(
+ valid_fit_iters,
+ valid_fit_vals,
+ color="#2ca02c",
+ linestyle="-",
+ label=self.y_fit_label,
+ linewidth=2,
+ )
+ return valid_fit_vals
- valid_pen_iters = [iterations[i] for i, v in enumerate(penalties_draw) if v is not None]
+ def _plot_penalty_curve(
+ self,
+ *,
+ ax2: plt.Axes,
+ iterations: List[int],
+ penalties_draw: List[Optional[float]],
+ valid_fit_vals: List[float],
+ ) -> List[float]:
valid_pen_vals = [v for v in penalties_draw if v is not None]
+ if not valid_fit_vals:
+ ax2.grid(True, linestyle="--", alpha=0.55)
- if valid_pen_vals:
- ax2.set_ylabel(self.y_pen_label, color="#d62728")
- ax2.tick_params(axis="y", labelcolor="#d62728")
- ax2.plot(
- valid_pen_iters,
- valid_pen_vals,
- color="#d62728",
- linestyle="-",
- label=self.y_pen_label,
- linewidth=2,
- )
- else:
+ if not valid_pen_vals:
ax2.set_ylabel("")
ax2.set_yticks([])
+ return []
- # --- Axis scaling ---------------------------------------------------
+ valid_pen_iters = [iterations[i] for i, v in enumerate(penalties_draw) if v is not None]
+ ax2.set_ylabel(self.y_pen_label, color="#d62728")
+ ax2.tick_params(axis="y", labelcolor="#d62728")
+ ax2.plot(
+ valid_pen_iters,
+ valid_pen_vals,
+ color="#d62728",
+ linestyle="-",
+ label=self.y_pen_label,
+ linewidth=2,
+ )
+ return valid_pen_vals
+
+ def _apply_axis_scaling(
+ self,
+ *,
+ ax1: plt.Axes,
+ ax2: plt.Axes,
+ valid_fit_vals: List[float],
+ valid_pen_vals: List[float],
+ min_fitness: Optional[float],
+ first_fitness: Optional[float],
+ all_zero: bool,
+ y_pen_zero_phys: Optional[float],
+ y_pen_max_phys: Optional[float],
+ ) -> None:
if self.y_lim is not None:
ax1.set_ylim(*self.y_lim)
ax2.set_ylim(*self.y_lim)
- else:
- all_y: List[float] = []
- if valid_fit_vals:
- all_y.extend(valid_fit_vals)
- if valid_pen_vals:
- all_y.extend(valid_pen_vals)
- if min_fitness is not None:
- all_y.append(min_fitness)
- if all_zero and first_fitness is not None:
- all_y.append(first_fitness)
- if y_pen_zero_phys is not None:
- all_y.append(y_pen_zero_phys)
- if y_pen_max_phys is not None:
- all_y.append(y_pen_max_phys)
-
- if all_y:
- lo, hi = min(all_y), max(all_y)
- pad = 0.5 if hi == lo else (hi - lo) * 0.05
- ax1.set_ylim(lo - pad, hi + pad)
- ax2.set_ylim(lo - pad, hi + pad)
+ return
- if self.x_lim is not None:
- ax1.set_xlim(*self.x_lim)
- ax2.set_xlim(*self.x_lim)
+ all_y: List[float] = []
+ if valid_fit_vals:
+ all_y.extend(valid_fit_vals)
+ if valid_pen_vals:
+ all_y.extend(valid_pen_vals)
+ if min_fitness is not None:
+ all_y.append(min_fitness)
+ if all_zero and first_fitness is not None:
+ all_y.append(first_fitness)
+ if y_pen_zero_phys is not None:
+ all_y.append(y_pen_zero_phys)
+ if y_pen_max_phys is not None:
+ all_y.append(y_pen_max_phys)
+
+ if not all_y:
+ return
+
+ lo, hi = min(all_y), max(all_y)
+ pad = 0.5 if hi == lo else (hi - lo) * 0.05
+ ax1.set_ylim(lo - pad, hi + pad)
+ ax2.set_ylim(lo - pad, hi + pad)
- # --- Tick formatters (penaltyΓÇôfitness alignment) --------------------
+ def _configure_tick_formatters(
+ self,
+ *,
+ ax1: plt.Axes,
+ ax2: plt.Axes,
+ first_zero_idx: int,
+ first_feasible_fitness: float,
+ all_zero: bool,
+ valid_fit_vals: List[float],
+ ) -> None:
_fzidx = first_zero_idx
_fffit = first_feasible_fitness if first_zero_idx != -1 else None
_allz = all_zero
@@ -403,7 +448,18 @@ class ConvergencePlotter:
if valid_fit_vals:
ax1.yaxis.set_major_formatter(mticker.FuncFormatter(_fitness_formatter))
- # --- Reference lines ------------------------------------------------
+ def _draw_reference_lines(
+ self,
+ *,
+ ax1: plt.Axes,
+ ax2: plt.Axes,
+ first_zero_idx: int,
+ all_zero: bool,
+ first_feasible_fitness: float,
+ min_fitness: Optional[float],
+ last_fitness: Optional[float],
+ y_pen_zero_phys: Optional[float],
+ ) -> None:
if first_zero_idx != -1 and not all_zero and first_feasible_fitness is not None:
ax1.axhline(
first_feasible_fitness,
@@ -444,23 +500,22 @@ class ConvergencePlotter:
alpha=0.6,
)
- ax1.set_title(self.title, pad=15)
-
- # --- Unified legend -------------------------------------------------
+ def _draw_legend(self, *, ax1: plt.Axes, ax2: plt.Axes) -> None:
lines1, labels1 = ax1.get_legend_handles_labels()
lines2, labels2 = ax2.get_legend_handles_labels()
all_lines = lines1 + lines2
+ if not all_lines:
+ return
all_labels = labels1 + labels2
- if all_lines:
- ax2.legend(
- all_lines,
- all_labels,
- loc="upper right",
- framealpha=0.85,
- edgecolor="#cccccc",
- )
+ ax2.legend(
+ all_lines,
+ all_labels,
+ loc="upper right",
+ framealpha=0.85,
+ edgecolor="#cccccc",
+ )
- # --- User-defined info boxes ----------------------------------------
+ def _draw_info_boxes(self, *, fig: plt.Figure, ax2: plt.Axes) -> None:
for box in self.text_boxes:
fig.text(
box.x,
@@ -479,8 +534,113 @@ class ConvergencePlotter:
),
)
- fig.tight_layout()
+ def plot(self, save_path: Optional[Union[str, Path]] = None) -> None:
+ """
+ Render the convergence plot.
+
+ Three scenarios are handled automatically:
+
+ 1. **All penalties zero** ΓÇö only the fitness curve is drawn.
+ 2. **No feasible solution found** ΓÇö only the penalty curve is drawn.
+ 3. **Mixed** ΓÇö penalty is drawn (shifted) up to the feasibility
+ transition point, then fitness takes over.
+
+ Parameters
+ ----------
+ save_path : str | Path | None
+ If given, the figure is saved at 300 DPI. Otherwise ``plt.show()``
+ is called.
+ """
+ _apply_academic_style()
+ if not self.iterations_data:
+ print("No data to plot!")
+ return
+
+ first_zero_idx, first_feasible_fitness, all_zero = self._phase_detection()
+ (
+ iterations,
+ fitness_values,
+ penalty_values,
+ min_fitness,
+ last_fitness,
+ max_penalty,
+ first_fitness,
+ ) = self._extract_series()
+
+ (
+ penalties_draw,
+ fitness_draw,
+ min_fitness,
+ last_fitness,
+ y_pen_zero_phys,
+ y_pen_max_phys,
+ ) = self._build_draw_series(
+ all_zero=all_zero,
+ first_zero_idx=first_zero_idx,
+ first_feasible_fitness=first_feasible_fitness,
+ fitness_values=fitness_values,
+ penalty_values=penalty_values,
+ min_fitness=min_fitness,
+ last_fitness=last_fitness,
+ max_penalty=max_penalty,
+ )
+
+ fig, ax1 = plt.subplots(figsize=(12, 6))
+ ax1.set_xlabel(self.x_label)
+ ax2 = ax1.twinx()
+ valid_fit_vals = self._plot_fitness_curve(
+ ax1=ax1,
+ iterations=iterations,
+ fitness_draw=fitness_draw,
+ )
+ valid_pen_vals = self._plot_penalty_curve(
+ ax2=ax2,
+ iterations=iterations,
+ penalties_draw=penalties_draw,
+ valid_fit_vals=valid_fit_vals,
+ )
+
+ self._apply_axis_scaling(
+ ax1=ax1,
+ ax2=ax2,
+ valid_fit_vals=valid_fit_vals,
+ valid_pen_vals=valid_pen_vals,
+ min_fitness=min_fitness,
+ first_fitness=first_fitness,
+ all_zero=all_zero,
+ y_pen_zero_phys=y_pen_zero_phys,
+ y_pen_max_phys=y_pen_max_phys,
+ )
+
+ if self.x_lim is not None:
+ ax1.set_xlim(*self.x_lim)
+ ax2.set_xlim(*self.x_lim)
+
+ self._configure_tick_formatters(
+ ax1=ax1,
+ ax2=ax2,
+ first_zero_idx=first_zero_idx,
+ first_feasible_fitness=first_feasible_fitness,
+ all_zero=all_zero,
+ valid_fit_vals=valid_fit_vals,
+ )
+ self._draw_reference_lines(
+ ax1=ax1,
+ ax2=ax2,
+ first_zero_idx=first_zero_idx,
+ all_zero=all_zero,
+ first_feasible_fitness=first_feasible_fitness,
+ min_fitness=min_fitness,
+ last_fitness=last_fitness,
+ y_pen_zero_phys=y_pen_zero_phys,
+ )
+
+ ax1.set_title(self.title, pad=15)
+ self._draw_legend(ax1=ax1, ax2=ax2)
+ self._draw_info_boxes(fig=fig, ax2=ax2)
+
+ fig.tight_layout()
if save_path:
plt.savefig(str(save_path), dpi=300, bbox_inches="tight")
plt.close(fig)
@@ -540,7 +700,7 @@ def plot_multi_run_convergence(
std = fitness_matrix.std(axis=0)
if ax is None:
- fig, ax = plt.subplots(figsize=(12, 6))
+ _, ax = plt.subplots(figsize=(12, 6))
ax.set_title(title, pad=15)
owns_figure = True
else:
diff --git a/benchmarks/welded_beam/dependent_space/run.py b/benchmarks/welded_beam/dependent_space/run.py
index 15af873..5d44b90 100644
--- a/benchmarks/welded_beam/dependent_space/run.py
+++ b/benchmarks/welded_beam/dependent_space/run.py
@@ -128,11 +128,11 @@ def objective(harmony: Dict[str, Any]) -> Tuple[float, float]:
tau_dash = P / (math.sqrt(2) * x1 * x2)
tau_dash_dash = M * R / J
tau = math.sqrt(tau_dash**2 + 2 * tau_dash * tau_dash_dash * (x2 / (2 * R)) + tau_dash_dash**2)
- Pc = ((4.013 * E * math.sqrt((x3**2 * x4**6) / 36.0)) / L**2) * (1.0 - (x3 / (2 * L)) * math.sqrt(E / (4 * G)))
+ pc = ((4.013 * E * math.sqrt((x3**2 * x4**6) / 36.0)) / L**2) * (1.0 - (x3 / (2 * L)) * math.sqrt(E / (4 * G)))
g1 = tau - TAU_MAX
g4 = 0.10471 * x1**2 + 0.04811 * x3 * x4 * (14.0 + x2) - 5.0
- g7 = P - Pc
+ g7 = P - pc
penalty: float = max(0.0, g1) + max(0.0, g4) + max(0.0, g7)
cost: float = 1.10471 * x1**2 * x2 + 0.04811 * x3 * x4 * (14.0 + x2)
@@ -180,7 +180,7 @@ def main() -> None:
plotter = ConvergencePlotter(OUTPUT_DIR / "history_data.csv")
plotter.set_labels(title="Welded Beam ΓÇö Dependent Space")
plotter.add_info_box(
- f"Cost: {result.best_fitness:.4f}\n" f"Penalty: {result.best_penalty:.4f}\n" f"Time: {t_elapsed:.2f}s"
+ f"Cost: {result.best_fitness:.4f}\nPenalty: {result.best_penalty:.4f}\nTime: {t_elapsed:.2f}s"
)
plotter.plot(save_path=OUTPUT_DIR / "convergence.png")
diff --git a/benchmarks/welded_beam/static_penalty/run.py b/benchmarks/welded_beam/static_penalty/run.py
index c341d06..b235d50 100644
--- a/benchmarks/welded_beam/static_penalty/run.py
+++ b/benchmarks/welded_beam/static_penalty/run.py
@@ -101,7 +101,7 @@ def objective(harmony: Dict[str, Any]) -> Tuple[float, float]:
sigma = 6 * P * L / (x4 * x3**2)
delta = 4 * P * L**3 / (E * x3**3 * x4)
- Pc = ((4.013 * E * math.sqrt((x3**2 * x4**6) / 36.0)) / L**2) * (1.0 - (x3 / (2 * L)) * math.sqrt(E / (4 * G)))
+ pc = ((4.013 * E * math.sqrt((x3**2 * x4**6) / 36.0)) / L**2) * (1.0 - (x3 / (2 * L)) * math.sqrt(E / (4 * G)))
# --- All 7 constraints ---
g1 = tau - TAU_MAX
@@ -110,7 +110,7 @@ def objective(harmony: Dict[str, Any]) -> Tuple[float, float]:
g4 = 0.10471 * x1**2 + 0.04811 * x3 * x4 * (14.0 + x2) - 5.0
g5 = 0.125 - x1
g6 = delta - DELTA_MAX
- g7 = P - Pc
+ g7 = P - pc
penalty: float = sum(max(0.0, g) for g in [g1, g2, g3, g4, g5, g6, g7])
cost: float = 1.10471 * x1**2 * x2 + 0.04811 * x3 * x4 * (14.0 + x2)
@@ -158,7 +158,7 @@ def main() -> None:
plotter = ConvergencePlotter(OUTPUT_DIR / "history_data.csv")
plotter.set_labels(title="Welded Beam ΓÇö Static Penalty")