Python and Python matrix interfaces
You can simply use the Gurobi interactive shell to run the examples by changing to the Gurobi Python example directory (<installdir>/examples/python) and issuing the following command::
gurobi.sh mip1.py
If you have installed gurobipy
into an existing Python installation as listed in the installation options, you should simply run these examples using this Python interpreter of your choice by issuing the command
python mip1.py
C interface
To build and run the example, please refer to the files in <installdir>/examples/build
. For Linux platforms, the <installdir>/examples/build directory contains an example Makefile. Typing make mip1_c will build and run this example.
The C example directory <installdir>/examples/c
contains a number of examples. We encourage you to browse and modify them in order to become more familiar with the Gurobi C interface. We also encourage you to read the Gurobi Example Tour for more information.
C++ interface
To build and run the example, we refer the user to the files in <installdir>/examples/build
. The <installdir>/examples/build directory contains an example Makefile. Typing make mip1_c++ will build and run this example.
If you want to create your own project or makefile to build a C++ program that calls Gurobi, the details will depend on your platform and development environment, but we'd like to point out a few common pitfalls:
- A C++ program that uses Gurobi must link in both the Gurobi C++ library libgurobi_c++.a and the Gurobi C library libgurobi100.so.
- The Gurobi Linux distribution includes multiple C++ libraries. You may need to choose an alternate version (e.g., libgurobi_g++5.2.a), depending on the version of g++ you are using. You should consult the supported platform list for additional information.
The C++ example directory <installdir>/examples/c++
contains a number of examples. We encourage you to browse and modify them in order to become more familiar with the Gurobi C++ interface. We also encourage you to read the Gurobi Example Tour for more information.
Java interface
To build and run the example, please refer to the files in <installdir>/examples/build
. For Linux platforms, the <installdir>/examples/build directory contains an example Makefile. Typing make Mip1 will build and run this example.
The Java example directory <installdir>/examples/java
contains a number of examples. We encourage you to browse and modify them in order to become more familiar with the Gurobi Java interface. We also encourage you to read the Gurobi Example Tour for more information.
.NET interface
The C# and Visual Basic example directories (<installdir>/examples/c#
and <installdir>/examples/vb
) contain a number of examples. We encourage you to browse and modify them in order to become more familiar with the Gurobi .NET interface. We also encourage you to read the Gurobi Example Tour for more information.
To run the C# examples on Linux, you can use the Visual Studio project file, dotnetcore2.csproj (in <installdir>/examples/build/DOTNETCore2), or you can use our standard example Makefile (in <installdir>/examples/build). To run the full set of examples using the Makefile, just execute the command make run_dotnet. You can also run an individual example with make run_mip1_cs (e.g.).
MATLAB interface
The Gurobi MATLAB examples can be found in the <installdir>/examples/matlab/
directory of your Gurobi installation (the default <installdir>
for Gurobi 10.0.1 is /opt/gurobi1001/linux64} for Linux). To run one of the examples, first change to this directory in MATLAB, then type its name into the MATLAB prompt. For example, to run example mip1
, you would say:
>> cd /opt/gurobi1001/linux64/examples/matlab
>> mip1
If Gurobi was successfully set up for use in MATLAB, you should see the following output in the command window:
status: 'OPTIMAL' versioninfo: [1x1 struct] runtime: 3.2401e-04 objval: 3 x: [3x1 double] slack: [2x1 double] poolobjbound: 3 pool: [1x2 struct] mipgap: 0 objbound: 3 objboundc: 3 itercount: 0 baritercount: 0 nodecount: 0 x 1 y 0 z 1 Obj: 3.000000e+00
From all this data we only use the fields objval
and x
in our example. Please refer to the Gurobi Reference Manual for a complete description of all the other output fields.
In order to get more familiar with the Gurobi MATLAB interface, we encourage you to browse through the files in the MATLAB example directory. Often these examples can be used as starting points for your own optimization projects.
R interface
To run one of the R examples provided with the Gurobi distribution, you can use the source
command in R. For example, if you are running R from the Gurobi R examples directory, you can say:
> source('mip.R')
If the Gurobi package was successfully installed, you should see the following output:
[1] "Solution:" [1] 3 [1] 1 0 1
The R example directory <installdir>/examples/R
contains a number of examples. We encourage you to browse and modify them in order to become more familiar with the Gurobi R interface.
Comments
0 comments
Please sign in to leave a comment.