Exemplo n.º 1
0
 def addConstraints(self, Solver):
     if self.label in ConjLabelEval:
         parameters = [p for pair in self.pairs for p in pair]
         for pair in self.pairs:
             func = self.pair_func(pair, self.op_conj)
             Solver.add(
                 CPS.FunctionConstraint(Basics.FuncWrapper(func, pair)),
                 pair)
     if self.label in DisjLabelEval:
         parameters = [p for pair in self.pairs for p in pair]
         Solver.add(
             CPS.FunctionConstraint(
                 Basics.FuncWrapper(self.DisjEval, parameters)), parameters)
Exemplo n.º 2
0
    def initialize(self, Model):
        self.regulator = self.regulator.initialize(Model)
        self.target = self.target.initialize(Model)

        accepted = False
        for comp, thrs in self.regulator.targets:
            if comp == self.target:
                if self.thr in thrs:
                    accepted = True
                    break

        if not accepted:
            raise Exception(
                'Non-existing threshold %i for interaction %s->%s' %
                (self.thr, self.regulator, self.target))

        ParsLHS = [
            p for p in self.target.parameters
            if self.thr in p.context[self.regulator]
        ]
        ParsRHS = [
            p for p in self.target.parameters
            if self.thr - 1 in p.context[self.regulator]
        ]

        if self.formula:
            self.formula.initialize(Model)

            prob = CPS.Problem()
            pairs = []
            for p1, p2 in zip(ParsLHS, ParsRHS):

                for comp in Model.components:
                    domain = list(p1.context.get(comp, range(comp.max + 1)))
                    prob.addVariable(comp.index, domain)

                prob.addConstraint(
                    CPS.FunctionConstraint(
                        Basics.FuncWrapper(self.formula, Model.components)),
                    Model.components)

                if prob.getSolution():
                    pairs.append((p1, p2))

                prob.reset()
            self.pairs = pairs
        else:
            self.pairs = zip(ParsLHS, ParsRHS)

        self.requirements = []
        if self.label in ConjLabelEval:
            self.op_conj = ConjLabelEval[self.label]
            self.requirements.append(self.ConjEval)
        if self.label in DisjLabelEval:
            self.op_disj = DisjLabelEval[self.label]
            self.requirements.append(self.DisjEval)
Exemplo n.º 3
0
    def initialize(self, Model):
        self.formula.initialize(Model)
        self.comp = self.comp.initialize(Model)

        prob = CPS.Problem()
        self.ones = []
        self.zeros = []
        for p in self.comp.parameters:

            for comp in Model.components:
                domain = list(p.context.get(comp, range(comp.max + 1)))
                prob.addVariable(comp, domain)
            prob.addConstraint(
                CPS.FunctionConstraint(
                    Basics.FuncWrapper(self.formula, Model.components)),
                Model.components)

            if prob.getSolution():
                self.ones.append(p)
            else:
                self.zeros.append(p)
            prob.reset()
Exemplo n.º 4
0
    def initialize(self, Model):
        for f in self.formulas:
            f.initialize(Model)
        self.comp = self.comp.initialize(Model)

        prob = CPS.Problem()
        classes = {}
        for p in self.comp.parameters:

            Id = []
            for func in self.formulas:
                for comp in Model.components:
                    domain = list(p.context.get(comp, range(comp.max + 1)))
                    prob.addVariable(comp, domain)
                prob.addConstraint(
                    CPS.FunctionConstraint(
                        Basics.FuncWrapper(func, Model.components)),
                    Model.components)

                if prob.getSolution():
                    Id.append(True)
                else:
                    Id.append(False)
                prob.reset()

            Id = tuple(Id)
            if Id in classes:
                classes[Id].append(p)
            else:
                classes[Id] = [p]

        self.classes = [tuple(c) for c in classes.values() if len(c) > 1]
        if not self.classes:
            raise Exception("'%s' defines only empty classes, please remove." %
                            self.s)
        self.parameters = set([p for c in classes.values() for p in c])
Exemplo n.º 5
0
 def addConstraints(self, Solver):
     if self.parameters:
         Solver.add(
             CPS.FunctionConstraint(
                 Basics.FuncWrapper(self.__call__, self.parameters)),
             self.parameters)