-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create flow variables using the indices table (#900)
- Loading branch information
Showing
5 changed files
with
48 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
export add_flow_variables! | ||
|
||
""" | ||
add_flow_variables!(model, dataframes) | ||
add_flow_variables!(model, variables) | ||
Adds flow variables to the optimization `model` based on data from the `dataframes`. | ||
Adds flow variables to the optimization `model` based on data from the `variables`. | ||
The flow variables are created using the `@variable` macro for each row in the `:flows` dataframe. | ||
""" | ||
function add_flow_variables!(model, dataframes) | ||
df_flows = dataframes[:flows] | ||
function add_flow_variables!(model, variables) | ||
# Unpacking the variable indices | ||
flows_indices = variables[:flow].indices | ||
|
||
model[:flow] = | ||
df_flows.flow = [ | ||
@variable( | ||
model, | ||
base_name = "flow[($(row.from), $(row.to)), $(row.year), $(row.rep_period), $(row.timesteps_block)]" | ||
) for row in eachrow(df_flows) | ||
] | ||
variables[:flow].container = [ | ||
@variable( | ||
model, | ||
base_name = "flow[($(row.from), $(row.to)), $(row.year), $(row.rep_period), $(row.timesteps_block)]" | ||
) for row in eachrow(flows_indices) | ||
] | ||
|
||
return | ||
end |