Integrating functions from other source codes in SCIP - c++

I'm a master student and I'm currently using SCIP for my thesis. The main implementation task of my thesis is to integrate a meta-heuristic already coded in C++ and ready to be used in the SCIP branch-and-bound process to enhance the solution process of my problem.
How can I call the functions from the meta-heuristic files?
I'm not sure if this information can be useful but I'm using Matlab to load my data and then to compile and run SCIP in Visual Studio using MEX functions. I have already set all the necessary headers in SCIP and Matlab.

I suggest you extend your SCIP by a primal heuristic plugin. General instructions about adding a primal heuristic can be found here.
A C++ Example in source code may be the well-documented TSP example.
In there, you can include and use your existing meta-heuristic code package.

Related

Using tensorflow in C++ on Windows

I know there are ways of using Tensorflow in C++ they even have a documentation for it but I can seem to be able to get the library for it. I've checked the build from source instructions but it seems to builds a pip package rather than a library I can link to my project. I also found a tutorial but when I tried it out I ran out of memory and my computer crashed. My question is, how can I actually get the C++ library to work on my project? I do have these requirements, I have to work on windows with Visual Studio in C++. What I would love to is if I could get a pre-compiled DLL that I could just link but I haven't found such a thing and I'm open to other alternatives.
I can't comment so I am writing this as an answer.
If you don't mind using Keras, you could use the package frugally deep. I haven't seen a library myself either, but I came across frugally deep and it seemed easy to implement. I am currently trying to use it, so I cannot guarantee it will work.
You could check out neural2D from here:
https://github.com/davidrmiller/neural2d
It is a neural network implementation without any dependent libraries (all written from scratch).
I would say that the best option is to use cppflow, an easy wrapper that I created to use Tensorflow from C++ easily.
You won't need to install anything, just download the TF C API, and place it somewhere in your computer. You can take a look to the docs to see how to do it, and how to use the library.
The answer seems to be that it is hard :-(
Try this to start. You can follow the latest instructions for building from source on Windows up to the point of building the pip package. But don't do that - do this/these instead:
bazel -config=opt //tensorflow:tensorflow.dll
bazel -config=opt //tensorflow:tensorflow.lib
bazel -config=opt tensorflow:install_headers
That much seems to work fine. The problems really start when you try to use Any of the header files - you will probably get compilation errors, at least with TF version >= 2.0. I have tried:
Build the label_image example (instructions in the readme.md file)
It builds and runs fine on Windows, meaning all the headers and source are there somewhere
Try incorporating that source into Windows console executable: runs into compiler errors due to conflicts with std::min & std::max, probably due to Windows SDK.
Include c_api.h in a Windows console application: won't compile.
Include TF-Lite header files: won't compile.
There is little point investing the lengthy compile time in the first two bazel commands if you can't get the headers to compile :-(
You may have time to invest in resolving these errors; I don't. At this stage Tensorflow lacks sufficient support for Windows C++ to rely on it, particularly in a commercial setting. I suggest exploring these options instead:
If TF-Lite is an option, watch this
Windows ML/Direct ML (requires conversion of TF models to ONNX format)
CPPFlow
Frugally Deep
Keras2CPP
UPDATE: having explored the list above, I eventually found the following worked best in my context (real-time continuous item recognition):
convert models to ONNX format (use tf2onnx or keras2onnx
use Microsoft's ONNX runtime
Even though Microsoft recommends using DirectML where milliseconds matter, the performance of ONNX runtime using DirectML as an execution provider means we can run a 224x224 RGB image through our Intel GPU in around 20ms, which is quick enough for us. But it was still hard finding our way to this answer

Generated C++ code using MATLAB Coder : Compilation Error "undefined reference to `rgb2gray_tbb_real64'"

Generated C++ code from MATLAB for converting an image to grayscale, using MATLAB Coder. While compiling it on Dev C++ it shows error- undefined reference to rgb2gray_tbb_real64
One of the Generated code uses header file libmwrgb2gray_tbb.h. Screenschot It calls a function rgb2gray_tbb_real64, which is not defined anywhere.
How to sort this out?
Image Processing Toolbox code generation supports 2 distinct modes:
Generated code uses platform-specific optimized shared libraries. This is enabled for the MATLAB Coder hardware target MATLAB Host Computer and a few other similar targets.
Generated code is standalone, independent of shared libraries, and portable
The documentation covers these concepts in more detail. When using option (1), you must package the generated code using Coder utilities in order to relocate it. MATLAB Coder knows how to properly gather and package all of the dependencies for your generated code.
To do this packaging, you can use the packNGo function, use the Package button on the Finish Workflow screen of the MATLAB Coder App, or the Package Code button in the MATLAB Coder report. These steps are detailed in the MATLAB Coder documentation. To use packNGo you can:
codegen myFunction -args {1,2,3} -config:lib -report
load(fullfile('codegen','lib','myFunction','buildInfo.mat'));
packNGo(buildInfo, 'fileName', 'myFunction.zip');
That will create myFunction.zip in your current directory which will contain your generated code and all of the headers and libraries on which it depends. You can then import all of those into your IDE of choice.

Debug Quantlib Source code

I recently started to use Quantlib in Visual Studio. I have succesfully got Quantlib installed and working. I also managed to use Quantlib to price some products such as Swap and Swaption. The Swap prices match my own VBA calculator quite well (<0.5% difference). For Swaption prices, there are some difference (around 5%). So I want to check through all the intermediate results in Quantlib to see where does this 5% difference comes from. However, I cannot debug through the Quantlib source code in my project. I think this is because my project only include the pre-built Quantlib libary and boost libary, so I can see the header files only in my project. But, I cannot put break points in the header files to debug.
Although I can manually locate the source file in the Quantlib installation folder, it doesn't help with debugging. So my question is that is there any way I can step through the Quantlib source code in my project?
For example, I am currently interested in the detail calculation steps in BlackSwaptionEngine. I just need to set up the swaption and pricing engine, and use the Quantlib NPV function to get the result:
boost::shared_ptr<Exercise> europeanExercise(new EuropeanExercise(expiryDate));
Swaption testSwaption(swap, europeanExercise);
boost::shared_ptr<PricingEngine> swaptionEngine(new BlackSwaptionEngine(forwardingTermStructure, Vol));
testSwaption.setPricingEngine(swaptionEngine);
double res = testSwaption.NPV();
Yes, I can get result. But I also want to know the intermediate result inside the BlackSwaptionEngine. So step through the source code seems to be a good way to find this out. How can I include the Quantlib source code in my project to debug?
Any help is appreciated. Many thanks.
I have managed to debug into the Quantlib source code in the end. As Luigi suggested, we need to build Quantlib in Debug mode, and then link the library and directory as this link:
quantlib.org/install/vc10.shtml
Then, we can step into the source code of Quantlib in the application project.

Calling GLPK from C++ while using Rcpp

I am developing part of my R package in C++ using Rcpp and I need to use a Linear Programming Solver.
After comparing some benchmarks using the solvers implementation into R (lpSolveAPI, Rglpk, Rsymphony and so on) I have decided to use GLPK. However, I have found no good way to use it in my C++ code developing under Windows.
Simply put, there is no simple way to just install GLPK and call it using something like
#include <glpk.h>
and I have found no implementations in R packages so that I can use a shortcut using Rcpp attributes like
// [[Rcpp::depends(package)]]
Any ideas?
I'm sure you are aware of the Rglpk package and its predecessor glpk. Often in these cases, it's helpful to stand on the shoulders of those that came before us. Having said that, we gleam from the package sources the following:
The source of Rglpk requires a pre-existing system install, does not enable linking, and is specific to Linux.
The source of glpk installs the library headers directly in R and it seems to also provide direct wrappers into the library.
Given the current implementations and your requirements, you would basically have to create an RcppGLPK package. This is primarily because no one really has a solution for what you need. I would highly suggest that you look at how RcppGSL is structured.

Activate Run the libLAS C++ library within R

I would like to use the libLAS C/C++ library functions within R to import, analyse, export terrestrial lidar data. libLAS is a C/C++ library for reading and writing the very common LAS LiDAR format ( http://liblas.org/index.html ).
Would it be possible to use the Rcpp package to run this library (or other packages)? http://dirk.eddelbuettel.com/code/rcpp.html
Or should I compile and install it in order to use it following the compilation instructions http://liblas.org/compilation.html ? I am working on a MacOSx 10.6.5. As such I could also use it within Open Source GIS GRASS as described in the following wiki http://grass.osgeo.org/wiki/LIDAR#Micro-tutorial_for_LAS_data_import .
All advice is welcome related to reading and processing LIDAR data with R/GRASS.
Thanks,
Jan
For the question
Would it be possible to use the Rcpp
package to run this library (or other
packages)?
the answer is whopping Yup! as using it for glueing R to a given C/C++ library was pretty much the reason Rcpp was written for. Come and see the documentation and/or the rcpp-devel list for examples. There is some exciting new stuff happening with Rcpp modules but you can also get going the old-fashioned way of writing your wrapper. Rcpp makes mapping and R and C++ types (in both directions) a lot easier.