Exemplo n.º 1
0
    def test_eval_jac_g(self):
        '''Gradient of the constraints'''
        ans = optimMinPow2x2DTX.eval_jac_g(self.x0, self.noisepower, self.H, self.rate, self.linkBandwidth, 0)
        answer = np.array([  1.00000000e+00,    1.00000000e+00,    1.00000000e+00,   1.00000000e+00,  -2.21240678e+03, 
               0.00000000e+00,    0.00000000e+00,    0.00000000e+00, 0.00000000e+00,   -9.91830431e+02, 
                  0.00000000e+00,    0.00000000e+00,   0.00000000e+00,  0.00000000e+00,   -1.47858865e+03, 0.00000000e+00])
        np.testing.assert_array_almost_equal(ans, answer, decimal=5)

        ans = optimMinPow2x2DTX.eval_jac_g(self.x0, self.noisepower, self.Htrivial, self.rate, self.linkBandwidth, 0)
        answer = np.array([  1.00000000e+00,   1.00000000e+00,   1.00000000e+00,
         1.00000000e+00,  -3.54891356e+04,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
        -3.54891356e+04,   0.00000000e+00,   0.00000000e+00,
         0.00000000e+00,   0.00000000e+00,  -3.54891356e+04,
         0.00000000e+00]) 
        np.testing.assert_array_almost_equal(ans, answer, decimal=3)
Exemplo n.º 2
0
    def test_eval_jac_g(self):
        '''Gradient of the constraints'''
        ans = optimMinPow2x2DTX.eval_jac_g(self.x0, self.noisepower, self.H,
                                           self.rate, self.linkBandwidth, 0)
        answer = np.array([
            1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00,
            -2.21240678e+03, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
            0.00000000e+00, -9.91830431e+02, 0.00000000e+00, 0.00000000e+00,
            0.00000000e+00, 0.00000000e+00, -1.47858865e+03, 0.00000000e+00
        ])
        np.testing.assert_array_almost_equal(ans, answer, decimal=5)

        ans = optimMinPow2x2DTX.eval_jac_g(self.x0, self.noisepower,
                                           self.Htrivial, self.rate,
                                           self.linkBandwidth, 0)
        answer = np.array([
            1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00,
            -3.54891356e+04, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00,
            0.00000000e+00, -3.54891356e+04, 0.00000000e+00, 0.00000000e+00,
            0.00000000e+00, 0.00000000e+00, -3.54891356e+04, 0.00000000e+00
        ])
        np.testing.assert_array_almost_equal(ans, answer, decimal=3)
Exemplo n.º 3
0
 def test_eval_jac_g_structure(self):
     ans = optimMinPow2x2DTX.eval_jac_g(self.x0, self.noisepower, self.H,
                                        self.rate, self.linkBandwidth, 1)
     answer = (np.array([0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]),
               np.array([0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]))
     np.testing.assert_equal(ans, answer)
Exemplo n.º 4
0
def optimizePCDTX(channel, noiseIfPower, rate, linkBandwidth, pMax, p0, m, pS, verbosity=0):
    ''' Uses channel values, PHY parameters and power consumption characteristics to find minimal resource allocation under power control with DTX. Returns resource allocation, objective value and IPOPT status. 
    Input:
        channel - 3d array. 0d users, 1d n_tx, 2d n_rx
        noiseIfPower - total noise power over the linkbandwidth
        rate - target rate in bps
        pMax - maximum allowed transmission power
        p0 - power consumption at zero transmission (not sleep)
        pS - power consumption during sleep mode
        m - power consumption load factor
        verbosity - IPOPT verbosity level
    Output:
        obj - solution objective value
        solution - resource share per user
        status - IPOPT status '''

    # the channel dimensions tell some more parameters
    users = channel.shape[0]
    n_tx  = channel.shape[1]
    n_rx  = channel.shape[2]

    # preparing IPOPT parameters
    nvar  = users + 1 # sleep mode is integrated as the last parameter 
    x_L = zeros((nvar), dtype=float_) * 0.0
    x_U = ones((nvar), dtype=float_) * 1.0
    ncon = users + 1 # transmit power constraints and the unit sum 
    g_L = zeros(ncon) # unit sum and all power constraints
    g_L[0] = 1.
    g_U = pMax * ones(ncon) # unit sum and all power constraints
    g_U[0] = 1.
    nnzj = ncon * ncon
    nnzh = 0 # tell that there is no hessian (Hessian approximation)
    x0 = repeat([1./(nvar + 1)], nvar) # Starting point

    # IPOPT requires single parameter functions
    if n_tx is 2 and n_rx is 2:
        eval_f = lambda mus: optimMinPow2x2DTX.eval_f(mus, noiseIfPower, channel, rate, linkBandwidth, p0, m, pS)
        eval_grad_f = lambda mus: optimMinPow2x2DTX.eval_grad_f(mus, noiseIfPower, channel, rate, linkBandwidth, p0, m, pS)
        eval_g = lambda mus: optimMinPow2x2DTX.eval_g(mus, noiseIfPower, channel, rate, linkBandwidth)
        eval_jac_g = lambda mus, flag: optimMinPow2x2DTX.eval_jac_g(mus, noiseIfPower, channel, rate, linkBandwidth, flag)
    else:
        raise NotImplementedError # other combinations may be needed later

    pyipopt.set_loglevel(min([verbosity, 2])) # verbose
    nlp = pyipopt.create(nvar, x_L, x_U, ncon, g_L, g_U, nnzj, nnzh, eval_f, eval_grad_f, eval_g, eval_jac_g)
    #nlp.int_option("max_iter", 3000)
    #nlp.num_option("tol", 1e-8)
    #nlp.num_option("acceptable_tol", 1e-2)
    #nlp.int_option("acceptable_iter", 0)
    nlp.str_option("derivative_test", "first-order")
    nlp.str_option("derivative_test_print_all", "yes")
    #nlp.str_option("print_options_documentation", "yes")
    nlp.int_option("print_level", min([verbosity, 12])) # maximum is 12
    nlp.str_option("print_user_options", "yes")
    
    solution, zl, zu, obj, status = nlp.solve(x0)
    nlp.close()

    if sum(solution) > 1.0001 or status is not 0:
        print 'Sum of solution:', sum(solution)
        print 'Status:', status
        raise ValueError('Invalid solution')

    return obj, solution, status
Exemplo n.º 5
0
 def test_eval_jac_g_structure(self):
     ans = optimMinPow2x2DTX.eval_jac_g(self.x0, self.noisepower, self.H, self.rate, self.linkBandwidth, 1)
     answer = (np.array([0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3]), np.array([0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]))
     np.testing.assert_equal(ans, answer)
Exemplo n.º 6
0
def optimizePCDTX(channel,
                  noiseIfPower,
                  rate,
                  linkBandwidth,
                  pMax,
                  p0,
                  m,
                  pS,
                  verbosity=0):
    ''' Uses channel values, PHY parameters and power consumption characteristics to find minimal resource allocation under power control with DTX. Returns resource allocation, objective value and IPOPT status. 
    Input:
        channel - 3d array. 0d users, 1d n_tx, 2d n_rx
        noiseIfPower - total noise power over the linkbandwidth
        rate - target rate in bps
        pMax - maximum allowed transmission power
        p0 - power consumption at zero transmission (not sleep)
        pS - power consumption during sleep mode
        m - power consumption load factor
        verbosity - IPOPT verbosity level
    Output:
        obj - solution objective value
        solution - resource share per user
        status - IPOPT status '''

    # the channel dimensions tell some more parameters
    users = channel.shape[0]
    n_tx = channel.shape[1]
    n_rx = channel.shape[2]

    # preparing IPOPT parameters
    nvar = users + 1  # sleep mode is integrated as the last parameter
    x_L = zeros((nvar), dtype=float_) * 0.0
    x_U = ones((nvar), dtype=float_) * 1.0
    ncon = users + 1  # transmit power constraints and the unit sum
    g_L = zeros(ncon)  # unit sum and all power constraints
    g_L[0] = 1.
    g_U = pMax * ones(ncon)  # unit sum and all power constraints
    g_U[0] = 1.
    nnzj = ncon * ncon
    nnzh = 0  # tell that there is no hessian (Hessian approximation)
    x0 = repeat([1. / (nvar + 1)], nvar)  # Starting point

    # IPOPT requires single parameter functions
    if n_tx is 2 and n_rx is 2:
        eval_f = lambda mus: optimMinPow2x2DTX.eval_f(
            mus, noiseIfPower, channel, rate, linkBandwidth, p0, m, pS)
        eval_grad_f = lambda mus: optimMinPow2x2DTX.eval_grad_f(
            mus, noiseIfPower, channel, rate, linkBandwidth, p0, m, pS)
        eval_g = lambda mus: optimMinPow2x2DTX.eval_g(
            mus, noiseIfPower, channel, rate, linkBandwidth)
        eval_jac_g = lambda mus, flag: optimMinPow2x2DTX.eval_jac_g(
            mus, noiseIfPower, channel, rate, linkBandwidth, flag)
    else:
        raise NotImplementedError  # other combinations may be needed later

    pyipopt.set_loglevel(min([verbosity, 2]))  # verbose
    nlp = pyipopt.create(nvar, x_L, x_U, ncon, g_L, g_U, nnzj, nnzh, eval_f,
                         eval_grad_f, eval_g, eval_jac_g)
    #nlp.int_option("max_iter", 3000)
    #nlp.num_option("tol", 1e-8)
    #nlp.num_option("acceptable_tol", 1e-2)
    #nlp.int_option("acceptable_iter", 0)
    nlp.str_option("derivative_test", "first-order")
    nlp.str_option("derivative_test_print_all", "yes")
    #nlp.str_option("print_options_documentation", "yes")
    nlp.int_option("print_level", min([verbosity, 12]))  # maximum is 12
    nlp.str_option("print_user_options", "yes")

    solution, zl, zu, obj, status = nlp.solve(x0)
    nlp.close()

    if sum(solution) > 1.0001 or status is not 0:
        print 'Sum of solution:', sum(solution)
        print 'Status:', status
        raise ValueError('Invalid solution')

    return obj, solution, status