Skip to content

Commit e832ae5

Browse files
Grufoonysbaldu
andauthored
Add examples of real applications (#184)
* Add simulations files, Makefile and data files * Add Python scripts for visualization * Add Readme * Add Via Stalingrado simulation * Add examples folder to clang-format checking * Fix comparison warning * Fix comparison compilation warnings * Add `CMakeLists` to build examples * Add workflow to build examples * Format code * Add requirements.txt file * Use only a global requirements file * Remove versions * Some pylint fixes * More pylint fixes * Even more pylint fixes * Moved python files to utils and add some argparsing * Set SEED at runtime * Set more args as runtime input * Updated Readmes * Format code * Update build type settings in CMake file * Update Readme with new cmake string * Coherent workflow name --------- Co-authored-by: Simone Balducci <[email protected]>
1 parent 68554a4 commit e832ae5

18 files changed

+3766
-3
lines changed

.github/workflows/clang_format.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
path:
1616
- 'src'
1717
- 'test'
18+
- 'examples'
1819
steps:
1920
- uses: actions/checkout@v3
2021
- name: Run clang-format style check

.github/workflows/cmake_examples.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Compile examples
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
env:
10+
BUILD_TYPE: Debug
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Configure CMake
20+
working-directory: ${{github.workspace}}/examples
21+
run: cmake -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
22+
23+
- name: Build
24+
working-directory: ${{github.workspace}}/examples
25+
run: cmake --build build

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@
2121
*cache
2222

2323
temp*
24+
25+
# Examples generated files
26+
examples/sctl/*
27+
examples/scrb/*
28+
examples/*.csv

examples/CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
cmake_minimum_required(VERSION 3.16.0)
2+
3+
project(dsm_examples VERSION 1.3.10 LANGUAGES CXX)
4+
5+
# Set the C++ standard
6+
set(CMAKE_CXX_STANDARD 23)
7+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
8+
set(CMAKE_CXX_EXTENSIONS OFF)
9+
10+
# Set the C++ flags
11+
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
12+
string(APPEND CMAKE_CXX_FLAGS "-Wall -Wextra -O0 -g")
13+
elseif (CMAKE_BUILD_TYPE STREQUAL "Release")
14+
string(APPEND CMAKE_CXX_FLAGS "-O3")
15+
endif()
16+
17+
# Set the folder for the executable
18+
set(EXECUTABLE_OUTPUT_PATH ../)
19+
20+
# add as executable all cpp files into '.' folder
21+
file(GLOB SOURCES "*.cpp")
22+
23+
# Loop through each source file and create an executable
24+
foreach(SOURCE ${SOURCES})
25+
get_filename_component(EXE_NAME ${SOURCE} NAME_WE)
26+
add_executable(${EXE_NAME}.out ${SOURCE})
27+
target_include_directories(${EXE_NAME}.out PRIVATE ../src/dsm/headers/ ../src/dsm/utility/TypeTraits/)
28+
endforeach()

examples/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
slow_charge_tl:
2+
./slow_charge_tl.out 69 0.3 ./sctl/ 0
3+
slow_charge_rb:
4+
./slow_charge_rb.out 69 0.3 ./scrb/
5+
stalingrado:
6+
./stalingrado.out

examples/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# DSM - Examples
2+
Here are reported some example studies using the dsm framework.
3+
Many of these simulations were used as thesis work.
4+
5+
To compile all simulations, use cmake inside the *examples* folder:
6+
```shell
7+
cmake -B build -DCMAKE_BUILD_TYPE=Release && make -C build
8+
```
9+
10+
## Simulation files
11+
C++ files (`cpp`) are simulation files and need to be compiled.
12+
13+
**NOTE**: you may have to modify some hard-coded parameters and recompile to set certain variables.
14+
15+
### Slow Charge
16+
Aim of these simulations is to load the road network in an adiabatic way, i.e. slowly increasing the mean density over streets.
17+
You can try it both using all roundabouts intersections (RB case) or traffic lights (TL case).
18+
To run the simulation you can use the Makefile:
19+
```shell
20+
make slow_charge_tl
21+
```
22+
### Stalingrado
23+
Aim of this program is to make a realistic simulation of *Via Stalingrado*, in Bologna, which is a street full of traffic lights that have high influence on the traffic.
24+
Also in this case, once compiled one can run it using the Makefile:
25+
```shell
26+
make stalingrado
27+
```

examples/data/coordinates.dsm

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
120
2+
0 0
3+
10 0
4+
20 0
5+
30 0
6+
40 0
7+
50 0
8+
60 0
9+
70 0
10+
80 0
11+
90 0
12+
100 0
13+
110 0
14+
0 10
15+
10 10
16+
20 10
17+
30 10
18+
40 10
19+
50 10
20+
60 10
21+
70 10
22+
80 10
23+
90 10
24+
100 10
25+
110 10
26+
0 20
27+
10 20
28+
20 20
29+
30 20
30+
40 20
31+
50 20
32+
60 20
33+
70 20
34+
80 20
35+
90 20
36+
100 20
37+
110 20
38+
0 30
39+
10 30
40+
20 30
41+
30 30
42+
40 30
43+
50 30
44+
60 30
45+
70 30
46+
80 30
47+
90 30
48+
100 30
49+
110 30
50+
0 40
51+
10 40
52+
20 40
53+
30 40
54+
40 40
55+
50 40
56+
60 40
57+
70 40
58+
80 40
59+
90 40
60+
100 40
61+
110 40
62+
0 50
63+
10 50
64+
20 50
65+
30 50
66+
40 50
67+
50 50
68+
60 50
69+
70 50
70+
80 50
71+
90 50
72+
100 50
73+
110 50
74+
0 60
75+
10 60
76+
20 60
77+
30 60
78+
40 60
79+
50 60
80+
60 60
81+
70 60
82+
80 60
83+
90 60
84+
100 60
85+
110 60
86+
0 70
87+
10 70
88+
20 70
89+
30 70
90+
40 70
91+
50 70
92+
60 70
93+
70 70
94+
80 70
95+
90 70
96+
100 70
97+
110 70
98+
0 80
99+
10 80
100+
20 80
101+
30 80
102+
40 80
103+
50 80
104+
60 80
105+
70 80
106+
80 80
107+
90 80
108+
100 80
109+
110 80
110+
0 90
111+
10 90
112+
20 90
113+
30 90
114+
40 90
115+
50 90
116+
60 90
117+
70 90
118+
80 90
119+
90 90
120+
100 90
121+
110 90

examples/data/matrix.dat

Lines changed: 121 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)