Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
test/build
test/bigg/*.json
!test/bigg/e_coli_core.json
external/_deps
examples/build
.vscode
Expand Down
68 changes: 68 additions & 0 deletions examples/metabolic_simplification/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# VolEsti (volume computation and sampling library)

# Copyright (c) 2012-2026 Vissarion Fisikopoulos
# Copyright (c) 2018-2026 Apostolos Chalkis
# Copyright (c) 2026 Dimitrios Pavlou

# Contributed and/or modified by Dimitrios Pavlou, as part of Google Summer of Code 2026 program

# Licensed under GNU LGPL.3, see LICENCE file

project (VolEsti)

CMAKE_MINIMUM_REQUIRED(VERSION 3.11)

set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true)

if(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)

add_definitions(-DDISABLE_NLP_ORACLES)

include("../../external/cmake-files/Eigen.cmake")
GetEigen()

include("../../external/cmake-files/Boost.cmake")
GetBoost()

include("../../external/cmake-files/Spectra.cmake")
GetSpectra()

include("../../external/cmake-files/HiGHS.cmake")
GetHighs()

include("../../external/cmake-files/LPSolve.cmake")
GetLPSolve()

include("../../external/cmake-files/SuiteSparse.cmake")
GetSuiteSparse()

include("../../external/cmake-files/JSON.cmake")
GetJSON()

set(CMAKE_EXPORT_COMPILE_COMMANDS "ON")

include_directories (BEFORE ../../external)
include_directories (BEFORE ../../include)
include_directories (BEFORE ../../include/convex_bodies)
include_directories (BEFORE ../../include/misc)
include_directories (BEFORE ../../include/preprocess)

# for Eigen
if (${CMAKE_VERSION} VERSION_LESS "3.12.0")
add_compile_options(-D "EIGEN_NO_DEBUG")
else ()
add_compile_definitions("EIGEN_NO_DEBUG")
endif ()


add_definitions(${CMAKE_CXX_FLAGS} "-std=c++17") # enable C++17 standard
add_definitions(${CMAKE_CXX_FLAGS} "-O3") # optimization of the compiler
add_definitions(${CMAKE_CXX_FLAGS} "-g")
add_definitions(${CXX_COVERAGE_COMPILE_FLAGS} "-DBOOST_NO_AUTO_PTR")

find_package(LAPACK REQUIRED)
find_package(BLAS REQUIRED)
add_executable(metabolic_simplification metabolic_simplification.cpp)
TARGET_LINK_LIBRARIES(metabolic_simplification highs::highs lp_solve nlohmann_json::nlohmann_json ${SUITESPARSE_LIBRARIES} ${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} ${MKL_LINK})
89 changes: 89 additions & 0 deletions examples/metabolic_simplification/metabolic_simplification.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// VolEsti (volume computation and sampling library)

// Copyright (c) 2012-2026 Vissarion Fisikopoulos
// Copyright (c) 2018-2026 Apostolos Chalkis
// Copyright (c) 2026 Dimitrios Pavlou

// Contributed and/or modified by Dimitrios Pavlou, as part of Google Summer of Code 2026 program

// Licensed under GNU LGPL.3, see LICENCE file

//
// Usage: ./metabolic_simplification <model_id.json>
//

#include "Eigen/Eigen"
#include "cartesian_geom/cartesian_kernel.h"
#include "convex_bodies/hpolytope.h"
#include "io/bigg_parser.hpp"
#include "preprocess/metabolic/exhaustive_simplification.hpp"
#include "preprocess/metabolic/clarkson_simplification.hpp"
#include "preprocess/metabolic/transformation.hpp"
#include "random_walks/random_walks.hpp"
#include "volume/volume_cooling_balls.hpp"
#include "generators/boost_random_number_generator.hpp"
#include <iostream>
#include <string>

typedef double NT;
typedef Cartesian<NT> Kernel;
typedef typename Kernel::Point Point;
typedef MetabolicPolytope<Point> Polytope;
typedef HPolytope<Point> Hpolytope;
typedef Eigen::Matrix<NT, Eigen::Dynamic, Eigen::Dynamic> DenseMT;
typedef typename Polytope::VT VT;
typedef BoostRandomNumberGenerator<boost::mt19937, NT> RNG;

int main(int argc, char* argv[]) {
if (argc != 2) {
std::cerr << "usage: " << argv[0] << " <model.json>" << std::endl;
return 1;
}

Polytope P = parse_from_json<Point>(argv[1]);

std::cout << "input polytope" << "\n"
<< " reactions : " << P.getDimension() << "\n"
<< " metabolites : " << P.getNumEqualities() << "\n"
<< " finite bounds : " << P.getNumFiniteBounds() << "\n" << std::endl;

// Simplifies the polytope, removing redundant bounds and fixing pinned variables.
clarkson_simplification::Config config;
config.fix_dimensions = true;
config.verbosity = clarkson_simplification::VerbosityLevel::Summary;

auto result = clarkson_simplification::simplify(P, config);

if (!result.success) {
std::cerr << "simplification failed" << std::endl;
return 1;
}

std::cout << "\nsimplified polytope" << "\n"
<< " finite bounds : " << result.P.getNumFiniteBounds() << "\n"
<< " bounds relaxed : " << result.bounds_relaxed << "\n"
<< " dimensions fixed : " << result.dims_fixed << std::endl;

// Transforms the simplified polytope, giving a full dimensional H-Polytope
// that volume estimation can work with.
auto trans_result = transform(result.P);
Hpolytope HP = std::get<0>(trans_result);
VT shift = std::get<1>(trans_result);
DenseMT N = std::get<2>(trans_result);

std::cout << "\ntransformed polytope\n"
<< " dimension : " << HP.dimension() << "\n"
<< " constraints (finite bounds) : " << HP.num_of_hyperplanes() << std::endl;

// Estimates the volume of the original polytope
unsigned walk_len = 10+HP.dimension()/10;
NT epsilon = 0.1;

auto volume = volume_cooling_balls<BallWalk, RNG, Hpolytope>(
HP, epsilon, walk_len
).second;

std::cout << "\nvolume\n" << "estimate : " << volume << std::endl;

return 0;
}
12 changes: 12 additions & 0 deletions external/cmake-files/HiGHS.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
set(HIGHS_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR})
function(GetHighs)
include(FetchContent)
set(FETCHCONTENT_BASE_DIR "${HIGHS_CMAKE_DIR}/../_deps")
FetchContent_Declare(
highs
GIT_REPOSITORY https://github.com/ERGO-Code/HiGHS.git
GIT_TAG v1.10.0
)
message(STATUS "Fetching HiGHS")
FetchContent_MakeAvailable(highs)
endfunction()
21 changes: 21 additions & 0 deletions external/nlohmann/LICENSE.MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2013-2026 Niels Lohmann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading