public class GRBEnv extends Object
The methods on environment objects are mainly used to manage Gurobi
parameters (e.g., get
, getParamInfo
, set
).
While the Java garbage collector will eventually collect an unused
GRBEnv
object, an environment will hold onto resources (Gurobi
licenses, file descriptors, etc.) until that collection occurs. If
your program creates multiple GRBEnv
objects, we recommend
that you call GRBEnv.dispose
when you are done using one.
Constructor and Description |
---|
GRBEnv()
Create a Gurobi environment (with logging disabled).
|
GRBEnv(boolean empty)
Create an empty Gurobi environment.
|
GRBEnv(String logFileName)
Create a Gurobi environment (with logging enabled).
|
GRBEnv(String s0,
String s1,
String s2) |
GRBEnv(String s0,
String s1,
String s2,
int i1,
String s3) |
Modifier and Type | Method and Description |
---|---|
void |
dispose()
Release the resources associated with a
GRBEnv object. |
protected void |
finalize() |
double |
get(GRB.DoubleParam param)
Query the value of a double-valued parameter.
|
int |
get(GRB.IntParam param)
Query the value of an int-valued parameter.
|
String |
get(GRB.StringParam param)
Query the value of a string-valued parameter.
|
String |
getErrorMsg()
Query the error message for the most recent exception associated with
this environment.
|
void |
getParamInfo(GRB.DoubleParam param,
double[] info)
Obtain detailed information about a double parameter.
|
void |
getParamInfo(GRB.IntParam param,
int[] info)
Obtain detailed information about an integer parameter.
|
void |
getParamInfo(GRB.StringParam param,
String[] info)
Obtain detailed information about a string parameter.
|
int |
getWLSTokenLifespan() |
void |
message(String message)
Write a message to the console and the log file.
|
protected void |
modelCntDecrease() |
protected void |
modelCntIncrease() |
protected boolean |
modelCntZero() |
void |
readParams(String paramFile)
Read new parameter settings from a file.
|
void |
release()
Release the license associated with this environment.
|
void |
resetParams()
Reset all parameters to their default values.
|
void |
set(GRB.DoubleParam param,
double newval)
Set the value of a double-valued parameter.
|
void |
set(GRB.IntParam param,
int newval)
Set the value of an int-valued parameter.
|
void |
set(GRB.StringParam param,
String newval)
Set the value of a string-valued parameter.
|
void |
set(String param,
String newval)
Set the value of any parameter using strings alone.
|
void |
setLogCallback(Consumer<String> logCallback)
Sets a logging callback function to query all output posted by the
environment object.
|
void |
start()
Start an empty environment.
|
void |
writeParams(String paramFile)
Write all non-default parameter settings to a file.
|
public GRBEnv() throws GRBException
In general, you should aim to create a single Gurobi environment in your program, even if you plan to work with multiple models. Reusing one environment is much more efficient than creating and destroying multiple environments. The one exception is if you are writing a multi-threaded program, since environments are not thread safe. In this case, you will need a separate environment for each of your threads.
GRBException
public GRBEnv(String logFileName) throws GRBException
In general, you should aim to create a single Gurobi environment in your program, even if you plan to work with multiple models. Reusing one environment is much more efficient than creating and destroying multiple environments. The one exception is if you are writing a multi-threaded program, since environments are not thread safe. In this case, you will need a separate environment for each of your threads.
logFileName
- The desired log file name.GRBException
public GRBEnv(boolean empty) throws GRBException
start
to start the environment. If the environment is not empty, This method will also populate any parameter (ComputeServer, TokenServer, ServerPassword, etc.) specified in your gurobi.lic file. This method will also check the current working directory for a file named gurobi.env, and it will attempt to read parameter settings from this file if it exists. The file should be in PRM format (briefly, each line should contain a parameter name, followed by the desired value for that parameter).
In general, you should aim to create a single Gurobi environment in your program, even if you plan to work with multiple models. Reusing one environment is much more efficient than creating and destroying multiple environments. The one exception is if you are writing a multi-threaded program, since environments are not thread safe. In this case, you will need a separate environment for each of your threads.
empty
- Indicates whether the environment should be empty. You should use
empty=true if you want to set parameters before actually
starting the environment. This can be useful if you want to connect to
a Compute Server, a Token Server, the Gurobi Instant Cloud, a Cluster
Manager or use a WLS license. See the Environment~Section for more
details.GRBException
public GRBEnv(String s0, String s1, String s2, int i1, String s3) throws GRBException
GRBException
public GRBEnv(String s0, String s1, String s2) throws GRBException
GRBException
public void start() throws GRBException
This method will also populate any parameter (ComputeServer, TokenServer, ServerPassword, etc.) specified in your gurobi.lic file. This method will also check the current working directory for a file named gurobi.env, and it will attempt to read parameter settings from this file if it exists. The file should be in PRM format (briefly, each line should contain a parameter name, followed by the desired value for that parameter). After that, it will apply all parameter changes specified by the user prior to this call. Note that this might overwrite parameters set in the license file, or in the gurobi.env file, if present.
After all these changes are performed, the code will actually activate the environment, and make it ready to work with models.
In general, you should aim to create a single Gurobi environment in your program, even if you plan to work with multiple models. Reusing one environment is much more efficient than creating and destroying multiple environments. The one exception is if you are writing a multi-threaded program, since environments are not thread safe. In this case, you will need a separate environment for each of your threads.
Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.
GRBException
public void release()
optimize
on models created with this environment after the license
has been released.public void dispose() throws GRBException
GRBEnv
object. While
the Java garbage collector will eventually reclaim these resources, we
recommend that you call the dispose
method when you are done
using an environment if your program creates more than one.
The dispose
method on a GRBEnv
should be called only
after you have called dispose
on all of the models that were
created within that environment. You should not attempt to use a
GRBEnv
object after calling dispose
.
GRBException
protected void finalize() throws GRBException
finalize
in class Object
GRBException
public int getWLSTokenLifespan() throws GRBException
GRBException
public void setLogCallback(Consumer<String> logCallback)
logCallback
- The logging callback function.public void message(String message) throws GRBException
message
- Print a message to the console and to the log file. Note that this
call has no effect unless the OutputFlag parameter is set.GRBException
public int get(GRB.IntParam param) throws GRBException
param
- The parameter being queried. Please consult the parameter section for
a complete list of Gurobi parameters, including descriptions of their
purposes and their minimum, maximum, and default values.GRBException
public double get(GRB.DoubleParam param) throws GRBException
param
- The parameter being queried. Please consult the parameter section for
a complete list of Gurobi parameters, including descriptions of their
purposes and their minimum, maximum, and default values.GRBException
public String get(GRB.StringParam param) throws GRBException
param
- The parameter being queried. Please consult the parameter section for
a complete list of Gurobi parameters, including descriptions of their
purposes and their minimum, maximum, and default values.GRBException
public void set(GRB.IntParam param, int newval) throws GRBException
param
- The parameter being modified. Please consult the parameter section for
a complete list of Gurobi parameters, including descriptions of their
purposes and their minimum, maximum, and default values.newval
- The desired new value of the parameter.GRBException
public void set(GRB.DoubleParam param, double newval) throws GRBException
param
- The parameter being modified. Please consult the parameter section for
a complete list of Gurobi parameters, including descriptions of their
purposes and their minimum, maximum, and default values.newval
- The desired new value of the parameter.GRBException
public void set(GRB.StringParam param, String newval) throws GRBException
param
- The parameter being modified. Please consult the parameter section for
a complete list of Gurobi parameters, including descriptions of their
purposes and their minimum, maximum, and default values.newval
- The desired new value of the parameter.GRBException
public void set(String param, String newval) throws GRBException
param
- The name of the parameter being modified. Please consult the parameter
section for a complete list of Gurobi parameters, including
descriptions of their purposes and their minimum, maximum, and default
values.newval
- The desired new value of the parameter.GRBException
public void getParamInfo(GRB.IntParam param, int[] info) throws GRBException
param
- The parameter of interest. Please consult the parameter section for a
complete list of Gurobi parameters, including descriptions of their
purposes and their minimum, maximum, and default values.info
- The returned information. The result will contain four entries: the
current value of the parameter, the minimum allowed value, the maximum
allowed value, and the default value.GRBException
public void getParamInfo(GRB.DoubleParam param, double[] info) throws GRBException
param
- The parameter of interest. Please consult the parameter section for a
complete list of Gurobi parameters, including descriptions of their
purposes and their minimum, maximum, and default values.info
- The returned information. The result will contain four entries: the
current value of the parameter, the minimum allowed value, the maximum
allowed value, and the default value.GRBException
public void getParamInfo(GRB.StringParam param, String[] info) throws GRBException
param
- The parameter of interest. Please consult the parameter section for a
complete list of Gurobi parameters, including descriptions of their
purposes and their minimum, maximum, and default values.info
- The returned information. The result will contain two entries: the
current value of the parameter and the default value.GRBException
public void resetParams() throws GRBException
Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.
GRBException
public void writeParams(String paramFile) throws GRBException
Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.
paramFile
- Name of the file to which non-default parameter settings should be
written. The previous contents are overwritten.GRBException
public void readParams(String paramFile) throws GRBException
Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.
paramFile
- Name of the file containing parameter settings. Parameters should be
listed one per line, with the parameter name first and the desired
value second. For example: Blank lines and lines that begin with the hash symbol are ignored.
GRBException
public String getErrorMsg()
protected void modelCntIncrease()
protected void modelCntDecrease()
protected boolean modelCntZero()
Copyright © 2024. All rights reserved.