Esempio n. 1
0
    def test_eval_grad_f(self):
        '''Gradient of the power consumption'''
        ans = optimMinPow2x2DTX.eval_grad_f(self.x0, self.noisepower, self.H, self.rate, self.linkBandwidth, self.p0, self.m, self.pS)
        answer = np.array([-314.15364962, -133.11575877, -203.26605186,    5.        ])
        np.testing.assert_array_almost_equal(ans, answer)

        ans = optimMinPow2x2DTX.eval_grad_f(self.x0, self.noisepower, self.Htrivial, self.rate, self.linkBandwidth, self.p0, self.m, self.pS)
        answer = np.array([ -6.06500000e+03,  -6.06500000e+03,  -6.06500000e+03,
         5.00000000e+00]) 
        np.testing.assert_array_almost_equal(ans, answer)

        ans = optimMinPow2x2DTX.eval_grad_f(self.x0[0:2], self.noisepower, self.H1, self.rate, self.linkBandwidth, self.p0, self.m, self.pS)
        answer = np.array([ 9.04084342,  5.        ])
        np.testing.assert_array_almost_equal(ans, answer)
Esempio n. 2
0
    def test_eval_grad_f(self):
        '''Gradient of the power consumption'''
        ans = optimMinPow2x2DTX.eval_grad_f(self.x0, self.noisepower, self.H,
                                            self.rate, self.linkBandwidth,
                                            self.p0, self.m, self.pS)
        answer = np.array([-314.15364962, -133.11575877, -203.26605186, 5.])
        np.testing.assert_array_almost_equal(ans, answer)

        ans = optimMinPow2x2DTX.eval_grad_f(self.x0, self.noisepower,
                                            self.Htrivial, self.rate,
                                            self.linkBandwidth, self.p0,
                                            self.m, self.pS)
        answer = np.array([
            -6.06500000e+03, -6.06500000e+03, -6.06500000e+03, 5.00000000e+00
        ])
        np.testing.assert_array_almost_equal(ans, answer)

        ans = optimMinPow2x2DTX.eval_grad_f(self.x0[0:2], self.noisepower,
                                            self.H1, self.rate,
                                            self.linkBandwidth, self.p0,
                                            self.m, self.pS)
        answer = np.array([9.04084342, 5.])
        np.testing.assert_array_almost_equal(ans, answer)
Esempio n. 3
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
Esempio 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