Beispiel #1
0
def test_ada_3d():
    problem = ada_3d_problem()
    diag_select("nothing")
    print "problem:"
    print problem
    solver = GeometricSolver(problem)
    print "drplan:"
    print solver.dr
    print "number of top-level rigids:",len(solver.dr.top_level())
    result = solver.get_result()
    print "result:"
    print result
    print "result is",result.flag, "with", len(result.solutions),"solutions"
    check = True
    if len(result.solutions) == 0:
        check = False
    diag_select(".*")
    for sol in result.solutions:
        print "solution:",sol
        check = check and problem.verify(sol)
    diag_select("nothing")
    if check: 
        print "all solutions valid"
    else:
        print "INVALID"
Beispiel #2
0
def test(problem):
    """Test solver on a given problem"""
    #diag_select(".*")
    print "problem:"
    print problem
    print "Solving..."
    solver = GeometricSolver(problem)
    print "...done"
    print "drplan:"
    print solver.dr
    print "top-level rigids:", list(solver.dr.top_level())
    result = solver.get_result()
    print "result:"
    print result
    print "result is", result.flag, "with", len(result.solutions), "solutions"
    check = True
    if len(result.solutions) == 0:
        check = False
    diag_select("(GeometricProblem.verify)|(satisfied)")
    for sol in result.solutions:
        print "solution:", sol
        check = check and problem.verify(sol)
    if check:
        print "all solutions valid"
    else:
        print "INVALID"
Beispiel #3
0
def test(problem):
    """Test solver on a given problem"""
    #diag_select(".*")
    print "problem:"
    print problem
    print "Solving..."
    solver = GeometricSolver(problem)
    print "...done"
    print "drplan:"
    print solver.dr
    print "top-level rigids:",list(solver.dr.top_level())
    result = solver.get_result()
    print "result:"
    print result
    print "result is",result.flag, "with", len(result.solutions),"solutions"
    check = True
    if len(result.solutions) == 0:
        check = False
    diag_select("(GeometricProblem.verify)|(satisfied)")
    for sol in result.solutions:
        print "solution:",sol
        check = check and problem.verify(sol)
    if check: 
        print "all solutions valid"
    else:
        print "INVALID"
Beispiel #4
0
 def test(self):
     """Test solver on a given problem"""
     problem = self.solver
     # problem = fix3_problem_3d()
     #diag_select(".*")
     print("problem:")
     print(problem)
     print("Solving...")
     solver = GeometricSolver(problem)
     print("...done")
     print("drplan:")
     print(solver.dr)
     print("top-level rigids:", list(solver.dr.top_level()))
     result = solver.get_result()
     print("result:")
     print(result)
     print("result is", result.flag, "with", len(result.solutions),
           "solutions")
     check = True
     if len(result.solutions) == 0:
         check = False
     diag_select("(GeometricProblem.verify)|(satisfied)")
     for sol in result.solutions:
         print("solution:", sol)
         check = check and problem.verify(sol)
     if check:
         print("all solutions valid")
     else:
         print("INVALID")
Beispiel #5
0
def stats_solving(minsize, maxsize, repeats):
    print "times for solving problems from scratch"
    print "size \t # \t time \t result"
    for size in range(minsize, maxsize + 1):
        for i in range(1, repeats + 1):
            problem = random_triangular_problem_3D(size, 10.0, 0.0, 0.0)
            t1 = time()
            solver = GeometricSolver(problem)
            result = solver.get_status()
            t2 = time()
            t = t2 - t1
            print size, "\t", i, "\t", t, "\t", result
Beispiel #6
0
def stats_solving(minsize, maxsize, repeats):
    print "times for solving problems from scratch"
    print "size \t # \t time \t result"
    for size in range(minsize,maxsize+1):
        for i in range(1,repeats+1):
            problem = random_triangular_problem_3D(size,10.0,0.0,0.0)
            t1 = time()
            solver = GeometricSolver(problem)
            result = solver.get_status()
            t2 = time()
            t = t2-t1
            print size,"\t",i,"\t",t,"\t",result
Beispiel #7
0
def stats_parametric(minsize, maxsize, repeats):
    #diag_select("clsolver.remove")
    print "times for parameteric updates (one constraint parameter)"
    print "size \t # \t time \t result"
    for size in range(minsize, maxsize + 1):
        for i in range(1, repeats + 1):
            problem = random_triangular_problem_3D(size, 10.0, 0.0, 0.0)
            solver = GeometricSolver(problem)
            constraint = random.choice(problem.cg.constraints())
            t1 = time()
            constraint.set_parameter(constraint.get_parameter())
            result = solver.get_status()
            t2 = time()
            t = t2 - t1
            print size, "\t", i, "\t", t, "\t", result
Beispiel #8
0
def stats_parametric(minsize, maxsize, repeats):
    #diag_select("clsolver.remove")
    print "times for parameteric updates (one constraint parameter)"
    print "size \t # \t time \t result"
    for size in range(minsize,maxsize+1):
        for i in range(1,repeats+1):
            problem = random_triangular_problem_3D(size,10.0,0.0,0.0)
            solver = GeometricSolver(problem)
            constraint = random.choice(problem.cg.constraints())
            t1 = time()
            constraint.set_parameter(constraint.get_parameter())
            result = solver.get_status()
            t2 = time()
            t = t2-t1
            print size,"\t",i,"\t",t,"\t",result
Beispiel #9
0
def stats_incremental(minsize, maxsize, repeats):
    #diag_select("clsolver.remove")
    print "times for incremental re-solving (one constraint removed and re-added)"
    print "size \t # \t time \t result"
    for size in range(minsize, maxsize + 1):
        for i in range(1, repeats + 1):
            problem = random_triangular_problem_3D(size, 10.0, 0.0, 0.0)
            solver = GeometricSolver(problem)
            t1 = time()
            constraint = random.choice(problem.cg.constraints())
            problem.rem_constraint(constraint)
            problem.add_constraint(constraint)
            result = solver.get_status()
            t2 = time()
            t = t2 - t1
            print size, "\t", i, "\t", t, "\t", result
Beispiel #10
0
def test_random_overconstrained(size):
    # start with random well-constrained problem
    problem = random_problem_2D(size, 0.0)
    # add one random contraint
    for i in range(100):
        try:
            add_random_constraint(problem, 0.5)
            break
        except:
            pass
    if i == 99:
        raise StandardError, "could not add extra constraint"
    # test
    try:
        drplanner = GeometricSolver(problem)
        ntop = len(drplanner.dr.top_level())
        if ntop > 1:
            message = "underconstrained"
            check = False
        elif ntop == 0:
            message = "no top level"
            check = False
        else:  # ntop == 1
            top = drplanner.dr.top_level()[0]
            if not top.overconstrained:
                message = "well-constrained"
                check = False
            else:
                check = True
    except Exception, e:
        message = "error:", e
        check = False
Beispiel #11
0
def stats_incremental(minsize, maxsize, repeats):
    #diag_select("clsolver.remove")
    print "times for incremental re-solving (one constraint removed and re-added)"
    print "size \t # \t time \t result"
    for size in range(minsize,maxsize+1):
        for i in range(1,repeats+1):
            problem = random_triangular_problem_3D(size,10.0,0.0,0.0)
            solver = GeometricSolver(problem)
            t1 = time()
            constraint = random.choice(problem.cg.constraints())
            problem.rem_constraint(constraint)
            problem.add_constraint(constraint)
            result = solver.get_status()
            t2 = time()
            t = t2-t1
            print size,"\t",i,"\t",t,"\t",result
Beispiel #12
0
def selection_test():
    problem = GeometricProblem(dimension=3,use_prototype=False)
    
    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.5, 0.5, 1.0]))
    problem.add_point('v5', vector([0.5, 0.5,-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(DistanceConstraint('v1', 'v5', 10.0))
    problem.add_constraint(DistanceConstraint('v2', 'v5', 10.0))
    problem.add_constraint(DistanceConstraint('v3', 'v5', 10.0))

    s1 = RightHandedConstraint('v1','v2','v4','v5')
    
    # add selection con
    problem.add_constraint(s1)
    
    # solve
    solver = GeometricSolver(problem)
    print len(solver.get_solutions()), "solutions"
    
    # remove and add constraint
    print "removing selection-constraint"
    problem.rem_constraint(s1)

    # solve again
    print len(solver.get_solutions()), "solutions"

    # remove and add constraint
    print "re-adding selection constraint"
    problem.add_constraint(s1)

    # solve again
    print len(solver.get_solutions()), "solutions"

    # remove distance
    print "removing and re-adding distance v1-v5"
    problem.rem_constraint(problem.get_distance("v1","v5"))
    problem.add_constraint(DistanceConstraint('v1', 'v5', 10.0))

    # solve again
    print len(solver.get_solutions()), "solutions"
Beispiel #13
0
def test_mergehogs():
    diag_select(".")
    problem = GeometricProblem(dimension=2)
    problem.add_point('x', vector([0.0, 0.0]))
    problem.add_point('a', vector([1.0, 0.0]))
    problem.add_point('b', vector([0.0, 1.0]))
    problem.add_point('c', vector([-1.0, 0.0]))
    problem.add_point('d', vector([0.0, -1.0]))
    problem.add_constraint(AngleConstraint('a', 'x', 'b',
                                           30.0 / 180 * math.pi))
    problem.add_constraint(AngleConstraint('b', 'x', 'c',
                                           30.0 / 180 * math.pi))
    problem.add_constraint(AngleConstraint('c', 'x', 'd',
                                           30.0 / 180 * math.pi))
    solver = GeometricSolver(problem)
    print solver.dr
    for hog in solver.dr.hedgehogs():
        conf = list(solver.mg.get(hog))[0]
        print hog
        print conf
        print problem.verify(conf.map)
Beispiel #14
0
def test_random_wellconstrained(size):
    problem = random_problem_2D(size, 0.0)
    try:
        drplanner = GeometricSolver(problem)
        ntop = len(drplanner.dr.top_level())
        if ntop > 1:
            message = "underconstrained"
            check = False
        elif ntop == 0:
            message = "no top level"
            check = False
        else:  # ntop == 1
            top = drplanner.dr.top_level()[0]
            if top.overconstrained:
                message = "overconstrained"
                check = False
            else:
                check = True
    except Exception, e:
        print "error in problem:", e
        check = False
Beispiel #15
0
def test_fix2(n):
    """Test fix constraints"""
    # diag_select("drplan.*")
    print "generate a random 2D problem"
    problem = random_problem_2D(n)

    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 "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 "create dr planner"
    drplanner = GeometricSolver(problem)
    print "number of top clusters:", len(drplanner.dr.top_level())
    print "top clusters:", map(str, drplanner.dr.top_level())
Beispiel #16
0
            top = drplanner.dr.top_level()[0]
            if not top.overconstrained:
                message = "well-constrained"
                check = False
            else:
                check = True
    except Exception, e:
        message = "error:", e
        check = False
    #end try
    if check == False:
        print "--- problem ---"
        print problem
        print "--- diasgnostic messages ---"
        diag_select("drplan")
        drplanner = GeometricSolver(problem)
        print "--- plan ---"
        top = drplanner.dr.top_level()
        print drplanner.dr
        print "--- top level ---"
        print len(top), "clusters:"
        for cluster in drplanner.dr.top_level():
            print cluster
        print "--- conclusion ---"
        print message
        return False
    else:
        return True


def test_random_wellconstrained(size):