Classes to manage INDP results

class indputils.INDPComponents

This class stores components of a network

components

List of components of the network

Type

list

num_components

Number of components of the network

Type

int

gc_size

Size of the largest component of the network

Type

int

add_component(members, excess_supply)

This function adds a components

Parameters
  • members (list) – List of nodes in the component

  • excess_supply (float) – Excess supply within the component

Returns

Return type

None.

classmethod calculate_components(m, net, t=0, layers=None)

Find the components and the corresponding excess supply

Parameters
  • m (gurobi.Model) – The object containing the solved optimization problem.

  • net (networkx.DiGraph) – The networkx graph object that stores node, arc, and interdependency information

  • t (int) – Time step. The default is zero.

  • layers (list) – List of layers in the analysis

Returns

indp_components – The object containing the components

Return type

INDPComponents

classmethod from_csv_string(csv_string)

This functions reads the components data from a string as a INDPComponents object

Parameters

csv_string (str) – The string containing the component data

Returns

indp_components – The object containing the components

Return type

INDPComponents

to_csv_string()

Convert the list of components to a string

Returns

  • str

  • List of components as a string

class indputils.INDPResults(layers=None)

This class saves INDP results including actions, costs, run time, and components

results

Dictionary containing INDP results including actions, costs, run time, and components

Type

dict

layers

List of layers in the analysis

Type

list

results_layer

Dictionary containing INDP results for each layer including actions, costs, run time, and components

Type

int

add_action(t, action, save_layer=True)

This function adds restoration actions to the results.

Parameters
  • t (int) – The time steps to which the actions should be added

  • action (list) – List of actions that are added

  • save_layer (bool) – If the actions should be added for each layer. The default is True.

Returns

Return type

None.

add_components(t, components)

This function adds the components to the results

Parameters
  • t (int) – The time steps to which the number of components should be added

  • components (list) – The list of components that is added

Returns

Return type

None.

add_cost(t, cost_type, cost, cost_layer=None)

This function adds cost values to the results.

Parameters
  • t (int) – The time steps to which the costs should be added

  • cost_type (str) – The cost types that is added. The options are: “Space Prep”, “Arc”, “Node”, “Over Supply”, “Under Supply”, “Flow”, “Total”, “Under Supply Perc”

  • cost (float) – The cost value that is added

  • cost_layer (dict) – The cost value that is added for each layer. The default is None, which adds no value for layers.

Returns

Return type

None.

add_gc_size(t, gc_size)

This function adds the giant component size to the results

Parameters
  • t (int) – The time steps to which the giant component size should be added

  • gc_size (int) – The giant component size that is added

Returns

Return type

None.

add_num_components(t, num_components)

This function adds the number of components to the results

Parameters
  • t (int) – The time steps to which the number of components should be added

  • num_components (int) – The number of components that is added

Returns

Return type

None.

add_run_time(t, run_time, save_layer=True)

This function adds run time to the results.

Parameters
  • t (int) – The time steps to which the run time should be added

  • run_time (float) – The run time that is added

  • save_layer (bool) – If the run time should be added for each layer. The default is True.

Returns

Return type

None.

extend(indp_result, t_offset=0, t_start=0, t_end=0)

This function extends the results to accommodate a new time step.

Parameters
  • indp_result (INDPResults) – The current INDPResults object before extension

  • t_offset (int) – The number of time steps that the current results should be shifted forward. The default is 0.

  • t_start (int) – The starting time step. The default is 0.

  • t_end (int) – The ending time step. The default is 0.

Returns

Return type

None.

classmethod from_csv(out_dir, sample_num=1, suffix='')

This function reads the results from file.

Parameters
  • out_dir (str) – Output directory from which the results should be read

  • sample_num (int) – The sample number corresponding to the results, The default is 1.

  • suffix (str) – The suffix of the file that is being read. The default is “”.

Returns

indp_result – The INDPResults object containing the read results

Return type

INDPResults

to_csv(out_dir, sample_num=1, suffix='')

This function writes the results to file.

Parameters
  • out_dir (str) – Output directory to which the results should be written

  • sample_num (int) – The sample number corresponding to the results, The default is 1.

  • suffix (str) – The suffix of the file that is being written. The default is “”.

Returns

Return type

None.

to_csv_layer(out_dir, sample_num=1, suffix='')

This function writes the results to file for each layer. The file for each layer are distinguished by “_L” + the layer number.

Parameters
  • out_dir (str) – Output directory to which the results should be written.

  • sample_num (int) – The sample number corresponding to the results, The default is 1.

  • suffix (str) – The suffix of the file that is being written. The default is “”.

Returns

Return type

None.