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
4 changes: 2 additions & 2 deletions .github/workflows/cmake_install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ jobs:
working-directory: ${{github.workspace}}
run: |
touch test.cpp
echo "#include <dsm/dsm.hpp>" >> test.cpp
echo "#include <dsf/dsf.hpp>" >> test.cpp
echo "int main() {}" >> test.cpp
g++ test.cpp -std=c++20 && echo "Compiled successfully" || echo "Cannot include dsm"
g++ test.cpp -std=c++20 && echo "Compiled successfully" || echo "Cannot include dsf"
4 changes: 2 additions & 2 deletions .github/workflows/cmake_install_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
working-directory: ${{github.workspace}}
run: |
touch test.cpp
echo "#include <dsm/dsm.hpp>" >> test.cpp
echo "#include <dsf/dsf.hpp>" >> test.cpp
echo "int main() {}" >> test.cpp
g++ test.cpp -std=c++20 -I$(brew --prefix tbb)/include -L$(brew --prefix tbb)/lib -ltbb \
&& echo "Compiled successfully" \
|| (echo "Cannot include dsm" ; exit 1)
|| (echo "Cannot include dsf" ; exit 1)
2 changes: 1 addition & 1 deletion .github/workflows/cmake_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:

- name: Run tests
working-directory: ${{github.workspace}}/test
run: ./dsm_tests.out
run: ./dsf_tests.out

- name: create Report
working-directory: ${{github.workspace}}/test
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cmake_test_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:

- name: Run tests
working-directory: ${{github.workspace}}/test
run: ./dsm_tests.out
run: ./dsf_tests.out
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ images
examples/debug
examples/release

test/data/*dsm
test/data/*dsf


webapp/data/*
*egg-info*
62 changes: 54 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
cmake_minimum_required(VERSION 3.16.0)

project(dms VERSION 2.5.8 LANGUAGES CXX)
# Read version from header file
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/dsf/dsf.hpp" DSF_HPP_CONTENT)
string(REGEX MATCH "DSF_VERSION_MAJOR = ([0-9]+)" _ ${DSF_HPP_CONTENT})
set(DSF_VERSION_MAJOR ${CMAKE_MATCH_1})
string(REGEX MATCH "DSF_VERSION_MINOR = ([0-9]+)" _ ${DSF_HPP_CONTENT})
set(DSF_VERSION_MINOR ${CMAKE_MATCH_1})
string(REGEX MATCH "DSF_VERSION_PATCH = ([0-9]+)" _ ${DSF_HPP_CONTENT})
set(DSF_VERSION_PATCH ${CMAKE_MATCH_1})

Comment on lines +5 to +11
Copy link

Copilot AI Jun 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a fallback or error-handling mechanism if the version extraction from dsf.hpp fails, to ensure that an appropriate version is always set during the build.

Suggested change
string(REGEX MATCH "DSF_VERSION_MAJOR = ([0-9]+)" _ ${DSF_HPP_CONTENT})
set(DSF_VERSION_MAJOR ${CMAKE_MATCH_1})
string(REGEX MATCH "DSF_VERSION_MINOR = ([0-9]+)" _ ${DSF_HPP_CONTENT})
set(DSF_VERSION_MINOR ${CMAKE_MATCH_1})
string(REGEX MATCH "DSF_VERSION_PATCH = ([0-9]+)" _ ${DSF_HPP_CONTENT})
set(DSF_VERSION_PATCH ${CMAKE_MATCH_1})
if(NOT DEFINED DSF_HPP_CONTENT OR DSF_HPP_CONTENT STREQUAL "")
message(WARNING "Failed to read dsf.hpp. Using default version 0.0.0.")
set(DSF_VERSION_MAJOR 0)
set(DSF_VERSION_MINOR 0)
set(DSF_VERSION_PATCH 0)
else()
string(REGEX MATCH "DSF_VERSION_MAJOR = ([0-9]+)" _ ${DSF_HPP_CONTENT})
if(NOT DEFINED CMAKE_MATCH_1)
message(WARNING "Failed to extract DSF_VERSION_MAJOR. Using default value 0.")
set(DSF_VERSION_MAJOR 0)
else()
set(DSF_VERSION_MAJOR ${CMAKE_MATCH_1})
endif()
string(REGEX MATCH "DSF_VERSION_MINOR = ([0-9]+)" _ ${DSF_HPP_CONTENT})
if(NOT DEFINED CMAKE_MATCH_1)
message(WARNING "Failed to extract DSF_VERSION_MINOR. Using default value 0.")
set(DSF_VERSION_MINOR 0)
else()
set(DSF_VERSION_MINOR ${CMAKE_MATCH_1})
endif()
string(REGEX MATCH "DSF_VERSION_PATCH = ([0-9]+)" _ ${DSF_HPP_CONTENT})
if(NOT DEFINED CMAKE_MATCH_1)
message(WARNING "Failed to extract DSF_VERSION_PATCH. Using default value 0.")
set(DSF_VERSION_PATCH 0)
else()
set(DSF_VERSION_PATCH ${CMAKE_MATCH_1})
endif()
endif()

Copilot uses AI. Check for mistakes.
set(DSF_VERSION "${DSF_VERSION_MAJOR}.${DSF_VERSION_MINOR}.${DSF_VERSION_PATCH}")

project(dsf VERSION ${DSF_VERSION} LANGUAGES CXX)

# Set the C++ standard
set(CMAKE_CXX_STANDARD 20)
Expand All @@ -14,16 +25,16 @@ endif()

find_package(TBB REQUIRED CONFIG)

file(GLOB SOURCES "src/dsm/sources/*.cpp" "src/dsm/utility/*.cpp")
file(GLOB SOURCES "src/dsf/sources/*.cpp" "src/dsf/utility/*.cpp")

add_library(dsm STATIC ${SOURCES})
target_include_directories(dsm PUBLIC
add_library(dsf STATIC ${SOURCES})
target_include_directories(dsf PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src/headers>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(dsm PRIVATE TBB::tbb)
target_link_libraries(dsf PRIVATE TBB::tbb)

install(TARGETS dsm
install(TARGETS dsf
EXPORT dsmConfig
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
Expand All @@ -33,5 +44,40 @@ install(DIRECTORY ${PROJECT_SOURCE_DIR}/src/ DESTINATION ${CMAKE_INSTALL_PREFIX}

install(EXPORT dsmConfig
FILE dsmConfig.cmake
NAMESPACE dsm::
DESTINATION lib/cmake/dsm)
NAMESPACE dsf::
DESTINATION lib/cmake/dsf)

# Optional Python bindings - only build if requested
option(BUILD_PYTHON_BINDINGS "Build Python bindings" OFF)

if(BUILD_PYTHON_BINDINGS)
include(FetchContent)

# Get pybind11
FetchContent_Declare(pybind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG v2.13.6
)
FetchContent_GetProperties(pybind11)
if(NOT pybind11_POPULATED)
FetchContent_MakeAvailable(pybind11)
endif()

# Add the Python binding module
add_library(dsf_python_module MODULE src/dsf/binding.cpp)

# Ensure the Python module name has no 'lib' prefix on Unix systems
set_target_properties(dsf_python_module PROPERTIES
PREFIX ""
OUTPUT_NAME "dsf"
)

# Link the pybind11 module with your static library and pybind11
target_link_libraries(dsf_python_module PRIVATE dsf pybind11::module pybind11::headers)

# Set include directories (if binding.cpp needs headers from your project)
target_include_directories(dsf_python_module PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/src/headers
)
endif()

2 changes: 1 addition & 1 deletion Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ WARN_LOGFILE =
# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING
# Note: If this tag is empty the current directory is searched.

INPUT = ./src/dsm/headers
INPUT = ./src/dsf/headers

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses
Expand Down
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@ cmake --build build
cmake --install build
```

## Installation via Pybind11
If you want to use the library from Python, you can build the Python bindings using [pybind11](https://github.com/pybind/pybind11). Make sure you have Python and pybind11 installed:
```shell
pip install pybind11
```

Then, the installation is automatic via `pip`:
```shell
pip install .
```

After installation, you should be able to import the module in Python:
```python
import dsf
```

If you encounter issues, ensure that the installation path is in your `PYTHONPATH` environment variable.

## Testing
This project uses [Doctest](https://github.com/doctest/doctest) for testing.

Expand All @@ -58,7 +76,7 @@ cmake -B build && make -C build
```
To run all the tests together use the command:
```shell
./dsm_tests.out
./dsf_tests.out
```

## Benchmarking
Expand Down
2 changes: 1 addition & 1 deletion benchmark/Adj/BenchAdj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "SparseMatrix.hpp"
#include "Bench.hpp"

using namespace dsm;
using namespace dsf;

using Bench = sb::Bench<long long int>;

Expand Down
6 changes: 3 additions & 3 deletions benchmark/Adj/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ string(APPEND CMAKE_CXX_FLAGS "-Wall -Wextra -O3")
# Set the folder for the executable
set(EXECUTABLE_OUTPUT_PATH ../../)

include_directories(../../src/dsm/headers)
include_directories(../../src/dsm/utility/)
include_directories(../../src/dsf/headers)
include_directories(../../src/dsf/utility/)

file(GLOB SOURCES "../../src/dsm/sources/*.cpp" "../../src/dsm/utility/*.cpp")
file(GLOB SOURCES "../../src/dsf/sources/*.cpp" "../../src/dsf/utility/*.cpp")

# Compile
add_executable(bench_adj.out BenchAdj.cpp ${SOURCES})
Expand Down
6 changes: 3 additions & 3 deletions benchmark/Dynamics/BenchDynamics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#include "FirstOrderDynamics.hpp"
#include "Bench.hpp"

using RoadNetwork = dsm::RoadNetwork;
using Itinerary = dsm::Itinerary;
using Dynamics = dsm::FirstOrderDynamics;
using RoadNetwork = dsf::RoadNetwork;
using Itinerary = dsf::Itinerary;
using Dynamics = dsf::FirstOrderDynamics;

using Bench = sb::Bench<long long int>;

Expand Down
6 changes: 3 additions & 3 deletions benchmark/Dynamics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ string(APPEND CMAKE_CXX_FLAGS "-Wall -Wextra -O3")
# Set the folder for the executable
set(EXECUTABLE_OUTPUT_PATH ../../)

include_directories(../../src/dsm/headers)
include_directories(../../src/dsm/utility/)
include_directories(../../src/dsf/headers)
include_directories(../../src/dsf/utility/)

file(GLOB SOURCES "../../src/dsm/sources/*.cpp" "../../src/dsm/utility/*.cpp")
file(GLOB SOURCES "../../src/dsf/sources/*.cpp" "../../src/dsf/utility/*.cpp")

# Compile
add_executable(bench_dynamics.out BenchDynamics.cpp ${SOURCES})
Expand Down
8 changes: 4 additions & 4 deletions benchmark/Graph/BenchGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

#include "RoadNetwork.hpp"

using RoadNetwork = dsm::RoadNetwork;
using Intersection = dsm::Intersection;
using Street = dsm::Street;
using SparseMatrix = dsm::SparseMatrix<bool>;
using RoadNetwork = dsf::RoadNetwork;
using Intersection = dsf::Intersection;
using Street = dsf::Street;
using SparseMatrix = dsf::SparseMatrix<bool>;

using Bench = sb::Bench<long long int>;

Expand Down
6 changes: 3 additions & 3 deletions benchmark/Graph/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ string(APPEND CMAKE_CXX_FLAGS "-Wall -Wextra -O3")
# Set the folder for the executable
set(EXECUTABLE_OUTPUT_PATH ../../)

include_directories(../../src/dsm/headers/)
include_directories(../../src/dsm/utility/)
include_directories(../../src/dsf/headers/)
include_directories(../../src/dsf/utility/)

file(GLOB SOURCES "../../src/dsm/sources/*.cpp" "../../src/dsm/utility/*.cpp")
file(GLOB SOURCES "../../src/dsf/sources/*.cpp" "../../src/dsf/utility/*.cpp")

# Compile
add_executable(bench_graph.out BenchGraph.cpp ${SOURCES})
Expand Down
6 changes: 3 additions & 3 deletions benchmark/Street/BenchStreet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

#include "RoadNetwork.hpp"

using Agent = dsm::Agent;
using Street = dsm::Street;
using SparseMatrix = dsm::SparseMatrix<bool>;
using Agent = dsf::Agent;
using Street = dsf::Street;
using SparseMatrix = dsf::SparseMatrix<bool>;

using Bench = sb::Bench<long long int>;

Expand Down
6 changes: 3 additions & 3 deletions benchmark/Street/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ string(APPEND CMAKE_CXX_FLAGS "-Wall -Wextra -O3")
# Set the folder for the executable
set(EXECUTABLE_OUTPUT_PATH ../../)

include_directories(../../src/dsm/headers)
include_directories(../../src/dsm/utility/)
include_directories(../../src/dsf/headers)
include_directories(../../src/dsf/utility/)

file(GLOB SOURCES "../../src/dsm/sources/*.cpp" "../../src/dsm/utility/*.cpp")
file(GLOB SOURCES "../../src/dsf/sources/*.cpp" "../../src/dsf/utility/*.cpp")

# Compile
add_executable(bench_street.out BenchStreet.cpp ${SOURCES})
Expand Down
6 changes: 3 additions & 3 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.16.0)

project(dsm_examples VERSION 1.3.10 LANGUAGES CXX)
project(dsf_examples VERSION 3.0.0 LANGUAGES CXX)

# Set the C++ standard
set(CMAKE_CXX_STANDARD 20)
Expand All @@ -21,12 +21,12 @@ set(EXECUTABLE_OUTPUT_PATH ../)

# add as executable all cpp files into '.' folder
file(GLOB SOURCES "*.cpp")
file(GLOB SRC_SOURCES "../src/dsm/sources/*.cpp" "../src/dsm/utility/*.cpp")
file(GLOB SRC_SOURCES "../src/dsf/sources/*.cpp" "../src/dsf/utility/*.cpp")

# Loop through each source file and create an executable
foreach(SOURCE ${SOURCES})
get_filename_component(EXE_NAME ${SOURCE} NAME_WE)
add_executable(${EXE_NAME}.out ${SOURCE} ${SRC_SOURCES})
target_include_directories(${EXE_NAME}.out PRIVATE ../src/dsm/headers/ ../src/dsm/utility/TypeTraits/)
target_include_directories(${EXE_NAME}.out PRIVATE ../src/dsf/headers/ ../src/dsf/utility/TypeTraits/)
target_link_libraries(${EXE_NAME}.out PRIVATE TBB::tbb)
endforeach()
6 changes: 3 additions & 3 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# DSM - Examples
Here are reported some example studies using the dsm framework.
Here are reported some example studies using the dsf framework.
Many of these simulations were used as thesis work.

To compile all simulations, use cmake inside the *examples* folder:
```shell
cmake -B release -DCMAKE_BUILD_TYPE=Release && make -C release
cmake -B build -DCMAKE_BUILD_TYPE=Release && make -C build
```
If anything goes wrong, try to build the example in debug mode:
```shell
cmake -B debug -DCMAKE_BUILD_TYPE=Debug && make -C debug
cmake -B build -DCMAKE_BUILD_TYPE=Debug && make -C build
```

## Simulation files
Expand Down
File renamed without changes.
16 changes: 8 additions & 8 deletions examples/slow_charge_rb.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../src/dsm/dsm.hpp"
#include "../src/dsf/dsf.hpp"
#include <array>
#include <cmath>
#include <cstdint>
Expand Down Expand Up @@ -33,11 +33,11 @@ std::atomic<bool> bExitFlag{false};
using Unit = unsigned int;
using Delay = uint8_t;

using RoadNetwork = dsm::RoadNetwork;
using Dynamics = dsm::FirstOrderDynamics;
using Street = dsm::Street;
using SpireStreet = dsm::SpireStreet;
using Roundabout = dsm::Roundabout;
using RoadNetwork = dsf::RoadNetwork;
using Dynamics = dsf::FirstOrderDynamics;
using Street = dsf::Street;
using SpireStreet = dsf::SpireStreet;
using Roundabout = dsf::Roundabout;

void printLoadingBar(int const i, int const n) {
std::cout << "Loading: " << std::setprecision(2) << std::fixed << (i * 100. / n) << "%"
Expand Down Expand Up @@ -66,7 +66,7 @@ int main(int argc, char** argv) {
std::cout << "-------------------------------------------------\n";

const std::string IN_MATRIX{"./data/matrix.dat"}; // input matrix file
const std::string IN_COORDS{"./data/coordinates.dsm"}; // input coords file
const std::string IN_COORDS{"./data/coordinates.dsf"}; // input coords file
const std::string OUT_FOLDER{std::format("{}output_scrb_{}_{}/",
BASE_OUT_FOLDER,
ERROR_PROBABILITY,
Expand All @@ -82,7 +82,7 @@ int main(int argc, char** argv) {
}
fs::create_directory(OUT_FOLDER);
// Starting
std::cout << "Using dsm version: " << dsm::version() << '\n';
std::cout << "Using dsf version: " << dsf::version() << '\n';
RoadNetwork graph{};
std::cout << "Importing matrix.dat...\n";
graph.importMatrix(IN_MATRIX, false);
Expand Down
Loading
Loading