torressa / cspy

A collection of algorithms for the (Resource) Constrained Shortest Path problem in Python / C++ / C#
https://torressa.github.io/cspy/
MIT License
77 stars 24 forks source link

cspy k path functionality #112

Open leonardosribeiro opened 1 year ago

leonardosribeiro commented 1 year ago

My name is Leonardo Ribeiro, and I have recently been using your cspy library in a research project that I am doing. I would like to congratulate you on your work. I am working with column generation and it would be interesting in the exact bidirectional algorithm to be able to generate several paths in one round. I saw that other people implemented this function. I am implementing it in Python and so I would need the updated pyBidirectionalCpp.pyd file. However my knowledge of c++ is not yet sufficient to generate the .pyd file from the source code updated by others. I would like to know if you have a tutorial for me to generate the updated pyBidirectionalCpp.pyd file.

Thank you very much!

torressa commented 1 year ago

Hi Leanardo (@leonardosribeiro)!

As you mention, this has already been requested a few times, #103, #105. The first issue, they have a fork (https://github.com/MattiaMiolato/cspy) with I believe working code, also further implementation discussion in the issue. The workflow to compile stuff would just be:

  1. clone (this repo, or the fork from the user in #103: )

  2. install all the dependencies: CMake, SWIG, Standard C++ toolchain, and Python (the last two are typically already installed on some machines).

  3. and just run make p. This compiles the Python library using the updated C++ code, packages it and runs the python unit tests in a virtual environment. I think they already exposed the functionality to Python so you only need to build then use in Python via bidirectional.path(k). The only function missing is setting the value of k (number of paths to store, by default, this is 2). To expose this from C++ to Python, you just need to add a line with the function name to the SWIG interface file here, but I can help you with this.

  4. To test this functionality, you will need to add a unittest to the test/python/ folder following the conventions there. Alternatively, you can install the wheel in build/python/ and play with it locally.

The errors you get from CMake are pretty good if you are missing (or I forgot to list, like in the README) a dependency or something else.

If you want to have a start at this, have a look at the work in the fork and we can go form there.

leonardosribeiro commented 1 year ago

Hi david, thanks for your response.

I ran make p and I`ve got the following error:

1>Checking Build System 1>Creating directories for 'SWIG_project' 2>Building Custom Rule C:/Users/leona/OneDrive/Documentos/CSPY_all_paths/cspy/build/swig-download/CMakeLists.txt Performing download step (download, verify and extract) for 'SWIG_project' CMake Error at swig-download/SWIG_project-prefix/src/SWIG_project-stamp/SWIG_project-download-Debug.cmake:49 (message): Command failed: 1

 'C:/Program Files/CMake/bin/cmake.exe' '-Dmake=' '-Dconfig=Debug' '-P' 'C:/Users/leona/OneDrive/Documentos/CSPY_all_paths/cspy/build/swig-download/SWIG_project-prefix/src/SWIG_project-stamp/SWIG_project-download-Debug-impl.cmake'

See also

  C:/Users/leona/OneDrive/Documentos/CSPY_all_paths/cspy/build/swig-download/SWIG_project-prefix/src/SWIG_project-stamp/SWIG_project-download-*.log

Do you know what happen?

Thank you very much!

torressa commented 1 year ago

Oops sorry since you are on windows please try the commands in this file (the command are the run blocks which you should leave out, you can also try leaving out the Python3 directory stuff as I'm not sure this is always needed)

https://github.com/torressa/cspy/blob/master/.github/workflows/windows_python.yml#L23-L29

leonardosribeiro commented 1 year ago

Hi David, Thank once more for your patience! Now I found this error:

CMake Error at C:/Program Files/CMake/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:230 (message): Could NOT find Python3 (missing: Development Development.Module Development.Embed) (found version "3.10.10") Call Stack (most recent call first): C:/Program Files/CMake/share/cmake-3.26/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE) C:/Program Files/CMake/share/cmake-3.26/Modules/FindPython/Support.cmake:3766 (find_package_handle_standard_args) C:/Program Files/CMake/share/cmake-3.26/Modules/FindPython3.cmake:551 (include) cmake/python.cmake:26 (find_package) CMakeLists.txt:150 (include)

-- Configuring incomplete, errors occurred!

leonardosribeiro commented 1 year ago

Hi David,

I ran the command "cmake -S. -Bbuild -G "Visual Studio 16 2019" -DCMAKE_BUILD_TYPE=Release -DBUILD_PYTHON=ON -DBUILD_TESTING=ON" successfully, but when I run the command "cmake --build build --config Release --target ALL_BUILD -- /verbosity:normal /maxcpucount", I am getting the following error: "C:\CSPY_all_paths\cspy\build\ALL_BUILD.vcxproj" (default target) (1) -> "C:\CSPY_all_paths\cspy\build\python_package.vcxproj" (default target) (3) -> "C:\CSPY_all_paths\cspy\build\src\cc\python\pyBiDirectionalCpp.vcxproj" (default target) (5) -> (Link target) -> bidirectionalPYTHON_wrap.obj : error LNK2019: unresolved external symbol "public: class std::vector<int,class std::allocator > __cdecl bidirectional::BiDirectional::getMerged(void)const " (?getMerged@BiDirectional@bid irectional@@QEBA?AV?$vector@HV?$allocator@H@std@@@std@@XZ) referenced in function _wrap_BiDirectionalCpp_getMerg ed [C:\CSPY_all_paths\cspy\build\src\cc\python\pyBiDirectionalCpp.vcxproj] C:\CSPY_all_paths\cspy\build\RELEASE\bin_pyBiDirectionalCpp.pyd : fatal error LNK1120: 1 unresolved externals [C:\CSPY_all_paths\cspy\build\src\cc\python\pyBiDirectionalCpp.vcxproj

Do you know how can I fix this?

Thanks a lot again!