Skip to content

Commit

Permalink
added bingind to makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Grufoony committed Jan 18, 2023
1 parent f5227a2 commit 11f8610
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: traveltime constant peaked periodic linux debug windows visual docs
.PHONY: traveltime constant peaked periodic linux debug windows visual docs binding
traveltime:
clear
./test.wsl ./data/matrix.dat ./data/vehicletype.dat 300 200 15001
Expand Down Expand Up @@ -31,4 +31,7 @@ visual:
python3 ./utils/visual.py
docs:
clear
doxygen Doxyfile
doxygen Doxyfile
binding:
clear
./src/compile.sh
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ With this script you can also merge differents PNG files into a unique GIF file,
You can also run the library on Python keeping the optimization level given by C++.
To make this you have to make the Pybinding of the code on your personal environment.

To do so, in the main folder run the following commands:
To do so, in the main folder you can just run:

python3 setup.py sdist
pip install .
make binding
3 changes: 1 addition & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ <h1><a class="anchor" id="autotoc_md5"></a>
<h1><a class="anchor" id="autotoc_md7"></a>
Pybinding</h1>
<p>You can also run the library on Python keeping the optimization level given by C++. To make this you have to make the Pybinding of the code on your personal environment.</p>
<p>To do so, in the main folder run the following commands: </p><pre class="fragment">python3 setup.py sdist
pip install .
<p>To do so, in the main folder you can just run: </p><pre class="fragment">make binding
</pre> </div></div><!-- PageDoc -->
</div><!-- contents -->
</div><!-- doc-content -->
Expand Down
28 changes: 13 additions & 15 deletions src/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@
#include "VehicleType.cpp"
#include "VehicleType.hpp"

namespace py = pybind11;

PYBIND11_MODULE(TrafficModel,m) {
m.doc() = "A library for generating traffic flow dynamics data.";

// Graph class
py::class_<Graph>(m,"Graph")
.def(py::init<const char *>())
pybind11::class_<Graph>(m,"Graph")
.def(pybind11::init<const char *>())
.def("addVehicle", static_cast<void (Graph::*)(int)>(&Graph::addVehicle))
.def("addRndmVehicles", &Graph::addRndmVehicles)
.def("addVehiclesUniformly", &Graph::addVehiclesUniformly)
Expand All @@ -37,8 +35,8 @@ PYBIND11_MODULE(TrafficModel,m) {
.def("test", &Graph::test);

// Street class
py::class_<Street>(m,"Street")
.def(py::init<int,int,double,int>())
pybind11::class_<Street>(m,"Street")
.def(pybind11::init<int,int,double,int>())
.def("getOrigin",&Street::getOrigin)
.def("getDestination",&Street::getDestination)
.def("getIndex",&Street::getIndex)
Expand All @@ -55,15 +53,15 @@ PYBIND11_MODULE(TrafficModel,m) {
.def("remVehicle",&Street::remVehicle);

// VehicleType class
py::class_<VehicleType>(m,"VehicleType")
.def(py::init<int,int>())
pybind11::class_<VehicleType>(m,"VehicleType")
.def(pybind11::init<int,int>())
.def("getSource", &VehicleType::getSource)
.def("getDestination", &VehicleType::getDestination)
.def("setTransMatrix", &VehicleType::setTransMatrix);

// Vehicle class
py::class_<Vehicle>(m,"Vehicle")
.def(py::init<int>())
pybind11::class_<Vehicle>(m,"Vehicle")
.def(pybind11::init<int>())
.def_static("addVehicleType", static_cast<void (*)(uint16_t,uint16_t)>(&Vehicle::addVehicleType))
.def_static("addVehicleType", static_cast<void (*)(const char *)>(&Vehicle::addVehicleType))
.def_static("getVehicleType", &Vehicle::getVehicleType)
Expand All @@ -81,11 +79,11 @@ PYBIND11_MODULE(TrafficModel,m) {
.def("getTimeTraveled",&Vehicle::getTimeTraveled)
.def("resetTimeTraveled",&Vehicle::resetTimeTraveled);

py::class_<SparseMatrix<bool>>(m, "SparseMatrix")
.def(py::init<>())
.def(py::init<int, int>())
.def(py::init<const char *>())
.def(py::init<SparseMatrix<bool> const &>())
pybind11::class_<SparseMatrix<bool>>(m, "SparseMatrix")
.def(pybind11::init<>())
.def(pybind11::init<int, int>())
.def(pybind11::init<const char *>())
.def(pybind11::init<SparseMatrix<bool> const &>())
.def("insert", static_cast<void (SparseMatrix<bool>::*)(int, int, bool)>(
&SparseMatrix<bool>::insert))
.def("insert", static_cast<void (SparseMatrix<bool>::*)(int, bool)>(
Expand Down
2 changes: 1 addition & 1 deletion src/compile.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#

g++ -Wall -shared -std=c++20 -fPIC $(python3 -m pybind11 --includes) ./binding.cc -o TrafficModel$(python3-config --extension-suffix)
g++ -O3 -Wall -shared -std=c++20 -fPIC $(python3 -m pybind11 --includes) ./src/binding.cc -o TrafficModel$(python3-config --extension-suffix)

0 comments on commit 11f8610

Please sign in to comment.