Esempio n. 1
0
    def decompose(self):
        """
            Gives an SOS decomposition of f if exists as a list of polynomials
            of at most half degree of f.
            This method also fills the 'Info' as 'minimize' does. In addition,
            returns Info['is sos'] which is Boolean depending on the status of 
            sdp solver.
        """
        n = self.NumVars
        N0 = self.NumMonomials(n, self.MainPolyHlfDeg)
        N1 = self.NumMonomials(n, self.MainPolyTotDeg)
        self.MatSize = [N0, N1]

        vec = self.MonomialsVec(self.MainPolyHlfDeg)
        m = Matrix(1, N0, vec)
        Mmnt = m.transpose() * m
        Blck = [[] for i in range(N1)]
        C = []

        h = Matrix(self.Field, N0, N0, 0)
        C.append(h)
        decomp = []

        for i in range(N1):
            p = self.Monomials[i]
            A = self.Calpha(p, Mmnt)
            Blck[i].append(A)

        from SDP import SDP
        sos_sdp = SDP.sdp(solver=self.solver, Settings={'detail': self.detail})
        sos_sdp.solve(C, self.PolyCoefFullVec(), Blck)

        if sos_sdp.Info['Status'] == 'Optimal':
            self.Info['status'] = 'Feasible'
            GramMtx = Matrix(sos_sdp.Info['X'][0])
            try:
                self.Info[
                    'Message'] = "A SOS decomposition of the polynomial were found."
                self.Info['is sos'] = True
                H1 = GramMtx.cholesky()
                tmpM = Matrix(1, N0, vec)
                decomp = list(tmpM * H1)[0]
                self.Info['Wall'] = sos_sdp.Info['Wall']
                self.Info['CPU'] = sos_sdp.Info['CPU']
            except:
                self.Info[
                    'Message'] = "The given polynomial seems to be a sum of squares, but no SOS decomposition were extracted."
                self.Info['is sos'] = False
                self.Info['Wall'] = sos_sdp.Info['Wall']
                self.Info['CPU'] = sos_sdp.Info['CPU']
        else:
            self.Info[
                'Message'] = "The given polynomial is not a sum of squares."
            self.Info['status'] = 'Infeasible'
            self.Info['is sos'] = False

        self.Info["Size"] = self.MatSize
        return decomp
Esempio n. 2
0
 def decompose(self):
     """
         Gives an SOS decomposition of f if exists as a list of polynomials
         of at most half degree of f.
         This method also fills the 'Info' as 'minimize' does. In addition,
         returns Info['is sos'] which is Boolean depending on the status of 
         sdp solver.
     """
     n = self.NumVars
     N0 = self.NumMonomials(n, self.MainPolyHlfDeg)
     N1 = self.NumMonomials(n, self.MainPolyTotDeg)
     self.MatSize = [N0, N1]
     
     vec = self.MonomialsVec(self.MainPolyHlfDeg)
     m = Matrix(1, N0, vec)
     Mmnt = m.transpose() * m
     Blck = [[] for i in range(N1)]
     C = []
     
     h = Matrix(self.Field, N0, N0, 0)
     C.append(h)
     decomp = []
     
     for i in range(N1):
         p = self.Monomials[i]
         A = self.Calpha(p, Mmnt)
         Blck[i].append(A)
     
     from SDP import SDP
     sos_sdp = SDP.sdp(solver = self.solver, Settings = {'detail':self.detail})
     sos_sdp.solve(C, self.PolyCoefFullVec(), Blck)
     
     if sos_sdp.Info['Status'] == 'Optimal':
         self.Info['status'] = 'Feasible'
         GramMtx = Matrix(sos_sdp.Info['X'][0])
         try:
             self.Info['Message'] = "A SOS decomposition of the polynomial were found."
             self.Info['is sos'] = True
             H1 = GramMtx.cholesky();
             tmpM = Matrix(1, N0, vec)
             decomp = list(tmpM*H1)[0]
             self.Info['Wall'] = sos_sdp.Info['Wall']
             self.Info['CPU'] = sos_sdp.Info['CPU']
         except:
             self.Info['Message'] = "The given polynomial seems to be a sum of squares, but no SOS decomposition were extracted."
             self.Info['is sos'] = False
             self.Info['Wall'] = sos_sdp.Info['Wall']
             self.Info['CPU'] = sos_sdp.Info['CPU']
     else:
         self.Info['Message'] = "The given polynomial is not a sum of squares."
         self.Info['status'] = 'Infeasible'
         self.Info['is sos']= False
     
     self.Info["Size"] = self.MatSize
     return decomp
Esempio n. 3
0
    def minimize(self):
        """
        Solves the semidefinite program coming from the set of input
        data and returns some information as outpu in 'Info'
        'Info' carries the following information:
			
            status':
                either 'Optimal' or 'Infeasible' based on the status of
                the solver.
            'Message':
                provides more detail on the final status of the solver
            'min':
                is the minimum computed for f over the set defined by
                g1>=0,..., gm>=0. It is None, if the solver fails.
            'Wall' & 'CPU':
                wall time and CPU time spent by the solver.
            'Size':
                a list which gives the dimention of sdp matrices
        """
        from SDP import SDP

        sos_sdp = SDP.sdp(solver=self.solver, Settings={'detail': self.detail})
        sos_sdp.solve(self.Matrice[0], self.Matrice[1], self.Matrice[2])

        if sos_sdp.Info['Status'] == 'Optimal':
            self.f_min = min(sos_sdp.Info['PObj'], sos_sdp.Info['DObj'])
            self.Info = {
                "min": self.f_min,
                "Wall": sos_sdp.Info['Wall'],
                "CPU": sos_sdp.Info['CPU']
            }
            self.Info['status'] = 'Optimal'
            self.Info[
                'Message'] = 'Feasible solution for moments of order ' + str(
                    self.Relaxation)
        else:
            self.f_min = None
            self.Info['min'] = self.f_min
            self.Info['status'] = 'Infeasible'
            self.Info[
                'Message'] = 'No feasible solution for moments of order ' + str(
                    self.Relaxation) + ' were found'

        self.Info["Size"] = self.MatSize
        return self.f_min
Esempio n. 4
0
 def fixSDP(self, msg, external, answer=False):
     sdp = reduce2audio(SDP(msg.body))
     if external:
         url1 = self.zsession.locGetAddress()
         url2 = self.zsession.locGetCtrlAddress()
     else:
         url1 = self.zsession.extGetAddress()
         url2 = self.zsession.extGetCtrlAddress()
     self.addrFromSDP[external] = fixConnection(sdp,
                                                URL(url1[0], port=url1[1]),
                                                URL(url2[0], port=url2[1]))
     setBody(msg, sdp.toString())
     if answer:
         self.zsession.setAudioInfo(self.addrFromSDP[external][2])
     if self.addrFromSDP[False] and self.addrFromSDP[True]:
         url1, url2, _ = self.addrFromSDP[False]
         self.zsession.locSetDstAddress((url1.host, url1.port))
         self.zsession.locSetDstCtrlAddress((url2.host, url2.port))
         url1, url2, _ = self.addrFromSDP[True]
         self.zsession.extSetDstAddress((url1.host, url1.port))
         self.zsession.extSetDstCtrlAddress((url2.host, url2.port))
         self.zsession.addressesReady()
Esempio n. 5
0
    def minimize(self):
        """
        Solves the semidefinite program coming from the set of input
        data and returns some information as outpu in 'Info'
        'Info' carries the following information:
			
            status':
                either 'Optimal' or 'Infeasible' based on the status of
                the solver.
            'Message':
                provides more detail on the final status of the solver
            'min':
                is the minimum computed for f over the set defined by
                g1>=0,..., gm>=0. It is None, if the solver fails.
            'Wall' & 'CPU':
                wall time and CPU time spent by the solver.
            'Size':
                a list which gives the dimention of sdp matrices
        """
        from SDP import SDP
        
        sos_sdp = SDP.sdp(solver = self.solver, Settings = {'detail':self.detail})
        sos_sdp.solve(self.Matrice[0], self.Matrice[1], self.Matrice[2])
        
        if sos_sdp.Info['Status'] == 'Optimal':
            self.f_min = min(sos_sdp.Info['PObj'], sos_sdp.Info['DObj'])
            self.Info = {"min":self.f_min, "Wall":sos_sdp.Info['Wall'], "CPU":sos_sdp.Info['CPU']}
            self.Info['status'] = 'Optimal'
            self.Info['Message'] = 'Feasible solution for moments of order ' + str(self.Relaxation)
        else:
            self.f_min = None
            self.Info['min'] = self.f_min
            self.Info['status'] = 'Infeasible'
            self.Info['Message'] = 'No feasible solution for moments of order ' + str(self.Relaxation) + ' were found'
        
        self.Info["Size"] = self.MatSize
        return self.f_min