本文整理匯總了Python中cylp.cy.CyClpSimplex.removeConstraint方法的典型用法代碼示例。如果您正苦於以下問題:Python CyClpSimplex.removeConstraint方法的具體用法?Python CyClpSimplex.removeConstraint怎麽用?Python CyClpSimplex.removeConstraint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cylp.cy.CyClpSimplex
的用法示例。
在下文中一共展示了CyClpSimplex.removeConstraint方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_removeConstraint
# 需要導入模塊: from cylp.cy import CyClpSimplex [as 別名]
# 或者: from cylp.cy.CyClpSimplex import removeConstraint [as 別名]
def test_removeConstraint(self):
'Test remove constraint'
model = CyLPModel()
x = model.addVariable('x', 3)
y = model.addVariable('y', 2)
A = csc_matrixPlus(([1, 2, 1, 1], ([0, 0, 1, 1], [0, 1, 0, 2])), shape=(2, 3))
B = csc_matrixPlus(([1, 1], ([0, 1], [0, 2])), shape=(2, 3))
D = np.matrix([[1., 2.],[0, 1]])
a = CyLPArray([3, 2.5])
b = CyLPArray([4.2, 3])
x_u= CyLPArray([2., 3.5])
model.addConstraint(A * x <= a, 'res1')
model.addConstraint(2 <= B * x + D * y <= b, 'res2')
model.addConstraint(y >= 0)
model.addConstraint(1.1 <= x[1:3] <= x_u)
model.addConstraint(x[0] >= 0.1)
c = CyLPArray([1., -2., 3.])
model.objective = c * x + 2 * y[0] + 2 * y[1]
s = CyClpSimplex(model)
s.primal()
sol = np.concatenate((s.primalVariableSolution['x'],
s.primalVariableSolution['y']))
self.assertTrue((abs(sol -
np.array([0.1, 1.45, 1.1, 0, 0.95]) ) <= 10**-6).all())
s.removeConstraint('res2')
s.primal()
sol = np.concatenate((s.primalVariableSolution['x'],
s.primalVariableSolution['y']))
self.assertTrue((abs(sol -
np.array([0.1, 1.45, 1.1, 0, 0]) ) <= 10**-6).all())
s.removeConstraint('res1')
s.primal()
sol = np.concatenate((s.primalVariableSolution['x'],
s.primalVariableSolution['y']))
self.assertTrue((abs(sol -
np.array([0.1, 2, 1.1, 0, 0]) ) <= 10**-6).all())
示例2: test_removeConst
# 需要導入模塊: from cylp.cy import CyClpSimplex [as 別名]
# 或者: from cylp.cy.CyClpSimplex import removeConstraint [as 別名]
def test_removeConst(self):
m = self.model
x = self.x
A = self.A
b = self.b
m.addConstraint(x >= 0)
m.addConstraint(A * x == b)
m.addConstraint(x[1:3].sum() >= 1, 'rr')
m.objective = x.sum()
s = CyClpSimplex(m)
s.primal()
self.assertAlmostEqual(s.primalVariableSolution['x'][1], 1, 7)
s.removeConstraint('rr')
s.primal()
self.assertAlmostEqual(s.primalVariableSolution['x'][1], 0, 7)