8.6.12. PsdConstr

class PsdConstr

代表模型中的一个半定规划的约束条件。约束的index从0开始递增,每次向模型添加一个约束,index增加。 半定约束往往被表示为一个半定表达式。

属性

index

半定约束的索引位置

方法

getAttr()

获取半定约束对应的attribute值

sameAs()

测试半定约束和另一个半定约束,是否相同

setAttr()

设置半定约束对应的attribute值

getAttr(attrname)

获取半定约束对应的attribute值

Parameters

attrname – 属性名称

example:

m = Model()
x = m.addPsdVar(dim = 2)
c = m.addConstr(x * numpy.identity(2) == 2, name="c0")
print(c.psdcname == "c0")
print(c.getAttr(MDO.Attr.PsdCName) == "c0")

Note

Attribute的读写也可以直接通过对象属性读写完,这种情况下,属性名称大小写不敏感

sameAs(constr)

测试半定约束和另一个半定约束,是否相同

Parameters

constr – 要测试的另一个半定约束

example:

m = Model()
x = m.addPsdVar(dim = 2)
c = m.addConstr(x * numpy.identity(2) == 2)
print(c.sameAs(m.getPsdConstrs()[0]))
setAttr(attrname, attrvalue)

设置半定约束对应的attribute值

Parameters
  • attrname – attribute的名称

  • attrvalue – 要设置的attribute值

example:

m = Model()
x = m.addPsdVar(dim = 2)
c = m.addConstr(x * numpy.identity(2) == 2, name = "x0")
c.setAttr(MDO.Attr.PsdCName, "c0")
print(c.psdcname)
c.psdcname = "c1"
print(c.psdcname)

Note

Attribute的读写也可以直接通过对象属性读写完,这种情况下,属性名称大小写不敏感