attempt to keep position and orientation of problem with no fixes closest to prototype

This commit is contained in:
kwikrick 2012-08-25 22:29:03 +00:00
parent 53d95d4a34
commit a1d5cc0187
3 changed files with 41 additions and 19 deletions

View File

@ -12,7 +12,7 @@ from multimethod import MultiVariable, MultiMethod
from cluster import * from cluster import *
from configuration import Configuration from configuration import Configuration
from gmatch import gmatch from gmatch import gmatch
from method import OrMethod from method import OrMethod,SetMethod
from incremental import MutableSet,Union,Filter from incremental import MutableSet,Union,Filter
# -------------------------------------------------- # --------------------------------------------------
@ -521,8 +521,10 @@ class ClusterSolver(Notifier):
diag_print("keep top-level: "+str(cluster),"clsolver") diag_print("keep top-level: "+str(cluster),"clsolver")
# add method to determine root-variable # add method to determine root-variable
self._add_root_method(merge.input_clusters(),merge.outputs()[0]) if hasattr(merge,"noremove") and merge.noremove == True:
self._add_root_false(merge.outputs()[0])
else:
self._add_root_method(merge.input_clusters(),merge.outputs()[0])
# add solution selection methods, only if information increasing # add solution selection methods, only if information increasing
if infinc: if infinc:
output2 = self._add_prototype_selector(merge) output2 = self._add_prototype_selector(merge)
@ -542,6 +544,14 @@ class ClusterSolver(Notifier):
# make sure its deleted when cluster is deleted # make sure its deleted when cluster is deleted
self._add_dependency(outcluster, method) self._add_dependency(outcluster, method)
def _add_root_false(self,outcluster):
outroot = rootname(outcluster)
method = SetMethod(outroot, False)
# add method
self._add_method(method)
# make sure its deleted when cluster is deleted
self._add_dependency(outcluster, method)
# -- removing objects # -- removing objects

View File

@ -119,7 +119,7 @@ class GeometricProblem (Notifier, Listener):
return self.has_variable(variable) return self.has_variable(variable)
def set_point(self, variable, prototype): def set_point(self, variable, prototype):
"""deprictaed - use set_prototype""" """depricated - use set_prototype"""
return self.set_prototype(variable, prototype) return self.set_prototype(variable, prototype)
def get_point(self, variable): def get_point(self, variable):
@ -326,6 +326,12 @@ class GeometricSolver (Listener):
# add constraints # add constraints
toadd = set(self.cg.constraints()) toadd = set(self.cg.constraints())
# add coincidences first. Prevents re-mapping of primitves and re-solving of problem
for con in list(toadd):
if isinstance(con, CoincidenceConstraint):
self._add_constraint(con)
toadd.remove(con)
# add selection constraints first. Prevents re-evaluation # add selection constraints first. Prevents re-evaluation
for con in list(toadd): for con in list(toadd):
if isinstance(con, SelectionConstraint): if isinstance(con, SelectionConstraint):
@ -649,11 +655,17 @@ class GeometricSolver (Listener):
v0 = vars[0] v0 = vars[0]
v1 = vars[1] v1 = vars[1]
dist = con.get_parameter() dist = con.get_parameter()
p0 = vector.vector([0.0,0.0]) #p0 = vector.vector([0.0,0.0])
p1 = vector.vector([dist,0.0]) #p1 = vector.vector([dist,0.0])
if self.dimension == 3: # use prototype to orient rigid - minimize difference solution and prototype
p0.append(0.0) p0 = self.problem.get_prototype(v0)
p1.append(0.0) v = self.problem.get_prototype(v1) - p0
if vector.norm(v) != 0:
v = v / vector.norm(v)
else:
v = vector.vector([0.0 for i in range(self.dimension)])
v[0] = 1.0
p1 = p0+v*dist
conf = Configuration({v0:p0,v1:p1}) conf = Configuration({v0:p0,v1:p1})
self.dr.set(rig, [conf]) self.dr.set(rig, [conf])
assert con.satisfied(conf.map) assert con.satisfied(conf.map)

View File

@ -357,19 +357,19 @@ def selection_problem():
def test3d(): def test3d():
#diag_select("clsolver") #diag_select("clsolver")
test(double_tetrahedron_problem()) #test(double_tetrahedron_problem())
test(ada_tetrahedron_problem()) #test(ada_tetrahedron_problem())
test(double_banana_problem()) #test(double_banana_problem())
test(double_banana_plus_one_problem()) #test(double_banana_plus_one_problem())
test(random_triangular_problem_3D(10,10.0,0.0,0.5)) #test(random_triangular_problem_3D(10,10.0,0.0,0.5))
test(random_distance_problem_3D(10,1.0,0.0)) #test(random_distance_problem_3D(10,1.0,0.0))
test(fix1_problem_3d()) test(fix1_problem_3d())
test(fix2_problem_3d()) test(fix2_problem_3d())
test(fix3_problem_3d()) test(fix3_problem_3d())
test(selection_problem()) #test(selection_problem())
selection_test() #selection_test()
test(overconstrained_tetra()) #test(overconstrained_tetra())
test(diamond_3d()) #test(diamond_3d())
if __name__ == "__main__": if __name__ == "__main__":
test3d() test3d()