def both_roles_constraint(cls, v1, v2, v3): lhs = flipy.LpExpression(expression={v1: 1, v2: 1}) rhs = flipy.LpExpression(expression={v3: 1}, constant=1) return flipy.LpConstraint(lhs, 'leq', rhs, name=f'_C_BothRolesPenalty_{cls._cons_id()}')
def constraint_sum_geq_weight_1(cls, lp_var_list: List[LpVariable], value: int, typ='default'): lhs = cls.sum_expr_weight_1(lp_var_list) rhs = cls.const_expr(value) return flipy.LpConstraint(lhs, 'geq', rhs, name=f'_C_{typ}_{cls._cons_id()}')
def constraint_sum_geq_weight_decrease(cls, lp_var_list: List[LpVariable], value: int, typ='default'): lhs = cls.sum_expr_weight(lp_var_list, False) # false means decrease rhs = cls.const_expr(value) return flipy.LpConstraint(lhs, 'leq', rhs, name=f'_C_{typ}_{cls._cons_id()}')
def constraint_vars_eq(cls, v1: List[LpVariable], v2: List[LpVariable], typ='default'): lhs = cls.sum_expr_weight_1(v1) rhs = cls.sum_expr_weight_1(v2) return flipy.LpConstraint(lhs, 'eq', rhs, name=f'_C_{typ}_{cls._cons_id()}')
def constraint_sum_eq(cls, lp_var_list: List[LpVariable], value: int): lhs = cls.sum_expr(lp_var_list) rhs = cls.const_expr(value) return flipy.LpConstraint(lhs, 'eq', rhs, name=f'_C{cls._cons_id()}')