Ejemplo n.º 1
0
    def _instantiate(self, component, count=1):
        for index in range(count):
            instance_name = component.name.lower() + "_%d" % index
            z3_instance = DefineObject(instance_name,
                                       self.find("CInstance"),
                                       suspended=True)
            self.define(instance_name, z3_instance)
            z3_instance.force_value("definition", self.find(component.name))

            # define partners
            partners = []
            for each_required_service in component.required_services:
                partner_name = self.qualified_name(instance_name,
                                                   each_required_service.name)

                z3_partner = DefineObject(partner_name,
                                          self.find("Partner"),
                                          suspended=True)
                self.define(partner_name, z3_partner)
                partners.append(z3_partner)

                z3_partner.force_value("service",
                                       self.find(each_required_service.name))

            z3_instance.force_value("partners", partners)

            values = []
            for each_variable in component.variables:
                qualified_variable_name = "%s_%s" % (component.name,
                                                     each_variable.name)
                value_name = "%s_%s" % (instance_name, each_variable.name)
                z3_value = DefineObject(value_name,
                                        self.find("Value"),
                                        suspended=True)
                self.define(value_name, z3_value)

                if each_variable.domain:
                    if each_variable.value_type != "Integer":
                        self._value_constraints.append(
                            "And([%s.value >= 0, %s.value < %d])" %
                            (value_name, value_name, len(
                                each_variable.domain)))
                    else:
                        clauses = ",".join("%s.value == %d" % (value_name, v)
                                           for v in each_variable.domain)
                        self._value_constraints.append("Or([" + clauses + "])")

                z3_value.force_value("variable",
                                     self.find(qualified_variable_name))

                values.append(z3_value)
            z3_instance.force_value("configuration", values)
Ejemplo n.º 2
0
    def _define_all_variables(self, component):
        for each_variable in component.variables:
            qualified_name = self.qualified_name(component.name,
                                                 each_variable.name)

            z3_variable = DefineObject(qualified_name, self.find("Variable"))
            self.define(qualified_name, z3_variable)
Ejemplo n.º 3
0
    def _define_all_components(self, model):
        for each_component in model.components:
            z3_component = DefineObject(each_component.name,
                                        self.find("Component"))
            self.define(each_component.name, z3_component)

            self._define_all_variables(each_component)

            provide_services = [self.find(each.name) \
                                for each in each_component.provided_services]
            z3_component.force_value("provide_services", provide_services)

            require_services = [self.find(each.name) \
                                for each in each_component.required_services]
            z3_component.force_value("require_services", require_services)

            provide_features = [self.find(each.name) \
                                for each in each_component.provided_features]
            z3_component.force_value("provide_features", provide_features)

            require_features = [self.find(each.name) \
                                for each in each_component.required_features]
            z3_component.force_value("require_features", require_features)

            settings = [self.find(self.qualified_name(each_component.name,
                                                      each.name)) \
                        for each in each_component.variables]
            z3_component.force_value("settings", settings)

            self._instantiate(each_component, 1)
Ejemplo n.º 4
0
 def _define_all_features(self, model):
     for each_feature in model.features:
         z3_feature = DefineObject(each_feature.name, self.find("Feature"))
         self.define(each_feature.name, z3_feature)
Ejemplo n.º 5
0
 def _define_all_services(self, model):
     for each_service in model.services:
         z3_service = DefineObject(each_service.name,
                                   self.find("Service"),
                                   suspended=True)
         self.define(each_service.name, z3_service)