Esempio n. 1
0
 def test_eval_jac_g(self):
     """docstring for test_eval_jac_g"""
     ans = optimMinPow2x2.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,   -2.21240678e+03, 
            0.00000000e+00,    0.00000000e+00,    0.00000000e+00,   -9.91830431e+02, 
               0.00000000e+00,    0.00000000e+00,    0.00000000e+00,   -1.47858865e+03])
     np.testing.assert_array_almost_equal(ans, answer, decimal=5)
Esempio n. 2
0
 def test_eval_jac_g_structure(self):
     ans = optimMinPow2x2.eval_jac_g(self.x0, self.noisepower, self.H,
                                     self.rate, self.linkBandwidth, 1)
     answer = (np.array([0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3,
                         3]), np.array([0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1,
                                        2]))
     np.testing.assert_equal(ans, answer)
Esempio n. 3
0
def optimizePC(channel, noiseIfPower, rate, linkBandwidth, pMax, p0, m, verbosity=0):
    ''' Uses channel values, PHY parameters and power consumption characteristics to find minimal resource allocation. 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)
        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 # for readability
    x_L = zeros((nvar), dtype=float_) * 0.0
    x_U = ones((nvar), dtype=float_) * 1.0
    ncon = nvar + 1 # transmit power constraints and the unit sum 
    g_L = zeros(1+nvar) # unit sum and all power constraints
    g_L[0] = 1.
    g_U = pMax * ones(1+nvar) # unit sum and all power constraints
    g_U[0] = 1.
    nnzj = nvar * (1+nvar)
    nnzh = 0 #used?
    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: optimMinPow2x2.eval_f(mus, noiseIfPower, channel, rate, linkBandwidth, p0, m)
        eval_grad_f = lambda mus: optimMinPow2x2.eval_grad_f(mus, noiseIfPower, channel, rate, linkBandwidth, p0, m)
        eval_g = lambda mus: optimMinPow2x2.eval_g(mus, noiseIfPower, channel, rate, linkBandwidth)
        eval_jac_g = lambda mus, flag: optimMinPow2x2.eval_jac_g(mus, noiseIfPower, channel, rate, linkBandwidth, flag)
    else:
        raise NotImplementedError # other combinations may be needed later

    # Call solve() 
    pyipopt.set_loglevel(min([2,verbosity])) # 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", "no")
    #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()

    return obj, solution, status
Esempio n. 4
0
 def test_eval_jac_g(self):
     """docstring for test_eval_jac_g"""
     ans = optimMinPow2x2.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, -2.21240678e+03,
         0.00000000e+00, 0.00000000e+00, 0.00000000e+00, -9.91830431e+02,
         0.00000000e+00, 0.00000000e+00, 0.00000000e+00, -1.47858865e+03
     ])
     np.testing.assert_array_almost_equal(ans, answer, decimal=5)
Esempio n. 5
0
 def test_eval_jac_g_structure(self):
     ans = optimMinPow2x2.eval_jac_g(self.x0, self.noisepower, self.H, self.rate, self.linkBandwidth, 1)
     answer = (np.array([0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3]), np.array([0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2]))
     np.testing.assert_equal(ans, answer)
Esempio n. 6
0
def optimizePC(channel,
               noiseIfPower,
               rate,
               linkBandwidth,
               pMax,
               p0,
               m,
               verbosity=0):
    ''' Uses channel values, PHY parameters and power consumption characteristics to find minimal resource allocation. 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)
        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  # for readability
    x_L = zeros((nvar), dtype=float_) * 0.0
    x_U = ones((nvar), dtype=float_) * 1.0
    ncon = nvar + 1  # transmit power constraints and the unit sum
    g_L = zeros(1 + nvar)  # unit sum and all power constraints
    g_L[0] = 1.
    g_U = pMax * ones(1 + nvar)  # unit sum and all power constraints
    g_U[0] = 1.
    nnzj = nvar * (1 + nvar)
    nnzh = 0  #used?
    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: optimMinPow2x2.eval_f(mus, noiseIfPower, channel,
                                                   rate, linkBandwidth, p0, m)
        eval_grad_f = lambda mus: optimMinPow2x2.eval_grad_f(
            mus, noiseIfPower, channel, rate, linkBandwidth, p0, m)
        eval_g = lambda mus: optimMinPow2x2.eval_g(mus, noiseIfPower, channel,
                                                   rate, linkBandwidth)
        eval_jac_g = lambda mus, flag: optimMinPow2x2.eval_jac_g(
            mus, noiseIfPower, channel, rate, linkBandwidth, flag)
    else:
        raise NotImplementedError  # other combinations may be needed later

    # Call solve()
    pyipopt.set_loglevel(min([2, verbosity]))  # 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", "no")
    #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()

    return obj, solution, status