You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What
The input data for allocation must be validated:
The set of nodes for a subnetwork should be directly connected, that is: there should be a path, not taking edge directions into account, between each pair of nodes in the allocation graph that only goes via nodes that are also in the same allocation graph. This requires some graph processing: perhaps the best way to do this is by starting a flood fill at a random point in the subnetwork and see whether you can cover the whole subnetwork from there. Some good things to know:
In the Julia core, node IDs are not just integers: each node ID is an integer wrapped in the NodeID type.
I use the terms subnetwork and allocation network. Let's say a subnetwork consists of all the nodes with the same allocation_network_id in the model input. The allocation network consists of the nodes which are selected from the subnetwork to be part of the network that is used for optimization. This information can be found in the node metadata, see below.
The set of nodes used for allocation optimization in a subnetwork are stored in p.graph[].node_ids[allocation_network_id];
To get the in-neighbors and out-neighbors of a node, use the functions inflow_ids_allocation and outflow_ids_allocation.
You do need to check for every node whether it is in the allocation network you are considering, which you can test by looking up the nodes' metadata by graph[node_id]. For the metadata fields see struct NodeMetadata.
The best way to apply this validation is just after the allocation network is initialized, which is in the function AllocationModel after allocation_graph is called.
The source edges should end in a node of the allocation network the source edge is associated with. This can be added to an already existing validation function for source edges: function valid_sources. Source edges can be found in graph[].edges_source[allocation_network_id]. Edit: this point can be skipped because the mentioned validation function is being updated in the main_network_allocation_main feature branch.
Demands should be non-negative. Some good things to know:
Demands are stored as (time) interpolation objects in the User node type. Node types are initialized in create.jl in functions with the same name as the node type.
There are several ways to implement validation. One of them is to first initialize an object and then run validation on its fields. Another way is to incorporate the validation into the inner constructor of an object, which I think is the best way to go here. See here for an example of this in our codebase.
Allocation network IDs is must be positive integers. A good place to check this is in function generate_allocation_models!.
Why
So that modelers get comprehensive error messages if the input is not as expected, instead of incomprehensible error messages or malfunctioning code.
How
This can be done analogously to existing validation and tests thereof. See:
The functions valid_* in validation.jl
The invalid models in invalid.py
The validation error tests in validation_test.jl
The text was updated successfully, but these errors were encountered:
What
The input data for allocation must be validated:
The set of nodes for a subnetwork should be directly connected, that is: there should be a path, not taking edge directions into account, between each pair of nodes in the allocation graph that only goes via nodes that are also in the same allocation graph. This requires some graph processing: perhaps the best way to do this is by starting a flood fill at a random point in the subnetwork and see whether you can cover the whole subnetwork from there. Some good things to know:
In the Julia core, node IDs are not just integers: each node ID is an integer wrapped in the
NodeID
type.I use the terms subnetwork and allocation network. Let's say a subnetwork consists of all the nodes with the same
allocation_network_id
in the model input. The allocation network consists of the nodes which are selected from the subnetwork to be part of the network that is used for optimization. This information can be found in the node metadata, see below.The set of nodes used for allocation optimization in a subnetwork are stored in
p.graph[].node_ids[allocation_network_id]
;To get the in-neighbors and out-neighbors of a node, use the functions
inflow_ids_allocation
andoutflow_ids_allocation
.You do need to check for every node whether it is in the allocation network you are considering, which you can test by looking up the nodes' metadata by
graph[node_id]
. For the metadata fields seestruct NodeMetadata
.The best way to apply this validation is just after the allocation network is initialized, which is in the function
AllocationModel
afterallocation_graph
is called.The source edges should end in a node of the allocation network the source edge is associated with. This can be added to an already existing validation function for source edges:
function valid_sources
. Source edges can be found ingraph[].edges_source[allocation_network_id]
.Edit: this point can be skipped because the mentioned validation function is being updated in the
main_network_allocation_main
feature branch.Demands should be non-negative. Some good things to know:
Demands are stored as (time) interpolation objects in the
User
node type. Node types are initialized increate.jl
in functions with the same name as the node type.There are several ways to implement validation. One of them is to first initialize an object and then run validation on its fields. Another way is to incorporate the validation into the inner constructor of an object, which I think is the best way to go here. See here for an example of this in our codebase.
Allocation network IDs is must be positive integers. A good place to check this is in
function generate_allocation_models!
.Why
So that modelers get comprehensive error messages if the input is not as expected, instead of incomprehensible error messages or malfunctioning code.
How
This can be done analogously to existing validation and tests thereof. See:
valid_*
invalidation.jl
invalid.py
validation_test.jl
The text was updated successfully, but these errors were encountered: