コード例 #1
0
 def test_one(self):
     """ Test for 1 by 1 matrix.
     """
     m = helpers.eye(1)
     v = helpers.rand(1)
     self.assertTrue(np.array_equal(m.dot(v), v))
     self.assertTrue(np.array_equal(v.dot(m), v))
コード例 #2
0
 def test_two(self):
     """ Test for 2 by 2 matrix.
     """
     m = helpers.eye(2)
     v = helpers.rand(2, 2)
     self.assertTrue(np.array_equal(m.dot(v), v))
     self.assertTrue(np.array_equal(v.dot(m), v))
コード例 #3
0
ファイル: box.py プロジェクト: discardthree/PyQPECgen
    def export_QPCC_data(self):
        P, info, param = self.return_problem()
        n = param['n']
        m = param['m']
        md = info['md']
        ms = info['ms']
        l = param['l']

        varsused = [1] * (n + m) + [0] * (m + md)
        names = create_name("x", n) + create_name("y", m) + \
            create_name("lamL", md) + create_name("lamL", ms, start=md) + \
            create_name("lamU", md)

        objQ = matrix([
            [matrix(0.5 * P['P']), matrix(zeros(m + md, m + n))],
            [matrix(zeros(m + n, m + md)), matrix(zeros(m + md, m + md))]])
        objp = conmat([P['c'], P['d'], zeros(m + md)])

        objr = 0

        G1 = conmat([P['A'], zeros(l, m + md)], option='h')
        h1 = -P['a']

        G2 = conmat([zeros(md, n), -eye(md), zeros(md, 2 * m)], option='h')
        h2 = zeros(md)

        G3 = conmat([zeros(md, n), eye(md), zeros(md, 2 * m)], option='h')
        h3 = P['u']

        G4 = conmat([zeros(ms, n + md), -eye(ms),
                     zeros(ms, m + md)], option='h')
        h4 = zeros(ms)

        G5 = conmat([zeros(m, n + m), -eye(m), zeros(m, md)], option='h')
        h5 = zeros(m)

        G6 = conmat([zeros(md, n + 2 * m), -eye(md)], option='h')
        h6 = zeros(md)

        if isinstance(self, Qpecgen201):
            G7 = conmat([-eye(n), zeros(n, 2 * m + md)], option='h')
            h7 = -self.info['xl']

            G8 = conmat([eye(n), zeros(n, 2 * m + md)], option='h')
            h8 = self.info['xu']

        A1 = conmat(
            [P['N'][:md], P['M'][:md], -eye(md), zeros(md, ms), eye(md)], option='h')
        b1 = -P['q'][:md]

        A2 = conmat(
            [P['N'][md:], P['M'][md:], zeros(ms, md), -eye(ms), zeros(ms, md)],
            option='h')
        b2 = -P['q'][md:]

        details = {
            'varsused': varsused,
            'geninfo': info,
            'genparam': param,
            'gensol': self.make_QPCC_sol()}

        return locals()