Пример #1
0
    def getGeneratorForVertices(self):
        #local vertices
        yield from BellPolytope.getGeneratorForVertices(self)

        #distributions with nontrivial use of the communication channel
        communicationStrgs = [
            format(i, '0' + str(self._numberOfInputsAlice()) + 'b')
            for i in range(1, 2**(self._numberOfInputsAlice() - 1))
        ]
        strgsAlice = [[
            (stgAlice[i], int(comm[i])) for i in range(0, len(stgAlice))
        ] for stgAlice in self._strategiesGenerator(self.outputsAlice)
                      for comm in communicationStrgs]

        strgsBob = [
            stgBob for stgBob in self._strategiesGenerator(
                reduce(lambda acum, elem: acum + [elem, elem], self.outputsBob,
                       [])) if stgBob[0::2] != stgBob[1::2]
        ]

        yield from ([
            int(a == stgAlice[x][0]) & (b == stgBob[2 * y + stgAlice[x][1]])
            for x in range(self._numberOfInputsAlice())
            for y in range(self._numberOfInputsBob())
            for a in range(self.outputsAlice[x])
            for b in range(self.outputsBob[y])
        ] for stgAlice in strgsAlice for stgBob in strgsBob)
Пример #2
0
    disjointness = lambda x, y: np.intersect1d(x, y).size == 0

    probabilities = {(x, y, a, b): 1 / 2 * int(
        (a != 2 and b != 2 and
         (a + b) % 2 == disjointness(toBin(x), toBin(y))))
                     for (x, y, a, b) in scenario.getTuplesOfEvents()}
    dist = Behaviour(scenario, probabilities).getProbabilityList()

    with Model("lo1") as M:

        fullSpaceDimension = sum(
            [sum([a * b for b in outputsBob]) for a in outputsAlice])
        bellFunctional = M.variable("bellFunctional", fullSpaceDimension)

        i = 0
        for vertice in poly.getGeneratorForVertices():
            M.constraint(
                'c' + str(i),
                Expr.dot(vertice.getProbabilityList(), bellFunctional),
                Domain.lessThan(1))
            i += 1
        i = 0
        for (x, y, a, b) in scenario.getTuplesOfEvents():
            indexPointer = list(np.zeros(fullSpaceDimension))
            indexPointer[i] = 1
            if (a == outputsAlice[x] - 1) & (b == outputsBob[y] - 1):
                M.constraint('p(' + str(i) + ')',
                             Expr.dot(bellFunctional, indexPointer),
                             Domain.equalsTo(0))
            else:
                if (a == outputsAlice[x] - 1) | (b == outputsBob[y] - 1):