 r_2(t),
\end{equation}

The data rate at $u_1$ and $u_2$ are given as:
\begin{align}
    &R_i(t) = \underset{\Phi}{\text{max}} \log_2 \bigg(1+ \frac{p_{\hat{i}}(t) |h_{{\hat{i}}i}+\mathbf{h}_i^T(t) \mathbf{\Phi_i}(t) \mathbf{h}_{{\hat{i}}}(t)|^2}{\sigma^2}\bigg) \label{R0}\\ 
\hspace{-1cm}  = & \log_2 \bigg(1+\frac{p_{\hat{i}}(t)(|h_{{\hat{i}}i}|+\alpha \sum_{n=1}^N \epsilon_{i,n}(t) |\mathbf{h}_{i,n}(t) \mathbf{h}_{{\hat{i}},n}(t)|)^2}{\sigma^2}\bigg)\label{R1}
\end{align}

where ${\hat{i}}=1$ if $i=2$ and vice versa.
Note that (\ref{R1}) can be derived from (\ref{R0}) based on the proof in \cite{Wu2}. It is worth pointing out that $\mathbf{h}_i^T(t) \mathbf{\Phi_i}(t) \mathbf{h}_{{\hat{i}}}(t) = \alpha \sum_{n=1}^N \epsilon_{i,n} |\mathbf{h}_{i,n}(t) \mathbf{h}_{{\hat{i}},n}(t)|$.


\begin{comment}
\small
\begin{align}
    &R_1(t) = \underset{\Phi}{\text{max}} \log_2 \bigg(1+ \frac{p_2(t) |h_{21}+\mathbf{h}_1^T(t) \mathbf{\Phi_1}(t) \mathbf{h}_2(t)|^2}{\sigma^2}\bigg) \label{R0}\\ 
    = & \log_2 \bigg(1+\frac{p_2(t)(|h_{21}|+\alpha \sum_{n=1}^N \epsilon_{1,n}(t) |\mathbf{h}_{1,n}(t) \mathbf{h}_{2,n}(t)|)^2}{\sigma^2}\bigg)\label{R1}
\end{align}


\small
\begin{align}
    &R_2(t) = \underset{\Phi}{\text{max}} \log_2 \bigg(1+ \frac{p_1(t) ||h_{12}|+\mathbf{h}_2^T(t) \mathbf{\Phi_2}(t) \mathbf{h}_1(t)|^2}{\sigma^2}\bigg)\\ 
    = & \log_2 \bigg(1+\frac{p_1(t)(|h_{12}|+\alpha \sum_{n=1}^N \epsilon_{2,n}(t) |\mathbf{h}_{2,n}^T(t) \mathbf{h}_{1,n}(t)|)^2}{\sigma^2}\bigg)\label{R2}
\end{align}
\normalsize
\end{comment}

\subsection{Energy Model}
In this paper, we assume that the RIS can harvest from Renewable Energy (RE) such as solar. We model the RE stochastic energy arrival rate as a random variable $\Theta$ Watt defined by a probability density function (pdf) $f_\Theta(\theta)$. For example, for photovoltaic energy, $\Theta$ can be interpreted as the received amount of energy per time unit with respect to the received luminous intensity in a particular direction per unit solid angle.


The power consumption of the RIS panel relates to the number of reflecting elements, $N$, and the bit resolution of the phase control. Since all the elements of the RIS panel are theoretically passive, they still consume energy in practical when the diodes used in each reflecting elements are ON \cite{RISpower}. However, this power is negligible compared with the power consumed by the smart controller. This power depends on the controller circuit implementation and the communication module used. Hence, it is reasonable to assume that the bit resolution of all phase shifters are identical on one RIS panel. Therefore the power consumption of the RIS is given by $NP_e$, where $P_e$ denotes the  dissipated  power  per  RIS  element  caused  by the circuitry required for the adaptive phase shift. Given that some elements may not be used, the RIS energy consumption during time slot $t$ can be given by the following:
\begin{equation}\label{consumed}
E^\text{RIS}_C(t)=T_s \sum\limits_{i=1}^2\sum\limits_{n=1}^N \epsilon_{i,n}(t) P_e 
\end{equation}
where $T_s$ is the time slot slot duration. The harvested energy at the end of time slot $t$ can be given as
\begin{equation}
E_H(t)=T_s \eta \, \theta(t),
\end{equation}
where $\eta$ is the energy conversion efficiency coefficient, where
$0\leq~\eta~\leq 1$.
Notice that the current stored energy in the RIS depends on the current harvested energy during slot time $t$, the previously stored energy during previous slots, and the energy consumption during time slot $t$.
Therefore, the stored energy in RIS at the end of time $t$ based on harvest-store-use model is given by
\begin{equation}\label{stored}
E_S(t)= \left[E_S(t-1)+E_H(t)- E^\text{RIS}_C(t)\right]^+, \forall l, \forall t,
\end{equation}
where $[x]^+=\max(0,x)$. 
The following constraint need to be respected to ensure that the harvested energy cannot exceed the battery capacity as
\begin{equation}\label{stored2}
E_S(t-1)+E_H(t) \leq \bar{E}_S, \forall t,
\end{equation}
In addition, to ensure the causality energy constraint (i.e., the RIS cannot consume energy more than the available energy in its battery at time $t$), we impose the following condition:
\begin{equation}\label{stored2}
E^\text{RIS}_C(t) \leq E_S(t-1), \forall t,
\end{equation}

The energy consumption at user $u_i$ for each $t$ is given as:

\begin{equation}
    E^U_i(t) = T_s p_i(t)
\end{equation}


\vspace{-.2cm}
\section{Problem Formulation}\label{problem}


\begin{equation}\label{R maximization2}
    \underset{\epsilon_{i,n}(t),p_i(t) \geq 1}{\text{minimize}} \quad \zeta E^\text{RIS}_C(t) + (1-\zeta) \sum\limits_{i=1}^2 E^U_i(t)
\end{equation}
subject to:
 \begin{equation}\label{peakP}
 p_i(t) \leq P^\text{max}, \quad \forall t, \forall i=1,2.
 \end{equation}
  \begin{equation}\label{assoc}
\sum\limits_{i=1}^ 2 \epsilon_{i,n}(t) \leq 1, \quad \forall n, \forall t,
 \end{equation}
  \begin{equation}\label{rate}
R_i(t) \geq R_{th} \quad \forall t, \forall i=1,2.
 \end{equation}
  \begin{equation}\label{energy1}
E^\text{RIS}_C(t) \leq E_S(t-1), \forall t,
 \end{equation}
  \begin{equation}\label{energy2}
E_S(t-1)+E_H(t) \leq \bar{E}_S, \forall t,
 \end{equation}
where $\zeta$ is the weight coefficient. 


\subsection{Solving The Optimizaton Problem Optimally}\label{optimalsolution}

For simplification, consider that $|\mathbf{h}_{i,n}(t) \mathbf{h}_{{\hat{i}},n}(t)| = \mathbf{H}_{i,{\hat{i}},n}$. Then \eqref{rate} can be written as:

\small
\begin{equation}\label{Rate_threshold}
    \log_2 \bigg(1+\frac{p_{\hat{i}}(t)(|h_{{\hat{i}}i}|+\alpha \sum_{n=1}^N \epsilon_{i,n}(t) \mathbf{H}_{