def create_linear_dual(self, c, b, P, d): ''' Robust constraint: c^T*w <= b for all P*w <= d ''' blk = Block() blk.construct() n, m = len(P), len(P[0]) # Add dual variables blk.var = Var(range(n), within=NonNegativeReals) # Dual objective blk.obj = Constraint(expr=quicksum(d[j]*blk.var[j] for j in range(n)) <= b) # Dual constraints blk.cons = ConstraintList() for i in range(m): lhs = quicksum(P[j][i]*blk.var[j] for j in range(n)) if lhs.__class__ not in native_numeric_types or lhs != 0: blk.cons.add(lhs == c[i]) return blk
def construct(self, data=None): Block.construct(self, data)