tools
Scalarization
Defines various functions for scalarizing multiobjective optimization problems.
Note that when scalarization functions are defined, they must add the post-fix '_min' to any symbol representing objective functions so that the maximization or minimization of the corresponding objective functions may be correctly accounted for when computing scalarization function values.
Op
Defines the supported operators in the MathJSON format.
Source code in desdeo/tools/scalarization.py
ScalarizationError
__create_HDF
Create a Harrington's one-sided desirability function.
Harrington's desirability function is used to compute the desirability of a given value of an objective function based on its aspiration and reservation levels.
The desirability function is defined as follows:
where
The desirability function returns a value between 0 and 1, where higher values indicate more desirable outcomes. I took the equations from the following source: Wagner, T., and Trautmann, H. Integration of preference in hypervolume-based multiobjective evolutionary algorithms by means of desirability functions. IEEE Transactions on Evolutionary Computation 14, 5 (2010), 688-701.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
str
|
The objective value to compute the desirability for. |
required |
a
|
float
|
Aspiration level for the objective. |
required |
r
|
float
|
Reservation level for the objective. |
required |
d1
|
float
|
The desirability for the aspiration level. |
0.9
|
d2
|
float
|
The desirability for the reservation level. |
0.1
|
Returns:
| Name | Type | Description |
|---|---|---|
callable |
Function
|
A function that computes the desirability for a given value. |
Source code in desdeo/tools/scalarization.py
__create_MDF
Create MaoMao's desirability function.
Distinctions form MaoMao's original function: - The upper and lower bounds of desirability are fixed to 0 and 1, respectively.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
y
|
str
|
The objective value to compute the desirability for. |
required |
a
|
float
|
Aspiration level for the objective. |
required |
r
|
float
|
Reservation level for the objective. |
required |
d1
|
float
|
The desirability for the aspiration level. |
0.9
|
d2
|
float
|
The desirability for the reservation level. |
0.1
|
Returns:
| Name | Type | Description |
|---|---|---|
callable |
Function
|
A function that computes the desirability for a given value. |
Source code in desdeo/tools/scalarization.py
add_asf_diff
add_asf_diff(
problem: Problem,
symbol: str,
reference_point: dict[str, float],
ideal: dict[str, float] | None = None,
nadir: dict[str, float] | None = None,
rho: float = 1e-06,
delta: float = 1e-06,
) -> tuple[Problem, str]
Adds the differentiable variant of the achievement scalarizing function.
where \(f_i\) are objective functions, \(z_i^{\star\star} = z_i^\star - \delta\) is a component of the utopian point, \(\bar{z}_i\) is a component of the reference point, \(\rho\) and \(\delta\) are small scalar values, \(S\) is the feasible solution space of the original problem, and \(\alpha\) is an auxiliary variable.
References
Wierzbicki, A. P. (1982). A mathematical basis for satisficing decision making. Mathematical modelling, 3(5), 391-405.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem the scalarization is added to. |
required |
symbol
|
str
|
the symbol given to the added scalarization. |
required |
reference_point
|
dict[str, float]
|
a dict with keys corresponding to objective function symbols and values to reference point components, i.e., aspiration levels. |
required |
ideal
|
dict[str, float]
|
ideal point values. If not given, attempt will be made to calculate ideal point from problem. |
None
|
nadir
|
dict[str, float]
|
nadir point values. If not given, attempt will be made to calculate nadir point from problem. |
None
|
rho
|
float
|
a small scalar value to scale the sum in the objective function of the scalarization. Defaults to 1e-6. |
1e-06
|
delta
|
float
|
a small scalar to define the utopian point. Defaults to 1e-6. |
1e-06
|
Returns:
| Type | Description |
|---|---|
tuple[Problem, str]
|
tuple[Problem, str]: a tuple with the copy of the problem with the added scalarization and the symbol of the added scalarization. |
Todo
Add reference in augmentation term option!
Source code in desdeo/tools/scalarization.py
1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 | |
add_asf_generic_diff
add_asf_generic_diff(
problem: Problem,
symbol: str,
reference_point: dict[str, float],
weights: dict[str, float],
reference_point_aug: dict[str, float] | None = None,
weights_aug: dict[str, float] | None = None,
rho: float = 1e-06,
) -> tuple[Problem, str]
Adds the differentiable variant of the generic achievement scalarizing function.
where \(f_i\) are objective functions, \(q_i\) is a component of the reference point,
and \(w_i\) are components of the weight vector (which are assumed to be positive),
\(\rho\) and \(\delta\) are small scalar values, \(S\) is the feasible solution
space of the original problem, and \(\alpha\) is an auxiliary variable.
The summation term in the scalarization is known as the augmentation term.
If a reference point is chosen to be used in the augmentation term, e.g., a separate
reference point for the augmentation term is given (reference_point_aug), then
the reference point components are subtracted from the objective function values
in the nominator of the augmentation term. That is:
References
Wierzbicki, A. P. (1982). A mathematical basis for satisficing decision making. Mathematical modelling, 3(5), 391-405.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem the scalarization is added to. |
required |
symbol
|
str
|
the symbol given to the added scalarization. |
required |
reference_point
|
dict[str, float]
|
a dict with keys corresponding to objective function symbols and values to reference point components, i.e., aspiration levels. |
required |
weights
|
dict[str, float]
|
the weights to be used in the scalarization function. Must be positive. |
required |
reference_point_aug
|
dict[str, float]
|
a dict with keys corresponding to objective function symbols and values to reference point components for the augmentation term, i.e., aspiration levels. Defeults to None. |
None
|
weights_aug
|
dict[str, float]
|
the weights to be used in the scalarization function's augmentation term. Must be positive. Defaults to None. |
None
|
rho
|
float
|
a small scalar value to scale the sum in the objective function of the scalarization. Defaults to 1e-6. |
1e-06
|
Returns:
| Type | Description |
|---|---|
tuple[Problem, str]
|
tuple[Problem, str]: a tuple with the copy of the problem with the added scalarization and the symbol of the added scalarization. |
Source code in desdeo/tools/scalarization.py
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 | |
add_asf_generic_nondiff
add_asf_generic_nondiff(
problem: Problem,
symbol: str,
reference_point: dict[str, float],
weights: dict[str, float],
reference_point_aug: dict[str, float] | None = None,
weights_aug: dict[str, float] | None = None,
rho: float = 1e-06,
) -> tuple[Problem, str]
Adds the generic achievement scalarizing function to a problem with the given reference point, and weights.
This is the non-differentiable variant of the generic achievement scalarizing function, which
means the resulting scalarization function is non-differentiable. Compared to add_asf_nondiff, this
variant is useful, when the problem being scalarized does not have a defined ideal or nadir point,
or both. The weights should be non-zero to avoid zero division.
The scalarization is defined as follows:
where \(\mathbf{q} = [q_1,\dots,q_k]\) is a reference point, \(\mathbf{w} =
[w_1,\dots,w_k]\) are weights, \(k\) is the number of objective functions, and
\(\delta\) and \(\rho\) are small scalar values. The summation term in the
scalarization is known as the augmentation term. If a reference point is
chosen to be used in the augmentation term, e.g., a separate
reference point for the augmentation term is given (reference_point_aug), then
the reference point components are subtracted from the objective function values
in the nominator of the augmentation term. That is:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem to which the scalarization function should be added. |
required |
symbol
|
str
|
the symbol to reference the added scalarization function. |
required |
reference_point
|
dict[str, float]
|
a reference point with as many components as there are objectives. |
required |
weights
|
dict[str, float]
|
the weights to be used in the scalarization function. must be positive. |
required |
reference_point_aug
|
dict[str, float]
|
a dict with keys corresponding to objective function symbols and values to reference point components for the augmentation term, i.e., aspiration levels. Defeults to None. |
None
|
weights_aug
|
dict[str, float]
|
the weights to be used in the scalarization function's augmentation term. Must be positive. Defaults to None. |
None
|
rho
|
float
|
the weight factor used in the augmentation term. Defaults to 0.000001. |
1e-06
|
Raises:
| Type | Description |
|---|---|
ScalarizationError
|
If either the reference point or the weights given are missing any of the objective components. |
ScalarizationError
|
If any of the ideal or nadir point values are undefined (None). |
Returns:
| Type | Description |
|---|---|
tuple[Problem, str]
|
tuple[Problem, str]: A tuple containing a copy of the problem with the scalarization function added, and the symbol of the added scalarization function. |
Source code in desdeo/tools/scalarization.py
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 | |
add_asf_nondiff
add_asf_nondiff(
problem: Problem,
symbol: str,
reference_point: dict[str, float],
ideal: dict[str, float] | None = None,
nadir: dict[str, float] | None = None,
delta: float = 1e-06,
rho: float = 1e-06,
*,
reference_in_aug=False,
) -> tuple[Problem, str]
Add the achievement scalarizing function for a problem with the reference point.
This is the non-differentiable variant of the achievement scalarizing function, which means the resulting scalarization function is non-differentiable. Requires that the ideal and nadir point have been defined for the problem.
The scalarization is defined as follows:
where \(\mathbf{q} = [q_1,\dots,q_k]\) is a reference point, \(\mathbf{z^\star} = [z_1^\star,\dots,z_k^\star]\)
is the ideal point, \(\mathbf{z}^\text{nad} = [z_1^\text{nad},\dots,z_k^\text{nad}]\) is the nadir point, \(k\)
is the number of objective functions, and \(\delta\) and \(\rho\) are small scalar values. The summation term
in the scalarization is known as the augmentation term. If the reference point is chosen to
be used in the augmentation term (reference_in_aug=True), then
the reference point components are subtracted from the objective function values in the nominator
of the augmentation term. That is:
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem to which the scalarization function should be added. |
required |
symbol
|
str
|
the symbol to reference the added scalarization function. |
required |
reference_point
|
dict[str, float]
|
a reference point as an objective dict. |
required |
ideal
|
dict[str, float]
|
ideal point values. If not given, attempt will be made to calculate ideal point from problem. |
None
|
nadir
|
dict[str, float]
|
nadir point values. If not given, attempt will be made to calculate nadir point from problem. |
None
|
delta
|
float
|
the scalar value used to define the utopian point (ideal - delta). Defaults to 0.000001. |
1e-06
|
rho
|
float
|
the weight factor used in the augmentation term. Defaults to 0.000001. |
1e-06
|
reference_in_aug
|
bool
|
whether the reference point should be used in the augmentation term as well. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
ScalarizationError
|
there are missing elements in the reference point, or if any of the ideal or nadir point values are undefined (None). |
Returns:
| Type | Description |
|---|---|
tuple[Problem, str]
|
tuple[Problem, str]: A tuple containing a copy of the problem with the scalarization function added, and the symbol of the added scalarization function. |
Source code in desdeo/tools/scalarization.py
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 | |
add_desirability_funcs
add_desirability_funcs(
problem: Problem,
aspiration_levels: dict[str, float],
reservation_levels: dict[str, float],
desirability_levels: dict[str, tuple[float, float]]
| None = None,
desirability_func: Literal[
"Harrington", "MaoMao"
] = "Harrington",
) -> tuple[Problem, list[str]]
Adds desirability functions to the problem based on the given aspiration and reservation levels.
Note that the desirability functions are added as scalarization functions to the problem. They are also multiplied by -1 to ensure that "desirability" values can be minimized, as is assumed by the optimizers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
The problem to which the desirability functions should be added. |
required |
aspiration_levels
|
dict[str, float]
|
A dictionary with keys corresponding to objective function symbols and values to aspiration levels. |
required |
reservation_levels
|
dict[str, float]
|
A dictionary with keys corresponding to objective function symbols and values to reservation levels. |
required |
desirability_levels
|
dict[str, tuple[float, float]] | None
|
A dictionary with keys corresponding to objective function symbols and values to desirability levels, where each value is a tuple of (d1, d2). If not given, the default values for d1 and d2 are used, which are 0.9 and 0.1 respectively. Defaults to None. |
None
|
desirability_func
|
str
|
The type of desirability function to use. Currently, only "Harrington" or "MaoMao" is supported. Defaults to "Harrington". |
'Harrington'
|
Returns:
| Name | Type | Description |
|---|---|---|
Problem |
Problem
|
A copy of the problem with the added desirability functions as scalarization functions. |
list[str]
|
list[str]: A list of symbols of the added desirability functions. |
Source code in desdeo/tools/scalarization.py
1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 | |
add_epsilon_constraints
add_epsilon_constraints(
problem: Problem,
symbol: str,
constraint_symbols: dict[str, str],
objective_symbol: str,
epsilons: dict[str, float],
) -> tuple[Problem, str, list[str]]
Creates expressions for an epsilon constraints scalarization and constraints.
It is assumed that epsilon have been given in a format where each objective is to be minimized.
The scalarization is defined as follows:
where \(\epsilon_j\) are the epsilon bounds used in the epsilon constraints \(f_j(\mathbf{x}) \leq \epsilon_j\), and \(k\) is the number of objective functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem to scalarize. |
required |
symbol
|
str
|
the symbol of the added objective function to be optimized. |
required |
constraint_symbols
|
dict[str, str]
|
a dict with the symbols to be used with the added constraints. The key indicates the name of the objective function the constraint is related to, and the value is the symbol to be used when defining the constraint. |
required |
objective_symbol
|
str
|
the objective used as the objective in the epsilon constraint scalarization. |
required |
epsilons
|
dict[str, float]
|
the epsilon constraint values in a dict with each key being an objective's symbol. The corresponding value is then used as the epsilon value for the respective objective function. |
required |
Raises:
| Type | Description |
|---|---|
ScalarizationError
|
|
Returns:
| Type | Description |
|---|---|
tuple[Problem, str, list[str]]
|
tuple[Problem, str, list[str]]: A triple with the first element being a copy of the problem with the added epsilon constraints. The second element is the symbol of the objective to be optimized. The last element is a list with the symbols of the added constraints to the problem. |
Source code in desdeo/tools/scalarization.py
1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 | |
add_guess_sf_diff
add_guess_sf_diff(
problem: Problem,
symbol: str,
reference_point: dict[str, float],
ideal: dict[str, float] | None = None,
nadir: dict[str, float] | None = None,
rho: float = 1e-06,
delta: float = 1e-06,
) -> tuple[Problem, str]
Adds the differentiable variant of the GUESS scalarizing function.
where \(f_{i}\) are objective functions, \(z_{i}^{nad}\) is a component of the nadir point, \(\bar{z}_{i}\) is a component of the reference point, \(\rho\) is a small scalar value, and \(S\) is the feasible solution space of the original problem. The index set \(I^\diamond\) represents objective vectors whose values are free to change. The indices belonging to this set are interpreted as those objective vectors whose components in the reference point is set to be the the respective nadir point component of the problem. Note that in Buchanan (1997), the GUESS method considers all objective functions, i.e. \(I^\diamond\) is an empty set. The functionality to have free-to-change objectives was added in Miettinen & Mäkelä (2006).
References
Buchanan, J. T. (1997). A naive approach for solving MCDM problems: The GUESS method. Journal of the Operational Research Society, 48, 202-206.
Miettinen, K., & Mäkelä, M. M. (2006). Synchronous approach in interactive multiobjective optimization. European Journal of Operational Research, 170(3), 909-922.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem the scalarization is added to. |
required |
symbol
|
str
|
the symbol given to the added scalarization. |
required |
reference_point
|
dict[str, float]
|
a dict with keys corresponding to objective function symbols and values to reference point components, i.e., aspiration levels. |
required |
ideal
|
dict[str, float]
|
ideal point values. If not given, attempt will be made to calculate ideal point from problem. |
None
|
nadir
|
dict[str, float]
|
nadir point values. If not given, attempt will be made to calculate nadir point from problem. |
None
|
rho
|
float
|
a small scalar value to scale the sum in the objective function of the scalarization. Defaults to 1e-6. |
1e-06
|
delta
|
float
|
a small scalar value to define the utopian point. Defaults to 1e-6. |
1e-06
|
Returns:
| Type | Description |
|---|---|
tuple[Problem, str]
|
tuple[Problem, str]: a tuple with the copy of the problem with the added scalarization and the symbol of the added scalarization. |
Source code in desdeo/tools/scalarization.py
1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 | |
add_guess_sf_nondiff
add_guess_sf_nondiff(
problem: Problem,
symbol: str,
reference_point: dict[str, float],
ideal: dict[str, float] | None = None,
nadir: dict[str, float] | None = None,
rho: float = 1e-06,
) -> tuple[Problem, str]
Adds the non-differentiable variant of the GUESS scalarizing function.
where \(f_{i}\) are objective functions, \(z_{i}^{nad}\) is a component of the nadir point, \(\bar{z}_{i}\) is a component of the reference point, \(\rho\) is a small scalar value, and \(S\) is the feasible solution space of the original problem. The index set \(I^\diamond\) represents objective vectors whose values are free to change. The indices belonging to this set are interpreted as those objective vectors whose components in the reference point is set to be the the respective nadir point component of the problem. Note that in Buchanan (1997), the GUESS method considers all objective functions, i.e. \(I^\diamond\) is an empty set. The functionality to have free-to-change objectives was added in Miettinen & Mäkelä (2006).
References
Buchanan, J. T. (1997). A naive approach for solving MCDM problems: The GUESS method. Journal of the Operational Research Society, 48, 202-206.
Miettinen, K., & Mäkelä, M. M. (2006). Synchronous approach in interactive multiobjective optimization. European Journal of Operational Research, 170(3), 909-922.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem the scalarization is added to. |
required |
symbol
|
str
|
the symbol given to the added scalarization. |
required |
reference_point
|
dict[str, float]
|
a dict with keys corresponding to objective function symbols and values to reference point components, i.e., aspiration levels. |
required |
ideal
|
dict[str, float]
|
ideal point values. If not given, attempt will be made to calculate ideal point from problem. |
None
|
nadir
|
dict[str, float]
|
nadir point values. If not given, attempt will be made to calculate nadir point from problem. |
None
|
rho
|
float
|
a small scalar value to scale the sum in the objective function of the scalarization. Defaults to 1e-6. |
1e-06
|
Returns:
| Type | Description |
|---|---|
tuple[Problem, str]
|
tuple[Problem, str]: a tuple with the copy of the problem with the added scalarization and the symbol of the added scalarization. |
Source code in desdeo/tools/scalarization.py
1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 | |
add_nimbus_sf_diff
add_nimbus_sf_diff(
problem: Problem,
symbol: str,
classifications: dict[str, tuple[str, float | None]],
current_objective_vector: dict[str, float],
ideal: dict[str, float] | None = None,
nadir: dict[str, float] | None = None,
delta: float = 1e-06,
rho: float = 1e-06,
) -> Problem
Implements the differentiable variant of the NIMBUS scalarization function.
where \(f_i\) are objective functions, \(f_i(\mathbf{x_c})\) is a component of the current objective function, \(\hat{z}_i\) is an aspiration level, \(\varepsilon_i\) is a reservation level, \(z_i^\star\) is a component of the ideal point, \(z_i^{\star\star} = z_i^\star - \delta\) is a component of the utopian point, \(z_i^\text{nad}\) is a component of the nadir point, \(\rho\) is a small scalar, \(S\) is the feasible solution space of the problem (i.e., it means the other constraints of the problem being solved should be accounted for as well), and \(\alpha\) is an auxiliary variable.
The \(I\)-sets are related to the classifications given to each objective function value in respect to the current objective vector (e.g., by a decision maker). They are as follows:
- \(I^{<}\): values that should improve,
- \(I^{\leq}\): values that should improve until a given aspiration level \(\hat{z}_i\),
- \(I^{=}\): values that are fine as they are,
- \(I^{\geq}\): values that can be impaired until some reservation level \(\varepsilon_i\), and
- \(I^{\diamond}\): values that are allowed to change freely (not present explicitly in this scalarization function).
The aspiration levels and the reservation levels are supplied for each classification, when relevant, in
the argument classifications as follows:
classifications = {
"f_1": ("<", None),
"f_2": ("<=", 42.1),
"f_3": (">=", 22.2),
"f_4": ("0", None)
}
Here, we have assumed four objective functions. The key of the dict is a function's symbol, and the tuple
consists of a pair where the left element is the classification (self explanatory, '0' is for objective values
that may change freely), the right element is either None or an aspiration or a reservation level
depending on the classification.
References
Miettinen, K., & Mäkelä, M. M. (2002). On scalarizing functions in multiobjective optimization. OR Spectrum, 24(2), 193-213.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem to be scalarized. |
required |
symbol
|
str
|
the symbol given to the scalarization function, i.e., target of the optimization. |
required |
classifications
|
dict[str, tuple[str, float | None]]
|
a dict, where the key is a symbol
of an objective function, and the value is a tuple with a classification and an aspiration
or a reservation level, or |
required |
current_objective_vector
|
dict[str, float]
|
the current objective vector that corresponds to a Pareto optimal solution. The classifications are assumed to been given in respect to this vector. |
required |
ideal
|
dict[str, float]
|
ideal point values. If not given, attempt will be made to calculate ideal point from problem. |
None
|
nadir
|
dict[str, float]
|
nadir point values. If not given, attempt will be made to calculate nadir point from problem. |
None
|
delta
|
float
|
a small scalar used to define the utopian point. Defaults to 0.000001. |
1e-06
|
rho
|
float
|
a small scalar used in the augmentation term. Defaults to 0.000001. |
1e-06
|
Returns:
| Type | Description |
|---|---|
Problem
|
tuple[Problem, str]: a tuple with a copy of the problem with the added scalarizations and the symbol of the scalarization. |
Source code in desdeo/tools/scalarization.py
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 | |
add_nimbus_sf_nondiff
add_nimbus_sf_nondiff(
problem: Problem,
symbol: str,
classifications: dict[str, tuple[str, float | None]],
current_objective_vector: dict[str, float],
ideal: dict[str, float] | None = None,
nadir: dict[str, float] | None = None,
delta: float = 1e-06,
rho: float = 1e-06,
) -> Problem
Implements the non-differentiable variant of the NIMBUS scalarization function.
where \(f_i\) are objective functions, \(f_i(\mathbf{x_c})\) is a component of the current objective function, \(\hat{z}_i\) is an aspiration level, \(\varepsilon_i\) is a reservation level, \(z_i^\star\) is a component of the ideal point, \(z_i^{\star\star} = z_i^\star - \delta\) is a component of the utopian point, \(z_i^\text{nad}\) is a component of the nadir point, \(\rho\) is a small scalar, and \(S\) is the feasible solution space of the problem (i.e., it means the other constraints of the problem being solved should be accounted for as well).
The \(I\)-sets are related to the classifications given to each objective function value in respect to the current objective vector (e.g., by a decision maker). They are as follows:
- \(I^{<}\): values that should improve,
- \(I^{\leq}\): values that should improve until a given aspiration level \(\hat{z}_i\),
- \(I^{=}\): values that are fine as they are,
- \(I^{\geq}\): values that can be impaired until some reservation level \(\varepsilon_i\), and
- \(I^{\diamond}\): values that are allowed to change freely (not present explicitly in this scalarization function).
The aspiration levels and the reservation levels are supplied for each classification, when relevant, in
the argument classifications as follows:
classifications = {
"f_1": ("<", None),
"f_2": ("<=", 42.1),
"f_3": (">=", 22.2),
"f_4": ("0", None)
}
Here, we have assumed four objective functions. The key of the dict is a function's symbol, and the tuple
consists of a pair where the left element is the classification (self explanatory, '0' is for objective values
that may change freely), the right element is either None or an aspiration or a reservation level
depending on the classification.
References
Miettinen, K., & Mäkelä, M. M. (2002). On scalarizing functions in multiobjective optimization. OR Spectrum, 24(2), 193-213.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem to be scalarized. |
required |
symbol
|
str
|
the symbol given to the scalarization function, i.e., target of the optimization. |
required |
classifications
|
dict[str, tuple[str, float | None]]
|
a dict, where the key is a symbol
of an objective function, and the value is a tuple with a classification and an aspiration
or a reservation level, or |
required |
current_objective_vector
|
dict[str, float]
|
the current objective vector that corresponds to a Pareto optimal solution. The classifications are assumed to been given in respect to this vector. |
required |
ideal
|
dict[str, float]
|
optional ideal point values. If not given, attempt will be made to calculate ideal point from problem. |
None
|
nadir
|
dict[str, float]
|
optional nadir point values. If not given, attempt will be made to calculate nadir point from problem. |
None
|
delta
|
float
|
a small scalar used to define the utopian point. Defaults to 0.000001. |
1e-06
|
rho
|
float
|
a small scalar used in the augmentation term. Defaults to 0.000001. |
1e-06
|
Returns:
| Type | Description |
|---|---|
Problem
|
tuple[Problem, str]: a tuple with a copy of the problem with the added scalarizations and the symbol of the scalarization. |
Source code in desdeo/tools/scalarization.py
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 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 | |
add_objective_as_scalarization
add_objective_as_scalarization(
problem: Problem, symbol: str, objective_symbol: str
) -> tuple[Problem, str]
Creates a scalarization where one of the problem's objective functions is optimized.
The scalarization is defined as follows:
where \(f_t(\mathbf{x})\) is the objective function to be minimized.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem to which the scalarization should be added. |
required |
symbol
|
str
|
the symbol to reference the added scalarization function. |
required |
objective_symbol
|
str
|
the symbol of the objective function to be optimized. |
required |
Raises:
| Type | Description |
|---|---|
ScalarizationError
|
the given objective_symbol does not exist in the problem. |
Returns:
| Type | Description |
|---|---|
tuple[Problem, str]
|
tuple[Problem, str]: A tuple containing a copy of the problem with the scalarization function added, and the symbol of the added scalarization function. |
Source code in desdeo/tools/scalarization.py
add_stom_sf_diff
add_stom_sf_diff(
problem: Problem,
symbol: str,
reference_point: dict[str, float],
ideal: dict[str, float] | None = None,
rho: float = 1e-06,
delta: float = 1e-06,
) -> tuple[Problem, str]
Adds the differentiable variant of the STOM scalarizing function.
where \(f_i\) are objective functions, \(z_i^{\star\star} = z_i^\star - \delta\) is a component of the utopian point, \(\bar{z}_i\) is a component of the reference point, \(\rho\) and \(\delta\) are small scalar values, \(S\) is the feasible solution space of the original problem, and \(\alpha\) is an auxiliary variable.
References
H. Nakayama, Y. Sawaragi, Satisficing trade-off method for multiobjective programming, in: M. Grauer, A.P. Wierzbicki (Eds.), Interactive Decision Analysis, Springer Verlag, Berlin, 1984, pp. 113-122.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem the scalarization is added to. |
required |
symbol
|
str
|
the symbol given to the added scalarization. |
required |
reference_point
|
dict[str, float]
|
a dict with keys corresponding to objective function symbols and values to reference point components, i.e., aspiration levels. |
required |
ideal
|
dict[str, float]
|
ideal point values. If not given, attempt will be made to calculate ideal point from problem. |
None
|
rho
|
float
|
a small scalar value to scale the sum in the objective function of the scalarization. Defaults to 1e-6. |
1e-06
|
delta
|
float
|
a small scalar value to define the utopian point. Defaults to 1e-6. |
1e-06
|
Returns:
| Type | Description |
|---|---|
tuple[Problem, str]
|
tuple[Problem, str]: a tuple with the copy of the problem with the added scalarization and the symbol of the added scalarization. |
Source code in desdeo/tools/scalarization.py
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 | |
add_stom_sf_nondiff
add_stom_sf_nondiff(
problem: Problem,
symbol: str,
reference_point: dict[str, float],
ideal: dict[str, float] | None = None,
rho: float = 1e-06,
delta: float = 1e-06,
) -> tuple[Problem, str]
Adds the non-differentiable variant of the STOM scalarizing function.
where \(f_i\) are objective functions, \(z_i^{\star\star} = z_i^\star - \delta\) is a component of the utopian point, \(\bar{z}_i\) is a component of the reference point, \(\rho\) and \(\delta\) are small scalar values, and \(S\) is the feasible solution space of the original problem.
References
H. Nakayama, Y. Sawaragi, Satisficing trade-off method for multiobjective programming, in: M. Grauer, A.P. Wierzbicki (Eds.), Interactive Decision Analysis, Springer Verlag, Berlin, 1984, pp. 113-122.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem the scalarization is added to. |
required |
symbol
|
str
|
the symbol given to the added scalarization. |
required |
reference_point
|
dict[str, float]
|
a dict with keys corresponding to objective function symbols and values to reference point components, i.e., aspiration levels. |
required |
ideal
|
dict[str, float]
|
ideal point values. If not given, attempt will be made to calculate ideal point from problem. |
None
|
rho
|
float
|
a small scalar value to scale the sum in the objective function of the scalarization. Defaults to 1e-6. |
1e-06
|
delta
|
float
|
a small scalar value to define the utopian point. Defaults to 1e-6. |
1e-06
|
Returns:
| Type | Description |
|---|---|
tuple[Problem, str]
|
tuple[Problem, str]: a tuple with the copy of the problem with the added scalarization and the symbol of the added scalarization. |
Source code in desdeo/tools/scalarization.py
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 | |
add_weighted_sums
add_weighted_sums(
problem: Problem, symbol: str, weights: dict[str, float]
) -> tuple[Problem, str]
Add the weighted sums scalarization to a problem with the given weights.
It is assumed that the weights add to 1.
The scalarization is defined as follows:
where \(\mathbf{w} = [w_1,\dots,w_k]\) are the weights and \(k\) is the number of objective functions.
Warning
The weighted sums scalarization is often not capable of finding most Pareto optimal solutions when optimized. It is advised to utilize some better scalarization functions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem to which the scalarization should be added. |
required |
symbol
|
str
|
the symbol to reference the added scalarization function. |
required |
weights
|
dict[str, float]
|
the weights. For the method to work, the weights should sum to 1. However, this is not a condition that is checked. |
required |
Raises:
| Type | Description |
|---|---|
ScalarizationError
|
if the weights are missing any of the objective components. |
Returns:
| Type | Description |
|---|---|
tuple[Problem, str]
|
tuple[Problem, str]: A tuple containing a copy of the problem with the scalarization function added, and the symbol of the added scalarization function. |
Source code in desdeo/tools/scalarization.py
create_epsilon_constraints_json
create_epsilon_constraints_json(
problem: Problem,
objective_symbol: str,
epsilons: dict[str, float],
) -> tuple[list[str | int | float], list[str]]
Creates JSON expressions for an epsilon constraints scalarization and constraints.
It is assumed that epsilon have been given in a format where each objective is to be minimized.
Warning
To be deprecated.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem to scalarize. |
required |
objective_symbol
|
str
|
the objective used as the objective in the epsilon constraint scalarization. |
required |
epsilons
|
dict[str, float]
|
the epsilon constraint values in a dict with each key being an objective's symbol. |
required |
Raises:
| Type | Description |
|---|---|
ScalarizationError
|
|
Returns:
| Type | Description |
|---|---|
tuple[list[str | int | float], list[str]]
|
tuple[list, list]: the first element is the expression of the scalarized objective expressed in MathJSON format. The second element is a list of expressions of the constraints expressed in MathJSON format. The constraints are in less than or equal format. |
Source code in desdeo/tools/scalarization.py
objective_dict_has_all_symbols
Check that a dict has all the objective function symbols of a problem as its keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem with the objective symbols. |
required |
obj_dict
|
dict[str, float]
|
a dict that should have a key for each objective symbol. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
whether all the symbols are present or not. |
Source code in desdeo/tools/scalarization.py
Gurobipy solver interfaces
Defines solver interfaces for gurobipy.
GurobipySolver
Bases: BaseSolver
Creates a gurobipy solver that utilizes gurobi's own Python implementation.
Source code in desdeo/tools/gurobipy_solver_interfaces.py
__init__
The solver is initialized by supplying a problem and options.
Unlike with Pyomo you do not need to have gurobi installed on your system for this to work. Suitable for solving mixed-integer linear and quadratic optimization problems.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem to be solved. |
required |
options
|
dict[str, any]
|
Dictionary of Gurobi parameters to set. You probably don't need to set any of these and can just use the defaults. For available parameters see https://www.gurobi.com/documentation/current/refman/parameters.html |
None
|
Source code in desdeo/tools/gurobipy_solver_interfaces.py
solve
Solve the problem for the given target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
the symbol of the function to be optimized, and which is defined in the problem given when initializing the solver. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SolverResults |
SolverResults
|
the results of the optimization. |
Source code in desdeo/tools/gurobipy_solver_interfaces.py
PersistentGurobipySolver
Bases: PersistentSolver
A persistent solver class utlizing gurobipy.
Use this instead of create_gurobipy_solver when re-initializing the solver every time the problem is changed is not practical.
Source code in desdeo/tools/gurobipy_solver_interfaces.py
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 | |
__init__
Initializer for the persistent solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem to be transformed in a GurobipyModel. |
required |
options
|
dict[str, any]
|
Dictionary of Gurobi parameters to set. You probably don't need to set any of these and can just use the defaults. For available parameters see https://www.gurobi.com/documentation/current/refman/parameters.html |
None
|
Source code in desdeo/tools/gurobipy_solver_interfaces.py
add_constraint
Add one or more constraint expressions to the solver.
If adding a lot of constraints or dealing with a large model, this function may end up being very slow compared to adding the constraints to the model stored in the evaluator directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraint
|
Constraint
|
the constraint function expression or a list of constraint function expressions. |
required |
Raises:
| Type | Description |
|---|---|
GurobipyEvaluatorError
|
when an unsupported constraint type is encountered. |
Returns:
| Type | Description |
|---|---|
Constr | list[Constr]
|
gurobipy.Constr: The gurobipy constraint that was added or a list of gurobipy constraints if the constraint argument was a list. |
Source code in desdeo/tools/gurobipy_solver_interfaces.py
add_objective
Adds an objective function expression to the solver.
Does not yet add any actual gurobipy optimization objectives, only adds them to the dict containing the expressions of the objectives. The objective expressions are stored in the evaluator and the evaluator must add the appropiate gurobipy objective before solving.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
objective
|
Objective
|
an objective function expression or a list of objective function expressions to be added. |
required |
Source code in desdeo/tools/gurobipy_solver_interfaces.py
add_scalarization_function
Adds a scalrization expression to the solver.
Scalarizations work identically to objectives, except they are stored in a different dict in the evaluator. If you want to solve the problem using a scalarization, the evaluator needs to set it as an optimization target first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scalarization
|
ScalarizationFunction
|
A scalarization function or a list of scalarization functions to be added. |
required |
Source code in desdeo/tools/gurobipy_solver_interfaces.py
add_variable
add_variable(
variable: Variable
| TensorVariable
| list[Variable]
| list[TensorVariable],
) -> gp.Var | gp.MVar | list[gp.Var] | list[gp.MVar]
Add one or more variables to the solver.
If adding a lot of variables or dealing with a large model, this function may end up being very slow compared to adding the variables to the model stored in the evaluator directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable
|
Variable
|
The definition of the variable or a list of variables to be added. |
required |
Raises:
| Type | Description |
|---|---|
GurobipyEvaluatorError
|
when a problem in extracting the variables is encountered. I.e., the variables are of a non supported type. |
Returns:
| Type | Description |
|---|---|
Var | MVar | list[Var] | list[MVar]
|
gp.Var: the variable that was added to the model or a list of variables if variable argument was a list. |
Source code in desdeo/tools/gurobipy_solver_interfaces.py
remove_constraint
Removes a constraint from the solver.
If removing a lot of constraints or dealing with a very large model this function may be slow because of the model.update() calls. Accessing the model stored in the evaluator directly may be faster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
a str representing the symbol of the constraint to be removed. Can also be a list of multiple symbols. |
required |
Source code in desdeo/tools/gurobipy_solver_interfaces.py
remove_variable
Removes a variable from the model.
If removing a lot of variables or dealing with a very large model this function may be slow because of the model.update() calls. Accessing the model stored in the evaluator directly may be faster.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
a str representing the symbol of the variable to be removed. Can also be a list of multiple symbols. |
required |
Source code in desdeo/tools/gurobipy_solver_interfaces.py
solve
Solves the current problem with the specified target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
a str representing the symbol of the target function. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SolverResults |
SolverResults
|
The results of the solver |
Source code in desdeo/tools/gurobipy_solver_interfaces.py
_constraint_contains_objective
Check if a constraint's function contains a specific objective symbol.
Source code in desdeo/tools/gurobipy_solver_interfaces.py
check_gurobi_license
Check if Gurobi is using a full license (not trial).
Returns:
| Type | Description |
|---|---|
|
True if using full academic/commercial license |
|
|
False if using trial license or no license found |
Source code in desdeo/tools/gurobipy_solver_interfaces.py
parse_gurobipy_optimizer_results
Parses results from GurobipyEvaluator's model into DESDEO SolverResults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem being solved. |
required |
evaluator
|
GurobipyEvaluator
|
the evaluator utilized to solve the problem. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SolverResults |
SolverResults
|
DESDEO solver results. |
Source code in desdeo/tools/gurobipy_solver_interfaces.py
Nevergrad solver interfaces
Solver interfaces to the optimization routines found in nevergrad.
For more info, see https://facebookresearch.github.io/nevergrad/index.html
_default_nevergrad_generic_options
module-attribute
The set of default options for nevergrad's NgOpt optimizer.
NevergradGenericOptions
Bases: BaseModel
Defines options to be passed to nevergrad's optimization routines.
Source code in desdeo/tools/ng_solver_interfaces.py
budget
class-attribute
instance-attribute
budget: int = Field(
description="The maximum number of allowed function evaluations.",
default=100,
)
The maximum number of allowed function evaluations. Defaults to 100.
num_workers
class-attribute
instance-attribute
num_workers: int = Field(
description="The maximum number of allowed parallel evaluations.",
default=1,
)
The maximum number of allowed parallel evaluations. This is currently used to define the batch size when evaluating problems. Defaults to 1.
optimizer
class-attribute
instance-attribute
optimizer: Literal[*available_nevergrad_optimizers,] = (
Field(
description="The optimizer to be used. Must be one of `NGOpt`, `TwoPointDE`, `PortfolioDiscreteOnePlusOne`, `OnePlusOne`, `CMA`, `TBPSA`, `PSO`, `ScrHammersleySearchPlusMiddlePoint`, or `RandomSearch`. Defaults to `NGOpt`.",
default="NGOpt",
)
)
The optimizer to be used. Must be one of NGOpt, TwoPointsDE, PortfolioDiscreteOnePlusOne,
OnePlusOne, CMA, TBPSA, PSO, ScrHammersleySearchPlusMiddlePoint, or RandomSearch.
Defaults to NGOpt.
NevergradGenericSolver
Bases: BaseSolver
Creates a solver that utilizes optimizations routines found in the nevergrad library.
Source code in desdeo/tools/ng_solver_interfaces.py
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 | |
__init__
__init__(
problem: Problem,
options: NevergradGenericOptions
| None = _default_nevergrad_generic_options,
)
Creates a solver that utilizes optimizations routines found in the nevergrad library.
These solvers are best utilized for black-box, gradient free optimization with
computationally expensive function calls. Utilizing multiple workers is recommended
(see NevergradGenericOptions) when function calls are heavily I/O bound.
See https://facebookresearch.github.io/nevergrad/getting_started.html for further information on nevergrad and its solvers.
References
Rapin, J., & Teytaud, O. (2018). Nevergrad - A gradient-free optimization platform. GitHub. https://GitHub.com/FacebookResearch/Nevergrad
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem to be solved. |
required |
options
|
NgOptOptions | None
|
options to be passes to the solver.
If none, |
_default_nevergrad_generic_options
|
Source code in desdeo/tools/ng_solver_interfaces.py
solve
Solve the problem for the given target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
the symbol of the objective function to be optimized. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SolverResults |
SolverResults
|
the results of the optimization. |
Source code in desdeo/tools/ng_solver_interfaces.py
parse_ng_results
Parses the optimization results returned by nevergrad solvers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
dict
|
the results. A dict with at least the keys
|
required |
problem
|
Problem
|
the problem the results belong to. |
required |
evaluator
|
GenericEvaluator
|
the evaluator used to evaluate the problem. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SolverResults |
SolverResults
|
a pydantic dataclass withthe relevant optimization results. |
Source code in desdeo/tools/ng_solver_interfaces.py
Scipy solver interfaces
Solver interfaces to the optimization routines found in scipy.
These solvers can solve various scalarized problems of multiobjective optimization problems.
EvalTargetEnum
Bases: str, Enum
An enum that describe whether the evaluator target is an objective or a constraint.
Source code in desdeo/tools/scipy_solver_interfaces.py
ScipyDeOptions
Bases: BaseModel
Defines a pydantic model to store and pass options to the Scipy differential evolution solver.
Source code in desdeo/tools/scipy_solver_interfaces.py
ScipyDeSolver
Bases: BaseSolver
Creates a scipy solver that utilizes differential evolution.
Source code in desdeo/tools/scipy_solver_interfaces.py
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 | |
__init__
Creates a solver that utilizes the scipy.optimize.differential_evolution routine.
The scipy.optimize.differential_evolution routine is fully accessible through this function.
For additional details and explanation of some of the argumetns, see
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.differential_evolution.html
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the multiobjective optimization problem to be solved. |
required |
options
|
ScipyDeOptions
|
Pydantic model containing arguments used by scipy DE solver. |
_default_scipy_de_options
|
Source code in desdeo/tools/scipy_solver_interfaces.py
solve
Solve the problem for a given target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
the symbol of the objective function to be optimized. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SolverResults |
SolverResults
|
results of the optimization. |
Source code in desdeo/tools/scipy_solver_interfaces.py
ScipyMinimizeOptions
Bases: BaseModel
Defines a pydantic model to store and pass options to the Scipy Minimize solver.
Source code in desdeo/tools/scipy_solver_interfaces.py
ScipyMinimizeSolver
Bases: BaseSolver
Creates a scipy solver that utilizes the minimization routine.
Source code in desdeo/tools/scipy_solver_interfaces.py
__init__
Initializes a solver that utilizes the scipy.optimize.minimize routine.
The scipy.optimize.minimze routine is fully accessible through this function.
For additional details and explanation of some of the argumetns, see
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html#scipy.optimize.minimize
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the multiobjective optimization problem to be solved. |
required |
options
|
ScipyMinimizeOptions
|
(ScipyMinimizeOptions): Pydantic model containing args for scipy minimize solver. |
_default_scipy_minimize_options
|
Source code in desdeo/tools/scipy_solver_interfaces.py
solve
Solves the problem for a given target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
the sumbol of the objective function to be optimized. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SolverResults |
SolverResults
|
results of the optimization. |
Source code in desdeo/tools/scipy_solver_interfaces.py
create_scipy_dict_constraints
Creates a dict with scipy compatible constraints.
It is assumed that there are constraints defined in problem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the Problem with the constraints. |
required |
evaluator
|
GenericEvaluator
|
the evaluator utilized to evaluate problem. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
a dict with scipy compatible constraints. |
Source code in desdeo/tools/scipy_solver_interfaces.py
create_scipy_object_constraints
create_scipy_object_constraints(
problem: Problem, evaluator: PolarsEvaluator
) -> list[NonlinearConstraint]
Creates a list with scipy constraint object NonLinearConstraints used by some scipy routines.
For more infor, see https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.NonlinearConstraint.html#scipy-optimize-nonlinearconstraint
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem with the original constraint to be utilized in creating the list of constraints. |
required |
evaluator
|
GenericEvaluator
|
the evaluator corresponding to problem that can be used to evaluate the constraints. |
required |
Returns:
| Type | Description |
|---|---|
list[NonlinearConstraint]
|
list[NonlinearConstraint]: a list of scipy's NonLinearConstraint objects. |
Source code in desdeo/tools/scipy_solver_interfaces.py
get_scipy_eval
get_scipy_eval(
problem: Problem,
evaluator: PolarsEvaluator,
target: str,
eval_target: EvalTargetEnum,
) -> Callable[[list[float | int]], list[float | int]]
Wraps the problem and evaluator into a callable function that can be used by scipy routines.
The returned function expects an array-like argument, such as a numpy array or list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem being solved. |
required |
evaluator
|
GenericEvaluator
|
the evaluator to evaluate the problem being solved. |
required |
target
|
str
|
the symbol of the objective to of the optimization, defined in problem. |
required |
eval_target
|
EvalTargetEnum
|
either objective or constraints. If objective, it is assumed that the evalution is about evaluating the objective function of the single-objective optimization problem being solved, e.g., a scalarization function defined in problem. If constraint, then the evalution is assumed to be about evaluating the constraints defined in problem. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[list[float | int]], list[float | int]]
|
Callable[[list[float | int]], list[float | int]]: a function that takes as its argument an array like object. |
Note
Constraints in scipy are defined such that a positive number means the constraint is respected. In DESDEO, this is the opposite, e.g., a positive number means a constraint is breached. We take this into account when returning the constraint values, but this does not affect the constraint values computed for the true constraints.
Source code in desdeo/tools/scipy_solver_interfaces.py
get_variable_bounds_pairs
Returns the variable bounds defined in a Problem as a list of tuples.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem with the variables of interest. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[float | int, float | int]]
|
list[tuple[float | int, float | int]]: a list of tuples, the first element of each tuple is the lower bound of a variable and the second its upper bound. Each tuple corresponds to a variable. |
Source code in desdeo/tools/scipy_solver_interfaces.py
parse_scipy_optimization_result
parse_scipy_optimization_result(
optimization_result: OptimizeResult,
problem: Problem,
evaluator: PolarsEvaluator,
) -> SolverResults
Parses the optimization results returned by various scipy methods.
For documentation, see https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.OptimizeResult.html#scipy.optimize.OptimizeResult
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
optimization_result
|
OptimizeResult
|
the optimization results. |
required |
problem
|
Problem
|
the problem to which the optimization results correspond to. |
required |
evaluator
|
GenericEvaluator
|
the evaluator that has been used in computing the optimization results. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SolverResults |
SolverResults
|
a pydantic dataclass with the relevant optimization results. |
Source code in desdeo/tools/scipy_solver_interfaces.py
set_initial_guess
Sets or gets the initial guess for each variable defined in a Problem.
For variables without initial guess, the initial guess is set to be the middle point of said variable's lower and upper bound.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem with the variables of which the initial values are of interest. |
required |
Returns:
| Type | Description |
|---|---|
list[float | int]
|
list[float | int]: a list of numbers, each number represents the initial guess of each variable in the problem. |
Source code in desdeo/tools/scipy_solver_interfaces.py
Pyomo solver interfaces
Defines solver interfaces for pyomo.
_default_bonmin_options
module-attribute
Defines Bonmin options with default values.
_default_cbc_options
module-attribute
Defines CBC options with default values.
_default_ipopt_options
module-attribute
Defines Ipopt optins with default values.
BonminOptions
Bases: BaseModel
Defines a pydantic model to store and pass options to the Bonmin solver.
Because Bonmin utilizes many sub-solver, the options specific to Bonmin
must be prefixed in their name with 'bonmin.{option_name}',
e.g., bonmin.integer_tolerance. For a list of options, see
https://www.coin-or.org/Bonmin/options_list.html
Note
Not all options are available through this model. Please add options as they are needed and make a pull request.
Source code in desdeo/tools/pyomo_solver_interfaces.py
bonmin_algorithm
class-attribute
instance-attribute
bonmin_algorithm: str = Field(
description="Presets some of the options in Bonmin based on the algorithm choice. Defaults to 'B-BB'. A good first option to try is 'B-Hyb'.",
default="B-BB",
)
Presets some of the options in Bonmin based on the algorithm choice. Defaults to 'B-BB'. A good first option to try is 'B-Hyb'.
bonmin_integer_tolerance
class-attribute
instance-attribute
bonmin_integer_tolerance: float = Field(
description="Numbers within this value of an integer are considered integers. Defaults to 1e-6.",
default=1e-06,
)
Numbers within this value of an integer are considered integers. Defaults to 1e-6.
tol
class-attribute
instance-attribute
tol: float = Field(
description="Sets the convergence tolerance of ipopt. Defaults to 1e-8.",
default=1e-08,
)
Sets the convergence tolerance of ipopt. Defaults to 1e-8.
asdict
Converts the Pydantic model into a dict so that Bonmin specific options are in the correct format.
This means that the attributes starting with bonmin_optionname will be
converted to keys in the format bonmin.optionname in the returned dict.
Source code in desdeo/tools/pyomo_solver_interfaces.py
CbcOptions
Bases: BaseModel
Defines a pydantic dataclass to pass options to the CBC solver.
For more information and documentation on the options, see https://github.com/coin-or/Cbc
Note
Not all options are available through this model. Please add options as they are needed and make a pull request.
Source code in desdeo/tools/pyomo_solver_interfaces.py
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 | |
absolute_gap
class-attribute
instance-attribute
absolute_gap: float = Field(
alias="absoluteGap",
description="Sets the absolute MIP gap (an absolute value) at which the solver will terminate. Defaults to 1.0.",
default=1.0,
)
Sets the absolute MIP gap (an absolute value) at which the solver will terminate. Defaults to 1.0.
feasibility_tolerance
class-attribute
instance-attribute
feasibility_tolerance: float = Field(
alias="feasibilityTolerance",
description="Sets the feasibility tolerance for constraints. Defaults to 1e-6.",
default=1e-06,
)
Sets the feasibility tolerance for constraints. Defaults to 1e-6.
integer_tolerance
class-attribute
instance-attribute
integer_tolerance: float = Field(
alias="integerTolerance",
description="Sets the tolerance for integrality of integer variables. Defaults to 1e-5.",
default=1e-05,
)
Sets the tolerance for integrality of integer variables. Defaults to 1e-5.
log_level
class-attribute
instance-attribute
log_level: int = Field(
alias="logLevel",
description="Controls the level of logging output. Values range from 0 (no output) to 5 (very detailed output). Defaults to 2.",
default=2,
)
Controls the level of logging output. Values range from 0 (no output) to 5 (very detailed output). Defaults to 2.
max_nodes
class-attribute
instance-attribute
max_nodes: int = Field(
alias="maxNodes",
description="Sets the maximum number of branch-and-bound nodes to explore. Defaults to 1000.",
default=1000,
)
Sets the maximum number of branch-and-bound nodes to explore. Defaults to 1000.
max_solutions
class-attribute
instance-attribute
max_solutions: int = Field(
alias="maxSolutions",
description="Limits the number of feasible solutions found by the solver. Defaults to 10.",
default=10,
)
Limits the number of feasible solutions found by the solver. Defaults to 10.
presolve
class-attribute
instance-attribute
presolve: int = Field(
description="Controls the presolve level (0: no presolve, 1: default, 2: aggressive). Defaults to 2.",
default=2,
)
Controls the presolve level (0: no presolve, 1: default, 2: aggressive). Defaults to 2.
ratio_gap
class-attribute
instance-attribute
ratio_gap: float = Field(
alias="ratioGap",
description="Sets the relative MIP gap (as a fraction of the optimal solution value) at which the solver will terminate. Defaults to 0.01.",
default=0.01,
)
Sets the relative MIP gap (as a fraction of the optimal solution value) at which the solver will terminate. Defaults to 0.01.
seconds
class-attribute
instance-attribute
seconds: int = Field(
description="The maximum amount of time (in seconds) the solver should run. Defaults to 600.",
default=600,
)
The maximum amount of time (in seconds) the solver should run. Defaults to 600.
solve
class-attribute
instance-attribute
solve: str = Field(
description="Determines the strategy to use for solving the problem (e.g., 'branchAndCut', 'tree', 'trunk'). Defaults to 'branchAndCut'.",
default="branchAndCut",
)
Determines the strategy to use for solving the problem (e.g., 'branchAndCut', 'tree', 'trunk'). Defaults to 'branchAndCut'.
IpoptOptions
Bases: BaseModel
Defines a pydantic dataclass to pass options to the Ipopt solver.
For more information and documentation on the options, see https://coin-or.github.io/Ipopt/
Note
Not all options are available through this model. Please add options as they are needed and make a pull request.
Source code in desdeo/tools/pyomo_solver_interfaces.py
max_iter
class-attribute
instance-attribute
max_iter: int = Field(
description="Maximum number of iterations. Must be >1. Defaults to 3000.",
default=3000,
)
Maximum number of iterations. Must be >1. Defaults to 3000.
PyomoBonminSolver
Bases: BaseSolver
Creates pyomo solvers that utilize bonmin.
Source code in desdeo/tools/pyomo_solver_interfaces.py
__init__
The solver is initialized with a problem and solver options.
Suitable for mixed-integer problems. The objective function being minimized (target) and the constraint functions must be twice continuously differentiable. When the objective functions and constraints are convex, the solution is exact. When the objective or any of the constraints, or both, are non-convex, then the solution is based on heuristics.
For more info about bonmin, see: https://www.coin-or.org/Bonmin/
Note
Bonmin must be installed on the system running DESDEO, and its executable must be defined in the PATH.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem to be solved. |
required |
options
|
BonminOptions
|
options to be passed to the Bonmin solver.
If |
_default_bonmin_options
|
Source code in desdeo/tools/pyomo_solver_interfaces.py
solve
Solve the problem for a given target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
the symbol of the objective function to be optimized. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SolverResults |
SolverResults
|
the results of the optimization. |
Source code in desdeo/tools/pyomo_solver_interfaces.py
PyomoCBCSolver
Bases: BaseSolver
Create a pyomo solver that utilizes CBC.
Source code in desdeo/tools/pyomo_solver_interfaces.py
__init__
The solver is initialized with a problem and solver options.
Suitable for combinatorial and large-scale mixed-integer linear problems.
For more information, see https://coin-or.github.io/Ipopt/
Note
CBC must be installed on the system running DESDEO, and its executable must be defined in the PATH.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem being solved. |
required |
options
|
CbcOptions
|
options to be passed to the CBC solver.
If |
_default_cbc_options
|
Source code in desdeo/tools/pyomo_solver_interfaces.py
solve
Solve the problem for a given target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
the symbol of the objective function to be optimized. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SolverResults |
SolverResults
|
results of the Optimization. |
Source code in desdeo/tools/pyomo_solver_interfaces.py
PyomoGurobiSolver
Bases: BaseSolver
Creates a pyomo solver that utilized Gurobi.
Source code in desdeo/tools/pyomo_solver_interfaces.py
__init__
Creates a pyomo solver that utilizes gurobi.
You need to have gurobi installed on your system for this to work.
Suitable for solving mixed-integer linear and quadratic optimization problems.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem to be solved. |
required |
options
|
GurobiOptions
|
Dictionary of Gurobi parameters to set. This is passed to pyomo as is, so it works the same as options would for calling pyomo SolverFactory directly. See https://www.gurobi.com/documentation/current/refman/parameters.html for information on the available options |
None
|
Source code in desdeo/tools/pyomo_solver_interfaces.py
solve
Solve the problem for a given target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
the symbol of the objective function to be optimized. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SolverResults |
SolverResults
|
the results of the optimization. |
Source code in desdeo/tools/pyomo_solver_interfaces.py
PyomoIpoptSolver
Bases: BaseSolver
Create a pyomo solver that utilizes Ipopt.
Source code in desdeo/tools/pyomo_solver_interfaces.py
__init__
The solver is initialized with a problem and solver options.
Suitable for non-linear, twice differentiable constrained problems. The problem may be convex or non-convex.
For more information, see https://coin-or.github.io/Ipopt/
Note
Ipopt must be installed on the system running DESDEO, and its executable must be defined in the PATH.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem being solved. |
required |
options
|
IpoptOptions
|
options to be passed to the Ipopt solver.
If |
_default_ipopt_options
|
Source code in desdeo/tools/pyomo_solver_interfaces.py
solve
Solve the problem for a given target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
the symbol of the objective function to be optimized. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SolverResults |
SolverResults
|
results of the Optimization. |
Source code in desdeo/tools/pyomo_solver_interfaces.py
parse_pyomo_optimizer_results
parse_pyomo_optimizer_results(
opt_res: SolverResults,
problem: Problem,
evaluator: PyomoEvaluator,
) -> SolverResults
Parses pyomo SolverResults into DESDEO SolverResults.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
opt_res
|
SolverResults
|
the pyomo solver results. |
required |
problem
|
Problem
|
the problem being solved. |
required |
evaluator
|
PyomoEvaluator
|
the evaluator utilized to get the pyomo solver results. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SolverResults |
SolverResults
|
DESDEO solver results. |
Source code in desdeo/tools/pyomo_solver_interfaces.py
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 | |
Proximal solver
Defines solvers meant to be utilized with Problems with discrete representations.
ProximalSolver
Bases: BaseSolver
Creates a solver that finds the closest solution given a fully discrete problem.
Note
This solver is extremely naive. It will optimize the problem and the result will be a point defined for a discrete problem that is closest (Euclidean distance) to the optimum. The result may be wildly inaccurate depending on how representative the discrete points are of the original problem.
Source code in desdeo/tools/proximal_solver.py
__init__
Creates a solver that assumes the problem being a fully discrete one.
Assumes that problem has only data-based objectives and a discrete definition that fully defines all the objectives.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem being solved. |
required |
kwargs
|
Optional[dict]
|
optional keyword arguments. Not used right now, but kept here for compatibility reasons. Defaults to None. |
None
|
Source code in desdeo/tools/proximal_solver.py
solve
Solve the problem for the given target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
the symbol of the objective function to be optimized. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SolverResults |
SolverResults
|
the results fo the optimization. |
Source code in desdeo/tools/proximal_solver.py
Publisher-Subscriber pattern
This module contains the classes for the publisher-subscriber (ish) pattern.
The pattern is used in the evolutionary algorithms to send messages between the different components. This allows the components to be decoupled and the messages to be sent between them without the components knowing about each other. The pattern closely resembles the publisher-subscriber pattern, with one key difference. The subscribers can also create messages and send them to the publisher, which then forwards the messages to the other subscribers.
The pattern is implemented with two classes: Subscriber and Publisher. The Subscriber class is an abstract
class that must be inherited by the classes that want to receive (or send) messages. All evolutionary operators
must inherit the Subscriber class. Some objects that may be interested in the messages, but otherwise unrelated
to the evolutionary operators, may also inherit the Subscriber class. Examples of such objects are a logging class,
an archive class, or a class that visualizes intermediate results.
The Publisher class is a class that stores the subscribers and forwards the messages to them. The Publisher class
is not connected to the evolutionary algorithms and only serves as a message router. As mentioned earlier, the
components do not know about each other, and the Publisher class is the only class that knows about all the
connections in between components. The user of the evolutionary algorithms is responsible for creating the connections.
However, the implementations of the operators do provide default, so called topics that the operator must subscribe to.
The way the pattern works is as follows. Each operator has a do method which is called by the evolutionary algorithm
when the operator is to be executed. This method has some default arguments, depending upon the class of the operator.
E.g., the do method of the mutation related classes may have a default arguments as offsprings and parents, where
each is a tuple of decision variables, objectives, and constraints. However, some special mutation operator may require
additional inputs. E.g., an adaptive mutation operator may require the current generation number as an input. To provide
this additional input, we do not change the signature of the do method.
Instead, we let the mutation operator subscribe to a topic called, e.g., current_generation. The publisher, is then
responsible for sending the current generation number to the mutation operator, whenever the generation number changes.
The mutation operator can then update its internal state based on the received generation number.
To be able to send this information, the Publisher class has a method called notify. Operators can call this method
to send messages to the subscribers. The idea is to do this at the end of the do method. That way, whenever any
operator is executed, it can send messages to the other operators (which have subscribed to the topics).
Note that the operators do not know about the other operators. The subscribers do not know the origin of the messages. This decoupling allows for a more modular design and easier extensibility of the evolutionary algorithms.
Publisher
Class for a publisher that sends messages to subscribers.
The publisher is unconnected from the evolutionary algorithms and only serves as a message router. The subscribers can subscribe to different message keys and receive messages when the publisher receives a message with the corresponding key.
Source code in desdeo/tools/patterns.py
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 | |
__init__
auto_subscribe
Store a subscriber for multiple message keys. The subscriber must have the topics attribute.
Whenever the publisher receives a message with the given key, it will notify the subscriber.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subscriber
|
Subscriber
|
the subscriber to notify. |
required |
Source code in desdeo/tools/patterns.py
check_consistency
Check if all subscribed topics have also been registered by a source.
Returns:
| Type | Description |
|---|---|
tuple[bool, dict[MessageTopics, list[str]]]
|
tuple[bool, dict[MessageTopics, list[str]]]: Returns a tuple. The first element is a bool. True if all subscribed topics have been registered by a source. False otherwise. The second element is a dictionary of unregistered topics that have been subscribed to. |
Source code in desdeo/tools/patterns.py
force_unsubscribe
Remove a subscriber from all message keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subscriber
|
Subscriber
|
the subscriber to remove. |
required |
Source code in desdeo/tools/patterns.py
notify
Notify subscribers of the received message/messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
Sequence[BaseMessage]
|
the messages to send to the subscribers. Each message is a pydantic model with a topic, value, and a source. |
required |
Source code in desdeo/tools/patterns.py
register_topics
Register topics provided to the publisher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
topics
|
list[MessageTopics]
|
the topics to register. |
required |
source
|
str
|
the source of the topics. |
required |
Source code in desdeo/tools/patterns.py
relationship_map
Make a diagram connecting sources to subscribers based on topics.
Source code in desdeo/tools/patterns.py
subscribe
Store a subscriber for a given message key.
Whenever the publisher receives a message with the given key, it will notify the subscriber. This method can be used to subscribe to multiple topics by calling it multiple times. Moreover, the user can force the subscriber to receive all messages by setting the topic to "ALL".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subscriber
|
Subscriber
|
the subscriber to notify. |
required |
topic
|
str
|
the message topic (key in message dictionary) to subscribe to. If "ALL", the subscriber is notified of all messages. |
required |
Source code in desdeo/tools/patterns.py
unsubscribe
Remove a subscriber from a given message key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subscriber
|
Subscriber
|
the subscriber to remove. |
required |
topic
|
str
|
the key of the message to unsubscribe from. |
required |
Source code in desdeo/tools/patterns.py
unsubscribe_multiple
Remove a subscriber from multiple message keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subscriber
|
Subscriber
|
the subscriber to remove. |
required |
topics
|
list[str]
|
the keys of the messages to unsubscribe from. |
required |
Source code in desdeo/tools/patterns.py
Subscriber
Bases: ABC
Base class for both subscriber and message sender.
These are used in the evolutionary algorithms to send messages between the different components. The pattern closely resembles the publisher-subscriber pattern, with one key difference. The subscribers can also create messages and send them to the publisher, which then forwards the messages to the other subscribers.
Source code in desdeo/tools/patterns.py
interested_topics
abstractmethod
property
Return the topics the subscriber is interested in.
provided_topics
abstractmethod
property
Return the topics the subscriber provides to the publisher, grouped by verbosity level.
__init__
Initialize a subscriber.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
publisher
|
Callable
|
the publisher to send messages to. |
required |
verbosity
|
int
|
the verbosity level of the messages. A value of 0 means no messages at all. |
required |
Source code in desdeo/tools/patterns.py
notify
Notify the publisher of changes in the subject.
The contents of the message (a dictionary) are defined in the state method. The state method can return
different messages depending on the verbosity level.
Source code in desdeo/tools/patterns.py
state
abstractmethod
update
abstractmethod
Update self as a result of messages from the publisher.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
Message
|
the message from the publisher. Note that each message is a pydantic model with a topic, value, and a source. |
required |
Source code in desdeo/tools/patterns.py
createblanksubs
Create a blank subscriber for testing purposes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interested_topics
|
list[MessageTopics]
|
the topics the subscriber is interested in. |
required |
Returns:
| Type | Description |
|---|---|
type[Subscriber]
|
type[Subscriber]: the blank subscriber class. |
Source code in desdeo/tools/patterns.py
Message Topics
Defines the messaging protocol used by the various EMO operators.
Array2DMessage
Bases: BaseMessage
A message containing a 2D array value, such as a population or a set of objectives.
Source code in desdeo/tools/message.py
BaseMessage
Bases: BaseModel
A message containing an integer value.
Source code in desdeo/tools/message.py
BoolMessage
CrossoverMessageTopics
Bases: Enum
Topics for messages related to crossover operators.
Source code in desdeo/tools/message.py
LAMBDA
class-attribute
instance-attribute
Lambda parameter used in crossover. Primarily used in the bounded exponential xover.
OFFSPRINGS
class-attribute
instance-attribute
The offsprings generated from the crossover.
TEST
class-attribute
instance-attribute
A message topic used only for testing the crossover operators.
XOVER_DISTRIBUTION
class-attribute
instance-attribute
The current crossover distribution index. Primary used in the SBX crossover.
DictMessage
EvaluatorMessageTopics
Bases: Enum
Topics for messages related to evaluator operators.
Source code in desdeo/tools/message.py
CONSTRAINTS
class-attribute
instance-attribute
The constraints of the population.
NEW_EVALUATIONS
class-attribute
instance-attribute
The number of new evaluations.
OBJECTIVES
class-attribute
instance-attribute
The true objective values of the population.
OUTPUTS
class-attribute
instance-attribute
The outputs of the population. Contains objectives, targets, constraints.
TARGETS
class-attribute
instance-attribute
The targets, i.e., objective values seen by the evolutionary operators.
TEST
class-attribute
instance-attribute
A message topic used only for testing the evaluator operators.
FloatMessage
GeneratorMessageTopics
Bases: Enum
Topics for messages related to population generator operators.
Source code in desdeo/tools/message.py
CONSTRAINTS
class-attribute
instance-attribute
The constraints of the population.
NEW_EVALUATIONS
class-attribute
instance-attribute
The number of new evaluations.
OBJECTIVES
class-attribute
instance-attribute
The true objective values of the population.
OUTPUTS
class-attribute
instance-attribute
The outputs of the population generation. Contains objectives, targets, and constraints.
TARGETS
class-attribute
instance-attribute
The targets, i.e., objective values seen by the evolutionary operators.
TEST
class-attribute
instance-attribute
A message topic used only for testing the evaluator operators.
GenericMessage
IntMessage
MutationMessageTopics
Bases: Enum
Topics for messages related to mutation operators.
Source code in desdeo/tools/message.py
MUTATION_DISTRIBUTION
class-attribute
instance-attribute
The current mutation distribution index. Primary used in the polynomial mutation.
MUTATION_PROBABILITY
class-attribute
instance-attribute
The current mutation probability.
OFFSPRINGS
class-attribute
instance-attribute
The offsprings after mutation.
OFFSPRING_ORIGINAL
class-attribute
instance-attribute
The original offsprings before mutation.
NumpyArrayMessage
Bases: BaseMessage
A message containing a numpy array value.
Source code in desdeo/tools/message.py
PolarsDataFrameMessage
Bases: BaseMessage
A message containing a 2D array value, such as a population or a set of objectives.
Source code in desdeo/tools/message.py
ReferenceVectorMessageTopics
SelectorMessageTopics
Bases: Enum
Topics for messages related to selector operators.
Source code in desdeo/tools/message.py
CONSTRAINTS
class-attribute
instance-attribute
The constraints of the individuals.
INDIVIDUALS
class-attribute
instance-attribute
The individuals to select from.
REFERENCE_VECTORS
class-attribute
instance-attribute
The reference vectors used in the selection in decomposition-based EMO algorithms.
SELECTED_FITNESS
class-attribute
instance-attribute
The fitness of the selected individuals. This is the fitness calculated by the selector, not the objectives.
SELECTED_INDIVIDUALS
class-attribute
instance-attribute
The individuals selected by the selector.
SELECTED_OUTPUTS
class-attribute
instance-attribute
The targets of the selected individuals.
SELECTED_VERBOSE_OUTPUTS
class-attribute
instance-attribute
Same as SELECTED_OUTPUTS + SELECTED_INDIVIDUALS
STATE
class-attribute
instance-attribute
The state of the parameters of the selector.
StringMessage
TerminatorMessageTopics
Bases: Enum
Topics for messages related to terminator operators.
Source code in desdeo/tools/message.py
EVALUATION
class-attribute
instance-attribute
The current number of evaluations.
GENERATION
class-attribute
instance-attribute
The current generation number.
MAX_EVALUATIONS
class-attribute
instance-attribute
The maximum number of evaluations.
MAX_GENERATIONS
class-attribute
instance-attribute
The maximum number of generations.
STATE
class-attribute
instance-attribute
The state of the parameters of the terminator.
TERMINATION
class-attribute
instance-attribute
The value of the termination condition.
Utilities
General utilities related to solvers.
find_compatible_solvers
Find solvers that are compatible with the problem that is being solved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
The problem being solved. |
required |
Returns:
| Type | Description |
|---|---|
list[BaseSolver]
|
list[BaseSolver]: A list of solvers that are compatible with the problem. |
Source code in desdeo/tools/utils.py
flip_maximized_objective_values
flip_maximized_objective_values(
problem: Problem, objective_values: dict[str, float]
) -> dict[str, float]
Flips the objective values if the objective function is to be maximized.
Flips the objective values if the objective function is to be maximized by multiplying the values related to maximized objective functions by -1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem the objective values are related to. |
required |
objective_values
|
dict[str, float]
|
the objective values to be flipped. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
dict[str, float]: the flipped objective values. |
Source code in desdeo/tools/utils.py
get_corrected_ideal
Compute the corrected ideal point depending if an objective function is to be maximized or not.
I.e., the ideal point element for objectives to be maximized will be multiplied by -1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem with the ideal point. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
some of the ideal point components have not been defined for some of the objectives. |
Returns:
| Type | Description |
|---|---|
dict[str, float | None]
|
list[float]: a list with the corrected ideal point. Will return None for missing elements. |
Source code in desdeo/tools/utils.py
get_corrected_ideal_and_nadir
get_corrected_ideal_and_nadir(
problem: Problem,
) -> tuple[
dict[str, float | None], dict[str, float | None] | None
]
Compute the corrected ideal and nadir points depending if an objective function is to be maximized or not.
I.e., the ideal and nadir point element for objectives to be maximized will be multiplied by -1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem with the ideal and nadir points. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
some of the ideal or nadir point components have not been defined for some of the objectives. |
Returns:
| Type | Description |
|---|---|
tuple[dict[str, float | None], dict[str, float | None] | None]
|
tuple[list[float], list[float]]: a list with the corrected ideal point and a list with the corrected nadir point. Will return None for missing elements. |
Source code in desdeo/tools/utils.py
get_corrected_nadir
Compute the corrected nadir point depending if an objective function is to be maximized or not.
I.e., the nadir point element for objectives to be maximized will be multiplied by -1.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem with the nadir points. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
some of the nadir point components have not been defined for some of the objectives. |
Returns:
| Type | Description |
|---|---|
dict[str, float | None]
|
list[float]: a list with the corrected nadir point. Will return None for missing elements. |
Source code in desdeo/tools/utils.py
guess_best_solver
Given a problem, tries to guess the best solver to handle it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
the problem being solved. |
required |
Note
Needs to be extended as new solvers are implemented.
Returns:
| Name | Type | Description |
|---|---|---|
BaseSolver |
BaseSolver
|
a solver class that uses BaseSolver as a base class |
Source code in desdeo/tools/utils.py
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 | |
payoff_table_method
payoff_table_method(
problem: Problem, solver: BaseSolver = None
) -> tuple[dict[str, float], dict[str, float]]
Solves a representation for the ideal and nadir points for a multiobjective optimization problem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
The problem for which the ideal and nadir are solved. |
required |
solver
|
BaseSolver
|
The solver to be used in solving the points. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[dict[str, float], dict[str, float]]
|
tuple[dict[str, float], dict[str, float]]: The estimated ideal and nadir points. |
Source code in desdeo/tools/utils.py
repair
repair(
lower_bounds: dict[str, float],
upper_bounds: dict[str, float],
) -> Callable[[pl.DataFrame], pl.DataFrame]
Repairs the offspring by clipping the values to be within the specified bounds.
Useful in evolutionary algorithms where offspring may go out of bounds due to crossover or mutation operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lower_bounds
|
dict[str, float]
|
The lower bounds for each variable. |
required |
upper_bounds
|
dict[str, float]
|
The upper bounds for each variable. |
required |
Returns:
| Type | Description |
|---|---|
Callable[[DataFrame], DataFrame]
|
Callable[[pl.DataFrame], pl.DataFrame]: A function that takes a DataFrame and returns a repaired DataFrame. |
Source code in desdeo/tools/utils.py
Generics
Defines generic classes, functions, and objects utilized in the tools module.
BaseSolver
Bases: ABC
Defines a schema for a solver base class.
Source code in desdeo/tools/generics.py
__init__
Initializer for the persistent solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
The problem for the solver. |
required |
options
|
dict[str, any]
|
Dictionary of parameters to set. What these should be depends on the solver used. |
None
|
Source code in desdeo/tools/generics.py
solve
abstractmethod
Solves the current problem with the specified target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
a str representing the symbol of the target function. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SolverResults |
SolverResults
|
The results of the solver |
Source code in desdeo/tools/generics.py
EMOResult
Bases: BaseModel
Defines a schema for a dataclass to store the results of an EMO method.
Source code in desdeo/tools/generics.py
optimal_outputs
class-attribute
instance-attribute
The objective vectors, constraint vectors, extra_funcs, and targets of the final population.
PersistentSolver
Defines a schema for a persistent solver class.
Can be used when reinitializing the solver every time the problem is changed is not practical.
Source code in desdeo/tools/generics.py
__init__
Initializer for the persistent solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
problem
|
Problem
|
The problem for the solver. |
required |
options
|
dict[str, any]
|
Dictionary of parameters to set. What these should be depends on the solver used. |
None
|
Source code in desdeo/tools/generics.py
add_constraint
Add a constraint expression to the solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
constraint
|
Constraint
|
the constraint function expression. |
required |
add_objective
Adds an objective function expression to the solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
objective
|
Objective
|
an objective function expression to be added. |
required |
add_scalarization_function
Adds a scalrization expression to the solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scalarization
|
ScalarizationFunction
|
A scalarization function to be added. |
required |
add_variable
Add a variable to the solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variable
|
Variable
|
The definition of the variable to be added. |
required |
remove_constraint
Removes a constraint from the solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
a str representing the symbol of the constraint to be removed. |
required |
remove_variable
Removes a variable from the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
a str representing the symbol of the variable to be removed. |
required |
solve
Solves the current problem with the specified target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target
|
str
|
a str representing the symbol of the target function. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SolverResults |
SolverResults
|
The results of the solver |
Source code in desdeo/tools/generics.py
SolverError
SolverResults
Bases: BaseModel
Defines a schema for a dataclass to store the results of a solver.
Source code in desdeo/tools/generics.py
SCORE Bands
Use the auto_SCORE function to generate the SCORE bands visualization.
This module contains the functions which generate SCORE bands visualizations. It also contains functions to calculate the order and positions of the objective axes, as well as a heatmap of correlation matrix.
To run the SCORE bands visualization, use the score_json function to generate the data for the visualization, and then
use the plot_score function to generate the figure. You can also pass the result of score_json to other frontends
for visualization.
CustomClusterOptions
Bases: BaseModel
Options for custom clustering provided by the user.
Source code in desdeo/tools/score_bands.py
DBSCANOptions
Bases: BaseModel
Options for DBSCAN clustering algorithm.
Source code in desdeo/tools/score_bands.py
DimensionClusterOptions
Bases: BaseModel
Options for clustering by one of the objectives/decision variables.
Source code in desdeo/tools/score_bands.py
kind
class-attribute
instance-attribute
Kind of clustering to use. Either "EqualWidth", which divides the dimension range into equal width intervals, or "EqualFrequency", which divides the dimension values into intervals with equal number of solutions. Defaults to "EqualWidth".
n_clusters
class-attribute
instance-attribute
Number of clusters to use. Defaults to 5.
DistanceFormula
GMMOptions
Bases: BaseModel
Options for Gaussian Mixture Model clustering algorithm.
Source code in desdeo/tools/score_bands.py
name
class-attribute
instance-attribute
Gaussian Mixture Model clustering algorithm.
KMeansOptions
Bases: BaseModel
Options for KMeans clustering algorithm.
Source code in desdeo/tools/score_bands.py
SCOREBandsConfig
Bases: BaseModel
Configuration options for SCORE bands visualization.
Source code in desdeo/tools/score_bands.py
axis_colours
class-attribute
instance-attribute
Optional dictionary to set the colour of the axes corresponding to each objective. The keys should be the same as in the 'dimensions' field. The values should be a valid plotly color string. Defaults to None.
Valid plotly color strings include
- A hex string (e.g. '#ff0000')
- An rgb/rgba string (e.g. 'rgb(255,0,0)')
- An hsl/hsla string (e.g. 'hsl(0,100%,50%)')
- An hsv/hsva string (e.g. 'hsv(0,100%,100%)')
- A named CSS color: see https://plotly.com/python/css-colors/ for a list
axis_positions
class-attribute
instance-attribute
Dictionary mapping objective names to their positions on the axes in the SCORE bands visualization. The first objective is at position 0.0, and the last objective is at position 1.0. Use this option if you want to manually set the axis positions. If None, the axis positions are calculated automatically based on correlations. Defaults to None.
clustering_algorithm
class-attribute
instance-attribute
Clustering algorithm to use. Currently supports one of ClusteringOptions.
descriptive_names
class-attribute
instance-attribute
Optional dictionary mapping dimensions to descriptive names for display in the visualization. If None, the original dimension names are used. Defaults to None.
dimensions
class-attribute
instance-attribute
List of variable/objective names (i.e., column names in the data) to include in the visualization. If None, all columns in the data are used. Defaults to None.
distance_formula
class-attribute
instance-attribute
Distance formula to use. The value should be 1 or 2. Check the paper for details. Defaults to 1.
distance_parameter
class-attribute
instance-attribute
Change the relative distances between the objective axes. Increase this value if objectives are placed too close together. Decrease this value if the objectives are equidistant in a problem with objective clusters. Defaults to 0.05.
highlight_cluster
class-attribute
instance-attribute
Cluster ID to highlight in the visualization. If None, no cluster is highlighted. Defaults to None. If a cluster ID is provided, the corresponding cluster is highlighted in the visualization by having a pattern fill in the band.
include_medians
class-attribute
instance-attribute
Whether to include cluster medians. Defaults to False. If True, the median traces are hidden by default, but can be viewed interactively in the figure.
include_solutions
class-attribute
instance-attribute
Whether to include individual solutions. Defaults to False. If True, the size of the resulting figure may be very large for datasets with many solutions. Moreover, the individual traces are hidden by default, but can be viewed interactively in the figure.
interval_size
class-attribute
instance-attribute
The size (as a fraction) of the interval to use for the bands. Defaults to 0.95, meaning that 95% of the middle solutions in a cluster will be included in the band. The rest will be considered outliers.
scales
class-attribute
instance-attribute
Optional dictionary specifying the min and max values for each objective. The keys should be the objective names (i.e., column names in the data), and the values should be tuples of (min, max). If not provided, the min and max will be calculated from the data.
units
class-attribute
instance-attribute
Optional dictionary mapping dimensions to their units for display in the visualization. If None, no units are displayed. Defaults to None.
SCOREBandsResult
Bases: BaseModel
Pydantic/JSON model for representing SCORE Bands.
Source code in desdeo/tools/score_bands.py
axis_positions
instance-attribute
Dictionary mapping objective names to their positions on the axes in the SCORE bands visualization. The first objective is at position 0.0, and the last objective is at position 1.0.
bands
instance-attribute
Dictionary mapping cluster IDs to dictionaries of objective names and their corresponding band extremes (min, max).
cardinalities
instance-attribute
Dictionary mapping cluster IDs to the number of solutions in each cluster.
cluster_hover_info
class-attribute
instance-attribute
Optional dictionary mapping cluster IDs to hover information for display in the visualization. If None, no additional hover information is displayed. Defaults to None.
cluster_names
class-attribute
instance-attribute
Optional dictionary mapping cluster IDs to descriptive names for display in the visualization. If None, the cluster IDs themselves are used as names. Defaults to None.
clusters
instance-attribute
List of cluster IDs (one for each solution) indicating the cluster to which each solution belongs.
medians
instance-attribute
Dictionary mapping cluster IDs to dictionaries of objective names and their corresponding median values.
options
instance-attribute
Configuration options used to generate the SCORE bands.
_DBSCANClustering
Cluster the data using DBSCAN with silhouette scoring to choose eps.
Source code in desdeo/tools/score_bands.py
_gaussianmixtureclusteringwithBIC
Cluster the data using Gaussian Mixture Model with BIC scoring.
Source code in desdeo/tools/score_bands.py
_gaussianmixtureclusteringwithsilhouette
Cluster the data using Gaussian Mixture Model with silhouette scoring.
Source code in desdeo/tools/score_bands.py
annotated_heatmap
annotated_heatmap(
correlation_matrix: ndarray,
col_names: list,
order: list | ndarray,
) -> go.Figure
Create a heatmap of the correlation matrix. Probably should be named something else.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
correlation_matrix
|
ndarray
|
2-D square array of correlation values between pairs of objectives. |
required |
col_names
|
List
|
Objective names. |
required |
order
|
Union[List, ndarray]
|
Order in which the objectives are shown in SCORE bands. |
required |
Returns:
| Type | Description |
|---|---|
Figure
|
go.Figure: The heatmap |
Source code in desdeo/tools/score_bands.py
calculate_axes_positions
calculate_axes_positions(
dimension_order: list[int],
corr: ndarray,
dist_parameter: float,
distance_formula: DistanceFormula = DistanceFormula.FORMULA_1,
) -> np.ndarray
Calculate the position of the axes for the SCORE bands visualization based on correlations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimension_order
|
list[int]
|
Order of the variables to be plotted. |
required |
corr
|
ndarray
|
Correlation (pearson) matrix. |
required |
dist_parameter
|
float
|
Change the relative distances between the axes. Increase this value if the axes are placed too close together. Decrease this value if the axes are equidistant. |
required |
distance_formula
|
DistanceFormula
|
The value should be 1 or 2. Check the paper for details. Defaults to DistanceFormula.FORMULA_1. |
FORMULA_1
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Positions of the axes in the range [0, 1]. |
Source code in desdeo/tools/score_bands.py
cluster
Cluster the data using the specified clustering algorithm and options.
Source code in desdeo/tools/score_bands.py
cluster_by_dimension
Cluster the data by a specific dimension.
Source code in desdeo/tools/score_bands.py
order_dimensions
order_dimensions(
data: DataFrame, use_absolute_corr: bool = False
) -> tuple[np.ndarray, list[int]]
Calculate the order of objectives.
Also returns the correlation matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Data to be visualized. |
required |
use_absolute_corr
|
bool
|
Use absolute value of the correlation to calculate order. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple[ndarray, list[int]]
|
The first element is the correlation matrix. The second element is the order of the objectives. |
Source code in desdeo/tools/score_bands.py
plot_score
Generate the SCORE Bands figure from the SCOREBandsResult data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Dataframe of objective values. The column names should be the objective names. Each row should be an objective vector. |
required |
result
|
SCOREBandsResult
|
The result containing all relevant data for the SCORE bands visualization. |
required |
Returns:
| Type | Description |
|---|---|
Figure
|
go.Figure: The SCORE bands plot. |
Source code in desdeo/tools/score_bands.py
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 | |
score_json
Generate the SCORE Bands data for a given dataset and configuration options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Dataframe of variable (decision or objective) values. The column names should be the names of the variables to be plotted. Each row should be a solution. |
required |
options
|
SCOREBandsConfig
|
Configuration options for generating the SCORE bands. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
SCOREBandsResult |
SCOREBandsResult
|
The result containing all relevant data for the SCORE bands visualization. |
Source code in desdeo/tools/score_bands.py
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 | |