Installing Xpress Solver and Loading it Dynamically¶
This document explains how to install the Xpress solver in both default and non-default locations, as well as how Antares-Xpansion dynamically loads the Xpress library and license.
Table of Contents¶
- Installing Xpress
- Default Installation
- Non-Default Installation
- How the Code Loads Xpress
- Locating Xpress Libraries
- Loading License Information
- Handling Different Platforms
Installing Xpress¶
Default Installation¶
By default, the Xpress solver will be installed in system-wide directories depending on your operating system. The default installation paths are:
- Windows:
C:\xpressmp\bin\xprs.dllorC:\Program Files\xpressmp\bin\xprs.dll - macOS:
/Library/xpressmp/lib/libxprs.dylib - Linux:
/opt/xpressmp/lib/libxprs.so
After installing the Xpress solver, the environment variable XPRESSDIR should point to the installation directory. This will help the system locate the required libraries.
Non-Default Installation¶
For non-default installations, you need to manually configure the XPRESSDIR environment variable to point to the custom installation path. For example:
Windows¶
set XPRESSDIR=C:\custom\xpress\path
Linux/macOS¶
export XPRESSDIR=/home/user/custom/xpress/path
How the Code Loads Xpress¶
The C++ code dynamically loads the Xpress solver library and configures the licensing environment at runtime. Here's a step-by-step explanation of how it works:
Locating Xpress Libraries¶
-
Check for
XPRESSDIR:
The code first checks if theXPRESSDIRenvironment variable is defined. This variable should point to the directory where the Xpress solver is installed. -
Build the Path to the Library:
Depending on the platform, the code appends the correct subdirectory to theXPRESSDIRpath: - Windows: Adds
\bin(e.g.,C:\xpressmp\bin\xprs.dll). -
macOS/Linux: Adds
/lib(e.g.,/opt/xpressmp/lib/libxprs.so). -
Attempt to Load the Library:
The code then attempts to load the Xpress library using platform-specific functions: - Windows: Uses
LoadLibrary()to loadxprs.dll. - macOS: Uses
dlopen()to loadlibxprs.dylib. -
Linux: Uses
dlopen()to loadlibxprs.so. -
Error Handling:
If the library cannot be found or loaded, an error message is displayed, providing troubleshooting suggestions for the user (e.g., checkingXPRESSDIRor ensuring the file is in the correct path).
Loading License Information¶
-
Locate License Directory:
The code looks for alicensesubdirectory inside theXPRESSDIRpath. This folder typically contains the necessary license files for the Xpress solver. -
Set Environment Variables for License:
To ensure Xpress can authenticate properly, the code sets the following environment variables: -
XPRESSDIR: Points to the root installation directory of the Xpress solver. XPAUTH: If this environment variable is set, it points directly to the license file (e.g.,xpauth.xpr). This provides a more explicit way to define the path to the license file rather than relying on the defaultlicensesubdirectory.
This approach allows greater flexibility when managing license files, especially in environments where the XPRESSDIR/license/ directory may not be the default location for license files.
- Error Handling for License:
If the license file or directory is missing, the code raises an error and provides recommendations: - Suggests checking the value of
XPRESSDIRand ensuring the license file exists in the defaultlicensesubdirectory. - Advises checking or setting the
XPAUTHenvironment variable to the correct license file path in case the file is stored in a custom location.
Using XPAUTH allows for better flexibility in license management, particularly in cloud or containerized environments, where environment variables are commonly used to configure paths dynamically.
Handling Different Platforms¶
To ensure cross-platform compatibility, the code contains specific logic to handle each operating system:
-
Windows:
The code uses theLoadLibrary()function to load thexprs.dllfile. After loading, it retrieves function pointers from the library usingGetProcAddress(). -
Linux/macOS:
The code usesdlopen()to load shared libraries (libxprs.sofor Linux andlibxprs.dylibfor macOS). Function pointers are retrieved usingdlsym().
The dynamic loading process ensures that the program does not need to be recompiled when the library is installed in different locations or on different platforms.