@@ -52,19 +52,19 @@ def create_routes(self, number_of_routes: int):
5252 """Create a number of lines from the substation to unconnected nodes"""
5353 # each source should have at least one route
5454 number_of_sources = len (self .grid .source )
55- from_nodes = self .rng .choice (self .grid .source . node , number_of_routes - number_of_sources , replace = True )
56- not_source_mask = ~ np .isin (self .grid .node . id , self .grid .source . node )
57- to_nodes = self .rng .choice (self .grid .node . id [not_source_mask ], number_of_routes , replace = False )
55+ from_nodes = self .rng .choice (self .grid .source [ " node" ] , number_of_routes - number_of_sources , replace = True )
56+ not_source_mask = ~ np .isin (self .grid .node [ "id" ] , self .grid .source [ " node" ] )
57+ to_nodes = self .rng .choice (self .grid .node [ "id" ] [not_source_mask ], number_of_routes , replace = False )
5858 capacities = 100 + self .rng .exponential (200 , number_of_routes )
5959 line_array = self .grid .line .__class__ .zeros (number_of_routes )
60- line_array . id = 1 + self .grid .max_id + np .arange (number_of_routes )
61- line_array . from_node = np .concatenate ((self .grid .source . node , from_nodes ))
62- line_array . to_node = to_nodes
63- line_array . from_status = [1 ] * number_of_routes
64- line_array . to_status = [1 ] * number_of_routes
65- line_array . r1 = self .rng .exponential (0.2 , number_of_routes )
66- line_array . x1 = self .rng .exponential (0.02 , number_of_routes )
67- line_array . i_n = capacities
60+ line_array [ "id" ] = 1 + self .grid .max_id + np .arange (number_of_routes )
61+ line_array [ " from_node" ] = np .concatenate ((self .grid .source [ " node" ] , from_nodes ))
62+ line_array [ " to_node" ] = to_nodes
63+ line_array [ " from_status" ] = [1 ] * number_of_routes
64+ line_array [ " to_status" ] = [1 ] * number_of_routes
65+ line_array [ "r1" ] = self .rng .exponential (0.2 , number_of_routes )
66+ line_array [ "x1" ] = self .rng .exponential (0.02 , number_of_routes )
67+ line_array [ " i_n" ] = capacities
6868 self .line_array = line_array
6969
7070 def determine_number_of_routes (self ) -> int :
@@ -78,56 +78,56 @@ def determine_number_of_routes(self) -> int:
7878 def connect_nodes (self ):
7979 """Add a new line between an active and inactive line"""
8080 to_node = self .rng .choice (self .unconnected_nodes )
81- to_voltage = self .grid .node [self .grid .node . id == to_node ]. u_rated [0 ]
82- same_voltage_mask = self .grid .node . u_rated == to_voltage
83- same_voltage_nodes = self .grid .node [same_voltage_mask ]
84- options_mask = np .isin (self .connected_nodes , same_voltage_nodes . id )
81+ to_voltage = self .grid .node . data [self .grid .node [ "id" ] == to_node ][ " u_rated" ] [0 ]
82+ same_voltage_mask = self .grid .node [ " u_rated" ] == to_voltage
83+ same_voltage_nodes = self .grid .node . data [same_voltage_mask ]
84+ options_mask = np .isin (self .connected_nodes , same_voltage_nodes [ "id" ] )
8585 from_node = self .rng .choice (np .array (self .connected_nodes )[options_mask ])
8686 capacity = 100 + self .rng .exponential (200 , 1 )
8787 new_line = self .grid .line .__class__ .zeros (1 )
88- new_line . id = 1 + max (max (self .line_array . id ), self .grid .max_id ) # pylint: disable=nested-min-max
89- new_line . from_node = from_node
90- new_line . to_node = to_node
91- new_line . from_status = [1 ]
92- new_line . to_status = [1 ]
93- new_line . r1 = self .rng .exponential (0.2 , 1 )
94- new_line . x1 = self .rng .exponential (0.02 , 1 )
95- new_line . i_n = capacity
88+ new_line [ "id" ] = 1 + max (max (self .line_array [ "id" ] ), self .grid .max_id ) # pylint: disable=nested-min-max
89+ new_line [ " from_node" ] = from_node
90+ new_line [ " to_node" ] = to_node
91+ new_line [ " from_status" ] = [1 ]
92+ new_line [ " to_status" ] = [1 ]
93+ new_line [ "r1" ] = self .rng .exponential (0.2 , 1 )
94+ new_line [ "x1" ] = self .rng .exponential (0.02 , 1 )
95+ new_line [ " i_n" ] = capacity
9696 self .line_array = fp .concatenate (self .line_array , new_line )
9797
9898 def create_nop_lines (self , number_of_nops : int ):
9999 """Create the inactive lines between different routes (Normally Open Points)"""
100- nops = [self .rng .choice (self .grid .node . id , 2 , replace = False ) for _ in range (number_of_nops )]
100+ nops = [self .rng .choice (self .grid .node [ "id" ] , 2 , replace = False ) for _ in range (number_of_nops )]
101101 from_nodes = [nop [0 ] for nop in nops ]
102102 to_nodes = [nop [1 ] for nop in nops ]
103103 capacities = 100 + self .rng .exponential (200 , number_of_nops )
104104 nop_lines = self .grid .line .__class__ .zeros (number_of_nops )
105- nop_lines . id = 1 + self .line_array . id .max () + np .arange (number_of_nops )
106- nop_lines . from_node = from_nodes
107- nop_lines . to_node = to_nodes
108- nop_lines . from_status = [1 ] * number_of_nops
109- nop_lines . to_status = [0 ] * number_of_nops
110- nop_lines . r1 = self .rng .exponential (0.2 , number_of_nops )
111- nop_lines . x1 = self .rng .exponential (0.02 , number_of_nops )
112- nop_lines . i_n = capacities
105+ nop_lines [ "id" ] = 1 + self .line_array [ "id" ] .max () + np .arange (number_of_nops )
106+ nop_lines [ " from_node" ] = from_nodes
107+ nop_lines [ " to_node" ] = to_nodes
108+ nop_lines [ " from_status" ] = [1 ] * number_of_nops
109+ nop_lines [ " to_status" ] = [0 ] * number_of_nops
110+ nop_lines [ "r1" ] = self .rng .exponential (0.2 , number_of_nops )
111+ nop_lines [ "x1" ] = self .rng .exponential (0.02 , number_of_nops )
112+ nop_lines [ " i_n" ] = capacities
113113 self .line_array = fp .concatenate (self .line_array , nop_lines )
114114
115115 def set_unconnected_nodes (self ) -> None :
116116 """From a line array and total set of nodes determine which are not yet connected"""
117117 connected_link_mask = np .logical_or (
118- np .isin (self .grid .node . id , self .line_array . from_node ),
119- np .isin (self .grid .node . id , self .line_array . to_node ),
118+ np .isin (self .grid .node [ "id" ] , self .line_array [ " from_node" ] ),
119+ np .isin (self .grid .node [ "id" ] , self .line_array [ " to_node" ] ),
120120 )
121121 connected_trafo_mask = np .logical_or (
122- np .isin (self .grid .node . id , self .trafo_array . from_node ),
123- np .isin (self .grid .node . id , self .trafo_array . to_node ),
122+ np .isin (self .grid .node [ "id" ] , self .trafo_array [ " from_node" ] ),
123+ np .isin (self .grid .node [ "id" ] , self .trafo_array [ " to_node" ] ),
124124 )
125125 connected_mask = np .logical_or (
126126 connected_link_mask ,
127127 connected_trafo_mask ,
128128 )
129- connected_nodes = self .grid .node . id [connected_mask ]
130- unconnected_nodes = self .grid .node . id [~ connected_mask ]
129+ connected_nodes = self .grid .node [ "id" ] [connected_mask ]
130+ unconnected_nodes = self .grid .node [ "id" ] [~ connected_mask ]
131131
132132 self .unconnected_nodes = unconnected_nodes .tolist ()
133133 self .connected_nodes = connected_nodes .tolist ()
0 commit comments