Class convenience method to search for the first solution to the
 constraints.
492479
def solve(failure_message = "No solution.")
      amb = self.new
      yield(amb)
    rescue Amb::ExhaustedError => ex
      puts
      puts "#{amb.branches_count} branches explored." if $DEBUG
      amb.report(failure_message)
    end
210282
public Collection findAll(Iterator it, Constraint constraint) {
		ElementGenerator finder = new IteratorTemplate(it).findAll(constraint);
		final Collection results = new ArrayList();
		finder.run(new Block() {
			protected void handle(Object element) {
				results.add(element);
			}
		});
		return results;
	}
363826
function () {
			var args = slice.call(arguments),
				constraint = options.args_map.getOrPut(args, function() {
					return new Constraint(function () {
						return getter_fn.apply(options.context, args);
					});
				});
			return constraint.get();
		}
637004
private void solve(int method) throws NullPointerException {
    // solution exists
    if(solved) {
      return;
    }

    // bring in reduced row echelon form
    if(!reducedRowEchelonForm) {
      reducedRowEchelonForm(method);
    }

    if(!isSolvable(method)) {
      if(LOG.isDebugging()) {
        LOG.debugFine("Equation system is not solvable!");
      }
      return;
    }

    // compute one special solution
    final int cols = coeff[0].length;
    int numbound = 0, numfree = 0;
    int[] boundIndices = new int[cols], freeIndices = new int[cols];
    x_0 = new double[cols];
    outer: for(int i = 0; i < coeff.length; i++) {
      for(int j = i; j < coeff[row[i]].length; j++) {
        if(coeff[row[i]][col[j]] == 1) {
          x_0[col[i]] = rhs[row[i]];
          boundIndices[numbound++] = col[i];
          continue outer;
        }
      }
      freeIndices[numfree++] = i;
    }

    StringBuilder msg = new StringBuilder();
    if(LOG.isDebugging()) {
      msg.append("\nSpecial solution x_0 = [").append(FormatUtil.format(x_0, ",", FormatUtil.NF4)).append(']') //
          .append("\nbound Indices ").append(FormatUtil.format(boundIndices, ",")) //
          .append("\nfree Indices ").append(FormatUtil.format(freeIndices, ","));
    }

    // compute solution space of homogeneous linear equation system
    Arrays.sort(boundIndices, 0, numbound);
    int freeIndex = 0;
    int boundIndex = 0;
    u = new double[cols][numfree];

    for(int j = 0; j < u[0].length; j++) {
      for(int i = 0; i < u.length; i++) {
        if(freeIndex < numfree && i == freeIndices[freeIndex]) {
          u[i][j] = 1;
        }
        else if(boundIndex < numbound && i == boundIndices[boundIndex]) {
          u[i][j] = -coeff[row[boundIndex]][freeIndices[freeIndex]];
          boundIndex++;
        }
      }
      freeIndex++;
      boundIndex = 0; // Restart
    }

    if(LOG.isDebugging()) {
      msg.append("\nU");
      for(double[] anU : u) {
        msg.append('\n').append(FormatUtil.format(anU, ",", FormatUtil.NF4));
      }
      LOG.debugFine(msg.toString());
    }

    solved = true;
  }
1354515
def find_first_object(self, ObjectClass, **kwargs):
        
        filter = None
        for k, v in kwargs.items():
            cond = getattr(ObjectClass, k) == v
            filter = cond if filter is None else filter & cond

        return list(ObjectClass.scan(filter, limit=1))[0]
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);
  }
915995
def get_first(self):
		""""""
		try: # Nested try..except because of Python 2.4
			self.lock.acquire()
			try:
				return self.get(self.data_idx[0])
			except (IndexError, ValueError):
				return "NONE"
		finally:
			self.lock.release()
1174759
function(){

            var its = this.options.iterations
                ,coef = 1 / its
                ;

            for (var i = 0; i < its; i++){

                // this.shuffleConstraints();
                this.resolveDistanceConstraints( coef );
                this.resolveAngleConstraints( coef );
            }
        }
498358
def check_constraint(self, pkge=None, constr=None):
        
        if not pkge is None:
            return javabridge.call(
                self.jobject, "checkConstraint", "(Lweka/core/packageManagement/Package;)Z", pkge.jobject)
        if not constr is None:
            return javabridge.call(
                self.jobject, "checkConstraint", "(Lweka/core/packageManagement/PackageConstraint;)Z", pkge.jobject)
        raise Exception("Either package or package constraing must be provided!")
943818
def find_first_object(self, ObjectClass, **kwargs):
        

        # Convert each name/value pair in 'kwargs' into a filter
        query = ObjectClass.query
        for field_name, field_value in kwargs.items():

            # Make sure that ObjectClass has a 'field_name' property
            field = getattr(ObjectClass, field_name, None)
            if field is None:
                raise KeyError("BaseAlchemyAdapter.find_first_object(): Class '%s' has no field '%s'." % (ObjectClass, field_name))

            # Add a case sensitive filter to the query
            query = query.filter(field==field_value)  # case sensitive!!

        # Execute query
        return query.first()
1235511
public Object findFirst(Iterator it, Constraint constraint) {
		return new IteratorTemplate(it).findFirst(constraint);
	}
737727
def set_constraint_bound(self, name, value):
        """"""
        index = self._get_constraint_index(name)
        self.upper_bounds[index] = value
        self._reset_solution()
148956
public void skipSolver(ConstraintSolver ... solvers) {
		if (solversToSkip == null) solversToSkip = new HashSet<ConstraintSolver>();
		for (ConstraintSolver solver : solvers) solversToSkip.add(solver);
	}
367322
def fetchFirstExample(self, exampleDict, rawResults = False) :
        """"""
        return self.simpleQuery('first-example', rawResults = rawResults, example = exampleDict)
73414
def first(self):
        
        self.reset()
        value = next(self, None)
        if value is None:
            raise ConstraintViolation("{} did not find any results.".format(self.mode.capitalize()))
        return value
417264
private void solution(BitSet traversed) {
        boolean included = false;
        BitSet projG1 = projectG1(traversed);
        BitSet projG2 = projectG2(traversed);

        // the solution must follows the search constrains
        // (must contain the mandatory elements in G1 an G2)
        if (isContainedIn(c1, projG1) && isContainedIn(c2, projG2)) {
            // the solution should not be included in a previous solution
            // at the RGraph level. So we check against all previous solution
            // On the other hand if a previous solution is included in the
            // new one, the previous solution is removed.
            for (Iterator<BitSet> i = solutionList.listIterator(); i.hasNext() && !included;) {
                BitSet sol = i.next();

                if (!sol.equals(traversed)) {
                    // if we asked to save all 'mappings' then keep this mapping
                    if (findAllMap && (projG1.equals(projectG1(sol)) || projG2.equals(projectG2(sol)))) {
                        // do nothing
                    }
                    // if the new solution is included mark it as included
                    else if (isContainedIn(projG1, projectG1(sol)) || isContainedIn(projG2, projectG2(sol))) {
                        included = true;
                    }
                    // if the previous solution is contained in the new one, remove the previous solution
                    else if (isContainedIn(projectG1(sol), projG1) || isContainedIn(projectG2(sol), projG2)) {
                        i.remove();
                    }
                } else {
                    // solution already exists
                    included = true;
                }
            }

            if (included == false) {
                // if it is really a new solution add it to the
                // list of current solution
                solutionList.add(traversed);
            }

            if (!findAllStructure) {
                // if we need only one solution
                // stop the search process
                // (e.g. substructure search)
                stop = true;
            }
        }
    }
244173
public static int ParetoConstraintCompare(Solution solution1, Solution solution2)
   {
      boolean dominate1 = false;
      boolean dominate2 = false;

      int constraint_count = solution1.getConstraints().size();
      for (int i = 0; i < constraint_count; i++)
      {
         if (Math.abs(solution1.getConstraint(i)) < Math.abs(solution2.getConstraint(i)))
         {
            dominate1 = true;
            if (dominate2)
            {
               return 0;
            }
         }
         else if (Math.abs(solution1.getConstraint(i)) > Math.abs(solution2.getConstraint(i)))
         {
            dominate2 = true;
            if (dominate1)
            {
               return 0;
            }
         }
      }

      if (dominate1 == dominate2)
      {
         return 0;
      }
      else if (dominate1)
      {
         return -1;
      }
      else
      {
         return 1;
      }
   }