-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopt_theory_hw.qmd
89 lines (66 loc) · 3.74 KB
/
opt_theory_hw.qmd
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
---
title: "Homework"
format:
html:
html-math-method: katex
engine: julia
---
## Electric vehicle charging
Solve the problem of distributing a limited power to $N$ electric vehicle chargers throughout the next $K$ hours. Specifically, you are supposed to find an hourly-sampled optimal plan for each car that minimizes the total cost of the charging.
You are given a time-dependent maximum energy $a[k]$ available for charging (in kWh), a time-dependent cost of the energy $c[k]$ (in €/kWh), maximum allowed charging energy per hour for the *i*th car $m_i$ (in kWh), total requested energy $r_i$ for the *i*th car (also in kWh), and the departure (discrete) time $d_i$ for each car.
All the cars are connected to chargers and can start charging from time 1. Departure time is the time when the energy charged to the *i*th car has reached at least $r_i$ and charging of the car must stop.
Let's emphasize: the index $k$ is a time index running from 1 to $K$, and the index $i$ specifies the corresponding car, i.e. $i\in\{1,2,\ldots, N\}$
Formulate this task as an optimization problem, identify the class of this optimization problem (LP, QP or NLP) and solve it by completing the following Julia script and heeding the following instructions.
* Model the optimization problem either trough `JuMP` or `Convex`.
* Solve it using one of the available solvers: `HiGHS, SCS, Ipopt`.
* Upload only a single file named `hw.jl` as your solution.
```{julia}
#| eval: false
using JuMP # or Convex
using HiGHS, SCS, Ipopt # Available solvers
"""
find_optimal_charging_plan(
a::Vector{Float64},
c::Vector{Float64},
m::Vector{Float64},
r::Vector{Float64},
d::Vector{Int64}
)
Computes an optimal charging schedule for `N` electric vehicles over `K` hours.
# Arguments
- `a`: A `K`-element vector specifying the maximum available charging energy per hour (kWh).
- `c`: A `K`-element vector representing the cost of charging per hour (€/kWh).
- `m`: An `N`-element vector with the maximum allowed charging energy for each vehicle (kWh).
- `r`: An `N`-element vector specifying the total energy required by each vehicle (kWh).
- `d`: An `N`-element vector indicating the departure time (hour) of each vehicle.
# Returns
A tuple containing:
- An `N × K` matrix representing the optimal charging schedule (kWh allocated per vehicle per hour).
- The optimal total charging cost (€).
- A symbol indicating the type of optimization problem solved (`:LP`, `:QP`, or `:NLP`).
"""
function find_optimal_charging_plan(
a::Vector{Float64},
c::Vector{Float64},
m::Vector{Float64},
r::Vector{Float64},
d::Vector{Int64}
)
K = length(a) # Timespan (hours)
N = length(m) # Number of vehicles
# TODO model and solve the problem
return zeros(N, K), 0.0, :NLP # or :LP or :QP
end
```
The data you can use to test your solution is given in the following tables.
| Car | $m_i$ (kWh) | $r_i$ (kWh) | $d_i$ |
|-----|------------------------------|------------------------------|---------|
| 1 | 6 | 15 | 3 |
| 2 | 6 | 25 | 7 |
| 3 | 4 | 30 | 10 |
: Data for the three vehicles: maximum energy per hour, total requested energy, and the departure time
| Time | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|------|------|------|------|------|------|------|------|------|------|------|
| $a[k]$ | 11.6 | 11.9 | 10.6 | 8.8 | 8.0 | 8.8 | 10.6 | 11.9 | 11.6 | 10.0 |
| $c[k]$ | 0.58 | 0.72 | 0.92 | 0.68 | 0.54 | 0.78 | 0.64 | 0.57 | 0.74 | 0.74 |
: Evolution in time of the maximum available energy and the cost of the energy