Exemplo n.º 1
0
def test_fix(n):
    """Test fix constraints"""
    #diag_select("drplan._search_triangle")

    print "generate a random 2D problem"
    problem = random_problem_2D(n)

    print "create dr planner"
    drplanner = GeometericSolver(problem)
    print "number of top clusters:", len(drplanner.dr.top_level())
    #print "top clusters:", map(str, drplanner.dr.top_level())

    cons = problem.cg.constraints()
    dists = filter(lambda d: isinstance(d, DistanceConstraint), cons)
    con = random.choice(dists)
    print "remove distance", con
    problem.rem_constraint(con)
    print "number of top clusters:", len(drplanner.dr.top_level())
    #print "top clusters:", map(str, drplanner.dr.top_level())

    print "replace with two fixes"
    v1 = con.variables()[0]
    v2 = con.variables()[1]
    f1 = FixConstraint(v1, problem.get_point(v1))
    f2 = FixConstraint(v2, problem.get_point(v2))
    problem.add_constraint(f1)
    problem.add_constraint(f2)
    print "number of top clusters:", len(drplanner.dr.top_level())
Exemplo n.º 2
0
def test_mate():
    problem = GeometricProblem(dimension=3)

    # create and  mate two blocks
    add_block(problem, "A", 4.0, 2.0, 6.0)
    add_block(problem, "B", 4.0, 2.0, 6.0)
    mate_blocks(problem, "A", 'right-bot-front', 'right-bot-back',
                'right-top-front', "B", 'left-bot-front', 'left-bot-back',
                'left-top-front', 0.5, 0.0)
    # add global coordinate system
    problem.add_point("origin", vector([0.0, 0.0, 0.0]))
    problem.add_point("x-axis", vector([1.0, 0.0, 0.0]))
    problem.add_point("y-axis", vector([0.0, 1.0, 0.0]))
    problem.add_constraint(FixConstraint("origin", vector([0.0, 0.0, 0.0])))
    problem.add_constraint(FixConstraint("x-axis", vector([1.0, 0.0, 0.0])))
    problem.add_constraint(FixConstraint("y-axis", vector([0.0, 1.0, 0.0])))

    # fix block1 to cs
    problem.add_constraint(
        MateConstraint("origin", "x-axis", "y-axis",
                       block_var("A", "left-bot-front"),
                       block_var("A", "right-bot-front"),
                       block_var("A", "left-top-front"), id_transform_3D()))

    test(problem)
Exemplo n.º 3
0
def fix2_problem_3d():
    """A problem with a fix constraint"""
    problem = GeometricProblem(dimension=3)
    problem.add_point('v1', vector([0.0, 0.0, 0.0]))
    problem.add_point('v2', vector([1.0, 0.0, 0.0]))
    problem.add_point('v3', vector([0.0, 1.0, 0.0]))
    problem.add_point('v4', vector([0.0, 0.0, 1.0]))
    #problem.add_constraint(DistanceConstraint('v1', 'v2', 10.0))
    problem.add_constraint(DistanceConstraint('v1', 'v3', 10.0))
    problem.add_constraint(DistanceConstraint('v2', 'v3', 10.0))
    problem.add_constraint(DistanceConstraint('v1', 'v4', 10.0))
    problem.add_constraint(DistanceConstraint('v2', 'v4', 10.0))
    problem.add_constraint(DistanceConstraint('v3', 'v4', 10.0))
    problem.add_constraint(FixConstraint('v1', vector([0.0,0.0,0.0])))
    problem.add_constraint(FixConstraint('v2', vector([10.0,0.0,0.0])))
    return problem
Exemplo n.º 4
0
    def solve_fixed(self, fixed, layers):

        for i, layer in enumerate(layers):
            print("Solving fixed ", layer.id)
            i = 0
            for point in layer.named_pairs:
                if point[0] in fixed:
                    self.problem.add_constraint(
                        FixConstraint(point[0], vector([point[1], point[2],
                                                        0])))

                i += 1