def random_problem_2D(numpoints, radius=10.0, roundoff=0.0, angleratio=0.5): """Generate a random problem with given number of points, a roundoff value for the prototype points, a radius for the cloud of prototype points and a ratio of angle constraints over distance constraints""" group = {} problem = GeometricProblem(dimension=2) i = 0 while i < numpoints: aname = 'p'+str(i) apoint = vector([ _round(random.uniform(-radius,radius),roundoff), _round(random.uniform(-radius,radius),roundoff) ]) unique = True for v in group: p = group[v] if tol_eq(apoint[0],p[0]) and tol_eq(apoint[1],p[1]): unique = False break if unique: problem.add_point(aname, apoint) group[aname] = apoint i = i + 1 #next _constraint_group(problem, group, None, angleratio) return problem
def random_problem_2D(numpoints, radius=10.0, roundoff=0.0, angleratio=0.5): """Generate a random problem with given number of points, a roundoff value for the prototype points, a radius for the cloud of prototype points and a ratio of angle constraints over distance constraints""" group = {} problem = GeometricProblem(dimension=2) i = 0 while i < numpoints: aname = 'p' + str(i) apoint = vector([ _round(random.uniform(-radius, radius), roundoff), _round(random.uniform(-radius, radius), roundoff) ]) unique = True for v in group: p = group[v] if tol_eq(apoint[0], p[0]) and tol_eq(apoint[1], p[1]): unique = False break if unique: problem.add_point(aname, apoint) group[aname] = apoint i = i + 1 #next _constraint_group(problem, group, None, angleratio) return problem
def random_distance_problem_3D(npoints, radius, roundoff): """creates a 3D problem with random distances""" problem = GeometricProblem(dimension=3) for i in range(npoints): # add point newvar = 'v' + str(i) newpoint = vector([ _round(random.uniform(-radius, radius), roundoff), _round(random.uniform(-radius, radius), roundoff), _round(random.uniform(-radius, radius), roundoff) ]) sellist = list(problem.cg.variables()) problem.add_point(newvar, newpoint) # add distance constraints for j in range(min(3, len(sellist))): index = random.randint(0, len(sellist) - 1) var = sellist.pop(index) point = problem.get_point(var) dist = distance_2p(point, newpoint) problem.add_constraint(DistanceConstraint(var, newvar, dist)) return problem
def random_distance_problem_3D(npoints, radius, roundoff): """creates a 3D problem with random distances""" problem = GeometricProblem(dimension=3) for i in range(npoints): # add point newvar = 'v'+str(i) newpoint = vector([ _round(random.uniform(-radius,radius),roundoff), _round(random.uniform(-radius,radius),roundoff), _round(random.uniform(-radius,radius),roundoff) ]) sellist = list(problem.cg.variables()) problem.add_point(newvar, newpoint) # add distance constraints for j in range(min(3,len(sellist))): index = random.randint(0,len(sellist)-1) var = sellist.pop(index) point = problem.get_point(var) dist = distance_2p(point,newpoint) problem.add_constraint(DistanceConstraint(var,newvar,dist)) return problem