Beispiel #1
0
 def __init__(self, code, gurobiParams=None, gurobiVersion=None, ml=False, name=None):
     if name is None:
         name = 'Explicit{}Decoder'.format('ML' if ml else 'LP')
     self.ml = ml
     GurobiDecoder.__init__(self, code, name, gurobiParams, gurobiVersion, integer=ml)
     self.timer = utils.Timer()
     assert code.q == 2, 'only binary codes are supported'
     from lpdec.polytopes import feldmanInequalities
     A, b = feldmanInequalities(code.parityCheckMatrix)
     for i in range(len(b)):
         self.model.addConstr(gu.LinExpr(A[i], self.xlist), gu.GRB.LESS_EQUAL, b[i])
     self.model.update()
Beispiel #2
0
 def __init__(self, code, gurobiParams=None, gurobiVersion=None, ml=False, name=None):
     if name is None:
         name = 'Explicit{}Decoder'.format('ML' if ml else 'LP')
     self.ml = ml
     GurobiDecoder.__init__(self, code, name, gurobiParams, gurobiVersion, integer=ml)
     self.timer = utils.Timer()
     assert code.q == 2, 'only binary codes are supported'
     from lpdec.polytopes import feldmanInequalities
     A, b = feldmanInequalities(code.parityCheckMatrix)
     for i in range(len(b)):
         self.model.addConstr(gu.LinExpr(A[i], self.xlist), gu.GRB.LESS_EQUAL, b[i])
     self.model.update()
Beispiel #3
0
 def __init__(self, code, gurobiParams=None, gurobiVersion=None, ml=False,
              cascade=False, name=None):
     if name is None:
         name = '{}{}Decoder'.format('Cascaded' if cascade else 'Static', 'ML' if ml else 'LP')
     self.ml = ml
     self.cascade = cascade
     GurobiDecoder.__init__(self, code, name, gurobiParams, gurobiVersion, integer=ml)
     self.timer = utils.Timer()
     self.numChiVars = 0
     self.numWvars = 0
     for j, row in enumerate(code.parityCheckMatrix):
         nonzeros = np.flatnonzero(row)
         h = row[nonzeros]
         d = h.size
         if (self.code.q**d > 1e6):
             raise ValueError('Code too dense!')
         if cascade and d > 3:
             L = list(range(1, d - 2))
             chi = {}
             for i in L:
                 for alpha in range(1, code.q):
                     chi[i, alpha] = self.model.addVar(0, 1,
                                                       name='chi^{}_{},{}'.format(j, i, alpha))
                     self.numChiVars += 1
             xvars1 = {}
             for alpha in range(1, code.q):
                 xvars1[0, alpha] = self.x[nonzeros[0], alpha]
                 xvars1[1, alpha] = self.x[nonzeros[1], alpha]
                 xvars1[2, alpha] = chi[1, alpha]
             self.createLocalCodePolytope('{}/0'.format(j), np.array([h[0], h[1], 1]), xvars1)
             for l in range(1, d - 3):
                 xvarsl = {}
                 for alpha in range(1, code.q):
                     xvarsl[0, alpha] = chi[l, alpha]
                     xvarsl[1, alpha] = self.x[nonzeros[l+1], alpha]
                     xvarsl[2, alpha] = chi[l+1, alpha]
                 self.createLocalCodePolytope('{}/{}'.format(j, l),
                                              np.array([code.q-1, h[l+1], 1]),
                                              xvarsl)
             xvarsd = {}
             for alpha in range(1, code.q):
                 xvarsd[0, alpha] = chi[d - 3, alpha]
                 xvarsd[1, alpha] = self.x[nonzeros[-2], alpha]
                 xvarsd[2, alpha] = self.x[nonzeros[-1], alpha]
             self.createLocalCodePolytope('{}/{}'.format(j, d - 3),
                                          np.array([code.q - 1, h[-2], h[-1]]),
                                          xvarsd)
         else:
             vars = {(ii, alpha): self.x[i, alpha] for ii, i in enumerate(nonzeros) for alpha
                      in range(1, code.q)}
             self.createLocalCodePolytope(j, h, vars)
     self.model.update()
Beispiel #4
0
 def __init__(self, code, gurobiParams=None, gurobiVersion=None, ml=False,
              cascade=False, name=None):
     if name is None:
         name = '{}{}Decoder'.format('Cascaded' if cascade else 'Static', 'ML' if ml else 'LP')
     self.ml = ml
     self.cascade = cascade
     GurobiDecoder.__init__(self, code, name, gurobiParams, gurobiVersion, integer=ml)
     self.timer = utils.Timer()
     self.numChiVars = 0
     self.numWvars = 0
     for j, row in enumerate(code.parityCheckMatrix):
         nonzeros = np.flatnonzero(row)
         h = row[nonzeros]
         d = h.size
         if (self.code.q**d > 1e5):
             raise ValueError('Code too dense!')
         if cascade and d > 3:
             L = list(range(1, d - 2))
             chi = {}
             for i in L:
                 for alpha in range(1, code.q):
                     chi[i, alpha] = self.model.addVar(0, 1,
                                                       name='chi^{}_{},{}'.format(j, i, alpha))
                     self.numChiVars += 1
             xvars1 = {}
             for alpha in range(1, code.q):
                 xvars1[0, alpha] = self.x[nonzeros[0], alpha]
                 xvars1[1, alpha] = self.x[nonzeros[1], alpha]
                 xvars1[2, alpha] = chi[1, alpha]
             self.createLocalCodePolytope('{}/0'.format(j), np.array([h[0], h[1], 1]), xvars1)
             for l in range(1, d - 3):
                 xvarsl = {}
                 for alpha in range(1, code.q):
                     xvarsl[0, alpha] = chi[l, alpha]
                     xvarsl[1, alpha] = self.x[nonzeros[l+1], alpha]
                     xvarsl[2, alpha] = chi[l+1, alpha]
                 self.createLocalCodePolytope('{}/{}'.format(j, l),
                                              np.array([code.q-1, h[l+1], 1]),
                                              xvarsl)
             xvarsd = {}
             for alpha in range(1, code.q):
                 xvarsd[0, alpha] = chi[d - 3, alpha]
                 xvarsd[1, alpha] = self.x[nonzeros[-2], alpha]
                 xvarsd[2, alpha] = self.x[nonzeros[-1], alpha]
             self.createLocalCodePolytope('{}/{}'.format(j, d - 3),
                                          np.array([code.q - 1, h[-2], h[-1]]),
                                          xvarsd)
         else:
             vars = {(ii, alpha): self.x[i, alpha] for ii, i in enumerate(nonzeros) for alpha
                      in range(1, code.q)}
             self.createLocalCodePolytope(j, h, vars)
     self.model.update()
Beispiel #5
0
 def params(self):
     ret = GurobiDecoder.params(self)
     ret['ml'] = self.ml
     return ret
Beispiel #6
0
 def setStats(self, stats):
     if 'lpTime' not in stats:
         stats['lpTime'] = 0.0
     if 'simplexIters' not in stats:
         stats['simplexIters'] = 0
     GurobiDecoder.setStats(self, stats)
Beispiel #7
0
 def params(self):
     ret = GurobiDecoder.params(self)
     ret['ml'] = self.ml
     return ret
Beispiel #8
0
 def setStats(self, stats):
     if 'lpTime' not in stats:
         stats['lpTime'] = 0.0
     if 'simplexIters' not in stats:
         stats['simplexIters'] = 0
     GurobiDecoder.setStats(self, stats)