From e99ab09c483fa5255aca12bfc662c732e9c6024b Mon Sep 17 00:00:00 2001 From: Jingru Feng Date: Thu, 1 Feb 2024 15:52:55 +0100 Subject: [PATCH] resolved Bart's second round of comments --- core/src/create.jl | 2 +- core/src/validation.jl | 6 +----- core/test/create_test.jl | 32 +++++++++++--------------------- 3 files changed, 13 insertions(+), 27 deletions(-) diff --git a/core/src/create.jl b/core/src/create.jl index 10d41ee5a..66e331e06 100644 --- a/core/src/create.jl +++ b/core/src/create.jl @@ -697,7 +697,7 @@ function User(db::DB, config::Config)::User first_row = time[first_row_idx] is_active = true else - @error "User node $node_id data not in any table." + @error "User node #$node_id data not in any table." errors = true end diff --git a/core/src/validation.jl b/core/src/validation.jl index 6102cbaeb..f74d03eb8 100644 --- a/core/src/validation.jl +++ b/core/src/validation.jl @@ -657,15 +657,11 @@ function valid_demand( return !errors end -function valid_connection(graph::MetaGraph)::Bool - return is_connected(graph) -end - function incomplete_subnetwork(graph::MetaGraph, node_ids::Dict{Int, Set{NodeID}})::Bool errors = false for (allocation_network_id, subnetwork_node_ids) in node_ids subnetwork, _ = induced_subgraph(graph, code_for.(Ref(graph), subnetwork_node_ids)) - if (!is_connected(subnetwork)) + if !is_connected(subnetwork) @error "All nodes in subnetwork $allocation_network_id should be connected" errors = true end diff --git a/core/test/create_test.jl b/core/test/create_test.jl index c46b06cea..b287d8ad2 100644 --- a/core/test/create_test.jl +++ b/core/test/create_test.jl @@ -5,21 +5,16 @@ using Ribasim using Accessors: @set - struct NodeMetadata - type::Symbol - allocation_network_id::Int - end - graph = MetaGraph( DiGraph(); label_type = Ribasim.NodeID, - vertex_data_type = NodeMetadata, + vertex_data_type = Ribasim.NodeMetadata, edge_data_type = Symbol, graph_data = Tuple, ) - graph[Ribasim.NodeID(1)] = NodeMetadata(Symbol(:delft), 1) - graph[Ribasim.NodeID(2)] = NodeMetadata(Symbol(:denhaag), -1) + graph[Ribasim.NodeID(1)] = Ribasim.NodeMetadata(Symbol(:delft), 1) + graph[Ribasim.NodeID(2)] = Ribasim.NodeMetadata(Symbol(:denhaag), -1) graph[1, 2] = :yes @@ -52,15 +47,10 @@ end using Logging using Ribasim - struct NodeMetadata - type::Symbol - allocation_network_id::Int - end - graph = MetaGraph( DiGraph(); label_type = Ribasim.NodeID, - vertex_data_type = NodeMetadata, + vertex_data_type = Ribasim.NodeMetadata, edge_data_type = Symbol, graph_data = Tuple, ) @@ -73,15 +63,15 @@ end node_ids[2] = Set{Ribasim.NodeID}() push!(node_ids[2], Ribasim.NodeID(4)) push!(node_ids[2], Ribasim.NodeID(5)) - push!(node_ids[2], Ribasim.NodeID(5)) + push!(node_ids[2], Ribasim.NodeID(6)) #node_ids = Dict([(1, Set(NodeID(1))), (2, Set(NodeID(2)))]) - graph[Ribasim.NodeID(1)] = NodeMetadata(Symbol(:delft), 1) - graph[Ribasim.NodeID(2)] = NodeMetadata(Symbol(:denhaag), 1) - graph[Ribasim.NodeID(3)] = NodeMetadata(Symbol(:rdam), 1) - graph[Ribasim.NodeID(4)] = NodeMetadata(Symbol(:adam), 2) - graph[Ribasim.NodeID(5)] = NodeMetadata(Symbol(:utrecht), 2) - graph[Ribasim.NodeID(6)] = NodeMetadata(Symbol(:leiden), 2) + graph[Ribasim.NodeID(1)] = Ribasim.NodeMetadata(Symbol(:delft), 1) + graph[Ribasim.NodeID(2)] = Ribasim.NodeMetadata(Symbol(:denhaag), 1) + graph[Ribasim.NodeID(3)] = Ribasim.NodeMetadata(Symbol(:rdam), 1) + graph[Ribasim.NodeID(4)] = Ribasim.NodeMetadata(Symbol(:adam), 2) + graph[Ribasim.NodeID(5)] = Ribasim.NodeMetadata(Symbol(:utrecht), 2) + graph[Ribasim.NodeID(6)] = Ribasim.NodeMetadata(Symbol(:leiden), 2) graph[Ribasim.NodeID(1), Ribasim.NodeID(2)] = :yes graph[Ribasim.NodeID(1), Ribasim.NodeID(3)] = :yes