Beispiel #1
0
 def __init__(self, dimension):
     """Create a new empty solver"""
     Notifier.__init__(self)
     self.dimension = dimension
     self._graph = Graph()
     self._graph.add_vertex("_root")
     self._graph.add_vertex("_toplevel")
     self._graph.add_vertex("_variables")
     self._graph.add_vertex("_distances")
     self._graph.add_vertex("_angles")
     self._graph.add_vertex("_rigids")
     self._graph.add_vertex("_hedgehogs")
     self._graph.add_vertex("_balloons")
     self._graph.add_vertex("_methods")
     # queue of new objects to process
     self._new = []
     # methodgraph
     self._mg = MethodGraph()
Beispiel #2
0
def test():
    graph = MethodGraph()
    graph.add_variable('a', 1)
    graph.add_variable('b', 2)
    mv_x = MultiVariable('x')
    graph.add_variable(mv_x)
    graph.add_method(SumProdMethod('a', 'b', mv_x))

    graph.add_variable('p', 3)
    graph.add_variable('q', 4)
    mv_y = MultiVariable('y')
    graph.add_variable(mv_y)
    graph.add_method(SumProdMethod('p', 'q', mv_y))

    mv_z = MultiVariable('z')
    graph.add_variable(mv_z)
    graph.add_method(SumProdMethod(mv_x, mv_y, mv_z))

    print graph.get(mv_z)

    graph.set('a', 100)
    print graph.get(mv_z)
Beispiel #3
0
 def __init__(self, methodclasses):
     """Create a new solver, using the given subclasses of ClusterMethod."""
     # init superclasses
     Notifier.__init__(self)
     # store arguments
     self._methodclasses = methodclasses
     self._pattern_methods = filter(lambda m: hasattr(m, "patterngraph"),
                                    self._methodclasses)
     self._handcoded_methods = filter(
         lambda m: hasattr(m, "handcoded_match"), self._methodclasses)
     self._incremental_methods = filter(
         lambda m: hasattr(m, "incremental_matcher"), self._methodclasses)
     # init instance vars
     self._graph = Graph()
     #self._graph.add_vertex("_root")
     # self._graph.add_vertex("_toplevel")
     self._graph.add_vertex("_variables")
     self._graph.add_vertex("_clusters")
     self._graph.add_vertex("_methods")
     self._new = []
     self._mg = MethodGraph()
     # add prototype_selection boolean var to method graph
     self._prototype_selection_var = "_prototype_selection_enabled"
     self._mg.add_variable(self._prototype_selection_var)
     self._mg.set(self._prototype_selection_var, True)
     # store map of selection_constraints to SelectionMethod (or None)
     self._selection_method = {}
     # store root cluster (will be assigned when first cluster added)
     self._rootcluster = None
     # an incrementally updated toplevel set
     self._toplevel = MutableSet()
     # incrementally updated set of applicable methods
     self._incremental_matchers = map(
         lambda method: method.incremental_matcher(self),
         self._incremental_methods)
     #print "incremental matchers:",self._incremental_matchers
     self._applicable_methods = Union(*self._incremental_matchers)