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