gurobi
Class GRBEnv

java.lang.Object
  extended by gurobi.GRBEnv

public class GRBEnv
extends java.lang.Object

Gurobi environment object. Gurobi models are always associated with an environment. You must create an environment before can you create and populate a model. You will generally only need a single environment object in your program.

The methods on environment objects are mainly used to manage Gurobi parameters (e.g., @link GRBEnv#get get, @link GRBEnv#getParamInfo getParamInfo, @link GRBEnv#set set).

While the Java garbage collector will eventually collect an unused


Constructor Summary
GRBEnv()
          Create a Gurobi environment (with logging disabled).
GRBEnv(boolean empty)
           
GRBEnv(java.lang.String logFileName)
          Create a Gurobi environment (with logging enabled).
GRBEnv(java.lang.String s0, java.lang.String s1, java.lang.String s2, int i1, java.lang.String s3)
           
GRBEnv(java.lang.String logfilename, java.lang.String accessID, java.lang.String secretKey, java.lang.String pool, int priority)
          Create a Gurobi environment on Gurobi Instant Cloud.
GRBEnv(java.lang.String logFileName, java.lang.String computeServer, java.lang.String router, java.lang.String password, java.lang.String group, int CStlsInsecure, int priority, double timeout)
          Create a client Gurobi environment on a compute server.
 
Method Summary
 void dispose()
          Release the resources associated with a @code 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.
 java.lang.String get(GRB.StringParam param)
          Query the value of a string-valued parameter.
 java.lang.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, java.lang.String[] info)
          Obtain detailed information about a string parameter.
 void message(java.lang.String message)
          Write a message to the console and the log file.
protected  void modelCntDecrease()
           
protected  void modelCntIncrease()
           
protected  boolean modelCntZero()
           
 void readParams(java.lang.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, java.lang.String newval)
          Set the value of a string-valued parameter.
 void set(java.lang.String param, java.lang.String newval)
          Set the value of any parameter using strings alone.
 void start()
          Start an empty environment.
 void writeParams(java.lang.String paramFile)
          Write all non-default parameter settings to a file.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GRBEnv

public GRBEnv()
       throws GRBException
Create a Gurobi environment (with logging disabled). 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 @literal 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.

Throws:
GRBException

GRBEnv

public GRBEnv(java.lang.String logFileName)
       throws GRBException
Create a Gurobi environment (with logging enabled). 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 @literal 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.

Parameters:
logFileName - The desired log file name.
Throws:
GRBException

GRBEnv

public GRBEnv(boolean empty)
       throws GRBException
Throws:
GRBException

GRBEnv

public GRBEnv(java.lang.String logFileName,
              java.lang.String computeServer,
              java.lang.String router,
              java.lang.String password,
              java.lang.String group,
              int CStlsInsecure,
              int priority,
              double timeout)
       throws GRBException
Create a client Gurobi environment on a compute server. 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 @literal 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.

Parameters:
logFileName - The name of the log file for this environment. Pass an empty string for no log file.
computeServer - A Compute Server. You can refer to the server using its name or its IP address. If you are using a non-default port, the server name should be followed by the port number (e.g., @literal server1:61000)
router - The router for a Compute Server cluster. A router can be used to improve the robustness of a Compute Server deployment. You should refer to the router using either its name or its IP address. If no router is used (which is the typical case), pass an empty string.
password - The password for gaining access to the specified Compute Server cluster. Pass an empty string if no password is required.
group - The name of the Compute Server group.
CStlsInsecure - Indicates whether to use insecure mode in the TLS (Transport Layer Security). Set this to 0 unless your server administrator tells you otherwise.
priority - The priority of the job. Priorities must be between -100 and 100, with a default value of 0 (by convention). Higher priority jobs are chosen from the server job queue before lower priority jobs. Depending on the configuration of the server, a job with priority 100 runs immediately, bypassing the job queue and ignoring the job limit on the server. You should exercise caution with priority 100 jobs, since they can severely overload a server, which can cause jobs to fail, and in extreme cases can cause the server to crash. This behavior is managed by the HARDJOBLIMIT, and is disabled by default. Refer to the Gurobi Remote Services Reference Manual for more information on starting Compute Server options.
timeout - Queue timeout (in seconds). If the job doesn't reach the front of the queue before the specified timeout, the call will exit with a @literal JOB_REJECTED error. Use -1 to indicate that the call should never timeout.
Throws:
GRBException

GRBEnv

public GRBEnv(java.lang.String logfilename,
              java.lang.String accessID,
              java.lang.String secretKey,
              java.lang.String pool,
              int priority)
       throws GRBException
Create a Gurobi environment on Gurobi Instant Cloud. 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 @literal 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.

Parameters:
logfilename - The name of the log file for this environment. May be @literal NULL (or an empty string), in which case no log file is created.
accessID - The access ID for your Gurobi Instant Cloud license. This can be retrieved from the Gurobi Instant Cloud website. When used in combination with your @literal secretKey, this allows you to launch Instant Cloud instances and submit jobs to them.
secretKey - The secret key for your Gurobi Instant Cloud license. This can be retrieved from the Gurobi Instant Cloud website. When used in combination with your @literal accessID, this allows you to launch Instant Cloud instances and submit jobs to them. Note that you should keep your secret key private.
pool - The machine pool. Machine pools allow you to create fixed configurations on the Instant Cloud website (capturing things like type of machine, geographic region, etc.), and then launch and share machines from client programs without having to restart the configuration information each time you launch a machine. May be
priority - The priority of the job. Priorities must be between -100 and 100, with a default value of 0 (by convention). Higher priority jobs are chosen from the server job queue before lower priority jobs.
Throws:
GRBException

GRBEnv

public GRBEnv(java.lang.String s0,
              java.lang.String s1,
              java.lang.String s2,
              int i1,
              java.lang.String s3)
       throws GRBException
Throws:
GRBException
Method Detail

start

public void start()
           throws GRBException
Start an empty environment. If the environment has already been started, this method will do nothing. If the call fails, the environment will have the same state as it had before the call to this method.

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 @literal 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.

Throws:
GRBException

release

public void release()
Release the license associated with this environment. You will no longer be able to call @link GRBModel#optimize optimize on models created with this environment after the license has been released.


dispose

public void dispose()
             throws GRBException
Release the resources associated with a @code GRBEnv object. While the Java garbage collector will eventually reclaim these resources, we recommend that you call the @code dispose method when you are done using an environment if your program creates more than one.

The @code dispose method on a @code GRBEnv should be called only after you have called @code dispose on all of the models that were created within that environment. You should not attempt to use a @code GRBEnv object after calling @code dispose.

Throws:
GRBException

finalize

protected void finalize()
                 throws GRBException
Overrides:
finalize in class java.lang.Object
Throws:
GRBException

message

public void message(java.lang.String message)
             throws GRBException
Write a message to the console and the log file.

Parameters:
message - Print a message to the console and to the log file. Note that this call has no effect unless the @literal OutputFlag parameter is set.
Throws:
GRBException

get

public int get(GRB.IntParam param)
        throws GRBException
Query the value of an int-valued parameter.

Parameters:
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.
Returns:
The current value of the requested parameter.
Throws:
GRBException

get

public double get(GRB.DoubleParam param)
           throws GRBException
Query the value of a double-valued parameter.

Parameters:
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.
Returns:
The current value of the requested parameter.
Throws:
GRBException

get

public java.lang.String get(GRB.StringParam param)
                     throws GRBException
Query the value of a string-valued parameter.

Parameters:
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.
Returns:
The current value of the requested parameter.
Throws:
GRBException

set

public void set(GRB.IntParam param,
                int newval)
         throws GRBException
Set the value of an int-valued parameter.

Parameters:
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.
Throws:
GRBException

set

public void set(GRB.DoubleParam param,
                double newval)
         throws GRBException
Set the value of a double-valued parameter.

Parameters:
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.
Throws:
GRBException

set

public void set(GRB.StringParam param,
                java.lang.String newval)
         throws GRBException
Set the value of a string-valued parameter.

Parameters:
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.
Throws:
GRBException

set

public void set(java.lang.String param,
                java.lang.String newval)
         throws GRBException
Set the value of any parameter using strings alone.

Parameters:
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.
Throws:
GRBException

getParamInfo

public void getParamInfo(GRB.IntParam param,
                         int[] info)
                  throws GRBException
Obtain detailed information about an integer parameter.

Parameters:
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.
Throws:
GRBException

getParamInfo

public void getParamInfo(GRB.DoubleParam param,
                         double[] info)
                  throws GRBException
Obtain detailed information about a double parameter.

Parameters:
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.
Throws:
GRBException

getParamInfo

public void getParamInfo(GRB.StringParam param,
                         java.lang.String[] info)
                  throws GRBException
Obtain detailed information about a string parameter.

Parameters:
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.
Throws:
GRBException

resetParams

public void resetParams()
                 throws GRBException
Reset all parameters to their default values.

Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.

Throws:
GRBException

writeParams

public void writeParams(java.lang.String paramFile)
                 throws GRBException
Write all non-default parameter settings to a file.

Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.

Parameters:
paramFile - Name of the file to which non-default parameter settings should be written. The previous contents are overwritten.
Throws:
GRBException

readParams

public void readParams(java.lang.String paramFile)
                throws GRBException
Read new parameter settings from a file.

Please consult the parameter section for a complete list of Gurobi parameters, including descriptions of their purposes and their minimum, maximum, and default values.

Parameters:
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.

Throws:
GRBException

getErrorMsg

public java.lang.String getErrorMsg()
Query the error message for the most recent exception associated with this environment.

Returns:
The error string.

modelCntIncrease

protected void modelCntIncrease()

modelCntDecrease

protected void modelCntDecrease()

modelCntZero

protected boolean modelCntZero()