# Optimal Energy Charging/discharging Scheduling Problem

I'm new to IBM CP optimizer.

I want to make charging / discharging scheduling based on cost (value will change on time) and my objective function is

$$\sum_{t=1}^{24}\sum_{j=1}^5x(1)^{(t,j)}x(2)^{(t,j)}\cdot\text{Price}_1^{(t)}-x(3)^{(t,j)}x(4)^{(t,j)}\cdot\text{Price}_2^{(t)}$$ where

1. $$t$$, $$j$$ means time (1 day) and machine number.
2. $$x(1)$$ and $$x(3)$$ means signal about charging or discharging (perhaps I can remove $$x(3)$$ and re-write $$(1-x(1)$$).
3. $$x(2)$$ and $$x(4)$$ means Power.
4. I have a few constraints about the machine's maximum and minimum battery capacity.

Then, how can I make codes of the objective function and interval? it is possible to make scheduling? I tried several days with the CP manual and IBM website, but it's still not working well.

(I will not use any API such as python, C++. I want to make in CP. )

• Welcome to OR StackExchange! Please consider taking the time to type the math instead of using a picture, as it makes the post more searchable. – Nikos Kazazakis Feb 6 '20 at 18:19
• Would you see IBM CPLEX forum? – A.Omidi Feb 7 '20 at 22:03

I assume that you want to model your problem in OPL. Here is a sketch of the model.

using CP;

range Hours = 1..24;
range Machines = 1..5;

// Data are just random:
int price1[Hours] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24];
int price2[Hours] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24];

// The ranges are also random:
dvar int x1[Hours][Machines] in 0..1000;
dvar int x2[Hours][Machines] in 0..1000;
dvar int x3[Hours][Machines] in 0..1000;
dvar int x4[Hours][Machines] in 0..1000;

minimize sum(t in Hours, j in Machines) (x1[t][j] * x2[t][j] * price1[t] - x3[t][j] * x4[t][j]*price2[t]);

subject to {