from __future__ import annotations from typing import List from models.constraints.generic_constraint import * class EnemyPairConstraint(GenericConstraint): @classmethod def create(cls: Type[_T], pair: List[int]) -> _T: return cls( minimum=0, maximum=0, reference_attribute=Attribute( value=pair, type='enemy_pair', id='enemy_pair' ) ) def build(self, problem_handler: Problem, **_) -> None: logging.info('Enemy Pair Constraint Generating...') pair = self.reference_attribute.value problem_handler.problem += lpSum( [ bundle.enemy_pair_count(pair) * problem_handler.solver_bundles_var[bundle.id] for bundle in problem_handler.bundles ] + [ (pair in item.enemy_pairs()).real * problem_handler.solver_items_var[item.id] for item in problem_handler.items ] ) <= 1, f'Enemy Pair constraint for pair: {pair}'