Thank you Niclas,

I’m going to try to clarify everything.

This is the ecuation I want to implement:

and this is the implementation in GAMS:

The idea of this ecuation is that the energy in the following period is going to be de energy in the current period plus Pc ( energy consume in the current period ) or minus Ph ( energy generated in the current period ).

and finally here is my code in Julia, sorry for all the mistakes but is my first full code and I still don’t understand some aspects of this language

```
#reading demand data.
csvfilename = "demand.csv"
csvdata = readcsv(csvfilename, header=true)
data = csvdata[1]
header = csvdata[2]
Pc= data[:,1]
#Prmax max grid potency
#Pr grid potency
#Pb Battery storage potency ( + - ).
#Pc Direct consume potency from grid.
#Pbmin y Pbmax Minimum and maximum potency battery
#Cpot Cost kW
#Cen Cost kWh
#Enom Battery nominal energy
using JuMP, Cbc
m = Model(solver=CbcSolver())
Prmax = 3
Pbmax = 1.7
Pbmin = -1.7
Cp = 0.15
Enom = 1.7
Cen = [0.01,0.01,0.01,0.01,0.01,0.01,0.01,0.012,0.012,0.08,0.08,0.08,0.08,0.08,0.08,0.08,0.08,0.08,0.08,0.08,0.08,0.08,0.08,0.08,0.08,0.08,0.08,0.12,0.12,0.12,0.12,0.12]
# Declaring variables
@variable(m, 0<= Pr[t=1:24] <= Prmax)
@variable(m, Pbmin <= Pb[t=1:24] <= Pbmax )
@variable(m, 0.1*Enom <= E[t=1:24] <= 0.9*Enom)
# Setting the objective
@objective(m, Min, (Prmax*Cpot) + ( Pr[t=1:24]*Cen[t=1:24] )
# Adding constraints
@constraint(m, constraint1, Pr[t=1:24] .== Pc[t=1:24] - Pb[t=1:24] )
# This is the problematic constraint
@constraint(m, constraint2, E[(t=1:24)+1] .== E[t=1:24]- Pr[t=1:24] )
@constraint(m, constraint3, Pbmin .<= Pb[t=1:24] .<= Pbmax)
@constraint(m, constraint4, (Enom*0.1) .<= E[t=1:24] .<= (Enom*0.9) )
# Printing the prepared optimization model
print(m)
# Solving the optimization problem
solve(m)
# Printing the optimal solutions obtained
println("Optimal Solutions:")
println("Pb = ", getvalue(Pb))
println("Pr = ", getvalue(Pr))
println("E = ", getvalue(E))
I hope this could help you to understand the problem.
thank you very much!!!!
```