Gurobi¶
Gurobi Optimizer¶
Gurobi Optimizer is a Mixed Integer Programming (MIP) solver provided by Gurobi that can handle quadratic problems in integer and real variables, including QUBO.
Note
To use Gurobi, you need to install the Gurobi Optimizer and license on the machine running the Amplify SDK.
- Solver specification:
Client class
Supported version
9.0.0 or later
API reference
Binary variable
Ising variable
Integer variable
Real variable
Objective function
2nd
-
2nd
2nd
Equality constraint
2nd
-
2nd
2nd
Inequality constraint
2nd
-
2nd
2nd
- Client class:
In addition to the common interface, the client class has the following method.
Note
GurobiClient
file output works as follows.write_request_data
:Output the model to a file with the specified file path extension.
Possible file extensions are.mps
,.rew
,.lp
,.rlp
,.dua/.dlp
(as a model of LP dual problem).
write_response_data
:Output the solution in a file with the specified file path extension.
Possible file extensions are.sol
or.json
.
See also
See Gurobi Parameters for details on the attributes of the
Parameters
class that can be specified inparameters
. Note that the attribute names of theParameters
class are standardized to snake_case.Note
All attributes of the
Parameters
class are initialized toNone
(unset) by default, but some attributes are explicitly passed to Gurobi whenNone
is specified for convenience, as follows.log_to_console
:Contrary to Gurobi’s default (
1
),0
(no output) is treated as default.
seed
:Contrary to Gurobi’s default (
0
), this is initialized by generating a hardware random number.
- Configuration example:
from amplify import GurobiClient from datetime import timedelta client = GurobiClient() # Set installation path # (necessary if the installation path is not detected automatically) # client.library_path = "/opt/gurobi950/linux64/lib/libgurobi.so.9.5.0" # Set the execution time to 100 seconds client.parameters.time_limit = timedelta(seconds=100)
- Execution example:
from amplify import Model, VariableGenerator, solve # Create decision variables and the objective function g = VariableGenerator() q = g.array("Binary", 2) f = q[0] * q[1] + q[0] - q[1] + 1 # Create a model model = Model(f) # Run the solver result = solve(model, client)
To obtain the solver version:
>>> client.version '9.5.0'