Commit b7c2dc7
authored
Feature/penalty as effect (#486)
* implemented the migration of Penalty to be a standard Effect. Here's what was done:
✅ Implementation Complete
Changes Made:
1. Penalty Effect Creation (flixopt/effects.py):
- Created _penalty effect automatically in FlowSystem.__init__
- Added penalty_effect property to EffectCollection
- Penalty now has temporal and periodic dimensions like other effects
2. Removed Old Penalty Infrastructure (flixopt/effects.py):
- Removed ShareAllocationModel penalty from EffectCollectionModel
- Removed add_share_to_penalty() method
- Updated objective to use penalty effect: objective_effect + penalty_effect
3. Updated Internal Usage:
- Bus (flixopt/elements.py:960-969): Now uses add_share_to_effects with target='temporal'
- Aggregation (flixopt/aggregation.py:351-355): Now uses add_share_to_effects with target='temporal'
4. Results Structure (flixopt/calculation.py:109-113):
- Changed from 'Penalty': scalar to 'Penalty': {temporal, periodic, total}
- Penalty excluded from regular Effects list (shown separately)
5. I/O & Serialization (flixopt/flow_system.py:613-614):
- Skip _penalty effect when loading from dataset (auto-created)
6. Documentation (docs/user-guide/mathematical-notation/effects-penalty-objective.md):
- Updated to reflect Penalty as an Effect
- Updated mathematical formulations
- Updated all objective function equations
7. Tests Updated:
- tests/test_bus.py: Updated penalty assertions
- tests/test_scenarios.py: Updated to use new penalty structure
Key Benefits:
✅ Unified Interface: Penalty shares added same way as effect shares
✅ Dimensional Support: Penalties can now vary by time/period/scenario
✅ Constrainable: Can add bounds to penalty (useful for debugging)
✅ Better Results: Penalty breakdown shows temporal vs periodic contributions
✅ Cleaner Architecture: One less special case in the codebase
Test Status:
The core functionality is working. Tests are passing for:
- Bus models with and without penalties
- Effect shares and constraints
- Scenario weighting
- Resample operations
- I/O operations
* Allow user defined enalty Effect
* Update CHANGELOG.md
* Update CHANGELOG.md
* Update CHANGELOG.md and docs
* Fix penöaty test
* Remove special treatment for Penalty effect in IO
* Update CHANGELOG.md
* Fix aggregation.py and its penalties
* Fix indices
* Revert some changes
* Verify that Penalty is not set as the objective
* Update docs a bit
* Update docs a bit
* Update docs a bit
* Fix test
* Update CHANGELOG.md
* Improve main results penalty display
* Update CHANGELOG.md
* Merge branch 'main' into feature/penalty-as-effect
# Conflicts:
# flixopt/calculation.py
# flixopt/clustering.py
* Revert some minimla changes from merge1 parent b591854 commit b7c2dc7
11 files changed
Lines changed: 261 additions & 59 deletions
File tree
- docs/user-guide/mathematical-notation
- flixopt
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
60 | 71 | | |
61 | 72 | | |
62 | 73 | | |
63 | 74 | | |
64 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
65 | 80 | | |
66 | 81 | | |
67 | 82 | | |
| |||
73 | 88 | | |
74 | 89 | | |
75 | 90 | | |
76 | | - | |
77 | | - | |
78 | | - | |
| 91 | + | |
79 | 92 | | |
80 | 93 | | |
81 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
| 117 | + | |
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
| |||
130 | 131 | | |
131 | 132 | | |
132 | 133 | | |
| 134 | + | |
| 135 | + | |
133 | 136 | | |
134 | 137 | | |
135 | 138 | | |
| |||
203 | 206 | | |
204 | 207 | | |
205 | 208 | | |
206 | | - | |
| 209 | + | |
207 | 210 | | |
208 | 211 | | |
209 | 212 | | |
210 | 213 | | |
| 214 | + | |
211 | 215 | | |
212 | 216 | | |
213 | 217 | | |
214 | 218 | | |
215 | 219 | | |
| 220 | + | |
216 | 221 | | |
217 | 222 | | |
218 | 223 | | |
| |||
Lines changed: 73 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
| 145 | + | |
| 146 | + | |
146 | 147 | | |
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 | + | |
148 | 181 | | |
149 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
150 | 186 | | |
151 | | - | |
152 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
153 | 190 | | |
154 | 191 | | |
155 | 192 | | |
156 | 193 | | |
157 | 194 | | |
158 | 195 | | |
159 | | - | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
160 | 200 | | |
161 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
162 | 208 | | |
163 | 209 | | |
164 | 210 | | |
165 | 211 | | |
166 | 212 | | |
167 | | - | |
| 213 | + | |
168 | 214 | | |
169 | 215 | | |
170 | | - | |
| 216 | + | |
171 | 217 | | |
172 | 218 | | |
173 | 219 | | |
174 | 220 | | |
175 | 221 | | |
176 | | - | |
| 222 | + | |
177 | 223 | | |
178 | | - | |
| 224 | + | |
179 | 225 | | |
180 | 226 | | |
181 | 227 | | |
| |||
198 | 244 | | |
199 | 245 | | |
200 | 246 | | |
201 | | - | |
| 247 | + | |
202 | 248 | | |
203 | 249 | | |
204 | 250 | | |
205 | | - | |
206 | | - | |
207 | | - | |
| 251 | + | |
| 252 | + | |
208 | 253 | | |
209 | 254 | | |
210 | 255 | | |
211 | 256 | | |
212 | 257 | | |
213 | 258 | | |
214 | | - | |
| 259 | + | |
215 | 260 | | |
216 | 261 | | |
217 | 262 | | |
218 | 263 | | |
219 | 264 | | |
220 | | - | |
221 | | - | |
222 | | - | |
| 265 | + | |
| 266 | + | |
223 | 267 | | |
224 | 268 | | |
225 | 269 | | |
226 | 270 | | |
227 | 271 | | |
| 272 | + | |
228 | 273 | | |
229 | 274 | | |
230 | 275 | | |
231 | 276 | | |
232 | 277 | | |
233 | 278 | | |
234 | | - | |
| 279 | + | |
235 | 280 | | |
236 | 281 | | |
237 | 282 | | |
238 | 283 | | |
239 | 284 | | |
240 | | - | |
| 285 | + | |
241 | 286 | | |
| 287 | + | |
242 | 288 | | |
243 | 289 | | |
244 | 290 | | |
245 | 291 | | |
246 | 292 | | |
247 | 293 | | |
248 | | - | |
| 294 | + | |
249 | 295 | | |
250 | 296 | | |
251 | 297 | | |
252 | 298 | | |
253 | 299 | | |
254 | 300 | | |
255 | 301 | | |
256 | | - | |
257 | | - | |
258 | | - | |
| 302 | + | |
| 303 | + | |
259 | 304 | | |
260 | 305 | | |
261 | 306 | | |
262 | 307 | | |
263 | 308 | | |
264 | 309 | | |
| 310 | + | |
265 | 311 | | |
266 | 312 | | |
267 | 313 | | |
| |||
274 | 320 | | |
275 | 321 | | |
276 | 322 | | |
277 | | - | |
| 323 | + | |
| 324 | + | |
278 | 325 | | |
279 | 326 | | |
280 | 327 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
349 | 349 | | |
350 | 350 | | |
351 | 351 | | |
352 | | - | |
353 | | - | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
354 | 362 | | |
355 | 363 | | |
356 | 364 | | |
| |||
0 commit comments