iesopt 2.9.1.dev0__tar.gz → 2.9.3__tar.gz

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 (103) hide show
  1. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/PKG-INFO +1 -1
  2. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/user_guides/general/solvers.md +10 -9
  3. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/pyproject.toml +1 -1
  4. iesopt-2.9.3/src/iesopt/alg/algorithm.py +2 -0
  5. iesopt-2.9.3/src/iesopt/alg/mga/__init__.py +4 -0
  6. iesopt-2.9.3/src/iesopt/alg/mga/nvp.py +300 -0
  7. iesopt-2.9.3/src/iesopt/alg/mga/util.py +19 -0
  8. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/src/iesopt/config.py +1 -1
  9. iesopt-2.9.3/tests/__init__.py +0 -0
  10. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/.codespellrc +0 -0
  11. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/.editorconfig +0 -0
  12. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
  13. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
  14. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/.github/actions/set-versions/action.yml +0 -0
  15. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/.github/workflows/documentation.yml +0 -0
  16. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/.github/workflows/pypi_publish.yml +0 -0
  17. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/.github/workflows/pytest.yml +0 -0
  18. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/.gitignore +0 -0
  19. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/.pre-commit-config.yaml +0 -0
  20. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/.python-version +0 -0
  21. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/CHANGELOG.md +0 -0
  22. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/LICENSE +0 -0
  23. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/README.md +0 -0
  24. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/Makefile +0 -0
  25. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/_extensions/julia_domain.py +0 -0
  26. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/_static/.gitkeep +0 -0
  27. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/_static/custom.css +0 -0
  28. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/_static/favicon.ico +0 -0
  29. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/conf.py +0 -0
  30. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/dynamic/core.py +0 -0
  31. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/dynamic/create.py +0 -0
  32. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/dynamic/julia.py +0 -0
  33. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/dynamic/out/.gitignore +0 -0
  34. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/getting_started.md +0 -0
  35. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/index.md +0 -0
  36. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/make.bat +0 -0
  37. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/notebooks/.gitignore +0 -0
  38. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/notebooks/custom_results_1.ipynb +0 -0
  39. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/notebooks/custom_results_2.ipynb +0 -0
  40. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/notebooks/example_52.ipynb +0 -0
  41. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/notebooks/example_53.ipynb +0 -0
  42. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/notebooks/example_54.ipynb +0 -0
  43. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/notebooks/example_55.ipynb +0 -0
  44. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/notebooks/first_model.ipynb +0 -0
  45. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/notebooks/pyproject.toml +0 -0
  46. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/notebooks/ruff.toml +0 -0
  47. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/dev/core.md +0 -0
  48. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/dev/general.md +0 -0
  49. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/dev/updating.md +0 -0
  50. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/manual/julia/.gitignore +0 -0
  51. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/manual/julia/index.md_template +0 -0
  52. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/manual/python/configuration.md +0 -0
  53. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/manual/python/index.md +0 -0
  54. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/manual/python/jump.md +0 -0
  55. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/manual/python/model.md +0 -0
  56. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/manual/python/results.md +0 -0
  57. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/manual/python/util.md +0 -0
  58. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/manual/yaml/core/.gitignore +0 -0
  59. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/manual/yaml/core_components.md +0 -0
  60. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/manual/yaml/index.md +0 -0
  61. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/manual/yaml/top_level.md +0 -0
  62. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/references/projects.md +0 -0
  63. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/references/publications.md +0 -0
  64. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/tutorials/.gitkeep +0 -0
  65. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/tutorials/addons.md +0 -0
  66. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/tutorials/templates/getter_setter.md +0 -0
  67. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/tutorials/templates_1.md +0 -0
  68. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/tutorials/templates_2.md +0 -0
  69. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/user_guides/general/best_practice.md +0 -0
  70. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/user_guides/general/common_errors.md +0 -0
  71. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/user_guides/general/global_parameters.md +0 -0
  72. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/user_guides/general/kwargs_config.md +0 -0
  73. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/user_guides/general/linking_components.md +0 -0
  74. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/user_guides/general/monte_carlo.md +0 -0
  75. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/user_guides/index.md +0 -0
  76. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/user_guides/qna/cop_interpolation.md +0 -0
  77. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/user_guides/qna/dynamic_marginal_costs.md +0 -0
  78. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/user_guides/qna/passive_charging.md +0 -0
  79. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/user_guides/qna/profiles_sign.md +0 -0
  80. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/user_guides/qna/snapshot_duration.md +0 -0
  81. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/user_guides/toc_general.md +0 -0
  82. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/pages/user_guides/toc_qna.md +0 -0
  83. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/tocs/examples.md +0 -0
  84. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/tocs/tutorials_extracting_results.md +0 -0
  85. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/docs/tocs/tutorials_templates.md +0 -0
  86. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/src/iesopt/__init__.py +0 -0
  87. {iesopt-2.9.1.dev0/tests → iesopt-2.9.3/src/iesopt/alg}/__init__.py +0 -0
  88. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/src/iesopt/iesopt.py +0 -0
  89. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/src/iesopt/julia/__init__.py +0 -0
  90. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/src/iesopt/julia/general.py +0 -0
  91. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/src/iesopt/julia/setup.py +0 -0
  92. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/src/iesopt/julia/util.py +0 -0
  93. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/src/iesopt/model.py +0 -0
  94. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/src/iesopt/results.py +0 -0
  95. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/src/iesopt/util/__init__.py +0 -0
  96. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/src/iesopt/util/logging.py +0 -0
  97. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/src/iesopt/util/util.py +0 -0
  98. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/tag_release.sh +0 -0
  99. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/tests/test_examples.py +0 -0
  100. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/tests/test_files.py +0 -0
  101. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/tests/test_julia_consistency.py +0 -0
  102. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/tests/test_python_julia_conversion.py +0 -0
  103. {iesopt-2.9.1.dev0 → iesopt-2.9.3}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: iesopt
3
- Version: 2.9.1.dev0
3
+ Version: 2.9.3
4
4
  Summary: IESopt -- an Integrated Energy System Optimization framework.
5
5
  Project-URL: Homepage, https://github.com/ait-energy/iesopt
6
6
  Project-URL: Documentation, https://ait-energy.github.io/iesopt
@@ -9,12 +9,13 @@ models. They are largely based on other model's defaults (see e.g.
9
9
  More information can be found at:
10
10
 
11
11
  - HiGHS:
12
- - https://ergo-code.github.io/HiGHS/stable/options/definitions/
12
+ - [HiGHS Documentation - List of Options](https://ergo-code.github.io/HiGHS/stable/options/definitions/)
13
13
  - Gurobi:
14
- - https://www.gurobi.com/wp-content/uploads/2022-10-Paris_Advanced_Algorithms.pdf
15
- - https://www.gurobi.com/documentation/current/refman/parameters.html
14
+ - [Gurobi Days Paris Advanced Gurobi Algorithms](https://www.gurobi.com/wp-content/uploads/2022-10-Paris_Advanced_Algorithms.pdf)
15
+ - [Gurobi Documentation - Parameter Reference](https://docs.gurobi.com/projects/optimizer/en/current/reference/parameters.html)
16
16
  - CPLEX:
17
- - https://www.ibm.com/docs/en/icos/22.1.1?topic=cplex-list-parameters
17
+ - [IBM ILOG CPLEX Optimization Studio - List of CPLEX parameters](https://www.ibm.com/docs/en/icos/22.1.2?topic=cplex-list-parameters)
18
+ - [IBM ILOG CPLEX Optimization Studio CPLEX Parameters Reference (outdated)](https://public.dhe.ibm.com/software/products/Decision_Optimization/docs/pdf/paramcplex.pdf)
18
19
 
19
20
  ### HiGHS
20
21
 
@@ -93,9 +94,9 @@ solver:
93
94
  solver:
94
95
  name: cplex
95
96
  attributes:
96
- threads: 4
97
- lpmethod: 4
98
- solutiontype: 2
99
- barrier_convergetol: 1.e-5
100
- feasopt_tolerance: 1.e-6
97
+ CPXPARAM_Threads: 8 # Number of Threads
98
+ CPXPARAM_LPMethod: 4 # Barrier
99
+ CPXPARAM_SolutionType: 2 # No Crossover
100
+ CPXPARAM_Barrier_ConvergeTol: 1e-5
101
+ CPXPARAM_Feasopt_Tolerance: 1.e-5
101
102
  ```
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "iesopt"
3
- version = "2.9.1.dev0"
3
+ version = "2.9.3"
4
4
  description = "IESopt -- an Integrated Energy System Optimization framework."
5
5
  keywords = ["integrated energy systems", "optimization", "energy model", "modelling"]
6
6
  authors = [
@@ -0,0 +1,2 @@
1
+ class Algorithm:
2
+ pass
@@ -0,0 +1,4 @@
1
+ from .nvp import NVP as NVP
2
+
3
+
4
+ print("EXPERIMENTAL WARNING: iesopt.alg.mga is an experimental module and its API may change in future releases.")
@@ -0,0 +1,300 @@
1
+ import numpy as np
2
+
3
+ try:
4
+ import matplotlib.pyplot as plt
5
+ from matplotlib.widgets import Slider
6
+ except ImportError:
7
+ print("ERROR: Matplotlib is required for NVP visualization. Please install it via 'uv add matplotlib'.")
8
+
9
+ try:
10
+ from scipy.spatial import ConvexHull
11
+ except ImportError:
12
+ print("ERROR: Scipy is required for NVP. Please install it via 'uv add scipy'.")
13
+
14
+ from ...model import Model
15
+ from ..algorithm import Algorithm
16
+ from .util import set_weighted_objective, add_obj_threshold_constraint
17
+
18
+
19
+ # Calculate the normal vector pointing inward the convex hull
20
+ def calculate_inward_normal(edge_start, edge_end, hull_vertices):
21
+ # Calculate the edge vector
22
+ edge_vector = edge_end - edge_start
23
+
24
+ # Calculate the perpendicular vector (rotate 90 degrees)
25
+ # For 2D: if edge is [dx, dy], perpendiculars are [-dy, dx] and [dy, -dx]
26
+ normal_candidate1 = np.array([-edge_vector[1], edge_vector[0]])
27
+ normal_candidate2 = np.array([edge_vector[1], -edge_vector[0]])
28
+
29
+ # Find the midpoint of the edge
30
+ edge_midpoint = (edge_start + edge_end) / 2
31
+
32
+ # Find the centroid of the convex hull
33
+ centroid = np.mean(hull_vertices, axis=0)
34
+
35
+ # Vector from centroid to edge midpoint
36
+ centroid_to_edge = edge_midpoint - centroid
37
+
38
+ # Choose the normal that points in the same direction as centroid_to_edge
39
+ # (i.e., away from the centroid, which means inward from the hull)
40
+ if np.dot(normal_candidate1, centroid_to_edge) < 0:
41
+ inward_normal = normal_candidate1
42
+ else:
43
+ inward_normal = normal_candidate2
44
+
45
+ # Normalize to unit vector
46
+ return inward_normal / np.linalg.norm(inward_normal)
47
+
48
+
49
+ class Trial:
50
+ def __init__(self, direction: dict):
51
+ self.direction = direction
52
+ self.solution = None
53
+ self.gain = -np.inf
54
+
55
+ @property
56
+ def redundant(self):
57
+ return self.gain < 1e-3
58
+
59
+
60
+ class Trials:
61
+ def __init__(self):
62
+ self._scheduled = []
63
+ self._completed = []
64
+
65
+ @property
66
+ def is_empty(self):
67
+ return len(self._scheduled) == 0
68
+
69
+ def schedule(self, direction):
70
+ self._scheduled.append(Trial(direction))
71
+
72
+ def pop(self):
73
+ return self._scheduled.pop(0)
74
+
75
+ def complete(self, trial, solution):
76
+ trial.solution = solution
77
+ self._completed.append(trial)
78
+
79
+ def get_solutions(self):
80
+ return [t.solution for t in self._completed]
81
+
82
+ def get_visited_directions(self):
83
+ return [t.direction for t in self._completed if all(v is not None for v in t.direction.values())]
84
+
85
+
86
+ class Domain:
87
+ def __init__(self, solutions):
88
+ self._solutions = solutions
89
+ self._points = np.array([[s[dim] for dim in list(solutions[0].keys())[1:]] for s in solutions])
90
+
91
+ try:
92
+ self._calculate_convex_hull()
93
+ self.valid = True
94
+ except Exception as _:
95
+ self.valid = False
96
+
97
+ def _calculate_convex_hull(self):
98
+ hull = ConvexHull(self._points)
99
+ vertices = self._points[hull.vertices]
100
+ edges = []
101
+ for simplex in hull.simplices:
102
+ edges.append((self._points[simplex[0]], self._points[simplex[1]]))
103
+ self.vertices = vertices
104
+ self.edges = edges
105
+ self.hull = hull
106
+
107
+ self._calculate_edge_normals()
108
+ self._calculate_edge_lengths()
109
+
110
+ def get_edge(self, index):
111
+ return self.edges[index], self._edge_lengths[index], self._normals[index]
112
+
113
+ def plot(self, ax=None):
114
+ # TODO: plot current "max domain" (and "direction"; but that not in the "domain")
115
+ create_fig = ax is None
116
+ if create_fig:
117
+ fig, ax = plt.subplots(figsize=(10, 8))
118
+ ax.scatter(self._points[:, 0], self._points[:, 1], c="lightblue", s=50, alpha=0.6, label="All Solutions")
119
+ ax.scatter(self.vertices[:, 0], self.vertices[:, 1], c="red", s=50, label="Hull Vertices", zorder=5)
120
+ for simplex in self.hull.simplices:
121
+ ax.plot(self._points[simplex, 0], self._points[simplex, 1], "r-", linewidth=2)
122
+ ax.fill(self.vertices[:, 0], self.vertices[:, 1], alpha=0.2, color="red")
123
+ ax.legend()
124
+ ax.grid(True, alpha=0.3)
125
+ if create_fig:
126
+ plt.tight_layout()
127
+ return fig, ax
128
+ return None
129
+
130
+ def _calculate_edge_lengths(self):
131
+ self._edge_lengths = [np.linalg.norm(edge_end - edge_start) for edge_start, edge_end in self.edges]
132
+
133
+ def _calculate_edge_normals(self):
134
+ self._normals = []
135
+ for edge_start, edge_end in self.edges:
136
+ normal = calculate_inward_normal(edge_start, edge_end, self.vertices)
137
+ self._normals.append(normal)
138
+
139
+
140
+ class Domains:
141
+ def __init__(self):
142
+ self._domains = []
143
+
144
+ def append(self, domain):
145
+ self._domains.append(domain)
146
+
147
+ def __len__(self):
148
+ return len(self._domains)
149
+
150
+ def __getitem__(self, index):
151
+ return self._domains[index]
152
+
153
+ def plot(self):
154
+ objectives = list(self._domains[0]._solutions[0].keys())
155
+ valid = [domain for domain in self._domains if domain.valid]
156
+
157
+ xvals = [val for d in valid for val in d._points[:, 0]]
158
+ yvals = [val for d in valid for val in d._points[:, 1]]
159
+ xrange = min(xvals) * 0.95, max(xvals) * 1.05
160
+ yrange = min(yvals) * 0.95, max(yvals) * 1.05
161
+
162
+ fig, ax = plt.subplots(figsize=(10, 8))
163
+ plt.subplots_adjust(bottom=0.25)
164
+
165
+ # Create a slider for navigating through the plots
166
+ ax_slider = plt.axes([0.1, 0.1, 0.8, 0.03])
167
+ self._plot_slider = Slider(ax_slider, "Plot Index", 0, len(valid) - 1, valinit=0, valstep=1)
168
+
169
+ def update(val):
170
+ ax.cla()
171
+ valid[int(val)].plot(ax=ax)
172
+ fig.canvas.draw_idle()
173
+ ax.set_xlabel(objectives[1])
174
+ ax.set_ylabel(objectives[2])
175
+ ax.set_xlim(xrange)
176
+ ax.set_ylim(yrange)
177
+
178
+ self._plot_slider.on_changed(update)
179
+ update(0)
180
+ return fig, ax
181
+
182
+
183
+ # NOTE on specific solver choice:
184
+ # dual: constraints change
185
+ # primal: objective change
186
+ # iesopt.JuMP.set_attribute(model.core, "Method", -1)
187
+ # iesopt.JuMP.set_attribute(model.core, "Method", 1) # dual (to change constraints)
188
+ # iesopt.JuMP.set_attribute(model.core, "Method", 0) # primal (to change objective)
189
+
190
+
191
+ class NVP(Algorithm):
192
+ """
193
+ Normal Vector Pushing (like the most basic HSJ MGA algorithm).
194
+
195
+ This requires the following additional dependencies:
196
+
197
+ - scipy
198
+ - matplotlib (for plotting)
199
+ - pyqt6 (for plotting if necessary to show the interactive windows)
200
+
201
+ Example usage:
202
+ ```python
203
+ import iesopt
204
+ import iesopt.alg.mga as mga
205
+
206
+ # Consider setting `verbosity.core: error` and `verbosity.solver: off` in the config!
207
+ model = iesopt.Model("config.iesopt.yaml")
208
+
209
+ nvp = mga.NVP(model, ["total_cost", "other_objective_A", "other_objective_B"], eps=0.05)
210
+ nvp.run(maxiter=25)
211
+ fig, ax = nvp.visualize()
212
+ fig.show()
213
+ # ... or save the figure!
214
+ ```
215
+
216
+ where the objectives could be defined like this in the config:
217
+
218
+ ```yaml
219
+ other_objective_A: [heatpump.exp.out_heat, hp_cool.heatpump.exp.out_heat]
220
+ other_objective_B: [hwk_ne2.exp.out_heat, hwk_ne3.boiler.exp.out_heat]
221
+ ```
222
+ """
223
+
224
+ def __init__(self, model: Model, objectives: list[str], eps: float):
225
+ assert len(objectives) == 3, "NVP currently only supports 3 objectives (1 primary + 2 secondary)."
226
+
227
+ self.model = model
228
+ self.objectives = objectives
229
+ self.eps = eps
230
+
231
+ self.domains = Domains()
232
+ self.trials = Trials()
233
+
234
+ def run(self, maxiter: int = -1):
235
+ iter = 0
236
+
237
+ # TODO: check model status for "ModelStatus.EMPTY"
238
+ print("Initial optimization...")
239
+ self.model.generate()
240
+ self.model.optimize()
241
+ iter += 1
242
+
243
+ self.trials.schedule({dim: None for dim in self.objectives[1:]})
244
+ trial = self.trials.pop()
245
+ self.trials.complete(trial, {dim: self.model.results.objectives[dim] for dim in self.objectives})
246
+
247
+ add_obj_threshold_constraint(
248
+ self.model.core,
249
+ self.objectives[0],
250
+ (1 + self.eps) * self.trials.get_solutions()[0][self.objectives[0]],
251
+ )
252
+ self.model.optimize()
253
+
254
+ for d in self.objectives[1:]:
255
+ self.trials.schedule({dim: (+1.0 if dim == d else 0.0) for dim in self.objectives[1:]})
256
+ self.trials.schedule({dim: (-1.0 if dim == d else 0.0) for dim in self.objectives[1:]})
257
+
258
+ # TODO: this is not really efficient, it just prevents "line"-like domains from "stalling" the algorithm
259
+ self.trials.schedule({dim: (1 / len(self.objectives[1:])) ** 0.5 for dim in self.objectives[1:]})
260
+ self.trials.schedule({dim: -((1 / len(self.objectives[1:])) ** 0.5) for dim in self.objectives[1:]})
261
+
262
+ print("Starting NVP iterations ", end="", flush=True)
263
+ while not self.trials.is_empty:
264
+ print(".", end="", flush=True)
265
+ if (maxiter > 0) and (iter >= maxiter):
266
+ print("\nMaximum iterations reached.")
267
+ break
268
+
269
+ trial = self.trials.pop()
270
+ set_weighted_objective(self.model.core, trial.direction)
271
+ self.model.optimize()
272
+ iter += 1
273
+ self.trials.complete(trial, {dim: self.model.results.objectives[dim] for dim in self.objectives})
274
+
275
+ domain = Domain(self.trials.get_solutions())
276
+ self.domains.append(domain)
277
+
278
+ if domain.valid:
279
+ visited = self.trials.get_visited_directions()
280
+ best = (None, -np.inf, None)
281
+ for i in range(len(domain.edges)):
282
+ edge, length, nv = domain.get_edge(i)
283
+ nv = dict(zip(self.objectives[1:], nv))
284
+ dist = min(sum((nv[obj] - v[obj]) ** 2 for obj in self.objectives[1:]) for v in visited)
285
+ if (dist > 1e-3) and (length > best[1]):
286
+ best = (edge, length, nv)
287
+
288
+ if best[0] is None:
289
+ print("\nNo new direction found, terminating.")
290
+ break
291
+
292
+ self.trials.schedule(best[2])
293
+
294
+ print("\nNVP completed.")
295
+
296
+ def iterate(self):
297
+ pass
298
+
299
+ def visualize(self):
300
+ return self.domains.plot()
@@ -0,0 +1,19 @@
1
+ import iesopt
2
+
3
+
4
+ add_obj_threshold_constraint = iesopt.IESopt.seval("""
5
+ function (model, obj, ub)
6
+ JuMP.@constraint(model, internal(model).model.objectives[obj].expr <= ub)
7
+ return nothing
8
+ end
9
+ """)
10
+
11
+ set_weighted_objective = iesopt.IESopt.seval("""
12
+ function (model, objs)
13
+ objectives = internal(model).model.objectives
14
+ JuMP.@objective(model, Min, sum(
15
+ objectives[name].expr * weight for (name, weight) in objs
16
+ ))
17
+ return nothing
18
+ end
19
+ """)
@@ -13,7 +13,7 @@ def _strtobool(val: str):
13
13
  class Config:
14
14
  DEFAULTS = {
15
15
  "IESOPT_JULIA": "1.11.7",
16
- "IESOPT_CORE": "2.9.0",
16
+ "IESOPT_CORE": "2.9.2",
17
17
  "IESOPT_JUMP": "1.29.1",
18
18
  "IESOPT_SOLVER_HIGHS": "1.19.0",
19
19
  "IESOPT_MULTITHREADED": "no", # yes, no
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes