Examples: batchmode, callback, feasopt, fixanddive, lp, lpmethod, lpmod, mip2, params, sensitivity
One of the most basic tasks you can perform with the Gurobi libraries
is to read a model from a file, optimize it, and report the result.
mip2_vb.vb) examples are
simple illustrations of how this is done in the various supported
Gurobi languages. While the specifics vary from one language to
another, the basic structure remains the same for all languages.
After initializing the Gurobi environment, the examples begin by reading the
model from the specified file. In C, you call the
error = GRBreadmodel(env, argv, &model);In C++, this is done by constructing a
GRBModel model = GRBModel(env, argv);In C# and Java, this is also done by constructing a
GRBModel model = new GRBModel(env, args);In Python, this is done via the
model = gp.read(sys.argv)
The next step is to invoke the Gurobi optimizer on the model.
In C, you call
GRBoptimize() on the
error = GRBoptimize(model);In C++, Java, and Python, this is accomplished by calling the
optimizemethod on the
model.optimize();In C#, the first letter of the method name is capitalized:
optimizecall populates a set of solution attributes in the model. For example, once the call completes, the
Xvariable attribute contains the solution value for each variable. Similarly, for continuous models, the
Piconstraint attribute contains the dual value for each constraint.
The examples then retrieve the value of the model
attribute to determine the result of the optimization. In the
lp example, an optimal solution is written to a solution file
There are many other things you can do once you have read and solved
the model. For example,
lp checks the solution status
-- which is highly recommended.
If the model is found to be infeasible,
this example computes an Irreducible Inconsistent Subsystem (IIS) to
isolate the source of the infeasibility.