pymetaheuristic 5.5.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. pymetaheuristic/__init__.py +162 -0
  2. pymetaheuristic/src/__init__.py +162 -0
  3. pymetaheuristic/src/actions.py +228 -0
  4. pymetaheuristic/src/api.py +192 -0
  5. pymetaheuristic/src/callbacks.py +147 -0
  6. pymetaheuristic/src/cec2022_input_data/M_10_D10.txt +100 -0
  7. pymetaheuristic/src/cec2022_input_data/M_10_D2.txt +16 -0
  8. pymetaheuristic/src/cec2022_input_data/M_10_D20.txt +200 -0
  9. pymetaheuristic/src/cec2022_input_data/M_11_D10.txt +100 -0
  10. pymetaheuristic/src/cec2022_input_data/M_11_D2.txt +16 -0
  11. pymetaheuristic/src/cec2022_input_data/M_11_D20.txt +200 -0
  12. pymetaheuristic/src/cec2022_input_data/M_12_D10.txt +100 -0
  13. pymetaheuristic/src/cec2022_input_data/M_12_D2.txt +16 -0
  14. pymetaheuristic/src/cec2022_input_data/M_12_D20.txt +200 -0
  15. pymetaheuristic/src/cec2022_input_data/M_1_D10.txt +10 -0
  16. pymetaheuristic/src/cec2022_input_data/M_1_D2.txt +2 -0
  17. pymetaheuristic/src/cec2022_input_data/M_1_D20.txt +20 -0
  18. pymetaheuristic/src/cec2022_input_data/M_2_D10.txt +10 -0
  19. pymetaheuristic/src/cec2022_input_data/M_2_D2.txt +2 -0
  20. pymetaheuristic/src/cec2022_input_data/M_2_D20.txt +20 -0
  21. pymetaheuristic/src/cec2022_input_data/M_3_D10.txt +10 -0
  22. pymetaheuristic/src/cec2022_input_data/M_3_D2.txt +2 -0
  23. pymetaheuristic/src/cec2022_input_data/M_3_D20.txt +20 -0
  24. pymetaheuristic/src/cec2022_input_data/M_4_D10.txt +10 -0
  25. pymetaheuristic/src/cec2022_input_data/M_4_D2.txt +2 -0
  26. pymetaheuristic/src/cec2022_input_data/M_4_D20.txt +20 -0
  27. pymetaheuristic/src/cec2022_input_data/M_5_D10.txt +10 -0
  28. pymetaheuristic/src/cec2022_input_data/M_5_D2.txt +2 -0
  29. pymetaheuristic/src/cec2022_input_data/M_5_D20.txt +20 -0
  30. pymetaheuristic/src/cec2022_input_data/M_6_D10.txt +10 -0
  31. pymetaheuristic/src/cec2022_input_data/M_6_D2.txt +2 -0
  32. pymetaheuristic/src/cec2022_input_data/M_6_D20.txt +20 -0
  33. pymetaheuristic/src/cec2022_input_data/M_7_D10.txt +10 -0
  34. pymetaheuristic/src/cec2022_input_data/M_7_D20.txt +20 -0
  35. pymetaheuristic/src/cec2022_input_data/M_8_D10.txt +10 -0
  36. pymetaheuristic/src/cec2022_input_data/M_8_D2.txt +2 -0
  37. pymetaheuristic/src/cec2022_input_data/M_8_D20.txt +20 -0
  38. pymetaheuristic/src/cec2022_input_data/M_9_D10.txt +100 -0
  39. pymetaheuristic/src/cec2022_input_data/M_9_D2.txt +16 -0
  40. pymetaheuristic/src/cec2022_input_data/M_9_D20.txt +200 -0
  41. pymetaheuristic/src/cec2022_input_data/Rand_Seeds.txt +1000 -0
  42. pymetaheuristic/src/cec2022_input_data/shift_data_1.txt +1 -0
  43. pymetaheuristic/src/cec2022_input_data/shift_data_10.txt +10 -0
  44. pymetaheuristic/src/cec2022_input_data/shift_data_11.txt +10 -0
  45. pymetaheuristic/src/cec2022_input_data/shift_data_12.txt +10 -0
  46. pymetaheuristic/src/cec2022_input_data/shift_data_2.txt +1 -0
  47. pymetaheuristic/src/cec2022_input_data/shift_data_3.txt +1 -0
  48. pymetaheuristic/src/cec2022_input_data/shift_data_4.txt +1 -0
  49. pymetaheuristic/src/cec2022_input_data/shift_data_5.txt +1 -0
  50. pymetaheuristic/src/cec2022_input_data/shift_data_6.txt +1 -0
  51. pymetaheuristic/src/cec2022_input_data/shift_data_7.txt +1 -0
  52. pymetaheuristic/src/cec2022_input_data/shift_data_8.txt +10 -0
  53. pymetaheuristic/src/cec2022_input_data/shift_data_9.txt +10 -0
  54. pymetaheuristic/src/cec2022_input_data/shuffle_data_6_D10.txt +1 -0
  55. pymetaheuristic/src/cec2022_input_data/shuffle_data_6_D20.txt +1 -0
  56. pymetaheuristic/src/cec2022_input_data/shuffle_data_7_D10.txt +1 -0
  57. pymetaheuristic/src/cec2022_input_data/shuffle_data_7_D20.txt +1 -0
  58. pymetaheuristic/src/cec2022_input_data/shuffle_data_8_D10.txt +1 -0
  59. pymetaheuristic/src/cec2022_input_data/shuffle_data_8_D20.txt +1 -0
  60. pymetaheuristic/src/controllers/__init__.py +7 -0
  61. pymetaheuristic/src/controllers/fixed.py +32 -0
  62. pymetaheuristic/src/controllers/rules.py +268 -0
  63. pymetaheuristic/src/cooperation.py +621 -0
  64. pymetaheuristic/src/engines/__init__.py +150 -0
  65. pymetaheuristic/src/engines/abco.py +143 -0
  66. pymetaheuristic/src/engines/acgwo.py +105 -0
  67. pymetaheuristic/src/engines/afsa.py +127 -0
  68. pymetaheuristic/src/engines/alo.py +128 -0
  69. pymetaheuristic/src/engines/aoa.py +81 -0
  70. pymetaheuristic/src/engines/ars.py +124 -0
  71. pymetaheuristic/src/engines/bat_a.py +123 -0
  72. pymetaheuristic/src/engines/bbo.py +95 -0
  73. pymetaheuristic/src/engines/ca.py +91 -0
  74. pymetaheuristic/src/engines/cat_so.py +98 -0
  75. pymetaheuristic/src/engines/cem.py +112 -0
  76. pymetaheuristic/src/engines/chicken_so.py +112 -0
  77. pymetaheuristic/src/engines/clonalg.py +93 -0
  78. pymetaheuristic/src/engines/coati_oa.py +85 -0
  79. pymetaheuristic/src/engines/cockroach_so.py +97 -0
  80. pymetaheuristic/src/engines/csa.py +87 -0
  81. pymetaheuristic/src/engines/cuckoo_s.py +99 -0
  82. pymetaheuristic/src/engines/da.py +141 -0
  83. pymetaheuristic/src/engines/de.py +89 -0
  84. pymetaheuristic/src/engines/dfo.py +87 -0
  85. pymetaheuristic/src/engines/dvba.py +105 -0
  86. pymetaheuristic/src/engines/eho.py +93 -0
  87. pymetaheuristic/src/engines/fda.py +109 -0
  88. pymetaheuristic/src/engines/firefly_a.py +92 -0
  89. pymetaheuristic/src/engines/fpa.py +96 -0
  90. pymetaheuristic/src/engines/ga.py +113 -0
  91. pymetaheuristic/src/engines/gmo.py +107 -0
  92. pymetaheuristic/src/engines/goa.py +91 -0
  93. pymetaheuristic/src/engines/gsa.py +102 -0
  94. pymetaheuristic/src/engines/gwo.py +95 -0
  95. pymetaheuristic/src/engines/hho.py +119 -0
  96. pymetaheuristic/src/engines/hsa.py +82 -0
  97. pymetaheuristic/src/engines/hus.py +102 -0
  98. pymetaheuristic/src/engines/i_gwo.py +110 -0
  99. pymetaheuristic/src/engines/i_woa.py +114 -0
  100. pymetaheuristic/src/engines/jso.py +100 -0
  101. pymetaheuristic/src/engines/jy.py +87 -0
  102. pymetaheuristic/src/engines/kha.py +139 -0
  103. pymetaheuristic/src/engines/mbo.py +104 -0
  104. pymetaheuristic/src/engines/memetic_a.py +137 -0
  105. pymetaheuristic/src/engines/mfa.py +91 -0
  106. pymetaheuristic/src/engines/mvo.py +96 -0
  107. pymetaheuristic/src/engines/pbil.py +62 -0
  108. pymetaheuristic/src/engines/pcx.py +302 -0
  109. pymetaheuristic/src/engines/pfa.py +102 -0
  110. pymetaheuristic/src/engines/protocol.py +961 -0
  111. pymetaheuristic/src/engines/pso.py +294 -0
  112. pymetaheuristic/src/engines/random_s.py +84 -0
  113. pymetaheuristic/src/engines/sa.py +244 -0
  114. pymetaheuristic/src/engines/sine_cosine_a.py +86 -0
  115. pymetaheuristic/src/engines/sos.py +105 -0
  116. pymetaheuristic/src/engines/spbo.py +116 -0
  117. pymetaheuristic/src/engines/ssa.py +96 -0
  118. pymetaheuristic/src/engines/tlbo.py +93 -0
  119. pymetaheuristic/src/engines/woa.py +96 -0
  120. pymetaheuristic/src/examples/__init__.py +6 -0
  121. pymetaheuristic/src/examples/collaboration_enhanced_demo.py +40 -0
  122. pymetaheuristic/src/examples/constrained_demo.py +30 -0
  123. pymetaheuristic/src/examples/cooperation_demo.py +32 -0
  124. pymetaheuristic/src/examples/orchestrated_rules_demo.py +39 -0
  125. pymetaheuristic/src/examples/parallel_cooperation_demo.py +29 -0
  126. pymetaheuristic/src/examples/single.py +102 -0
  127. pymetaheuristic/src/examples/telemetry_demo.py +26 -0
  128. pymetaheuristic/src/execution.py +69 -0
  129. pymetaheuristic/src/graphs.py +1168 -0
  130. pymetaheuristic/src/io.py +289 -0
  131. pymetaheuristic/src/orchestration.py +436 -0
  132. pymetaheuristic/src/reference.py +160 -0
  133. pymetaheuristic/src/schemas.py +142 -0
  134. pymetaheuristic/src/telemetry.py +155 -0
  135. pymetaheuristic/src/termination.py +271 -0
  136. pymetaheuristic/src/test_functions.py +1097 -0
  137. pymetaheuristic/src/tests/__init__.py +0 -0
  138. pymetaheuristic/src/tests/test_cooperation_enhancements.py +60 -0
  139. pymetaheuristic/src/tuner.py +662 -0
  140. pymetaheuristic/src/utils/__init__.py +81 -0
  141. pymetaheuristic/src/utils/chaotic.py +409 -0
  142. pymetaheuristic/src/utils/initialization.py +129 -0
  143. pymetaheuristic/src/utils/problems.py +250 -0
  144. pymetaheuristic/src/utils/random.py +20 -0
  145. pymetaheuristic/src/utils/repair.py +90 -0
  146. pymetaheuristic/src/utils/space.py +492 -0
  147. pymetaheuristic/src/viz.py +388 -0
  148. pymetaheuristic-5.5.2.dist-info/LICENSE.txt +14 -0
  149. pymetaheuristic-5.5.2.dist-info/METADATA +786 -0
  150. pymetaheuristic-5.5.2.dist-info/RECORD +152 -0
  151. pymetaheuristic-5.5.2.dist-info/WHEEL +5 -0
  152. pymetaheuristic-5.5.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,162 @@
1
+ """Public package for pymetaheuristic."""
2
+
3
+ from .src.api import create_optimizer, get_algorithm_info, list_algorithms, optimize
4
+ from .src.callbacks import Callback, CallbackList, EarlyStopping, HistoryRecorder, ProgressPrinter
5
+ from .src.cooperation import cooperative_optimize, replay_cooperative_result
6
+ from .src.graphs import (
7
+ compare_convergence,
8
+ plot_benchmark_summary,
9
+ plot_collaboration_network,
10
+ plot_convergence,
11
+ plot_function,
12
+ plot_function_1d,
13
+ plot_function_2d,
14
+ plot_function_3d,
15
+ plot_function_contour,
16
+ plot_function_nd,
17
+ plot_function_surface,
18
+ plot_island_dynamics,
19
+ plot_population_snapshot,
20
+ )
21
+ from .src.orchestration import orchestrated_optimize
22
+ from .src.reference import (
23
+ ARGUMENT_REFERENCE,
24
+ search_reference,
25
+ print_reference,
26
+ print_root_exports,
27
+ )
28
+ from .src.schemas import (
29
+ ActionOutcome,
30
+ ActionSpec,
31
+ AgentSnapshot,
32
+ CollaborativeConfig,
33
+ DecisionPlan,
34
+ OrchestratedCooperativeResult,
35
+ OrchestrationSpec,
36
+ OrchestratorSnapshot,
37
+ RulesConfig,
38
+ )
39
+ from .src.test_functions import FUNCTIONS, get_test_function
40
+ from .src.actions import estimate_action_cost
41
+ from .src.telemetry import (
42
+ convergence_data,
43
+ export_history_csv,
44
+ export_island_telemetry_csv,
45
+ export_population_snapshots_json,
46
+ export_replay_manifest_json,
47
+ summarize_cooperative_result,
48
+ summarize_result,
49
+ )
50
+ from .src.termination import Termination
51
+ from .src.viz import (
52
+ plot_diversity_chart,
53
+ plot_diversity_comparison,
54
+ plot_explore_exploit_chart,
55
+ plot_global_best_chart,
56
+ plot_run_dashboard,
57
+ plot_runtime_chart,
58
+ )
59
+ from .src.utils import (
60
+ AVAILABLE_CHAOTIC_MAPS,
61
+ AVAILABLE_INIT_STRATEGIES,
62
+ AVAILABLE_REPAIR_STRATEGIES,
63
+ AVAILABLE_TRANSFER_FUNCTIONS,
64
+ AckleyProblem,
65
+ BinaryAdapter,
66
+ BinaryVar,
67
+ CategoricalVar,
68
+ ChaoticMap,
69
+ FloatVar,
70
+ FunctionalProblem,
71
+ IntegerVar,
72
+ PermutationVar,
73
+ Problem,
74
+ RastriginProblem,
75
+ RosenbrockProblem,
76
+ SphereProblem,
77
+ ZakharovProblem,
78
+ apply_transfer,
79
+ binarize,
80
+ build_problem_spec,
81
+ chaotic_init_function,
82
+ chaotic_population,
83
+ chaotic_sequence,
84
+ decode_position,
85
+ encode_position,
86
+ full_array,
87
+ get_init_function,
88
+ get_repair_function,
89
+ get_test_problem,
90
+ lhs_population,
91
+ levy_flight,
92
+ limit,
93
+ limit_inverse,
94
+ obl_population,
95
+ rand,
96
+ reflect,
97
+ sobol_population,
98
+ sstf_01, sstf_02, sstf_03, sstf_04,
99
+ uniform_population,
100
+ vstf_01, vstf_02, vstf_03, vstf_04,
101
+ wang,
102
+ )
103
+ from .src.tuner import BenchmarkRunner, HyperparameterTuner
104
+ from .src.io import (
105
+ load_checkpoint,
106
+ load_result,
107
+ result_from_json,
108
+ result_to_json,
109
+ save_checkpoint,
110
+ save_result,
111
+ )
112
+
113
+ __version__ = "5.5.2"
114
+
115
+ __all__ = [
116
+ "FUNCTIONS",
117
+ "ActionOutcome", "ActionSpec", "AgentSnapshot",
118
+ "ARGUMENT_REFERENCE",
119
+ "Callback", "CallbackList", "EarlyStopping", "HistoryRecorder", "ProgressPrinter",
120
+ "CollaborativeConfig", "DecisionPlan",
121
+ "OrchestratedCooperativeResult", "OrchestrationSpec",
122
+ "OrchestratorSnapshot", "RulesConfig",
123
+ "compare_convergence", "cooperative_optimize", "replay_cooperative_result",
124
+ "convergence_data",
125
+ "create_optimizer", "estimate_action_cost",
126
+ "export_history_csv", "export_island_telemetry_csv",
127
+ "export_population_snapshots_json", "export_replay_manifest_json",
128
+ "get_algorithm_info", "get_test_function", "get_test_problem",
129
+ "list_algorithms", "optimize", "orchestrated_optimize",
130
+ "plot_benchmark_summary", "plot_collaboration_network",
131
+ "plot_convergence", "plot_function",
132
+ "plot_function_1d", "plot_function_2d", "plot_function_3d",
133
+ "plot_function_contour", "plot_function_nd", "plot_function_surface",
134
+ "plot_island_dynamics", "plot_population_snapshot",
135
+ "print_reference", "print_root_exports", "search_reference",
136
+ "summarize_cooperative_result", "summarize_result",
137
+ "Termination",
138
+ "plot_diversity_chart", "plot_diversity_comparison",
139
+ "plot_explore_exploit_chart", "plot_global_best_chart",
140
+ "plot_run_dashboard", "plot_runtime_chart",
141
+ "BinaryVar", "CategoricalVar", "FloatVar", "IntegerVar", "PermutationVar",
142
+ "build_problem_spec", "decode_position", "encode_position",
143
+ "AVAILABLE_CHAOTIC_MAPS", "ChaoticMap", "chaotic_population", "chaotic_sequence",
144
+ "AVAILABLE_TRANSFER_FUNCTIONS", "BinaryAdapter", "apply_transfer", "binarize",
145
+ "vstf_01", "vstf_02", "vstf_03", "vstf_04",
146
+ "sstf_01", "sstf_02", "sstf_03", "sstf_04",
147
+ "AVAILABLE_REPAIR_STRATEGIES", "get_repair_function", "limit", "limit_inverse",
148
+ "rand", "reflect", "wang",
149
+ "AVAILABLE_INIT_STRATEGIES", "get_init_function", "uniform_population",
150
+ "lhs_population", "obl_population", "sobol_population", "chaotic_init_function",
151
+ "Problem", "FunctionalProblem", "SphereProblem", "RastriginProblem",
152
+ "AckleyProblem", "RosenbrockProblem", "ZakharovProblem", "full_array",
153
+ "levy_flight",
154
+ "HyperparameterTuner", "BenchmarkRunner",
155
+ "load_checkpoint", "load_result",
156
+ "result_from_json", "result_to_json",
157
+ "save_checkpoint", "save_result",
158
+ ]
159
+
160
+ from . import src # noqa: E402
161
+ examples = src.examples
162
+ reference = src.reference
@@ -0,0 +1,162 @@
1
+ """Core implementation package for pymetaheuristic."""
2
+
3
+ from . import (
4
+ actions,
5
+ api,
6
+ callbacks,
7
+ controllers,
8
+ cooperation,
9
+ engines,
10
+ examples,
11
+ execution,
12
+ graphs,
13
+ io,
14
+ orchestration,
15
+ reference,
16
+ schemas,
17
+ telemetry,
18
+ termination,
19
+ test_functions,
20
+ tuner,
21
+ utils,
22
+ viz,
23
+ )
24
+
25
+ from .api import create_optimizer, get_algorithm_info, list_algorithms, optimize
26
+ from .callbacks import Callback, CallbackList, EarlyStopping, HistoryRecorder, ProgressPrinter
27
+ from .cooperation import cooperative_optimize, replay_cooperative_result
28
+ from .io import (
29
+ load_checkpoint,
30
+ load_result,
31
+ result_from_json,
32
+ result_to_json,
33
+ save_checkpoint,
34
+ save_result,
35
+ )
36
+ from .orchestration import orchestrated_optimize
37
+ from .reference import (
38
+ ARGUMENT_REFERENCE,
39
+ search_reference,
40
+ print_reference,
41
+ print_root_exports,
42
+ )
43
+ from .schemas import (
44
+ ActionOutcome,
45
+ ActionSpec,
46
+ AgentSnapshot,
47
+ CollaborativeConfig,
48
+ DecisionPlan,
49
+ OrchestratedCooperativeResult,
50
+ OrchestrationSpec,
51
+ OrchestratorSnapshot,
52
+ RulesConfig,
53
+ )
54
+ from .telemetry import (
55
+ convergence_data,
56
+ export_history_csv,
57
+ export_island_telemetry_csv,
58
+ export_population_snapshots_json,
59
+ export_replay_manifest_json,
60
+ summarize_cooperative_result,
61
+ summarize_result,
62
+ )
63
+ from .termination import Termination
64
+ from .test_functions import FUNCTIONS, get_test_function
65
+ from .actions import estimate_action_cost
66
+ from .tuner import BenchmarkRunner, HyperparameterTuner
67
+ from .utils import (
68
+ AVAILABLE_CHAOTIC_MAPS,
69
+ AVAILABLE_INIT_STRATEGIES,
70
+ AVAILABLE_REPAIR_STRATEGIES,
71
+ AVAILABLE_TRANSFER_FUNCTIONS,
72
+ AckleyProblem,
73
+ BinaryAdapter,
74
+ BinaryVar,
75
+ CategoricalVar,
76
+ ChaoticMap,
77
+ FloatVar,
78
+ FunctionalProblem,
79
+ IntegerVar,
80
+ PermutationVar,
81
+ Problem,
82
+ RastriginProblem,
83
+ RosenbrockProblem,
84
+ SphereProblem,
85
+ ZakharovProblem,
86
+ apply_transfer,
87
+ binarize,
88
+ build_problem_spec,
89
+ chaotic_init_function,
90
+ chaotic_population,
91
+ chaotic_sequence,
92
+ decode_position,
93
+ encode_position,
94
+ full_array,
95
+ get_init_function,
96
+ get_repair_function,
97
+ get_test_problem,
98
+ lhs_population,
99
+ levy_flight,
100
+ limit,
101
+ limit_inverse,
102
+ obl_population,
103
+ rand,
104
+ reflect,
105
+ sobol_population,
106
+ sstf_01, sstf_02, sstf_03, sstf_04,
107
+ uniform_population,
108
+ vstf_01, vstf_02, vstf_03, vstf_04,
109
+ wang,
110
+ )
111
+ from .viz import (
112
+ plot_diversity_chart,
113
+ plot_diversity_comparison,
114
+ plot_explore_exploit_chart,
115
+ plot_global_best_chart,
116
+ plot_run_dashboard,
117
+ plot_runtime_chart,
118
+ )
119
+
120
+ __all__ = [
121
+ "FUNCTIONS",
122
+ "ActionOutcome", "ActionSpec", "AgentSnapshot",
123
+ "ARGUMENT_REFERENCE",
124
+ "Callback", "CallbackList", "EarlyStopping", "HistoryRecorder", "ProgressPrinter", "callbacks",
125
+ "CollaborativeConfig", "DecisionPlan",
126
+ "OrchestratedCooperativeResult", "OrchestrationSpec",
127
+ "OrchestratorSnapshot", "RulesConfig",
128
+ "actions", "api", "controllers", "cooperation",
129
+ "cooperative_optimize", "convergence_data", "create_optimizer",
130
+ "engines", "estimate_action_cost", "examples", "execution",
131
+ "export_history_csv", "export_island_telemetry_csv",
132
+ "export_population_snapshots_json", "export_replay_manifest_json",
133
+ "get_algorithm_info", "get_test_function", "get_test_problem",
134
+ "graphs", "list_algorithms", "optimize", "orchestration",
135
+ "orchestrated_optimize", "print_reference", "print_root_exports",
136
+ "reference", "replay_cooperative_result",
137
+ "schemas", "search_reference",
138
+ "summarize_cooperative_result", "summarize_result",
139
+ "telemetry", "test_functions",
140
+ "Termination", "termination",
141
+ "plot_diversity_chart", "plot_diversity_comparison",
142
+ "plot_explore_exploit_chart", "plot_global_best_chart",
143
+ "plot_run_dashboard", "plot_runtime_chart", "viz",
144
+ "AVAILABLE_CHAOTIC_MAPS", "AVAILABLE_TRANSFER_FUNCTIONS",
145
+ "AVAILABLE_INIT_STRATEGIES", "AVAILABLE_REPAIR_STRATEGIES",
146
+ "BinaryVar", "CategoricalVar", "FloatVar", "IntegerVar", "PermutationVar",
147
+ "build_problem_spec", "decode_position", "encode_position", "utils",
148
+ "ChaoticMap", "chaotic_population", "chaotic_sequence",
149
+ "BinaryAdapter", "apply_transfer", "binarize",
150
+ "vstf_01", "vstf_02", "vstf_03", "vstf_04",
151
+ "sstf_01", "sstf_02", "sstf_03", "sstf_04",
152
+ "HyperparameterTuner", "BenchmarkRunner", "tuner",
153
+ "Problem", "FunctionalProblem", "SphereProblem", "RastriginProblem",
154
+ "AckleyProblem", "RosenbrockProblem", "ZakharovProblem", "full_array",
155
+ "get_init_function", "uniform_population", "lhs_population", "obl_population",
156
+ "sobol_population", "chaotic_init_function",
157
+ "get_repair_function", "limit", "limit_inverse", "rand", "reflect", "wang",
158
+ "levy_flight",
159
+ "io", "load_checkpoint", "load_result",
160
+ "result_from_json", "result_to_json",
161
+ "save_checkpoint", "save_result",
162
+ ]
@@ -0,0 +1,228 @@
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import asdict
4
+ from typing import Any
5
+ import math
6
+ import random
7
+
8
+ import numpy as np
9
+
10
+ from .engines import CandidateRecord
11
+ from .schemas import ActionSpec, ActionOutcome, DecisionPlan
12
+
13
+
14
+ def select_candidates(engine, state, mode: str = "best", k: int = 1) -> list[CandidateRecord]:
15
+ k = max(1, int(k))
16
+ return list(engine.export_candidates(state, k=k, mode=mode))
17
+
18
+
19
+
20
+ def perturb_candidates(
21
+ candidates: list[CandidateRecord],
22
+ sigma: float,
23
+ min_values: list[float],
24
+ max_values: list[float],
25
+ seed: int | None = None,
26
+ ) -> list[CandidateRecord]:
27
+ if not candidates:
28
+ return []
29
+ rng = np.random.default_rng(seed)
30
+ lo = np.asarray(min_values, dtype=float)
31
+ hi = np.asarray(max_values, dtype=float)
32
+ out: list[CandidateRecord] = []
33
+ for cand in candidates:
34
+ pos = np.asarray(cand.position, dtype=float)
35
+ eps = rng.normal(0.0, float(sigma), size=pos.shape)
36
+ new_pos = np.clip(pos + eps, lo, hi)
37
+ out.append(CandidateRecord(
38
+ position=new_pos.tolist(),
39
+ fitness=float(cand.fitness),
40
+ source_algorithm=cand.source_algorithm,
41
+ source_step=cand.source_step,
42
+ role=cand.role,
43
+ metadata=dict(cand.metadata or {}),
44
+ ))
45
+ return out
46
+
47
+
48
+
49
+ def _random_candidate(problem, rng: random.Random) -> CandidateRecord:
50
+ pos = [rng.uniform(lo, hi) for lo, hi in zip(problem.min_values, problem.max_values)]
51
+ fit = float(problem.evaluate(pos))
52
+ return CandidateRecord(position=pos, fitness=fit, role="restart")
53
+
54
+
55
+
56
+ def execute_decision_plan(
57
+ plan: DecisionPlan,
58
+ engines: dict[str, Any],
59
+ states: dict[str, Any],
60
+ objective: str,
61
+ seed: int | None = None,
62
+ ) -> tuple[dict[str, Any], list[ActionOutcome]]:
63
+ outcomes: list[ActionOutcome] = []
64
+ rng = random.Random(seed)
65
+
66
+ for action in plan.actions:
67
+ try:
68
+ if action.type == "wait":
69
+ outcomes.append(ActionOutcome(action=action, executed=True, status="applied", message="No action taken."))
70
+ continue
71
+
72
+ if action.type == "set_checkpoint":
73
+ outcomes.append(ActionOutcome(action=action, executed=True, status="applied", message="Checkpoint interval updated by runner."))
74
+ continue
75
+
76
+ target_engine = engines.get(action.target_label) if action.target_label else None
77
+ target_state = states.get(action.target_label) if action.target_label else None
78
+ source_engine = engines.get(action.source_label) if action.source_label else None
79
+ source_state = states.get(action.source_label) if action.source_label else None
80
+
81
+ if action.type in {"inject", "inject_perturbed", "restart_agent"} and (source_engine is None and not action.params.get("random_seed_receiver")):
82
+ outcomes.append(ActionOutcome(action=action, executed=False, status="skipped", message="Missing source engine."))
83
+ continue
84
+ if action.type in {"inject", "inject_perturbed", "rebalance", "reconfigure", "restart_agent"} and target_engine is None:
85
+ outcomes.append(ActionOutcome(action=action, executed=False, status="skipped", message="Missing target engine."))
86
+ continue
87
+
88
+ if action.type in {"inject", "inject_perturbed"}:
89
+ mode = action.source_mode or "best"
90
+ k = int(action.k or 1)
91
+ migrants = select_candidates(source_engine, source_state, mode=mode, k=k)
92
+ source_fit = migrants[0].fitness if migrants else None
93
+ if action.type == "inject_perturbed":
94
+ sigma = float((action.perturbation or {}).get("sigma", 0.05))
95
+ migrants = perturb_candidates(migrants, sigma=sigma, min_values=target_engine.problem.min_values, max_values=target_engine.problem.max_values, seed=seed)
96
+ before = target_state.best_fitness
97
+ if not target_engine.capabilities.supports_candidate_injection:
98
+ outcomes.append(ActionOutcome(action=action, executed=False, status="skipped", message="Target engine does not support candidate injection.", source_fitness=source_fit, target_fitness_before=before, target_fitness_after=before))
99
+ continue
100
+ states[action.target_label] = target_engine.inject_candidates(target_state, migrants, policy=action.replace_policy or "native")
101
+ after = states[action.target_label].best_fitness
102
+ outcomes.append(ActionOutcome(action=action, executed=True, status="applied", message="Candidates injected.", source_fitness=source_fit, target_fitness_before=before, target_fitness_after=after))
103
+ continue
104
+
105
+ if action.type == "rebalance":
106
+ before = target_state.best_fitness
107
+ if not target_engine.capabilities.supports_candidate_injection or not target_engine.capabilities.has_population:
108
+ outcomes.append(ActionOutcome(action=action, executed=False, status="skipped", message="Target engine cannot rebalance population.", target_fitness_before=before, target_fitness_after=before))
109
+ continue
110
+ fraction = float(action.params.get("fraction", 0.2))
111
+ try:
112
+ pop = target_engine.get_population(target_state)
113
+ n = max(1, int(math.ceil(len(pop) * fraction)))
114
+ except Exception:
115
+ n = max(1, int(action.k or 1))
116
+ migrants = [_random_candidate(target_engine.problem, rng) for _ in range(n)]
117
+ states[action.target_label] = target_engine.inject_candidates(target_state, migrants, policy=action.replace_policy or "native")
118
+ after = states[action.target_label].best_fitness
119
+ outcomes.append(ActionOutcome(action=action, executed=True, status="applied", message=f"Population rebalanced with {n} random candidates.", target_fitness_before=before, target_fitness_after=after))
120
+ continue
121
+
122
+ if action.type == "reconfigure":
123
+ before = target_state.best_fitness
124
+ states[action.target_label] = target_engine.reconfigure(target_state, dict(action.params or {}))
125
+ after = states[action.target_label].best_fitness
126
+ outcomes.append(ActionOutcome(action=action, executed=True, status="applied", message="Engine reconfigured.", target_fitness_before=before, target_fitness_after=after))
127
+ continue
128
+
129
+ if action.type == "restart_agent":
130
+ before = target_state.best_fitness
131
+ seeds = []
132
+ if action.params.get("random_seed_receiver"):
133
+ seeds = [_random_candidate(target_engine.problem, rng)]
134
+ else:
135
+ seeds = select_candidates(source_engine, source_state, mode=action.source_mode or "best", k=int(action.k or 1))
136
+ if not target_engine.capabilities.supports_restart:
137
+ msg = "Target engine does not support restart; downgraded to injection." if target_engine.capabilities.supports_candidate_injection else "Target engine does not support restart."
138
+ if target_engine.capabilities.supports_candidate_injection:
139
+ states[action.target_label] = target_engine.inject_candidates(target_state, seeds, policy=action.replace_policy or "native")
140
+ after = states[action.target_label].best_fitness
141
+ outcomes.append(ActionOutcome(action=action, executed=True, status="downgraded", message=msg, target_fitness_before=before, target_fitness_after=after))
142
+ else:
143
+ outcomes.append(ActionOutcome(action=action, executed=False, status="skipped", message=msg, target_fitness_before=before, target_fitness_after=before))
144
+ continue
145
+ states[action.target_label] = target_engine.restart(target_state, seeds=seeds, preserve_best=bool(action.params.get("preserve_best", True)))
146
+ after = states[action.target_label].best_fitness
147
+ outcomes.append(ActionOutcome(action=action, executed=True, status="applied", message="Engine restarted.", target_fitness_before=before, target_fitness_after=after))
148
+ continue
149
+
150
+ outcomes.append(ActionOutcome(action=action, executed=False, status="skipped", message=f"Unsupported action: {action.type}"))
151
+ except Exception as exc:
152
+ outcomes.append(ActionOutcome(action=action, executed=False, status="failed", message=str(exc)))
153
+ return states, outcomes
154
+
155
+
156
+
157
+ def outcome_to_dict(outcome: ActionOutcome) -> dict[str, Any]:
158
+ data = asdict(outcome)
159
+ data["action"] = asdict(outcome.action)
160
+ return data
161
+
162
+
163
+ # ---------------------------------------------------------------------------
164
+ # Action-cost estimation
165
+ # ---------------------------------------------------------------------------
166
+ # Default evaluation-equivalent action cost table. The spec requires the
167
+ # ordering:
168
+ # wait < inject ≤ inject_perturbed < rebalance ≤ reconfigure < restart_agent.
169
+ # These are dimensionless units that sum with the 1/H_t weighting used by the
170
+ # cost heuristics; they are intentionally small and monotonic, not tuned.
171
+ _ACTION_COST_BASE: dict[str, float] = {
172
+ "wait": 0.0,
173
+ "set_checkpoint": 0.0,
174
+ "inject": 1.0,
175
+ "inject_perturbed": 1.0,
176
+ "rebalance": 5.0,
177
+ "reconfigure": 5.0,
178
+ "restart_agent": 20.0,
179
+ }
180
+
181
+
182
+ def estimate_action_cost(
183
+ action: ActionSpec,
184
+ snapshot: Any,
185
+ states: dict[str, Any] | None,
186
+ engines: dict[str, Any] | None,
187
+ ) -> float:
188
+ """Return an evaluation-equivalent cost estimate for ``action``.
189
+
190
+ Deterministic and conservative: the returned value is a pure function of
191
+ the ActionSpec's type and of the target engine's population size when
192
+ relevant. It is used by orchestration diagnostics and for comparing intervention intensity.
193
+
194
+ The ordering invariant required by the spec is preserved by the base
195
+ table ``_ACTION_COST_BASE``.
196
+ """
197
+ if action is None or action.type is None:
198
+ return 0.0
199
+ base = float(_ACTION_COST_BASE.get(action.type, 1.0))
200
+
201
+ # Scale rebalance / restart by the target population size when we have it
202
+ # so larger populations cost more. We cap the multiplier so a 200-strong
203
+ # population does not destroy the ordering.
204
+ if action.type in {"rebalance", "restart_agent"}:
205
+ mult = 1.0
206
+ try:
207
+ target_label = getattr(action, "target_label", None)
208
+ if target_label and engines and states and target_label in engines:
209
+ eng = engines[target_label]
210
+ st = states[target_label]
211
+ if eng.capabilities.has_population:
212
+ try:
213
+ pop = eng.get_population(st)
214
+ n = max(1, int(len(pop)))
215
+ # Cost grows with sqrt(n) and is capped at 4x for
216
+ # very large populations.
217
+ mult = min(4.0, max(1.0, math.sqrt(n / 20.0)))
218
+ except Exception:
219
+ pass
220
+ except Exception:
221
+ pass
222
+ base *= float(mult)
223
+
224
+ if action.type in {"inject", "inject_perturbed"}:
225
+ k = int(action.k or 1)
226
+ base *= max(1.0, float(k) / 2.0)
227
+
228
+ return float(base)