Skip to content

Commit 9c7b06a

Browse files
committed
Add/remove docstrings.
1 parent 539ac9b commit 9c7b06a

1 file changed

Lines changed: 59 additions & 14 deletions

File tree

src/main/helper.jl

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11

2+
"""
3+
dict_to_namedtuple(dict)
4+
5+
Convert a dictionary to a NamedTuple.
6+
7+
If the input is already a NamedTuple, it is returned unchanged.
8+
Otherwise, it creates a new NamedTuple from the dictionary's keys and values.
9+
10+
# Arguments
11+
- `dict`: A dictionary or NamedTuple to be converted.
12+
13+
# Returns
14+
- A NamedTuple equivalent to the input dictionary.
15+
"""
216
function dict_to_namedtuple(dict)
317
if dict isa NamedTuple
418
return dict
@@ -7,6 +21,20 @@ function dict_to_namedtuple(dict)
721
end
822
end
923

24+
"""
25+
namedtuple_to_dict(namedtuple)
26+
27+
Convert a NamedTuple to a dictionary.
28+
29+
If the input is already a dictionary, it is returned unchanged.
30+
Otherwise, it creates a new dictionary from the NamedTuple's pairs.
31+
32+
# Arguments
33+
- `namedtuple`: A NamedTuple or dictionary to be converted.
34+
35+
# Returns
36+
- A dictionary equivalent to the input NamedTuple.
37+
"""
1038
function namedtuple_to_dict(namedtuple)
1139
if namedtuple isa Dict
1240
return namedtuple
@@ -31,11 +59,7 @@ function gen_network_flows(Qin, graph, N)
3159
return Qjkn
3260
end
3361

34-
"""
35-
kappa_extract(graph, kappa)
36-
37-
Description: auxiliary function that converts kappa_jk into kappa_i
38-
"""
62+
# Description: auxiliary function that converts kappa_jk into kappa_i
3963
function kappa_extract(graph, kappa)
4064
kappa_ex = zeros(graph.ndeg)
4165
nodes = graph.nodes
@@ -92,6 +116,22 @@ function rowmult(A, v)
92116
return r
93117
end
94118

119+
"""
120+
represent_edges(graph)
121+
122+
Creates a NamedTuple providing detailed representation of the graph edges.
123+
124+
# Arguments
125+
- `graph`: NamedTuple that contains the underlying graph (created by `dict_to_namedtuple(create_graph())`)
126+
127+
# Returns
128+
- A NamedTuple with the following fields:
129+
- `A`: J x ndeg matrix where each column represents an edge. The value is 1 if the edge starts at node J, -1 if it ends at node J, and 0 otherwise.
130+
- `Apos`: J x ndeg matrix where each column represents an edge. The value is the positive part of the edge flow.
131+
- `Aneg`: J x ndeg matrix where each column represents an edge. The value is the negative part of the edge flow.
132+
- `edge_start`: J x ndeg matrix where each column represents an edge. The value is the starting node of the edge.
133+
- `edge_end`: J x ndeg matrix where each column represents an edge. The value is the ending node of the edge.
134+
"""
95135
function represent_edges(graph)
96136
# Create matrix A
97137
# Note: matrix A is of dimension J*ndeg and takes value 1 when node J is
@@ -127,13 +167,18 @@ end
127167
Creates the auxdata structure that contains all the auxiliary parameters for estimation
128168
129169
# Arguments
130-
- `param`: structure that contains the model's parameters
131-
- `graph`: structure that contains the underlying graph (created by create_graph function)
132-
- `edges`: structure that contains the edges of the graph (created by represent_edges function)
133-
- `I`: provides the current JxJ symmetric matrix of infrastructure investment
170+
- `param`: NamedTuple that contains the model's parameters (created by `dict_to_namedtuple(init_parameters())`)
171+
- `graph`: NamedTuple that contains the underlying graph (created by `dict_to_namedtuple(create_graph())`)
172+
- `edges`: NamedTuple that contains the edges of the graph (created by `represent_edges()`)
173+
- `I`: J x J symmetric matrix of current infrastructure (investments)
134174
135-
# Output
136-
- `auxdata`: structure auxdata to be used by IPOPT bundle.
175+
# Returns
176+
- A NamedTuple with the following fields:
177+
- `param`: The input parameter NamedTuple.
178+
- `graph`: The input graph NamedTuple.
179+
- `edges`: The edges of the graph.
180+
- `kappa`: The kappa matrix: I^gamma / delta_tau
181+
- `kappa_ex`: The extracted kappa values (ndeg x 1)
137182
"""
138183
function create_auxdata(param, graph, edges, I)
139184
# Make named tuples
@@ -161,13 +206,13 @@ end
161206
"""
162207
get_model(auxdata)
163208
164-
Construct the appropriate model based on the parameters and auxiliary data.
209+
Construct the appropriate JuMP model based on the parameters and auxiliary data.
165210
166211
# Arguments
167-
- `auxdata`: Auxiliary data required for constructing the model.
212+
- `auxdata`: Auxiliary data required for constructing the model (created by `create_auxdata()`).
168213
169214
# Returns
170-
- `model`: The constructed model.
215+
- `model`: The constructed JuMP model.
171216
- `recover_allocation`: A function to recover the allocation from the model solution.
172217
"""
173218
function get_model(auxdata)

0 commit comments

Comments
 (0)