def add(self, lin_expr: "mip.LinExpr", name: str = "") -> "mip.Constr": if not name: name = "constr({})".format(len(self.__constrs)) new_constr = mip.Constr(self.__model, len(self.__constrs)) self.__model.solver.add_constr(lin_expr, name) self.__constrs.append(new_constr) return new_constr
def __getitem__(self: "VConstrList", key): if isinstance(key, str): return self.__model.constr_by_name(key) elif isinstance(key, int): return mip.Constr(self.__model, key) elif isinstance(key, slice): return self[key] raise TypeError("Use int, string or slice as key")
def add( self, lin_expr: "mip.LinExpr", name: str = "", priority: "mip.constants.ConstraintPriority" = None, ) -> "mip.Constr": if not name: name = "constr({})".format(len(self.__constrs)) new_constr = mip.Constr(self.__model, len(self.__constrs), priority=priority) self.__model.solver.add_constr(lin_expr, name) self.__constrs.append(new_constr) return new_constr
def update_constrs(self: "ConstrList", n_constrs: int): self.__constrs = [ mip.Constr(self.__model, i) for i in range(n_constrs) ]