Movatterモバイル変換


[0]ホーム

URL:


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

Concepts

Features

Reference

Gurobi
Back to top

gurobipy.MGenConstr#

classMGenConstr#

Gurobi matrix general constraint object. AnMGenConstr object is anarray-like data structure that represents multiple general constraints(in contrast to aGenConstr object, which represents asingle general constraint). It behaves similar to NumPy’sndarrays, e.g., it has a shape and can be indexed and sliced.Matrix general constraints are always associated with a particularmodel. Currently only theModel.addGenConstrIndicator methodproducesMGenConstr objects when matrix-friendly objects are used asinputs.

General constraint objects have a number of attributes. The full listcan be found in theAttributes section of thisdocument. Some general constraint attributes can only be queried, whileothers can also be set. Recall that the Gurobi Optimizer employs a lazyupdate approach, so changes to attributes don’t take effect until thenext call toModel.update,Model.optimize, orModel.write on the associated model.

Note that in most cases to query general constraint data, you will needto index into the MGenConstr object and pass individual GenConstrobjects to methods such asModel.getGenConstrIndicator toread back general constraint data.

fromlist(genconstrlist)#

Convert a list of general constraints into an MGenConstr object. Theshape is inferred from the contents of the list - a list of GenConstrobjects produces a 1-D MGenConstr object, a list of lists of GenConstrobjects produces a 2-D MGenConstr, etc.

Parameters:

genconstrlist – A list of GenConstr objects to populate thereturned MGenConstr.

Returns:

MGenConstr object corresponding to the input generalconstraints.

Example:
gc0,gc1,gc2,gc3=model.getGenConstrs()mgc_1d=MGenConstr.fromlist([gc0,gc1,gc2,gc3])# 1-D MGenConstrmgc_2d=MGenConstr.fromlist([[gc0,gc1],[gc2,gc3]])# 2-D MGenConstr
getAttr(attrname)#

Query the value of an attribute for a matrix general constraint. Thefull list of available attributes can be found in theAttributes section.

Raises anAttributeError if the requested attribute doesn’t exist orcan’t be queried. Raises aGurobiError if there is a problem withtheMGenConstr object (e.g., it was removed from the model).

The result is returned as a NumPyndarray with the same shape as theMGenConstr object.

Parameters:

attrname – The attribute being queried.

Returns:

ndarray of current values for the requested attribute.

Example:
mgc=model.addGenConstrIndicator(z,1.0,A@x<=b)model.computeIIS()iis=mc.getAttr("IISGenConstr")
setAttr(attrname,newvalue)#

Set the value of a matrix general constraint attribute.

Note that, due to our lazy update approach,the change won’t actually take effect until you update the model (usingModel.update), optimize the model (usingModel.optimize), or write the model to disk (usingModel.write).

The full list of available attributes can be found in theAttributes section.

Raises anAttributeError if the specified attribute doesn’t exist orcan’t be set. Raises aGurobiError if there is a problem with theMGenConstr object (e.g., it was removed from the model).

Parameters:
  • attrname – The attribute being modified.

  • newvaluendarray of desired new values for the attribute.The shape must be the same as theMGenConstr object. Alternatively,you can pass a scalar argument, which will automatically be promoted tohave the right shape.

Example:
mgc=model.addGenConstrIndicator(z,1.0,A@x<=b)iis=mc.setAttr("IISGenConstrForce",1)model.computeIIS()
tolist()#

Return the general constraints associated with this matrix generalconstraint as a list of individualGenConstr objects.

Returns:

List ofGenConstr objects.

Example:
mgc=model.addGenConstrIndicator(z,True,A@x<=b)genconstrlist=mgc.tolist()

Help and Feedback

On this page

[8]ページ先頭

©2009-2025 Movatter.jp