How to use Google Optimization Tools DLLs ?

Hi !

I need to use one algorithm from the Google Optimizations Tools (OR-Tools  |  Google for Developers). I saw they are distributed as DLLs for C#, so I guess there must be some way to use them in Unity. But I couldn’t make it work.

I downloaded the binaries, and dropped Google.OrTools.dll and Google.Protobuf.dll to my Assets. In Visual Studio, when I add the DLLs using “Add reference”, they seem to load correctly (I have auto completion). So I wrote some code. But back in Unity, I get compile errors :

Assets/GameManagement/GameManager.cs(7,7): error CS0246: The type or namespace name `Google' could not be found. Are you missing an assembly reference?

I tried activating the experimental 4.6 .NET framework in the Player menu. It makes a small difference, as it seems this time Google.Protobuf.dll is recognized, as now I get this error :

Assets/GameManagement/GameManager.cs(7,14): error CS0234: The type or namespace name `OrTools' does not exist in the namespace `Google'. Are you missing an assembly reference?

I noticed a strange thing : Google.Protobuf.dll loads as a “managed” plugin, while Google.OrTools.dll loads as a “native” plugin. But both are supposed to be C# (as far as I understood).

Any idea about how I can make this work ?

Thank you very much !!

I was thinking about using ortools in Unity3D, and I found your question @unity_OEAzALRYPNThtQ

AFAIK C# version of ortools is just a wrapper. That means that there is C# code that calls a C++ dll compiled for x86/x64 architecture under Windows, Linux and OSX distributions.

So, there are some problems.

If you want just to use ortools with supported architectures (windows, linux and osx - x86 and x64), you need a Unity 3D commercial license, because the actual ortools code that will be called is still written as a C++ unmanaged library, and probably that’s the missing assembly reference you have in Unity3D.

Keep in mind that a “managed” dll is a dll written in C# (and only in C#), while an “unmanaged” library is a library written in C++. The name difference is that in managed you use a managed memory allocation, provided by .net framework (garbage collection) while in unmanaged you need to take care of memory allocation details (new/delete mechanism in C++).

If you want to use ortools with other targets (arm for example) I guess you’d need to build (crosscompile) ortools for arm, because current distribution of ortools targets x86/x64 version. That is doable, and I would be thrilled to try to do it.

For reference: I did crosscompile external libs written in C using android (x86/x64/arm/can’t remember :D), but it required me to use Crystax NDK, because default NDK didn’t support (yet) some standard C math function. I don’t know if this is the case, but it could save some time :slight_smile: