Movatterモバイル変換


[0]ホーム

URL:


ContentsMenuExpandLight modeDark modeAuto light/dark mode
Gurobi Optimizer Reference Manual
Light LogoDark Logo

Concepts

Features

Reference

Gurobi
Back to top

Model Solution#

intGRBoptimize(GRBmodel*model)#

Optimize a model. The algorithm used for theoptimization depends on the model type (simplex or barrier for acontinuous model; branch-and-cut for a MIP model). Upon successfulcompletion, this method will populate the solution related attributesof the model. See theAttributes section formore information on attributes. The algorithm will terminate early if itreaches any of the limits set bytermination parameters.

Please consultthis section for adiscussion of some of the practical issues associated with solving aprecisely defined mathematical model using finite-precisionfloating-point arithmetic.

Note that this routine will process all pending model modifications.

Return value:

A non-zero return value indicates that a problem occurred while optimizing the model. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • model – The model to optimize. Note that this routine only reportswhether the optimization ran into an error. Query theStatusattribute to determine the result of the optimization (see theAttributes section for more information onquerying attributes).

Example:
error=GRBoptimize(model);
intGRBoptimizeasync(GRBmodel*model)#

Optimize a model asynchronously. This routine returns immediately. Yourprogram can perform other computations while optimization proceeds inthe background. To check the state of the asynchronous optimization,query theStatus attribute for the model. A value ofGRB_INPROGRESS indicates that the optimization has not yet completed.When you are done with your foreground tasks, you must callGRBsync to sync your foreground program with the asynchronousoptimization task.

Note that the set of Gurobi calls that you are allowed to make whileoptimization is running in the background is severely limited.Specifically, you can only perform attribute queries, and only for afew attributes (listed below). Any other calls on the running model,or on any other models that were built within the same Gurobienvironment, will fail with error codeGRB_ERROR_OPTIMIZATION_IN_PROGRESS.

Note that there are no such restrictions on models built in otherenvironments. Thus, for example, you could create multiple environments,and then have a single foreground program launch multiple simultaneousasynchronous optimizations, each in its own environment.

As already noted, you are allowed to query the value of theStatus attribute while an asynchronous optimization is inprogress. The other attributes that can be queried are:ObjVal,ObjBound,IterCount,NodeCount,BarIterCount,NLBarIterCount, andNLBarIterCount. In each case, the returned value reflectsprogress in the optimization to that point. Any attempt to query the valueof an attribute not on this list will fail with error codeGRB_ERROR_OPTIMIZATION_IN_PROGRESS.

Return value:

A non-zero return value indicates that a problem occurred while optimizing the model. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • model – The model to optimize. Note that this routine only reportswhether launching the asynchronous job ran into an error. Query theStatus attribute to determine the result of the optimization(see theAttributes section for more informationon querying attributes). The return value ofGRBsync indicateswhether the background optimization ran into an error.

Example:
error=GRBoptimizeasync(model);/* ... perform other compute-intensive tasks... */error=GRBsync(model);
intGRBpresolvemodel(GRBmodel*model,GRBmodel**presolvedP)#

Perform presolve on a model.

Please note that the presolved modelcomputed by this function may be different from the presolved modelcomputed when optimizing the model.

Return value:

A non-zero return value indicates that a problem occurred while presolving the model. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • model – The model to be presolved.

  • presolveP – The location in which the pointer to the presolved modelshould be placed.

Example:
error=GRBpresolvemodel(model,&presolvedP);
intGRBcomputeIIS(GRBmodel*model)#

Compute an Irreducible Inconsistent Subsystem (IIS).

An IIS is a subset of the constraints and variable bounds with thefollowing properties:

  • It is still infeasible, and

  • If a single constraint or bound is removed, the subsystem becomesfeasible.

Note that an infeasible model may have multiple IISs. The one returnedby Gurobi is not necessarily the smallest one; there may exist otherswith fewer constraints or bounds.

IIS results are returned in a number of attributes:IISConstr,IISLB,IISUB,IISSOS,IISQConstr, andIISGenConstr.Each indicates whether the corresponding model element is a member ofthe computed IIS.

Note that for models with general function constraints, piecewise-linearapproximation of the constraints may cause unreliable IIS results.

TheIIS log provides information about theprogress of the algorithm, including a guess at the eventual IIS size.

Termination parameters such asTimeLimit,WorkLimit,MemLimit, andSoftMemLimit are considered when computing an IIS. If an IIScomputation is interrupted before completion or stops due to a terminationparameter, Gurobi will return the smallest infeasible subsystem found to thatpoint. The model attributeIISMinimal can be used to check whetherthe computed IIS is minimal.

TheIISConstrForce,IISLBForce,IISUBForce,IISSOSForce,IISQConstrForce, andIISGenConstrForce attributesallow you mark model elements to either include or exclude from thecomputed IIS. Setting the attribute to 1 forces the correspondingelement into the IIS, setting it to 0 forces it out of the IIS, andsetting it to -1 allows the algorithm to decide.

To give an example of when these attributes might be useful, considerthe case where an initial model is known to be feasible, but it becomesinfeasible after adding constraints or tightening bounds. If you areonly interested in knowing which of the changes caused theinfeasibility, you can force the unmodified bounds and constraints intothe IIS. That allows the IIS algorithm to focus exclusively on the newconstraints, which will often be substantially faster.

Note that setting any of theForce attributes to 0 may make theresulting subsystem feasible, which would then make it impossible toconstruct an IIS. Trying anyway will result in aIIS_NOT_INFEASIBLE error. Similarly, settingthis attribute to 1 may result in an IIS that is not irreducible. Moreprecisely, the system would only be irreducible with respect to themodel elements that have force values of -1 or 0.

This routine populates theIISConstr,IISGenConstr,IISQConstr,IISSOS,IISLB, andIISUB attributes. You can also obtaininformation about the results of the IIS computation by writing a.ilp format file (seeGRBwrite). This file contains onlythe IIS from the original model.

Use theIISMethod parameter to adjust the behavior ofthe IIS algorithm.

Note that this routine can be used to compute IISs for both continuousand MIP models.

Return value:

A non-zero return value indicates that a problem occurred while computing the IIS. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • model – The infeasible model. This routine will return an error ifthe input model is feasible.

Important

This routine only reports whether the computation ran into an error.Query theIISConstr,IISGenConstr,IISQConstr,IISSOS,IISLB, orIISUB attributes to determine the result of the computation(see theAttributes section for more informationon querying attributes).

Example:
error=GRBcomputeIIS(model);
intGRBconverttofixed(GRBmodel*model)#

Turn the MIP model into a continuousone, in place.A solution (e.g. obtained through a call toGRBoptimize) or a MIP start must beavailable in the MIP model. If no solution is available, the MIP startspecified withStartNumber is used.

In the model, each integer variable is fixed to the value that variable takesin the MIP solution or MIP start. In addition, continuous variables may befixed to satisfy SOS or general constraints. The result is that the model hasneither integrality constraints, SOS constraints, nor general constraints anymore.

Note

While the fixed problem is always a continuous model, it may contain anon-convex quadratic objective or non-convex quadratic constraints. As aresult, it may still be solved using the MIP algorithm.

Note

An error is raised if the converted model contains more than oneobjective or scenario, or if the model contains concurrent environmentsor tune environments.

Return value:

A non-zero return value indicates that a problem occurred while creating the fixed model.Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • model – The MIP model (with a solution loaded) to fix.

intGRBfeasrelax(GRBmodel*model,intrelaxobjtype,intminrelax,double*lbpen,double*ubpen,double*rhspen,double*feasobjP)#

Modifies the input model to create a feasibility relaxation. Note thatyou need to callGRBoptimize on the result to compute theactual relaxed solution.

The feasibility relaxation is a model that, when solved, minimizes theamount by which the solution violates the bounds and linear constraintsof the original model. This routine provides a number of options forspecifying the relaxation.

If you specifyrelaxobjtype=0, the objective of the feasibilityrelaxation is to minimize the sum of the weighted magnitudes of thebound and constraint violations. Thelbpen,ubpen, andrhspen arguments specify the cost per unit violation in the lowerbounds, upper bounds, and linear constraints, respectively.

If you specifyrelaxobjtype=1, the objective of the feasibilityrelaxation is to minimize the weighted sum of the squares of the boundand constraint violations. Thelbpen,ubpen, andrhspenarguments specify the coefficients on the squares of the lower bound,upper bound, and linear constraint violations, respectively.

If you specifyrelaxobjtype=2, the objective of the feasibilityrelaxation is to minimize the weighted count of bound and constraintviolations. Thelbpen,ubpen, andrhspen arguments specifythe cost of violating a lower bound, upper bound, and linear constraint,respectively.

To give an example, a violation of 2.0 on constrainti wouldcontribute2*rhspen[i] to the feasibility relaxation objective forrelaxobjtype=0, it would contribute2*2*rhspen[i] forrelaxobjtype=1, and it would contributerhspen[i] forrelaxobjtype=2.

Theminrelax argument is a boolean that controls the type offeasibility relaxation that is created. Ifminrelax=0, optimizingthe returned model gives a solution that minimizes the cost of theviolation. Ifminrelax=1, optimizing the returned model finds asolution that minimizes the original objective, but only from amongthose solutions that minimize the cost of the violation. Note thatGRBfeasrelax must solve an optimization problem to find the minimumpossible relaxation forminrelax=1, which can be quite expensive.

In all cases, you can specify a penalty ofGRB_INFINITY to indicatethat a specific bound or linear constraint may not be violated.

For an example of how this routine transforms a model, and more detailsabout the variables and constraints created, please seethis section.

Note that this is a destructive routine: it modifies the model passed toit. If you don’t want to modify your original model, useGRBcopymodel to create a copy before calling this routine.

Return value:

A non-zero return value indicates that a problem occurred while computing the feasibilityrelaxation. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • model – The original (infeasible) model. The model is modified bythis routine.

  • relaxobjtype – The cost function used when finding the minimum costrelaxation.

  • minrelax – The type of feasibility relaxation to perform.

  • lbpen – The penalty associated with violating a lower bound. CanbeNULL, in which case no lower bound violations are allowed.If notNULL, this should be an array with as many values asvariables that currently exist in the model. Note that artificialvariables may have been created automatically by Gurobi for rangeconstraints.

  • ubpen – The penalty associated with violating an upper bound. CanbeNULL, in which case no upper bound violations are allowed. IfnotNULL, this should be an array with as many values asvariables that currently exist in the model. Note that artificialvariables may have been created automatically by Gurobi for rangeconstraints.

  • rhspen – The penalty associated with violating a linearconstraint. Can beNULL, in which case no constraintviolations are allowed. If notNULL, this should be an arraywith as many values as constraints that currently exist in themodel.

  • feasobjP – Whenminrelax=1, this returns the objective value forthe minimum cost relaxation.

Example:
doublepenalties[];error=GRBfeasrelax(model,0,0,NULL,NULL,penalties,NULL);error=GRBoptimize(model);
intGRBfixmodel(GRBmodel*model,GRBmodel**fixedP)#

Create the fixed model associated witha MIP model.A solution (e.g. obtained through a call toGRBoptimize) or a MIP start must beavailable in the MIP model. If no solution is available, the MIP startspecified withStartNumber is used.

In the model, each integer variable is fixed to the value that variable takesin the MIP solution or MIP start. In addition, continuous variables may befixed to satisfy SOS or general constraints. The result is that the model hasneither integrality constraints, SOS constraints, nor general constraints anymore.

Note

While the fixed problem is always a continuous model, it may contain anon-convex quadratic objective or non-convex quadratic constraints. As aresult, it may still be solved using the MIP algorithm.

Note

On a multi-objective model, all but the first objectives are ignored. Allscenarios are ignored as well, if any.

Return value:

A non-zero return value indicates that a problem occurred while creating the fixed model.Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • model – The MIP model (with a solution loaded).

  • fixedP – The computed fixed model.

Example:
GRBmodel*fixed;error=GRBfixmodel(model,&fixed);
intGRBreset(GRBmodel*model,intclearall)#

Reset the model to an unsolved state, discarding any previously computedsolution information.

Return value:

A non-zero return value indicates that a problem occurred while resetting the model. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • model – The model to reset.

  • clearall – A value of 1 discards additional information that affectsthe solution process but not the actual model (currently MIP starts,variable hints, branching priorities, lazy flags, and partitioninformation). Pass 0 to just discard the solution.

Example:
error=GRBreset(model,0);
intGRBsync(GRBmodel*model)#

Wait for a previous asynchronous optimization call to complete.

CallingGRBoptimizeasync returns control to the callingroutine immediately. The caller can perform other computations whileoptimization proceeds, and can check on the progress of the optimizationby querying various model attributes. TheGRBsync call forces thecalling program to wait until the asynchronous optimization completes.Youmust callGRBsync before the corresponding model is freed.

TheGRBsync call returns a non-zero error code if the optimizationitself ran into any problems. In other words, error codes returned bythis method are those thatGRBoptimize itself would have returned,had the original method not been asynchronous.

Note that you need to callGRBsync even if you know that theasynchronous optimization has already completed.

Return value:

A non-zero return value indicates that a problem occurred while solving the model. Refer to theError Codes tablefor a list of possible return values. Details on the error can be obtainedby callingGRBgeterrormsg.

Arguments:
  • model – The model that is currently being solved.

Example:
error=GRBoptimizeasync(model);/* ... perform other compute-intensive tasks... */error=GRBsync(model);

Help and Feedback

On this page

[8]ページ先頭

©2009-2025 Movatter.jp