How to use the ortools.sat.python.cp_model_helper.AssertIsInt64 function in ortools

To help you get started, we’ve selected a few ortools examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github google / or-tools / ortools / sat / python / cp_model.py View on Github external
if not transition_variables:
            raise ValueError(
                'AddAutomaton expects a non-empty transition_variables '
                'array')
        if not final_states:
            raise ValueError('AddAutomaton expects some final states')

        if not transition_triples:
            raise ValueError('AddAutomaton expects some transtion triples')

        ct = Constraint(self.__model.constraints)
        model_ct = self.__model.constraints[ct.Index()]
        model_ct.automaton.vars.extend(
            [self.GetOrMakeIndex(x) for x in transition_variables])
        cp_model_helper.AssertIsInt64(starting_state)
        model_ct.automaton.starting_state = starting_state
        for v in final_states:
            cp_model_helper.AssertIsInt64(v)
            model_ct.automaton.final_states.append(v)
        for t in transition_triples:
            if len(t) != 3:
                raise TypeError('Tuple ' + str(t) +
                                ' has the wrong arity (!= 3)')
            cp_model_helper.AssertIsInt64(t[0])
            cp_model_helper.AssertIsInt64(t[1])
            cp_model_helper.AssertIsInt64(t[2])
            model_ct.automaton.transition_tail.append(t[0])
            model_ct.automaton.transition_label.append(t[1])
            model_ct.automaton.transition_head.append(t[2])
        return ct
github google / or-tools / ortools / sat / python / cp_model.py View on Github external
def AddLinearExpressionInDomain(self, linear_expr, domain):
        """Adds the constraint: `linear_expr` in `domain`."""
        if isinstance(linear_expr, LinearExpr):
            ct = Constraint(self.__model.constraints)
            model_ct = self.__model.constraints[ct.Index()]
            coeffs_map, constant = linear_expr.GetVarValueMap()
            for t in iteritems(coeffs_map):
                if not isinstance(t[0], IntVar):
                    raise TypeError('Wrong argument' + str(t))
                cp_model_helper.AssertIsInt64(t[1])
                model_ct.linear.vars.append(t[0].Index())
                model_ct.linear.coeffs.append(t[1])
            model_ct.linear.domain.extend([
                cp_model_helper.CapSub(x, constant)
                for x in domain.FlattenedIntervals()
            ])
            return ct
        elif isinstance(linear_expr, numbers.Integral):
            if not domain.Contains(linear_expr):
                return self.AddBoolOr([])  # Evaluate to false.
            # Nothing to do otherwise.
        else:
            raise TypeError(
                'Not supported: CpModel.AddLinearExpressionInDomain(' +
                str(linear_expr) + ' ' + str(domain) + ')')
github google / or-tools / ortools / sat / python / cp_model.py View on Github external
def __gt__(self, arg):
        if isinstance(arg, numbers.Integral):
            cp_model_helper.AssertIsInt64(arg)
            if arg == INT_MAX:
                raise ArithmeticError('> INT_MAX is not supported')
            return BoundedLinearExpression(
                self, [cp_model_helper.CapInt64(arg + 1), INT_MAX])
        else:
            return BoundedLinearExpression(self - arg, [1, INT_MAX])
github google / or-tools / ortools / sat / python / cp_model.py View on Github external
"""

        if not variables:
            raise ValueError(
                'AddAllowedAssignments expects a non-empty variables '
                'array')

        ct = Constraint(self.__model.constraints)
        model_ct = self.__model.constraints[ct.Index()]
        model_ct.table.vars.extend([self.GetOrMakeIndex(x) for x in variables])
        arity = len(variables)
        for t in tuples_list:
            if len(t) != arity:
                raise TypeError('Tuple ' + str(t) + ' has the wrong arity')
            for v in t:
                cp_model_helper.AssertIsInt64(v)
            model_ct.table.values.extend(t)
        return ct
github google / or-tools / ortools / sat / python / cp_model.py View on Github external
ct = Constraint(self.__model.constraints)
        model_ct = self.__model.constraints[ct.Index()]
        model_ct.automaton.vars.extend(
            [self.GetOrMakeIndex(x) for x in transition_variables])
        cp_model_helper.AssertIsInt64(starting_state)
        model_ct.automaton.starting_state = starting_state
        for v in final_states:
            cp_model_helper.AssertIsInt64(v)
            model_ct.automaton.final_states.append(v)
        for t in transition_triples:
            if len(t) != 3:
                raise TypeError('Tuple ' + str(t) +
                                ' has the wrong arity (!= 3)')
            cp_model_helper.AssertIsInt64(t[0])
            cp_model_helper.AssertIsInt64(t[1])
            cp_model_helper.AssertIsInt64(t[2])
            model_ct.automaton.transition_tail.append(t[0])
            model_ct.automaton.transition_label.append(t[1])
            model_ct.automaton.transition_head.append(t[2])
        return ct
github google / or-tools / ortools / sat / python / cp_model.py View on Github external
def __eq__(self, arg):
        if arg is None:
            return False
        if isinstance(arg, numbers.Integral):
            cp_model_helper.AssertIsInt64(arg)
            return BoundedLinearExpression(self, [arg, arg])
        else:
            return BoundedLinearExpression(self - arg, [0, 0])
github google / or-tools / ortools / sat / python / cp_model.py View on Github external
def __init__(self, expr, coef):
        cp_model_helper.AssertIsInt64(coef)
        if isinstance(expr, _ProductCst):
            self.__expr = expr.Expression()
            self.__coef = expr.Coefficient() * coef
        else:
            self.__expr = expr
            self.__coef = coef
github google / or-tools / ortools / sat / python / cp_model.py View on Github external
def __rmul__(self, arg):
        cp_model_helper.AssertIsInt64(arg)
        if arg == 1:
            return self
        return _ProductCst(self, arg)
github google / or-tools / ortools / sat / python / cp_model.py View on Github external
'AddAutomaton expects a non-empty transition_variables '
                'array')
        if not final_states:
            raise ValueError('AddAutomaton expects some final states')

        if not transition_triples:
            raise ValueError('AddAutomaton expects some transtion triples')

        ct = Constraint(self.__model.constraints)
        model_ct = self.__model.constraints[ct.Index()]
        model_ct.automaton.vars.extend(
            [self.GetOrMakeIndex(x) for x in transition_variables])
        cp_model_helper.AssertIsInt64(starting_state)
        model_ct.automaton.starting_state = starting_state
        for v in final_states:
            cp_model_helper.AssertIsInt64(v)
            model_ct.automaton.final_states.append(v)
        for t in transition_triples:
            if len(t) != 3:
                raise TypeError('Tuple ' + str(t) +
                                ' has the wrong arity (!= 3)')
            cp_model_helper.AssertIsInt64(t[0])
            cp_model_helper.AssertIsInt64(t[1])
            cp_model_helper.AssertIsInt64(t[2])
            model_ct.automaton.transition_tail.append(t[0])
            model_ct.automaton.transition_label.append(t[1])
            model_ct.automaton.transition_head.append(t[2])
        return ct