コード例 #1
0
def onerun(data, loads, forecasts, errors=True):

    status = []
    times = []
    mo, c_, v_ = init_problem(data)
    for i in range(0, H - T):
        start = time.perf_counter()
        price = P[i: i + T, :]
    #    load = L[i : i + T]
        if errors:
            load = forecasts[i: i + T].copy()
            load[0] = loads[i]
        else:
            load = loads[i: i + T].copy()

        data['price'] = price
        data['load'] = load
        mo = update_problem(mo, c_, v_, data)
        _ = mo.solve()
        sol = cleanup_solution(mo, c_, v_, data)
        bat = sol['var'][SLICE] - sol['var'][2 * SLICE]
        net = sol['net'][0]
        data['history_bat'][i] = bat
        data['history_cost'][i] = sol['var'][0]
        data['history_post_net'][i] = sol['net'][0]

        data['charge'] += bat
        end = time.perf_counter() - start
        times.append(end)
            
        if i % 50 == 0:
            print('ITER', i)

    return data
コード例 #2
0
ファイル: core_loop.py プロジェクト: gus0k/lemsim_code
def init_players(players):
    P = len(players)
    L = players[0]['L']
    for i in range(P):
        data = players[i]
        mo, c_, v_ = init_problem(data)
        players[i]['model'] = mo
        players[i]['con'] = c_
        players[i]['var'] = v_
        players[i]['history_bat'] = np.zeros(L)
        players[i]['history_cost'] = np.zeros(L)
        players[i]['history_pre_net'] = np.zeros(L)
        players[i]['history_post_net'] = np.zeros(L)
コード例 #3
0
def test_simple_opt_2(opt_problem_2):

    data = opt_problem_2 
    data['T'] = 1
    data['price'] = np.array([[1, 1, 3, 3, 0, 0, 0]])
    data['load'] = np.array([-2])
    data['commitment'] = -1

    mo, c_, v_ = init_problem(data) 
    _ = mo.solve()
    res = cleanup_solution(mo, c_, v_, data)

    np.testing.assert_allclose(res['obj'], -2, atol=1e-5)
    np.testing.assert_allclose(res['var'], np.array([-2, 0, 0]), atol=1e-5)
    np.testing.assert_allclose(res['net'], np.array([-2]), atol=1e-5)
コード例 #4
0
def test_simple_opt_1(opt_problem_2):

    data = opt_problem_2 
    mo, c_, v_ = init_problem(data) 
    _ = mo.solve()
    res = cleanup_solution(mo, c_, v_, data)
    np.testing.assert_allclose(res['obj'], 21.3, atol=1e-5)
    np.testing.assert_allclose(res['var'], np.array([13.8, 7.5, 0, 0, 0, 0]), atol=1e-5)
    np.testing.assert_allclose(res['net'], np.array([2.0, 2.0]), atol=1e-5)


    data['charge'] = 0.5
    data['bmax'] = 0.5
    mo = update_problem(mo, c_, v_, data)
    _ = mo.solve()
    res = cleanup_solution(mo, c_, v_, data)
    np.testing.assert_allclose(res['obj'], 17.7, atol=1e-5)
    np.testing.assert_allclose(res['var'], np.array([10.2, 7.5, 0, 0, 0.5, 0]), atol=1e-5)
    np.testing.assert_allclose(res['net'], np.array([1.55, 2.0]), atol=1e-5)


    data['price'][1] = np.array([2, 2, 3, 3, -1, 0 , 1])
    mo = update_problem(mo, c_, v_, data)
    _ = mo.solve()
    res = cleanup_solution(mo, c_, v_, data)
    np.testing.assert_allclose(res['obj'], 16.2, atol=1e-5)
    np.testing.assert_allclose(res['var'], np.array([10.2, 6, 0, 0, 0.5, 0]), atol=1e-5)
    np.testing.assert_allclose(res['net'], np.array([1.55, 2]), atol=1e-5)

    data['commitment'] = 1.7
    mo = update_problem(mo, c_, v_, data)
    _ = mo.solve()
    res = cleanup_solution(mo, c_, v_, data)
    np.testing.assert_allclose(res['obj'], 16.95, atol=1e-4)
    np.testing.assert_allclose(res['var'], np.array([11.4, 5.55, 0, 0, 1/3, 1/6]), atol=1e-4)
    np.testing.assert_allclose(res['net'], np.array([1.7, 1.85]), atol=1e-4)


    del data['commitment']
    mo = update_problem(mo, c_, v_, data)
    _ = mo.solve()
    res = cleanup_solution(mo, c_, v_, data)
    np.testing.assert_allclose(res['obj'], 16.2, atol=1e-5)
    np.testing.assert_allclose(res['var'], np.array([10.2, 6, 0, 0, 0.5, 0]), atol=1e-5)
    np.testing.assert_allclose(res['net'], np.array([1.55, 2]), atol=1e-5)
コード例 #5
0
ファイル: benchmark.py プロジェクト: gus0k/mpcbat
def simulate():
    status = []
    times = []
    mo, c_, v_ = init_problem(D)
    for i in range(0, H - T):
        start = time.perf_counter()
        price = P[i:i + T, :]
        load = L[i:i + T]
        D['price'] = price
        D['load'] = load
        mo = update_problem(mo, c_, v_, D)
        sol = mo.solve()
        end = time.perf_counter() - start
        status.append(sol.solve_status)
        times.append(end)

        if i % 50 == 0:
            print('ITER', i)
    return status, times