Skip to content

SMSpp-Project/TwoStageStochasticBlock

Repository files navigation

TwoStageStochasticBlock

SMS++ Block for two-stage stochastic programming problems.

The TwoStageStochasticBlock is a :Block that represents a two-stage stochastic programming problem contained in its inner Block. It currently supports the "Lagrangian version" of the formulation by building the explicit form of a two-stage stochastic problem by:

  • creating N copies of the inner deterministic Block (one per scenario)

  • adding non-anticipativity constraints to ensure first-stage variables are the same across all scenarios

  • combining objectives weighted by probabilities.

TODO: We need Objective::scale() to be implemented. Currently we have a workaround for LinearFunction objectives (like those of CapacitatedFacilityLocationBlock or UCBlock) that should be replaced.

The class uses serialization/deserialization to create copies of the inner Block, which works for all Block types without requiring them to implement any special copy methods. The inner Block is serialized once and then deserialized N times to create independent copies for each scenario.

Scenario data is applied automatically when a ScenarioGenerator is provided, either through deserialization (when a ScenarioSet is present in the netCDF) or by explicitly setting one via set_scenario_generator(). The class uses the StochasticBlock as a temporary "applicator" for scenarios: it sets each Block copy as the inner block of StochasticBlock, applies the scenario data through the StochasticBlock::set_data() method (which uses the DataMappings), then restores the original inner Block. This approach eliminates the need for DataMapping::set_caller() and provides a cleaner architecture.

Getting started

These instructions will let you build TwoStageStochasticBlock on your system.

Requirements

Build and install with CMake

Configure and build the library with:

mkdir build
cd build
cmake ..
cmake --build .

The library has the same configuration options of SMS++.

Optionally, install the library in the system with:

cmake --install .

Usage with CMake

After the library is built, you can use it in your CMake project with:

find_package(TwoStageStochasticBlock)
target_link_libraries(<my_target> SMS++::TwoStageStochasticBlock)

Build and install with makefiles

Carefully hand-crafted makefiles have also been developed for those unwilling to use CMake. Makefiles build the executable in-source (in the same directory tree where the code is) as opposed to out-of-source (in the copy of the directory tree constructed in the build/ folder) and therefore it is more convenient when having to recompile often, such as when developing/debugging a new module, as opposed to the compile-and-forget usage envisioned by CMake.

Each executable using TwoStageStochasticBlock has to include a "main makefile" of the module, which typically is either makefile-c including all necessary libraries comprised the "core SMS++" one, or makefile-s including all necessary libraries but not the "core SMS++" one (for the common case in which this is used together with other modules that already include them). A relevant example is the tssb_solver available in the tools repository. The makefiles in turn recursively include all the required other makefiles, hence one should only need to edit the "main makefile" for compilation type (C++ compiler and its options) and it all should be good to go. In case some of the external libraries (say, StOpt) are not at their default location, it should only be necessary to create the ../extlib/makefile-paths out of the extlib/makefile-default-paths-* for your OS * and edit the relevant bits (commenting out all the rest).

Check the SMS++ installation wiki for further details.

Tests

The test folder contains a tester for TwoStageStochasticBlock, which loads an instance from a netCDF file, attaches one or two :Solver through a BlockSolverConfig and compares their results.

Getting help

If you need support, you want to submit bugs or propose a new feature, you can open a new issue.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting merge requests to us.

Authors

Current Lead Authors

  • Donato Meoli
    Dipartimento di Informatica
    Università di Pisa

Contributors

  • Antonio Frangioni
    Dipartimento di Informatica
    Università di Pisa

License

This code is provided free of charge under the GNU Lesser General Public License version 3.0 - see the LICENSE file for details.

Disclaimer

The code is currently provided free of charge under an open-source license. As such, it is provided "as is", without any explicit or implicit warranty that it will properly behave or it will suit your needs. The Authors of the code cannot be considered liable, either directly or indirectly, for any damage or loss that anybody could suffer for having used it. More details about the non-warranty attached to this code are available in the license description file.

About

Block for representing two-stage stochastic mathematical models. | mirror of https://gitlab.com/smspp/twostagestochasticblock

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors