Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### New Features and Major Changes

* [Avoid shell=true in subprocess and generalize options: add explicit solverconfig option and kwargs to generalize options #73](https://github.com/SPSUnipi/pySMSpp/pull/73)
* [Generalize solver_log #72](https://github.com/SPSUnipi/pySMSpp/pull/72)
* [Convert documentation from Sphinx/RST to MkDocs PR #68](https://github.com/SPSUnipi/pySMSpp/pull/68)
* [Add `plot()` methods to `Variable` and `Block` PR #66](https://github.com/SPSUnipi/pySMSpp/pull/66)
Expand Down
2 changes: 1 addition & 1 deletion pysmspp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@
SMSPPSolverTool as SMSPPSolverTool,
UCBlockSolver as UCBlockSolver,
InvestmentBlockTestSolver as InvestmentBlockTestSolver,
TSSBlockSolver as TSSBlockSolver,
TSSBSolver as TSSBSolver,
Comment thread
davide-f marked this conversation as resolved.
is_smspp_installed as is_smspp_installed,
)
Comment thread
davide-f marked this conversation as resolved.
13 changes: 11 additions & 2 deletions pysmspp/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
UCBlockSolver,
InvestmentBlockTestSolver,
InvestmentBlockSolver,
TSSBSolver,
)
from enum import IntEnum

Expand Down Expand Up @@ -1422,6 +1423,8 @@ def optimize(
fp_solution: Path | str = None,
smspp_solver: SMSPPSolverTool | str = "auto",
inner_block_name: str = "Block_0",
logging=True,
tracking_period=0.1,
**kwargs,
):
"""
Expand All @@ -1447,22 +1450,28 @@ def optimize(

inner_block_name : str (default: "Block_0")
The name of the inner block, to decide on the automatic solver to use.
logging : bool (default: True)
Whether to enable logging during optimization.
tracking_period : float (default: 0.1)
The period (in seconds) to track optimization progress when logging is enabled.
kwargs : dict
The arguments to pass to the optimization function.
Optional arguments to pass to the solver constructor. These can include any additional parameters required by specific solvers.
"""

# Map block type to default solver (for 'auto' mode)
default_solver_map = {
"UCBlock": "UCBlockSolver",
"InvestmentBlock": "InvestmentBlockTestSolver",
"SDDPBlock": "InvestmentBlockSolver",
"TwoStageStochasticBlock": "TSSBSolver",
}

# Map solver names to actual solver classes
solver_factory = {
"UCBlockSolver": UCBlockSolver,
"InvestmentBlockTestSolver": InvestmentBlockTestSolver,
"InvestmentBlockSolver": InvestmentBlockSolver,
"TSSBSolver": TSSBSolver,
}

if isinstance(smspp_solver, str) and smspp_solver == "auto":
Expand Down Expand Up @@ -1491,4 +1500,4 @@ def optimize(
)

self.to_netcdf(fp_temp, force=True)
return smspp_solver.optimize(**kwargs)
return smspp_solver.optimize(logging=logging, tracking_period=tracking_period)
Comment thread
davide-f marked this conversation as resolved.
21 changes: 21 additions & 0 deletions pysmspp/data/configs/InvestmentBlock/OSolCfg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - OSolCfg.txt - - - - - - - - - - - - - - - -
#
# A txt description of a SimpleConfiguration<int> to set the type of the
# output Solution of the UnitBlock
Comment thread
davide-f marked this conversation as resolved.
#
# Antonio Frangioni
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SimpleConfiguration<int> # exact type of the Configuration object
# the int value is coded bit-wise to specify what is saved:
15 # = bit 0 (& 1): the solution of all UnitBlock
# = bit 1 (& 2): the solution of all NetworkBlock
# = bit 2 (& 4): the NetworkBlock are in compressed format
# = bit 3 (& 8): the dual variables of the node injection constraints

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - END OSolCfg.txt - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
8 changes: 5 additions & 3 deletions pysmspp/data/configs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Description of available configuration files

- UCBlock/uc_solverconfig.txt copied from smspp-project/tools/ucblock_solver
- InvestmentBlock/{BSPar.txt, uc_solverconfig.txt}, copied from smspp-project/InvestmentBlock/test/config
- UCBlock/{uc_solverconfig.txt, OSolCfg.txt} copied from smspp-project/tools/ucblock_solver.
- InvestmentBlock/{BSPar.txt, uc_solverconfig.txt}, copied from smspp-project/InvestmentBlock/test/config.
- TSSBlock/* copied from smspp-project/tools/tssb_solver.

For uc_solverconfig in both folders, the version using Gurobi is also provided under name uc_solverconfig_grb
For uc_solverconfig in both folders, the version using Gurobi is also provided under name uc_solverconfig_grb.
Comment thread
davide-f marked this conversation as resolved.
The template configuration option for OSolCfg.txt allows to extract the most information from tools.
3 changes: 2 additions & 1 deletion pysmspp/data/configs/TSSBlock/OSolCfg.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SimpleConfiguration<int> # exact type of the Configuration object
3 # = bit 0 (& 1): means "store the value of the here_and_now variables"
# the int value is coded bit-wise to specify what is saved:
7 # = bit 0 (& 1): means "store the value of the here_and_now variables"
Comment thread
davide-f marked this conversation as resolved.
# = bit 1 (& 2): means "store the solutions of each scenario"
# = bit 2 (& 4): means "store the dual prices of the non-anticipativity
# constraints"
Expand Down
21 changes: 21 additions & 0 deletions pysmspp/data/configs/UCBlock/OSolCfg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - OSolCfg.txt - - - - - - - - - - - - - - - -
#
# A txt description of a SimpleConfiguration<int> to set the type of the
# output Solution of the UnitBlock
Comment thread
davide-f marked this conversation as resolved.
#
# Antonio Frangioni
#
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

SimpleConfiguration<int> # exact type of the Configuration object
# the int value is coded bit-wise to specify what is saved:
15 # = bit 0 (& 1): the solution of all UnitBlock
# = bit 1 (& 2): the solution of all NetworkBlock
# = bit 2 (& 4): the NetworkBlock are in compressed format
# = bit 3 (& 8): the dual variables of the node injection constraints

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - END OSolCfg.txt - - - - - - - - - - - - - -
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Loading
Loading