Given set of equivalences, return map of transitive equivalence classes.

    >> constraints = [(1,2), (2,3)]
    >> get_scc_from_tuples(constraints)
    {
        1: (1, 2, 3),
        2: (1, 2, 3),
        3: (1, 2, 3),
    }
176010
def get_scc_from_tuples(constraints):
    
    classes = unionfind.classes(constraints)
    return dict((x, tuple(c)) for x, c in classes.iteritems())
699649
def _linear_constraints(self, om):
        
        A, l, u = om.linear_constraints() # l <= A*x <= u

        # Indexes for equality, greater than (unbounded above), less than
        # (unbounded below) and doubly-bounded box constraints.
#        ieq = flatnonzero( abs(u - l) <= EPS )
#        igt = flatnonzero( (u >=  1e10) & (l > -1e10) )
#        ilt = flatnonzero( (l <= -1e10) & (u <  1e10) )
#        ibx = flatnonzero( (abs(u - l) > EPS) & (u < 1e10) & (l > -1e10) )

        # Zero-sized sparse matrices not supported.  Assume equality
        # constraints exist.
##        AA = A[ieq, :]
##        if len(ilt) > 0:
##            AA = vstack([AA, A[ilt, :]], "csr")
##        if len(igt) > 0:
##            AA = vstack([AA, -A[igt, :]], "csr")
##        if len(ibx) > 0:
##            AA = vstack([AA, A[ibx, :], -A[ibx, :]], "csr")
#
#        if len(ieq) or len(igt) or len(ilt) or len(ibx):
#            sig_idx = [(1, ieq), (1, ilt), (-1, igt), (1, ibx), (-1, ibx)]
#            AA = vstack([sig * A[idx, :] for sig, idx in sig_idx if len(idx)])
#        else:
#            AA = None
#
#        bb = r_[u[ieq, :], u[ilt], -l[igt], u[ibx], -l[ibx]]
#
#        self._nieq = ieq.shape[0]
#
#        return AA, bb

        return A, l, u
754709
public static EquivalenceClasser<List<String>, String> typedDependencyClasser() {
    return new EquivalenceClasser<List<String>, String>() {
      public String equivalenceClass(List<String> s) {
        if(s.get(5).equals(leftHeaded))
          return s.get(2) + '(' + s.get(3) + "->" + s.get(4) + ')';
        return s.get(2) + '(' + s.get(4) + "<-" + s.get(3) + ')';
      }
    };
  }
994813
def fermionic_constraints(a):
    
    substitutions = {}
    for i, ai in enumerate(a):
        substitutions[ai ** 2] = 0
        substitutions[Dagger(ai) ** 2] = 0
        substitutions[ai * Dagger(ai)] = 1.0 - Dagger(ai) * ai
        for aj in a[i+1:]:
            # substitutions[ai*Dagger(aj)] = -Dagger(ai)*aj
            substitutions[ai*Dagger(aj)] = -Dagger(aj)*ai
            substitutions[Dagger(ai)*aj] = -aj*Dagger(ai)
            substitutions[ai*aj] = -aj*ai
            substitutions[Dagger(ai) * Dagger(aj)] = - Dagger(aj) * Dagger(ai)

    return substitutions
393082
def types(cls):
        
        redundant_types = \
            set(cls.types_mapping) & set(cls._types_from_methods)
        if redundant_types:
            warn("These types are defined both with a method and in the"
                 "'types_mapping' property of this validator: %s"
                 % redundant_types)

        return tuple(cls.types_mapping) + cls._types_from_methods
392804
def constraints(self):
        
        cs = []
        for pop in self.poplist:
            cs += [c for c in pop.constraints]
        return list(set(cs))
1002093
def get_comparable_values(self):
        
        return (str(self.name), str(self.description), str(self.constraints))
598598
def transitive_reduction(self):
        
        combinations = []
        for node, edges in self.graph.items():
            combinations += [[node, edge] for edge in edges]

        while True:
            new_combinations = []
            for comb1 in combinations:
                for comb2 in combinations:
                    if not comb1[-1] == comb2[0]:
                        continue
                    new_entry = comb1 + comb2[1:]
                    if new_entry not in combinations:
                        new_combinations.append(new_entry)
            if not new_combinations:
                break
            combinations += new_combinations

        constructed = {(c[0], c[-1]) for c in combinations if len(c) != 2}
        for node, edges in self.graph.items():
            bad_nodes = {e for n, e in constructed if node == n}
            self.graph[node] = edges - bad_nodes
1330084
def _merge_constraints(constraints, overrides):
    
    for o in overrides:
        i = 0
        while i < len(constraints):
            c = constraints[i]
            if _same(o, c):
                constraints[i].update(o)
                break
            i = i + 1
584624
async def get_constraints(self):
        
        constraints = {}
        client_facade = client.ClientFacade.from_connection(self.connection())
        result = await client_facade.GetModelConstraints()

        # GetModelConstraints returns GetConstraintsResults which has a
        # 'constraints' attribute. If no constraints have been set
        # GetConstraintsResults.constraints is None. Otherwise
        # GetConstraintsResults.constraints has an attribute for each possible
        # constraint, each of these in turn will be None if they have not been
        # set.
        if result.constraints:
            constraint_types = [a for a in dir(result.constraints)
                                if a in Value._toSchema.keys()]
            for constraint in constraint_types:
                value = getattr(result.constraints, constraint)
                if value is not None:
                    constraints[constraint] = getattr(result.constraints,
                                                      constraint)
        return constraints
206957
def constrains(self):
        
        params = []
        for constraint in self.in_constraints:
            for var in constraint._vars:
                param = var.get_parameter()
                if param.component == constraint.component and param.qualifier == constraint.qualifier:
                    if param not in params and param.uniqueid != self.uniqueid:
                        params.append(param)
        return params
1350971
public Collection findAll(Collection collection, Constraint constraint) {
		return findAll(collection.iterator(), constraint);
	}
1332444
def convert_schema(self, nuc_tuple, inner_sat_tuples, outer_sat_tuples):
        
        nuc_tree, nuc_pos = nuc_tuple
        sat_tuples = inner_sat_tuples + outer_sat_tuples
        last_sat_tuple_pos = len(sat_tuples)-1

        for i, (sat_tree, sat_pos) in enumerate(sat_tuples):
            relname = self.get_relname(sat_tree.root_id)
            if sat_pos < nuc_pos:
                ordered_trees = [sat_tree, nuc_tree]
            else:
                ordered_trees = [nuc_tree, sat_tree]

            if i == last_sat_tuple_pos:
                nuc_tree = t(relname, ordered_trees, debug=self.debug, root_id=nuc_tree.root_id)
            else:
                nuc_tree = t('N', [(relname, ordered_trees)], debug=self.debug, root_id=nuc_tree.root_id)
        return nuc_tree
1122800
def constraints_since(self, other):
        

        constraints = [ ]
        cur = self
        while cur is not other and cur is not None:
            constraints.extend(cur.recent_constraints)
            cur = cur.parent
        return constraints
348757
def get_constrained_fc2(supercell,
                        dataset_second_atoms,
                        atom1,
                        reduced_site_sym,
                        symprec):
    
    lattice = supercell.get_cell().T
    positions = supercell.get_scaled_positions()
    num_atom = supercell.get_number_of_atoms()

    fc2 = np.zeros((num_atom, num_atom, 3, 3), dtype='double')
    atom_list = np.unique([x['number'] for x in dataset_second_atoms])
    for atom2 in atom_list:
        disps2 = []
        sets_of_forces = []
        for disps_second in dataset_second_atoms:
            if atom2 != disps_second['number']:
                continue
            bond_sym = get_bond_symmetry(
                reduced_site_sym,
                lattice,
                positions,
                atom1,
                atom2,
                symprec)

            disps2.append(disps_second['displacement'])
            sets_of_forces.append(disps_second['delta_forces'])

        solve_force_constants(fc2,
                              atom2,
                              disps2,
                              sets_of_forces,
                              supercell,
                              bond_sym,
                              symprec)

    # Shift positions according to set atom1 is at origin
    pos_center = positions[atom1].copy()
    positions -= pos_center
    rotations = np.array(reduced_site_sym, dtype='intc', order='C')
    translations = np.zeros((len(reduced_site_sym), 3),
                            dtype='double', order='C')
    permutations = compute_all_sg_permutations(positions,
                                               rotations,
                                               translations,
                                               lattice,
                                               symprec)
    distribute_force_constants(fc2,
                               atom_list,
                               lattice,
                               rotations,
                               permutations)
    return fc2
920469
def _con(self):
        
        class Constraints(object):
            def __getitem__(_self, name):
                return self.getConstraint(name)

            def __setitem__(_self, name, value):
                self.getConstraint(name).setDual(value)

            def __iter__(_self):
                return self.getConstraints()

        return Constraints()
613430
def _tupleCompare(tuple1, ineq, tuple2,
                 eq=lambda a,b: (a==b),
                 ander=AND,
                 orer=OR):
    

    orholder = []
    for limit in range(len(tuple1)):
        eqconstraint = [
            eq(elem1, elem2) for elem1, elem2 in zip(tuple1, tuple2)[:limit]]
        ineqconstraint = ineq(tuple1[limit], tuple2[limit])
        orholder.append(ander(*(eqconstraint + [ineqconstraint])))
    return orer(*orholder)