P_grid = cvx.Variable(24)r_t = cvx.Variable(1,T+1)
d_t = cvx.Variable(1,T+1)
P_grid = cvx.Variable(1,T+1)
E_t = cvx.Variable(1,T+1)
grid_list = np.zeros(25)
avg = np.eye(25)for i in range(T):
gridsave = (grid_list[-1])
grid_list = grid_list.tolist()
grid_list.remove(grid_list[0])
grid_list.append(gridsave)
if t == 0:
avg_grid = 0
else:
avg_grid = (1/t)*sum(grid_list)
obj = cvx.Minimize(cvx.sum_squares(P_grid[:,t+1] - avg_grid))
constraints = [E_t[:,t+1] >= (1 - DOD) * E_cap,
E_t[:,t+1] <= E_cap,
r_t[:,t+1] <= P_cap,
r_t[:,t+1] >= 0,
d_t[:,t+1] <= P_cap,
d_t[:,t+1] >= 0,
P_grid[:,t+1] == P_load[t] + r_t[:,t+1] - d_t[:,t+1] - P_wind[t],
E_t[:,t+1] == E_t[:,t] + r_t[:,t+1] - d_t[:,t+1],
E_t[:,0] == 0,
d_t[:,0] == 0,
r_t[:,0] == 0,
P_grid[:,0] == 0]
prob = cvx.Problem(obj, constraints)
prob.solve(solver=cvx.CVXOPT)
grid_list.append(P_grid[:,t+1].value)54 states.append(cvx.Problem(cvx.Minimize(obj), constraints)) ---> 55 prob = sum(states) 56 prob.constraints += [E_t[:,0] == 0, d_t[:,0] == 0, r_t[:,0] == 0, P_grid[:,0] == 0]
57 prob.solve(solver=cvx.CVXOPT, verbose=True) TypeError: unsupported operand type(s) for +: 'int' and 'Problem'
56 prob = sum(states)
57 prob.constraints += [E_t[:,0] == 0, d_t[:,0] == 0, r_t[:,0] == 0, P_grid[:,0] == 0]
58 prob.solve(solver=cvx.CVXOPT, verbose=True)
TypeError: unsupported operand type(s) for +: 'int' and 'Problem' According to the 'Problem Arithmetic' in the Advanced Section of the cvxpy.org website (and the notebook) summing should work however I am unable to add all problems objects and optimize. I tried printing the states list and it gave me the following output, which seems incorrect.
[Problem(Minimize(square(var6009[0:, 1]) + -303.060478524), [50.0 <= var6010[0:, 1], var6010[0:, 1] <= 500, var6007[0:, 1] <= 2000, 0 <= var6007[0:, 1], var6008[0:, 1] <= 2000, 0 <= var6008[0:, 1], var6009[0:, 1] == 189.1872146 + var6007[0:, 1] + -var6008[0:, 1] + -122.6652946, var6010[0:, 1] == var6010[0:, 0] + var6007[0:, 1] + -var6008[0:, 1]]), Problem(Minimize(square(var6009[0:, 1]) + -91845.653643), [50.0 <= var6010[0:, 1], var6010[0:, 1] <= 500, var6007[0:, 1] <= 2000, 0 <= var6007[0:, 1], var6008[0:, 1] <= 2000, 0 <= var6008[0:, 1], var6009[0:, 1] == 189.1872146 + var6007[0:, 1] + -var6008[0:, 1] + -122.6652946, var6010[0:, 1] == var6010[0:, 0] + var6007[0:, 1] + -var6008[0:, 1]]), ....................... #so on and so forth
Where am I messing up?
My cvxpy version says:Metadata-Version: 1.0By optimizing at each step, I meant that each entry for each the constants (P_wind, P_Load) is only available for a step ahead in the horizon, something like real-time. So I wouldn't have all the entires for the corresponding variable for the day. Therefore I tried to model for each entry in P_wind = Variable(25) (each time-step) AND then store the resultant decision variable entries from the optimization, in that single variable like an array. But I figured that wouldn't work (naive me) so I switched to doing it differently as shown above.
Version: 0.3.5
Now it doesn't converge with the solvers.
2) The second doubt in the previous comment I had is regarding the control example in the notebook link from the examples in cvxpy repository.56 prob = sum(states)
57 prob.constraints += [E_t[:,0] == 0, d_t[:,0] == 0, r_t[:,0] == 0, P_grid[:,0] == 0]
58 prob.solve(solver=cvx.CVXOPT, verbose=True)TypeError: unsupported operand type(s) for +: 'int' and 'Problem'According to the 'Problem Arithmetic' in the Advanced Section of the cvxpy.org website (and the notebook) summing should work however I am unable to add all problems objects and optimize. I tried printing the states list and it gave me the following output, which seems incorrect.Where am I messing up?[Problem(Minimize(square(var6009[0:, 1]) + -303.060478524), [50.0 <= var6010[0:, 1], var6010[0:, 1] <= 500, var6007[0:, 1] <= 2000, 0 <= var6007[0:, 1], var6008[0:, 1] <= 2000, 0 <= var6008[0:, 1], var6009[0:, 1] == 189.1872146 + var6007[0:, 1] + -var6008[0:, 1] + -122.6652946, var6010[0:, 1] == var6010[0:, 0] + var6007[0:, 1] + -var6008[0:, 1]]), Problem(Minimize(square(var6009[0:, 1]) + -91845.653643), [50.0 <= var6010[0:, 1], var6010[0:, 1] <= 500, var6007[0:, 1] <= 2000, 0 <= var6007[0:, 1], var6008[0:, 1] <= 2000, 0 <= var6008[0:, 1], var6009[0:, 1] == 189.1872146 + var6007[0:, 1] + -var6008[0:, 1] + -122.6652946, var6010[0:, 1] == var6010[0:, 0] + var6007[0:, 1] + -var6008[0:, 1]]), ....................... #so on and so forth
11 states.append( Problem(Minimize(cost), constr) )
12 # sums problem objectives and concatenates constraints.
---> 13 prob = sum(states)
14 prob.constraints += [x[:,T] == 0, x[:,0] == x_0]
15 prob.solve()
TypeError: unsupported operand type(s) for +: 'int' and 'Problem'
Stupid question but you tried to compile this with the latest updates on CVXPY? Otherwise I think there might be a problem with the cvxpy on my PC since I don't seem to have enough solvers either as stated earlier and the solvers_installed() function isn't recognized either. But all my packages are updated (according to pip/conda).