### Start an empty GRBEnv with Compute Server parameters (Visual Basic) Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/dotnet/env.html Visual Basic equivalent of the C# example: creates an empty environment, sets Compute Server and password parameters, then starts the environment. ```Visual Basic ' Create empty environment Dim env As GRBEnv = New GRBEnv(true) ' Populate Compute Server parameters env.Set("ComputeServer", "server1:61000") env.Set("ServerPassword", "passwd") ' Start the environment env.Start() ``` -------------------------------- ### Run the mip1 MATLAB example Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/matlab/setup.html Change to the examples/matlab directory and run the mip1 example. If the installation is successful, the output shows the optimal solution with status 'OPTIMAL' and objective value 3. ```matlab >> cd c:/Users/jones/gurobi1100/win64/examples/matlab >> mip1 ``` -------------------------------- ### Compute Server Example in C++ Source: https://docs.gurobi.com/projects/optimizer/en/current/concepts/environments/configuration.html Creates an empty environment, sets Compute Server parameters (ComputeServer, ServerPassword), starts the environment, and loads/optimizes a model. Uses GRBEnv(true), set, start, GRBModel, and optimize. ```C++ #include "gurobi_c++.h" // Create empty environment, set options and start GRBEnv env = GRBEnv(true); env.set(GRB_StringParam_ComputeServer, "server1:61000"); env.set(GRB_StringParam_ServerPassword, "passwd"); env.start(); // Load model and optimize GRBModel model = GRBModel(env, "misc07.mps"); model.optimize(); ``` -------------------------------- ### Command-line tuning with MIP start file Source: https://docs.gurobi.com/projects/optimizer/en/current/features/tuning.html Use this command to start a tuning run with a MIP start file. The start file name is placed immediately after the model name. The example sets TuneTimeLimit to 3600 and TimeLimit to 100. ```bash grbtune TuneTimeLimit=3600 TimeLimit=100 glass4.mps glass4.mst ``` -------------------------------- ### Cluster Manager Example in C++ Source: https://docs.gurobi.com/projects/optimizer/en/current/concepts/environments/configuration.html Creates an empty environment, sets Cluster Manager parameters (CSManager, CSAPIAccessID, CSAPISecret), starts the environment, and loads/optimizes a model. Uses GRBEnv(true), set, start, GRBModel, and optimize. ```C++ #include "gurobi_c++.h" // Create empty environment, set options and start GRBEnv env = GRBEnv(true); env.set(GRB_StringParam_CSManager, "server1:61080"); env.set(GRB_StringParam_CSAPIAccessID, "12345-678990"); env.set(GRB_StringParam_CSAPISecret, "abcdef-abcdef"); env.start(); // Load model and optimize GRBModel model = GRBModel(env, "misc07.mps"); model.optimize(); ``` -------------------------------- ### Cluster Manager Example in C# Source: https://docs.gurobi.com/projects/optimizer/en/current/concepts/environments/configuration.html Creates an empty environment, sets Cluster Manager parameters (CSManager, CSAPIAccessID, CSAPISecret), starts the environment, and loads/optimizes a model. Uses GRBEnv(true), Set, Start, GRBModel, and Optimize. ```C# using Gurobi; // Create empty environment, set options and start using GRBEnv env = new GRBEnv(true); env.Set("CSManager", "server1:61080"); env.Set("CSAPIAccessID", "12345-678990"); env.Set("CSAPISecret", "abcdef-abcdef"); env.Start(); // Load model and optimize using GRBModel model = new GRBModel(env, "misc07.mps"); model.Optimize(); ``` -------------------------------- ### Start an empty GRBEnv with Compute Server parameters (C#) Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/dotnet/env.html Creates an empty environment, sets Compute Server and password parameters, then starts the environment. The Start() method applies parameters from gurobi.lic and gurobi.env before activating. ```C# // Create empty environment GRBEnv env = new GRBEnv(true); // Populate Compute Server parameters env.Set("ComputeServer", "server1:61000"); env.Set("ServerPassword", "passwd"); // Start the environment env.Start(); ``` -------------------------------- ### get(GRB.CharAttr attr, GRBVar[] objs, int start, int len), get(GRB.CharAttr attr, GRBConstr[] objs, int start, int len), get(GRB.CharAttr attr, GRBQConstr[] objs, int start, int len), get(GRB.DoubleAttr attr, GRBVar[] objs, int start, int len), get(GRB.DoubleAttr attr, GRBConstr[] objs, int start, int len), get(GRB.DoubleAttr attr, GRBQConstr[] objs, int start, int len) Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/java/model.html Queries an attribute for a subset of an array of modeling objects, starting at a given index and length. ```APIDOC ## get(GRB.CharAttr attr, GRBVar[] objs, int start, int len), get(GRB.CharAttr attr, GRBConstr[] objs, int start, int len), get(GRB.CharAttr attr, GRBQConstr[] objs, int start, int len), get(GRB.DoubleAttr attr, GRBVar[] objs, int start, int len), get(GRB.DoubleAttr attr, GRBConstr[] objs, int start, int len), get(GRB.DoubleAttr attr, GRBQConstr[] objs, int start, int len) ### Description Queries an attribute for a subset of an array of modeling objects, starting at a given index and length. ### Method get ### Signatures - `char[] get(GRB.CharAttr attr, GRBVar[] objs, int start, int len)` - `char[] get(GRB.CharAttr attr, GRBConstr[] objs, int start, int len)` - `char[] get(GRB.CharAttr attr, GRBQConstr[] objs, int start, int len)` - `double[] get(GRB.DoubleAttr attr, GRBVar[] objs, int start, int len)` - `double[] get(GRB.DoubleAttr attr, GRBConstr[] objs, int start, int len)` - `double[] get(GRB.DoubleAttr attr, GRBQConstr[] objs, int start, int len)` ### Parameters - **attr** - The attribute being queried. - **objs** - The modeling objects, i.e., variables or constraints, whose attribute values are being queried. - **start** - The starting index in the array. - **len** - The number of elements to query. ### Return Value The current values of the requested attribute for the specified subset of input objects. ``` -------------------------------- ### Compute Server Example in C Source: https://docs.gurobi.com/projects/optimizer/en/current/concepts/environments/configuration.html Creates an empty environment, sets Compute Server parameters (ComputeServer, ServerPassword), starts the environment, and loads/optimizes a model. Uses GRBemptyenv, GRBsetstrparam, GRBstartenv, GRBreadmodel, and GRBoptimize. ```C #include "gurobi_c.h" int main(void) { GRBenv *env = NULL; GRBmodel *model = NULL; int error = 0; /* Create empty environment, set options and start */ error = GRBemptyenv(&env); if (error) goto QUIT; error = GRBsetstrparam(env, GRB_STR_PAR_COMPUTESERVER, "server1:61000"); if (error) goto QUIT; error = GRBsetstrparam(env, GRB_STR_PAR_SERVERPASSWORD, "passwd"); if (error) goto QUIT; error = GRBstartenv(env); if (error) goto QUIT; /* Load model and optimize */ error = GRBreadmodel(env, "misc07.mps", &model); if (error) goto QUIT; error = GRBoptimize(model); if (error) goto QUIT; QUIT: /* Clean up model and environment */ GRBfreemodel(model); GRBfreeenv(env); return error; } ``` -------------------------------- ### C#: Set and Get Parameters Source: https://docs.gurobi.com/projects/optimizer/en/current/concepts/parameters/examples.html Examples of setting and getting Gurobi parameters in C# using properties and methods. ```APIDOC ## C#: Set and Get Parameters ### Description Examples of setting and getting Gurobi parameters in C# using properties and methods. ### Method N/A (C# API) ### Endpoint N/A ### Parameters #### Enums - `GRB.DoubleParam` - Enum for double parameters. - `GRB.IntParam` - Enum for integer parameters. - `GRB.StringParam` - Enum for string parameters. ### Request Example ```csharp GRBModel m = ...; ``` ### Response #### Success Response N/A #### Response Example N/A ### Code Examples #### Set TimeLimit using property ```csharp m.Parameters.TimeLimit = 100.0; ``` #### Set TimeLimit using Set method ```csharp m.Set(GRB.DoubleParam.TimeLimit, 100.0); ``` #### Set TimeLimit using strings ```csharp m.Set("TimeLimit", "100.0"); ``` #### Query TimeLimit using property ```csharp currentlimit = m.Parameters.TimeLimit; ``` #### Query TimeLimit using Get method ```csharp currentlimit = m.Get(GRB.DoubleParam.TimeLimit); ``` ``` -------------------------------- ### C++: Set and Get Parameters Source: https://docs.gurobi.com/projects/optimizer/en/current/concepts/parameters/examples.html Examples of setting and getting Gurobi parameters in C++ using enums and model methods. ```APIDOC ## C++: Set and Get Parameters ### Description Examples of setting and getting Gurobi parameters in C++ using enums and model methods. ### Method N/A (C++ API) ### Endpoint N/A ### Parameters #### Enums - `GRB_DoubleParam` - Enum for double parameters. - `GRB_IntParam` - Enum for integer parameters. - `GRB_StringParam` - Enum for string parameters. ### Request Example ```cpp GRBModel *m = ...; ``` ### Response #### Success Response N/A #### Response Example N/A ### Code Examples #### Set TimeLimit using enum ```cpp m->set(GRB_DoubleParam_TimeLimit, 100.0); ``` #### Set TimeLimit using strings ```cpp m->set("TimeLimit", "100.0"); ``` #### Query TimeLimit ```cpp currentlimit = m.get(GRB_DoubleParam_TimeLimit); ``` ``` -------------------------------- ### Start a Gurobi environment with Compute Server parameters Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/java/env.html Creates an empty environment, sets Compute Server and password parameters, then starts the environment. The start() method populates parameters from gurobi.lic and gurobi.env, applies user-set parameters, and activates the environment. Environments are not thread-safe; create one per thread if needed. ```java // Create empty environment GRBEnv env = new GRBEnv(true); // Populate Compute Server parameters env.set("ComputeServer", "server1:61000"); env.set("ServerPassword", "passwd"); // Start the environment env.start() ``` -------------------------------- ### C: Set and Get Parameters Source: https://docs.gurobi.com/projects/optimizer/en/current/concepts/parameters/examples.html Examples of setting and getting Gurobi parameters in C using the symbolic constants and routines. ```APIDOC ## C: Set and Get Parameters ### Description Examples of setting and getting Gurobi parameters in C using the symbolic constants and routines. ### Method N/A (C API) ### Endpoint N/A ### Parameters #### Symbolic Constants - `GRB_INT_PAR_THREADS` (string) - Symbolic constant for the integer Threads parameter. - `GRB_DBL_PAR_TIMELIMIT` (string) - Symbolic constant for the double TimeLimit parameter. ### Request Example ```c #define GRB_INT_PAR_THREADS "Threads" ``` ### Response #### Success Response N/A #### Response Example N/A ### Code Examples #### Set TimeLimit using symbolic constant ```c error = GRBsetdblparam(GRBgetenv(model), GRB_DBL_PAR_TIMELIMIT, 100.0); ``` #### Set TimeLimit using string name ```c error = GRBsetdblparam(GRBgetenv(model), "TimeLimit", 100.0); ``` #### Query TimeLimit ```c double currentvalue; error = GRBgetdblparam(modelenv, "TimeLimit", ¤tvalue); ``` ``` -------------------------------- ### void start() Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/java/env.html Starts an empty environment. If the environment has already been started, this method does nothing. It populates parameters from gurobi.lic and gurobi.env files, applies user parameter changes, and activates the environment. ```APIDOC ## void start() ### Description 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. 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. ### Method start ### Parameters None ### Request Example ```java // Create empty environment GRBEnv env = new GRBEnv(true); // Populate Compute Server parameters env.set("ComputeServer", "server1:61000"); env.set("ServerPassword", "passwd"); // Start the environment env.start() ``` ### Response No return value. ``` -------------------------------- ### Get coefficient of quadratic term with getCoeff Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/java/quadexpr.html Retrieves the coefficient of the quadratic term at a given index. The example gets the coefficient of the first quadratic term. ```java // Get coefficient of first quadratic term of quadratic expression double coeff = qexpr.getCoeff(0); ``` -------------------------------- ### Create empty environment and set parameters before start Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/java/env.html Creates an empty GRBEnv with empty=true, sets Compute Server parameters, then starts the environment. Use this when you need to set parameters before starting, such as for Compute Server, Token Server, or WLS licenses. ```java // Create empty environment GRBEnv env = new GRBEnv(true); // Populate Compute Server parameters env.set("ComputeServer", "server1:61000"); env.set("ServerPassword", "passwd"); // Start the environment env.start(); ``` -------------------------------- ### getGenConstrOr Example: Retrieve OR Constraint Data Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/python/model.html Retrieves the resultant variable and operand variables of an OR general constraint. The example adds an OR constraint and then calls getGenConstrOr to get its data. ```python # x5 = or(x1, x3, x4) orconstr = model.addGenConstrOr(x5, [x1, x3, x4], "orconstr") model.update() (resvar, vars) = model.getGenConstrOr(orconstr) ``` -------------------------------- ### Get parameter values (TimeLimit, PumpPasses, LogFile) Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/java/model.html Queries double, integer, and string parameters using the get overloads. The example retrieves TimeLimit, PumpPasses, and LogFile. ```java // Get value of TimeLimit parameter double timelimit = model.get(GRB.DoubleParam.TimeLimit); // Get value of PumpPasses parameter int pumppasses = model.get(GRB.IntParam.PumpPasses); // Get value of LogFile parameter String logfile = model.get(GRB.StringParam.LogFile); ``` -------------------------------- ### Create empty environment and set Compute Server parameters (C#) Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/dotnet/env.html Creates an empty GRBEnv, sets Compute Server and password parameters, then starts the environment. Use empty=true when you need to set parameters before starting the environment, such as for Compute Server, Token Server, or WLS licenses. ```csharp // Create empty environment GRBEnv env = new GRBEnv(true); // Populate Compute Server parameters env.Set("ComputeServer", "server1:61000"); env.Set("ServerPassword", "passwd"); // Start the environment env.Start() ``` -------------------------------- ### Get variable from first term in expression (getVar) Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/java/linexpr.html Retrieves the GRBVar object for the term at a given index. The example gets the variable from the first term (index 0). ```java // Get variable from first term in expression GRBVar v = expr.getVar(0); ``` -------------------------------- ### GRBEnv::start Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/cpp/env.html Starts the environment. If already started, does nothing. Populates parameters from license file, gurobi.env file, and user-set parameters before activating the environment. ```APIDOC ## GRBEnv::start ### Description Starts the environment. If the environment has already been started, this method does nothing. If the call fails, the environment will have the same state as it had before the call. This method populates parameters from the license file, the gurobi.env file, and user-set parameters before activating the environment. ### Method start ### Endpoint GRBEnv::start() ### Parameters None ### Response No return value. ``` -------------------------------- ### AddTerms with start and len (C# and VB) Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/dotnet/linexpr.html Adds a subset of terms from arrays using start index and length. The example adds 2.0 x + 3.0 y from the arrays. ```csharp // Add 2.0 x + 3.0 y to linear expression double[] coeffs = { 2.0, 3.0, 4.0 }; GRBVar[] vars = { x, y, z }; lexpr.AddTerms(coeffs, vars, 0, 2); ``` ```vb ' Add 2.0 x + 3.0 y to linear expression Dim coeffs As Double() = New Double() {2.0, 3.0, 4.0} Dim vars As GRBVar() = New GRVar() {x, y, z} lexpr.AddTerms(coeffs, vars, 0, 2) ``` -------------------------------- ### Get attributes for arrays of objects with Get(attr, objs) in C# and Visual Basic Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/dotnet/model.html Queries an attribute for an array of modeling objects (variables or constraints). The example retrieves variable types, RHS values, and constraint names. Note: the C# example uses 'qconstrs' for constraint names, which may be a typo. ```C# // Get variable type attribute values GRBVar[] vars = model.GetVars(); char[] vtype = model.Get(GRB.CharAttr.VType, vars); // Get RHS attribute values of all linear constraints GRBConstr[] constrs = model.GetConstrs(); double[] rhs = model.Get(GRB.DoubleAttr.RHS, constrs); // Get constraint name values of all linear constraints string[] constrNames = model.Get(GRB.StringAttr.ConstrName, qconstrs); ``` ```Visual Basic ' Get variable type attribute values Dim vars As GRBVar() = model.GetVars() Dim vtype As Char() = model.Get(GRB.CharAttr.VType, vars) ' Get RHS attribute values of all linear constraints Dim constrs As GRBConstr() = model.GetConstrs() Dim rhs As Double() = model.Get(GRB.DoubleAttr.RHS, constrs) ' Get constraint name values of all linear constraints Dim constrNames As String() = model.Get(GRB.StringAttr.ConstrName, qconstrs) ``` -------------------------------- ### C: Create empty environment with WLS credentials and optimize Source: https://docs.gurobi.com/projects/optimizer/en/current/concepts/environments/configuration.html Creates an empty Gurobi environment, sets LicenseID, WLSAccessID, and WLSSecret parameters, starts the environment, then loads and optimizes a model from misc07.mps. Includes error handling and cleanup. ```C #include "gurobi_c.h" int main(void) { GRBenv *env = NULL; GRBmodel *model = NULL; int error = 0; /* Create empty environment, set options and start */ error = GRBemptyenv(&env); if (error) goto QUIT; error = GRBsetstrparam(env, GRB_STR_PAR_LICENSEID, "12345"); if (error) goto QUIT; error = GRBsetstrparam(env, GRB_STR_PAR_WLSACCESSID, "12345-678990"); if (error) goto QUIT; error = GRBsetstrparam(env, GRB_STR_PAR_WLSSECRET, "abcdef-abcdef"); if (error) goto QUIT; error = GRBstartenv(env); if (error) goto QUIT; /* Load model and optimize */ error = GRBreadmodel(env, "misc07.mps", &model); if (error) goto QUIT; error = GRBoptimize(model); if (error) goto QUIT; QUIT: /* Clean up model and environment */ GRBfreemodel(model); GRBfreeenv(env); return error; } ``` -------------------------------- ### Get model attributes (ObjVal, NumVars, ModelName) Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/java/model.html Queries double, integer, and string model attributes using the get overloads. The example retrieves ObjVal, NumVars, and ModelName. ```java // Get value ObjVal attribute double val = model.get(GRB.DoubleAttr.ObjVal); // Get number of variables in the model int numvars = model.get(GRB.IntAttr.NumVars); // Get ModelName attribute String modelname = model.get(GRB.StringAttr.ModelName); ``` -------------------------------- ### C#: Create empty environment, set options, start, and optimize Source: https://docs.gurobi.com/projects/optimizer/en/current/concepts/environments/configuration.html Creates an empty Gurobi environment, sets ComputeServer and ServerPassword, starts it, loads a model, and optimizes. Uses the Gurobi .NET API. ```csharp using Gurobi; // Create empty environment, set options and start using GRBEnv env = new GRBEnv(true); env.Set("ComputeServer", "server1:61000"); env.Set("ServerPassword", "passwd"); env.Start(); // Load model and optimize using GRBModel model = new GRBModel(env, "misc07.mps"); model.Optimize(); ``` -------------------------------- ### Get coefficient of first term in expression (getCoeff) Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/java/linexpr.html Retrieves the coefficient of the term at a given index. The example gets the coefficient of the first term (index 0) from the expression 'expr'. ```java // Get coefficient of first term in expression double coeff = expr.getCoeff(0); ``` -------------------------------- ### Cluster Manager Example in C Source: https://docs.gurobi.com/projects/optimizer/en/current/concepts/environments/configuration.html Creates an empty environment, sets Cluster Manager parameters (CSManager, CSAPIAccessID, CSAPISecret), starts the environment, and loads/optimizes a model. Uses GRBemptyenv, GRBsetstrparam, GRBstartenv, GRBreadmodel, and GRBoptimize. ```C #include "gurobi_c.h" int main(void) { GRBenv *env = NULL; GRBmodel *model = NULL; int error = 0; /* Create empty environment, set options and start */ error = GRBemptyenv(&env); if (error) goto QUIT; error = GRBsetstrparam(env, GRB_STR_PAR_CSMANAGER, "server1:61080"); if (error) goto QUIT; error = GRBsetstrparam(env, GRB_STR_PAR_CSAPIACCESSID, "12345-678990"); if (error) goto QUIT; error = GRBsetstrparam(env, GRB_STR_PAR_CSAPISECRET, "abcdef-abcdef"); if (error) goto QUIT; error = GRBstartenv(env); if (error) goto QUIT; /* Load model and optimize */ error = GRBreadmodel(env, "misc07.mps", &model); if (error) goto QUIT; error = GRBoptimize(model); if (error) goto QUIT; QUIT: /* Clean up model and environment */ GRBfreemodel(model); GRBfreeenv(env); return error; } ``` -------------------------------- ### Set a double array attribute with GRBsetdblattrarray Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/c/attribute.html Sets a sub-array of a double-valued array attribute. The example sets the 'Start' attribute for the first four variables to the values in the 'start' array. ```c double start[] = {1.0, 1.0, 0.0, 1.0}; error = GRBsetdblattrarray(model, "Start", 0, 4, start); ``` -------------------------------- ### Java: Create empty environment with WLS credentials and optimize Source: https://docs.gurobi.com/projects/optimizer/en/current/concepts/environments/configuration.html Creates an empty Gurobi environment, sets LicenseID, WLSAccessID, and WLSSecret parameters, starts the environment, then loads and optimizes a model from misc07.mps. Includes cleanup in a finally block. ```Java import gurobi.*; GRBEnv env = null; GRBModel model = null; try { // Create empty environment, set options and start env = new GRBEnv(true); env.set(GRB.StringParam.LicenseID, "12345"); env.set(GRB.StringParam.WLSAccessID, "12345-678990"); env.set(GRB.StringParam.WLSSecret, "abcdef-abcdef"); env.start(); // Load model and optimize model = new GRBModel(env, "misc07.mps"); model.optimize(); // Extract the solution // ... } finally { // Clean up model and environment if (model != null) { model.dispose(); } if (env != null) { env.dispose(); } } ``` -------------------------------- ### Get parameter values with Get(GRB.DoubleParam/IntParam/StringParam) in C# and Visual Basic Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/dotnet/model.html Queries the current value of a double, integer, or string-valued parameter. The example retrieves TimeLimit, PumpPasses, and LogFile parameters. ```C# // Get value of TimeLimit parameter double val = model.Get(GRB.DoubleParam.TimeLimit); // Get value of PumpPasses parameter int val = model.Get(GRB.IntParam.PumpPasses); // Get value of LogFile parameter string val = model.Get(GRB.StringParam.LogFile); ``` ```Visual Basic ' Get value of TimeLimit parameter Dim val As Double = model.Get(GRB.DoubleParam.TimeLimit) ' Get value of PumpPasses parameter Dim val As Integer = model.Get(GRB.IntParam.PumpPasses) ' Get value of LogFile parameter Dim val As String = model.Get(GRB.StringParam.LogFile) ``` -------------------------------- ### Cluster Manager Example in Java Source: https://docs.gurobi.com/projects/optimizer/en/current/concepts/environments/configuration.html Creates an empty environment, sets Cluster Manager parameters (CSManager, CSAPIAccessID, CSAPISecret), starts the environment, and loads/optimizes a model. Uses GRBEnv(true), set, start, GRBModel, and optimize. Includes cleanup in finally block. ```Java import gurobi.*; GRBEnv env = null; GRBModel model = null; try { // Create empty environment, set options and start env = new GRBEnv(true); env.set(GRB.StringParam.CSManager, "server1:61080"); env.set(GRB.StringParam.CSAPIAccessID, "12345-678990"); env.set(GRB.StringParam.CSAPISecret, "abcdef-abcdef"); env.start(); // Load model and optimize model = new GRBModel(env, "misc07.mps"); model.optimize(); // Extract the solution // ... } finally { // Clean up model and environment if (model != null) { model.dispose(); } if (env != null) { env.dispose(); } } ``` -------------------------------- ### Get second variable of quadratic term with getVar2 Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/java/quadexpr.html Retrieves the second variable object of the quadratic term at a given index. The example gets the second variable of the first quadratic term. ```java // Get second variable of first quadratic term of quadratic expression GRBVar v = qexpr.getVar2(0); ``` -------------------------------- ### C: Create empty environment, set options, start, and optimize Source: https://docs.gurobi.com/projects/optimizer/en/current/concepts/environments/configuration.html Creates an empty Gurobi environment, sets ComputeServer and ServerPassword, starts it, loads a model, and optimizes. Uses the Gurobi C API. ```c #include "gurobi_c.h" int main(void) { GRBenv *env = NULL; GRBmodel *model = NULL; int error = 0; /* Create empty environment, set options and start */ error = GRBemptyenv(&env); if (error) goto QUIT; error = GRBsetstrparam(env, GRB_STR_PAR_COMPUTESERVER, "server1:61000"); if (error) goto QUIT; error = GRBsetstrparam(env, GRB_STR_PAR_SERVERPASSWORD, "passwd"); if (error) goto QUIT; error = GRBstartenv(env); if (error) goto QUIT; /* Load model and optimize */ error = GRBreadmodel(env, "misc07.mps", &model); if (error) goto QUIT; error = GRBoptimize(model); if (error) goto QUIT; QUIT: /* Clean up model and environment */ GRBfreemodel(model); GRBfreeenv(env); return error; } ``` -------------------------------- ### Run Gurobi R example with source Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/r/setup.html Use the R 'source' command to run an example script, such as 'mip.R', from the Gurobi R examples directory. ```r > source('mip.R') ``` -------------------------------- ### Get first variable of quadratic term with getVar1 Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/java/quadexpr.html Retrieves the first variable object of the quadratic term at a given index. The example gets the first variable of the first quadratic term. ```java // Get first variable of first quadratic term of quadratic expression GRBVar v = qexpr.getVar1(0); ``` -------------------------------- ### Java: Create empty environment, set options, start, and optimize Source: https://docs.gurobi.com/projects/optimizer/en/current/concepts/environments/configuration.html Creates an empty Gurobi environment, sets ComputeServer and ServerPassword, starts it, loads a model, and optimizes. Uses the Gurobi Java API. ```java import gurobi.*; GRBEnv env = null; GRBModel model = null; try { // Create empty environment, set options and start env = new GRBEnv(true); env.set(GRB.StringParam.ComputeServer, "server1:61000"); env.set(GRB.StringParam.ServerPassword, "passwd"); env.start(); // Load model and optimize model = new GRBModel(env, "misc07.mps"); model.optimize(); // Extract the solution // ... } finally { // Clean up model and environment if (model != null) { model.dispose(); } if (env != null) { env.dispose(); } } ``` -------------------------------- ### C#: Create empty environment with WLS credentials and optimize Source: https://docs.gurobi.com/projects/optimizer/en/current/concepts/environments/configuration.html Creates an empty Gurobi environment, sets LicenseID, WLSAccessID, and WLSSecret parameters, starts the environment, then loads and optimizes a model from misc07.mps. ```C# using Gurobi; // Create empty environment, set options and start using GRBEnv env = new GRBEnv(true); env.Set("LicenseID", "12345"); env.Set("WLSAccessID", "12345-678990"); env.Set("WLSSecret", "abcdef-abcdef"); env.Start(); // Load model and optimize using GRBModel model = new GRBModel(env, "misc07.mps"); model.Optimize(); ``` -------------------------------- ### getGenConstrPWL Example: Retrieve PWL Constraint Data Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/python/model.html Retrieves the x and y variables and the points defining a piecewise-linear general constraint. The example adds a PWL constraint and then calls getGenConstrPWL to get its data. ```python pwlconstr = model.addGenConstrPWL(x, y, [0, 1, 2], [1.5, 0, 3], "myPWLConstr") model.update() (xvar, yvar, xpts, ypts) = model.getGenConstrPWL(pwlconstr) ``` -------------------------------- ### C++: Create empty environment, set options, start, and optimize Source: https://docs.gurobi.com/projects/optimizer/en/current/concepts/environments/configuration.html Creates an empty Gurobi environment, sets ComputeServer and ServerPassword, starts it, loads a model, and optimizes. Uses the Gurobi C++ API. ```cpp #include "gurobi_c++.h" // Create empty environment, set options and start GRBEnv env = GRBEnv(true); env.set(GRB_STR_PAR_COMPUTESERVER, "server1:61000"); env.set(GRB_STR_PAR_SERVERPASSWORD, "passwd"); env.start(); // Load model and optimize GRBModel model = GRBModel(env, "misc07.mps"); model.optimize(); ``` -------------------------------- ### Get left-hand side of linear constraint with getRow Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/java/model.html Retrieves the left-hand side expression of a linear constraint as a GRBLinExpr object. The example gets all linear constraints and then retrieves the expression for the first one. ```java GRBConstr[] constrs = model.getConstrs(); // Get left-hand side of first linear constraint GRBLinExpr lexpr = model.getRow(constrs[0]); ``` -------------------------------- ### Get model attributes with Get(GRB.DoubleAttr/IntAttr/StringAttr) in C# and Visual Basic Source: https://docs.gurobi.com/projects/optimizer/en/current/reference/dotnet/model.html Queries the current value of a double, integer, or string-valued model attribute. The example retrieves NumVars, ModelName, and Runtime attributes. ```C# // Get number of variables in the model int numvars = model.Get(GRB.IntAttr.NumVars); // Get ModelName attribute string modelname = model.Get(GRB.StringAttr.ModelName); // Get runtime for the most recent optimization (in seconds) double runtime = model.Get(GRB.DoubleAttr.Runtime); ``` ```Visual Basic ' Get number of variables in the model Dim numvars As Integer = model.Get(GRB.IntAttr.NumVars) ' Get ModelName attribute Dim modelname As String = model.Get(GRB.StringAttr.ModelName) ' Get runtime for the most recent optimization (in seconds) Dim runtime As Double = model.Get(GRB.DoubleAttr.Runtime) ``` -------------------------------- ### Python: Create empty environment, set options, start, and optimize Source: https://docs.gurobi.com/projects/optimizer/en/current/concepts/environments/configuration.html Creates an empty Gurobi environment, sets ComputeServer and ServerPassword, starts it, loads a model, and optimizes. Uses the Gurobi Python API (gurobipy). ```python import gurobipy as gp with gp.Env( params={ "ComputeServer": "server1:61000", "ServerPassword": "passwd", } ) as env, gp.read("misc07.mps", env=env) as model: model.optimize() # Extract the solution # ... ```