Shaokang's Blog

A simple limitation is too less sometime. If we are using the fixed threshold, then we could simply let threshold to be the time that consumption is equal to usage. And we are not able to handle the battery capacity as well. This might not meet the real case. In the real case, equipment will use large amount of energy when they start. So the model should be able to predict. Thought wind does change everyday, but it is still some kind of predictable. So, we could train a model from the history data and then predict the wind speed in the future, like one year. We could use TensorFlow.js for training. Then Solve an optimization problem to see what would be the best time to start the engine and what would be the best time to stop the engine. Or solving an optimization problem to find the threshold to turn on or off the equipment would also better than a simple one.

Normal Count Model

Define variables

n : number of days

c : the normal energy consumption per unit time

S = {0,1}n^n, the status code to identify if we need to turn on the machine in this day/unit time.

C = {0,1,2}n^n, the counter to count and analyze the normal energy consumption per day/unit time. 2 stand for the unit time that this machine needs to be turned on(as more energy needs to be consumed in the turning on process). 1 identify as daily normal consumption. 0 identify this machine is turned off.

W = Rn\mathbf{R}^n, the energy produced per day/unit time

Optimization Model

\begin{equation} \begin{split} &\text{Maximize } & \sum_{i\in n}W_iS_i-c\sum_{i\in n}C_iS_i\\ &\text{Subject to } & C_i=S_i-S_{i-1}+1 \ \forall i\in \{2,\cdots,n\}\\ & & 0 \le C_i \le 2 \ \forall i\in \{1,\cdots,n\}\\ & & 0 \le S_i \le 1 \ \forall i\in \{1,\cdots,n\}\\ \end{split} \end{equation}

Use MIP to solve it

Sample data

Sample data should be in csv format, each column contains different information. Only wind data is represented in the section below

u is the x component of wind, v is the y component of the wind. Final wind speed is calculated by using ws=u2+v2ws = \sqrt{u^2+v^2}

1
2
3
4
Time,u,v
0.2,12,15
0.3,16,12
0.5,12,16

If we need to make this simpler or we are not able to collect related data for each type of energy, we could also use data in the below format:

1
2
3
4
Time,var
0.2,12
0.3,16
0.5,12

var is the input energy or data used to calculate. Like we are able to calculate the final energy based on this result in some way, e.g. wind speed.

Possible GAMS code

Interpret to Js

Analyze

Pros

  • Considered the immediate on will consume much more energy.
  • model could be extended to handle all power source in this single model

Cons

  • wind is not possible to be predicted, so turning on and off has less significance as the situation in the next year might be different.

Expected Count Model

Because the wind is hard to predict, especially in some unstable situation. And battery could only store a limited amount of energy. Using statistic data might be a better way to calculate. We could calculate the expectation of total energy and find a threshold for each type of energy to measure maximize possible energy production instead of in a specific day.

In this setting, we only need to run the optimization for one turn and could overcome a lot of unnecessary production.

Sample data before analyze

IndexVal(W)Possibility(%)Day countExpectation
065.2825.216/130.4
132.8411.312/32.8
223.3410.932/23.3

This data needs to be purified ahead of time, for those cases that produced energy is less than equipment consumption, we could simply set its total to 0.

Define variables

J : type of energy, JJ\in {wind, water, \cdots }

N : value index, 1, 2, \cdots.

C = RJ\mathbf{R}^J: the normal energy consumption per unit time for each producer (Need to consider as a combination of multiple equipments, like: if we have two wind machine(user is able to define this in control), each machine will consume 10 W. Then CwindC_{wind}=10*2=20)

U = R\mathbf{R}: Total user consumption

W = RJ,N\mathbf{R}^{J,N}, the expected energy(total in above table) produced in each value index, either pre-calculated or calculate in model.

S = {0,1}J,N^{J,N}, to indicate I should turn on wind on this statistic data or not

B R\in \mathbf{R} : The battery charging limitation.

Optimization Model

\begin{equation}\begin{split}&\text{Maximize } & \sum_{i\in N}\sum_{j\in J}W_{ij}S_{ij}-\sum_{i\in N}\sum_{j\in J}C_{j}S_{ij}\\& \text{Subject to}\ & 0 \le S_{ij} \le 1 \ \forall i\in N j\in J\\& & \sum_{i\in N}\sum_{j\in J}W_{ij}S_{ij}-\sum_{i\in N}\sum_{j\in J}C_{j}S_{ij}-U\le B\end{split}\end{equation}

Use MIP to solve it

Sample data

Sample data should be in csv format, each column contains different information. Data defined in teh previous section is acceptable but not efficient. Only wind data is represented in the section below.

If data input is in a range, then we are going to use median of each group. Like this:

1
2
3
4
eType,Range (mph), Total
1, 1.3 - 4,3.3
1, 4 - 8,23.5
1, 8 - 13,46.4

Or the specific data and occurrence count in csv file:

1
2
3
4
eType,val (mph), Total
1, 1.3,3.3
1, 4,23.5
1, 8,46.4

Total could be either the possibility this data occurs or the number of days.

Range or val could be the input energy or data used to calculate. Like we are able to calculate the final energy based on this result in some way, e.g. wind speed.

Possible GAMS code

Interpret to Js

Analyze

Pros

  • Use expectation to simulate a better estimate of wind speed in different scenario
  • Save calculation

Cons

  • Data has higher wind speed would usually has less possibility. Then the model won’t focus on them, so they might be ignored in the model. (Too big wind might harm the equipment, so this make sense sometime)
  • User consumption is not perfect estimate

Modified Version for Normal Count

Battery limitation is a long term limitation, each one has some kind of relationship. Has battery limitation and want to find global optimal.

Variables

J : type of energy, JJ\in {wind, water, \cdots }

N : number of days, $\in $ {1,2,3, \cdots ,n}

c = RJ\mathbf{R}^J: the normal energy consumption per unit time for each producer (Need to consider as a combination of multiple equipments, like: if we have two wind machine(user is able to define this in control), each machine will consume 10 W. Then CwindC_{wind}=10*2=20)

U = RN\mathbf{R}^N: User consumption per unit time N

S = {0,1}J,N^{J,N}, the status code to identify if we need to turn on the machine in this day/unit time.

C = {0,1,2}J,N^{J,N}, the counter to count and analyze the normal energy consumption per day/unit time. 2 stand for the unit time that this machine needs to be turned on(as more energy needs to be consumed in the turning on process). 1 identify as daily normal consumption. 0 identify this machine is turned off.

W = RJ,N\mathbf{R}^{J,N}, the energy produced per day/unit time for j equipment

B RN\in \mathbf{R}^N : The battery charging limitation. With B0=0B_0=0

B R\in \mathbf{R} : Constant to represent the battery charging limitation.

Optimization Model

\begin{equation} \begin{split} &\text{Maximize } & \sum_{i\in N}\sum_{j\in J}W_{ij}S_{ij}-\sum_{j\in J}c_j\sum_{i\in N}C_{ij}S_{ij}\\ &\text{Subject to } & C_{ij}=S_{ij}-S_{i-1,j}+1 \ \forall i\in \{2,\cdots,n\}\\ & & 0 \le C_{ij} \le 2 \ \forall i\in N j\in J\\ & & 0 \le S_{ij} \le 1 \ \forall i\in N j\in J\\ & & B_i\le B \ \forall i\in \{2,\cdots, n\}\\ & & B_i=B_{i-1}+\sum_{j\in J}W_{ij}S_{ij}-\sum_{j\in J}c_jC_{ij}S_{ij}-U_i \end{split} \end{equation}

Use MIP to solve it

Sample data

Sample data should be in csv format, each column contains different information. Only wind data is represented in the section below

u is the x component of wind/other type of energy, v is the y component of the wind. Final wind speed is calculated by using ws=u2+v2ws = \sqrt{u^2+v^2} .

1
2
3
4
Time,eType,u,v
0.2,1,12,15
0.3,1,16,12
0.5,1,12,16

If we need to make this simpler or we are not able to collect related data for each type of energy, we could also use data in the below format:

1
2
3
4
Time,eType,var
0.2,1,12
0.3,1,16
0.5,1,12

eType is the type of energy, 1 means wind, 2 means sun …

var is the input energy or data used to calculate. Like we are able to calculate the final energy based on this result in some way.

Let thresholds high

To overcome the cons that some high energy production case will be ignored in the previous cases, use this model to find it. Instead of previous cases, we want to minimize the i,jSij\sum_{i,j}S_{ij}, to use as many as high production case as we could. So the thresholds could be as high as possible.

Variables

J : type of energy, JJ\in {wind, water, \cdots }

N : number of days, $\in $ {1,2,3, \cdots ,n}

c = RJ\mathbf{R}^J: the normal energy consumption per unit time for each producer (Need to consider as a combination of multiple equipments, like: if we have two wind machine(user is able to define this in control), each machine will consume 10 W. Then CwindC_{wind}=10*2=20)

U = RN\mathbf{R}^N: User consumption per unit time N

S = {0,1}J,N^{J,N}, the status code to identify if we need to turn on the machine in this day/unit time.

C = {0,1,2}J,N^{J,N}, the counter to count and analyze the normal energy consumption per day/unit time. 2 stand for the unit time that this machine needs to be turned on(as more energy needs to be consumed in the turning on process). 1 identify as daily normal consumption. 0 identify this machine is turned off.

W = RJ,N\mathbf{R}^{J,N}, the energy produced per day/unit time for j equipment

B RN\in \mathbf{R}^N : The amount of energy battery has. With B0=B_0=user defined, could be 70% of the battery size

B R\in \mathbf{R} : Constant to represent the battery charging limitation.

Optimization Model

\begin{equation}\begin{split}&\text{Minimize } & \sum_{i,j}C_{ij}S_{ij}\\&\text{Subject to } & C_{ij}=S_{ij}-S_{i-1,j}+1 \ \forall i\in \{2,\cdots,n\}\\& & 0 \le C_{ij} \le 2 \ \forall i\in N j\in J\\& & 0 \le S_{ij} \le 1 \ \forall i\in N j\in J\\& & B_i\ge B \ \forall i\in \{2,\cdots, n\}\\& & B_i=B_{i-1}+\sum_{j\in J}W_{ij}S_{ij}-\sum_{j\in J}c_jC_{ij}S_{ij}-U_i\end{split}\end{equation}

Use MIP to solve it

We could use default value if no applied answer found

Sample data

Data format is the same as format defined in Modified Version for Normal Count.

Possible GAMS code

Interpret to Js

Analyze

Pros

  • We will use as much as high production scenario as we could
  • Because thresholds is high, a lot of unexpected energy consumption in the turning on process could be eliminated.

Cons

  • Total energy is not maximized(This makes sense, as we only have a limited energy storage)

Expected Count for Let thresholds high case

Data source definition is the same as the previous situation

Define variables

J : type of energy, JJ\in {wind, water, \cdots }

N : value index, 1, 2, \cdots.

C = RJ\mathbf{R}^J: the normal energy consumption per unit time for each producer (Need to consider as a combination of multiple equipments, like: if we have two wind machine(user is able to define this in control), each machine will consume 10 W. Then CwindC_{wind}=10*2=20)

U = R\mathbf{R}: Total user consumption

W = RJ,N\mathbf{R}^{J,N}, the expected energy(total in above table) produced in each value index, either pre-calculated or calculate in model.

S = {0,1}J,N^{J,N}, to indicate I should turn on wind on this statistic data or not

B R\in \mathbf{R} : The battery charging limitation.

D RJ,N\in \mathbf{R}^{J,N}, indicate the day count each value index, either pre-calculated or calculate in model.

Optimization Model

\begin{equation}\begin{split}&\text{Minimize } & \sum_{i\in N}\sum_{j\in J}D_{ij}S_{ij}\\& \text{Subject to}\ & 0 \le S_{ij} \le 1 \ \forall i\in N j\in J\\& & \sum_{i\in N}\sum_{j\in J}W_{ij}S_{ij}-\sum_{i\in N}\sum_{j\in J}C_{j}S_{ij}-U\ge B\end{split}\end{equation}

Use MIP to solve it

Sample data

Data format is the same as format defined in Expected Count Model.

Possible GAMS code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
$ontext
generating gdx
gdxxrw E:\test\OptimizationData.xlsx par=data rng=OptimizationData!A1:I12 cDim=1 rDim=1 set=row rng=OptimizationData!A1:I1 cDim=1 set=idx rng=OptimizationData!A2:A12 rDim=1
assume 365 hrs in total to make calculation simpler
Need to add user consumption in the future
//permit partially open, for case when half of days needs to be opened.
MIP is reqired, as we are calculating the expectation, I only know this might happen, but I don't know and no need to know the exact day to turn on or off the device.
So, it is saying we need to turn on this device at this energy level or not.
We can not half turn on the device
wind_count could be wind possibility
$offtext

sets idx(*), row(*);
parameter data(idx, row);

$gdxin OptimizationData.gdx
$load idx row data
$gdxin

alias(idx,i);
Sets
j(row) / wind_value,light_value,wave_value,current_value/ ;

scalar U "Total user consumption in 365 hrs" /[2139300*365]/
B "battery capacity" /1000000000/;

integer variable a(i,j);
variable k;
equations obj, limit, limitvar1, limitvar2;
obj..
k =e= sum(i,a(i,"wind_value")*data(i,"wind_count")+a(i,"light_value")*data(i,"light_count")+a(i,"wave_value")*data(i,"wave_count")+a(i,"current_value")*data(i,"current_count"));
limit..
sum(i, a(i,"wind_value")*data(i,"wind_count")*data(i,"wind_value")+a(i,"light_value")*data(i,"light_count")*data(i,"light_value")+a(i,"wave_value")*data(i,"wave_value")*data(i,"wave_count")+a(i,"current_value")*data(i,"current_value")*data(i,"current_count")) - U =g= B;
limitvar1(i,j)..
a(i,j) =g= 0;
limitvar2(i,j)..
a(i,j) =l= 1;
model energy /all/;
solve energy using mip minimizing k;

display a.l;

Analyze

Pros

  • Use expectation to simulate a better estimate of wind speed in different scenario
  • Save calculation

Cons

  • User consumption is not perfect estimate
  • Energy stored in battery is not perfectly estimated

Last thought:

Both model doesn’t consider extreme case, as people will still have control on the entire system and most of people won’t use this in extreme case.

To make all models become portable and not using too many calculation, I choose LP or MIP model, instead of building some better estimate model.

Battery has some specific charging and discharging curve, like this:

Need discussion

  • Do we know normal user consumption of energy?

  • If no history data provided, then use fixed threshold=energy consumed by equipment in normal life.

  • Another thought: Use a single line and calculate how many value is below the line, estimate and find the least number of turning on/off (Not possible, as turning off is a point but wind might remain low for a duration of time)

 Comments