Given a constraint, _get_assumptions() returns a set of constraints that are implicitly
        assumed to be true. For example, `x <= 10` would return `x >= 0`.
553865
def _get_assumptions(t):
        

        if t.op in ('__le__', '__lt__', 'ULE', 'ULT'):
            return [ t.args[0] >= 0 ]
        elif t.op in ('__ge__', '__gt__', 'UGE', 'UGT'):
            return [ t.args[0] <= 2**len(t.args[0])-1 ]
        elif t.op in ('SLE', 'SLT'):
            return [ _all_operations.SGE(t.args[0], -(1 << (len(t.args[0])-1))) ]
        elif t.op in ('SGE', 'SGT'):
            return [ _all_operations.SLE(t.args[0], (1 << (len(t.args[0])-1)) - 1) ]
        else:
            return [ ]
700875
def xorc_constraint(v=0, sense="maximize"):
    
    assert v in [0,1], "v must be 0 or 1 instead of %s" % v.__repr__()
    model, x, y, z = _init()
    r = model.addVar("r", "B")
    n = model.addVar("n", "I") # auxiliary
    model.addCons(r+quicksum([x,y,z]) == 2*n)
    model.addCons(x==v)
    model.setObjective(r, sense=sense)
    _optimize("Custom XOR (as variable)", model)
1144996
def xors_constraint(v=1):
    
    assert v in [0,1], "v must be 0 or 1 instead of %s" % v.__repr__()
    model, x, y, z = _init()
    r = True
    model.addConsXor([x,y,z], r)
    model.addCons(x==v)
    _optimize("Standard XOR (as boolean)", model)
318347
def satisfiable(self, **kwargs):
        
        if o.ABSTRACT_SOLVER in self.options or o.SYMBOLIC not in self.options:
            extra_constraints = kwargs.pop('extra_constraints', ())
            for e in extra_constraints:
                if self.solver.is_false(e):
                    return False

            return self._satisfiable
        else:
            return self.solver.satisfiable(**kwargs)
1041563
def assume(self, cond):
        
        fn = self.module.declare_intrinsic("llvm.assume")
        return self.call(fn, [cond])
751698
def _calc_mask(self):
    """"""
    mask = []
    for row in self._constraints:
      mask.append(tuple(x is None for x in row))
    return tuple(mask)
345926
def check_constraints(self, instance):
        '''
        
        '''
        recalc_fields = []
        for constraint in self.constraints:
            try:
                constraint(self.model, instance)
            except constraints.InvalidConstraint as e:
                recalc_fields.extend(e.fields)
        return recalc_fields
289774
def hidden_constraints(self):
        
        try:
            return self._hidden_constraints
        except AttributeError:
            self._hidden_constraints = ConstraintDict()
            return self._hidden_constraints
1303053
private void evaluateConstraints(DoubleSolution solution)  {
    double[] constraint = new double[this.getNumberOfConstraints()];

    double x1 = solution.getVariableValue(0);
    double x2 = solution.getVariableValue(1);
        
    constraint[0] = -x2 - (4.0 * x1) + 4.0  ;
    constraint[1] = x1 + 1.0 ;
    constraint[2] = x2 - x1 + 2.0 ;

    double overallConstraintViolation = 0.0;
    int violatedConstraints = 0;
    for (int i = 0; i < getNumberOfConstraints(); i++) {
      if (constraint[i]<0.0){
        overallConstraintViolation+=constraint[i];
        violatedConstraints++;
      }
    }

    overallConstraintViolationDegree.setAttribute(solution, overallConstraintViolation);
    numberOfViolatedConstraints.setAttribute(solution, violatedConstraints);
  }
88093
@SuppressWarnings("unchecked")
    public Constraint getConstraint(String ... typeInfo) {
        if( typeInfo == null || typeInfo.length < 1 ) {
            return getConstraints().iterator().next();
        }
        else if( typeInfo.length == 1 ) {
            Constraint c = getConstraint(new String[0]);
            DataType<?> attr = c.getType();
            Boolean b;
            
            b = (Boolean)attr.getValue(typeInfo[0]);
            if( b == null || !b ) {
                return constraints.get(1);
            }
            else {
                return constraints.get(2);
            }
        }
        else {
            return super.getConstraint(typeInfo);
        }
    }
478518
def solve(self, assumptions=[]):
        

        if self.lingeling:
            if self.use_timer:
                 start_time = time.clock()

            # saving default SIGINT handler
            def_sigint_handler = signal.signal(signal.SIGINT, signal.SIG_DFL)

            self.status = pysolvers.lingeling_solve(self.lingeling, assumptions)

            # recovering default SIGINT handler
            def_sigint_handler = signal.signal(signal.SIGINT, def_sigint_handler)

            if self.use_timer:
                self.call_time = time.clock() - start_time
                self.accu_time += self.call_time

            self.prev_assumps = assumptions
            return self.status
1343929
def __has_no_dependents (self, obj, constraints):
        
        failed = False
        while constraints and not failed:
            c = constraints [0]

            if c [1] == obj:
                failed = True

            constraints = constraints [1:]

        return not failed
1103724
def _combine(self, x, y):
    """"""
    if x is None or y is None:
      return x or y
    if x != y:
      raise ValueError('Incompatible set of constraints provided.')
    return x
680865
def _constrain(value, lb=0, ub=1):
    """"""
    if value < lb:
        return lb
    elif value > ub:
        return ub
    else:
        return value
826489
def hasconstraint(self):
        
        constrained = False
        for term in self._terms:
            constrained = constrained or term.hasconstraint
        return constrained
875108
def satisfies_constraints(self, possible_solution):
        """"""
        for c in self._constraints:
            values = c.extract_values(possible_solution)
            if any(type(v) is NilObject for v in values) or not c(*values):
                return False
        return True
971813
def _enforce_bounds(self, x):
        """""""
        assert len(x) == len(self.bounds)
        x_enforced = []
        for x_i, (lb, ub) in zip(x, self.bounds):
            if x_i < lb:
                if x_i > lb - (ub-lb)/1e10:
                    x_enforced.append(lb)
                else:
                    x_enforced.append(x_i)
            elif x_i > ub:
                if x_i < ub + (ub-lb)/1e10:
                    x_enforced.append(ub)
                else:
                    x_enforced.append(x_i)
            else:
                x_enforced.append(x_i)
        return np.array(x_enforced)