def __init__(self, model, e=None, constant=0, name=None, safe=False, transient=False): ModelingObjectBase.__init__(self, model, name) if not safe and constant: model._typecheck_num(constant, 'LinearExpr()') self._constant = constant self._transient = transient self._subscribers = [] if isinstance(e, dict): if safe: self.__terms = e else: self_terms = model._lfactory.term_dict_type() for (v, k) in iteritems(e): model._typecheck_var(v) model._typecheck_num(k, 'LinearExpr') if k != 0: self_terms[v] = k self.__terms = self_terms return else: self.__terms = model._lfactory._new_term_dict() if e is None: pass elif isinstance(e, Var): self.__terms[e] = 1 elif is_number(e): self._constant += e elif isinstance(e, MonomialExpr): # TODO: simplify by self_terms[e.var] = e.coef self._add_term(e.var, e.coef) elif isinstance(e, LinearExpr): # note that transient is not kept. self._constant = e.get_constant() self.__terms = self._new_terms_dict( model, e._get_terms_dict()) # make a copy elif isinstance(e, tuple): v, k = e self.__terms[v] = k else: self.fatal( "Cannot convert {0!r} to docplex.mp.LinearExpr, type is {1}", e, type(e))
def __init__(self, model): ModelingObjectBase.__init__(self, model) self._subscribers = []
def __init__(self, model, cst): ModelingObjectBase.__init__(self, model=model, name=None) # assume constant is a number (to be checked upfront) self._constant = cst self._subscribers = []
def __init__(self, model, pwl_def, name=None): ModelingObjectBase.__init__(self, model, name=name) self._pwl_def = pwl_def self._pwl_def_as_breaks = None self._set_pwl_definition(pwl_def)