Function: summarize_and_plot_graph_and_distribution_structure_information

summarize_and_plot_graph_and_distribution_structure_information = 
    function (PU_spp_pair_indices, 
              cor_or_app_label, 
              all_correct_node_IDs,
              plot_output_dir, 
              spp_col_name, 
              PU_col_name, 
              presences_col_name)

Function: compute_network_measures_using_bipartite_package

compute_network_measures_using_bipartite_package = function (bpm)

Function: summarize_and_plot_graph_and_distribution_structure_information

compute_igraph_related_network_measures <- 
    function (
              num_spp, 
              num_PUs, 
              PU_spp_pair_indices, 
              emulatingTzar, 
              DEBUG_LEVEL, 
              network_output_dir, 
#              cor_num_PUs,   #  app_ ???
#              cor_num_spp,
              PU_col_name, 
              spp_col_name
              ) 

Function: create_PU_spp_pair_names

HAVEN'T DECODED THIS ONE YET. JUST LEAVING HERE WHAT I HAD CUT OUT OF THE CODE TO TRY TO FIGURE OUT WHETHER THERE SHOULD BE app_num_spp AND app_num_PUs AND WHAT WERE PU_spp_pair_names AND PU_spp_pair_names_triple.

REMEMBER THAT THE KEY IS THE FLAGGING OF top AND bottom. THEY ARE THE THINGS THAT INDICATE THE FACT THAT THIS IS A BIPARTITE NETWORK. THE True AND False VALUES IN THE VERTICES type INDICATE WHETHER A NODE IS PART OF THE top OR bottom HALF OF THE BIPARTITE NETWORK. PUs ARE top? SPECIES ARE bottom?

PU_spp_pair_names_triple = create_PU_spp_pair_names (cor_num_PUs,   #  app_ ???
                                                     cor_num_spp,  #  app_ ???
                                                     PU_spp_pair_indices, #  app_ ???
                                                     PU_col_name, 
                                                     spp_col_name
                                                     ) 
PU_spp_pair_names = PU_spp_pair_names_triple$PU_spp_pair_names
PU_vertex_names = PU_spp_pair_names_triple$PU_vertex_names
spp_vertex_names = PU_spp_pair_names_triple$spp_vertex_names

#  ...

vertices = data.frame (name=c(spp_vertex_names, PU_vertex_names), 
                     type=c(rep(FALSE, num_spp),
                            rep(TRUE, num_PUs)))

bg = graph.data.frame (PU_spp_pair_names, directed=FALSE, vertices=vertices)
bgp = bipartite.projection (bg)
bgp_proj1_PUs = bgp$proj1
bgp_proj2_spp = bgp$proj2

head(bg)
6 x 936 sparse Matrix of class "dgCMatrix"
   [[ suppressing 936 column names ‘s1’, ‘s2’, ‘s3’ ... ]]

s1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

...

s1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

s1 . . . . . . . . . . . . . . . 1 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s2 . . . . . . . . . . . . . . . . . 1 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s3 . . . . . . . . . . . . . . . . . . . 1 1 . . . . . . . . . . . . . . . . 1 . . . . . . . . .
s4 . . . . . . . . . . . . . . . . . . . . . 1 1 . . . . . . . . . . . . . . . . . . . . . . . .
s5 . . . . . . . . . . . . . . . . . . . . . . . 1 1 . . . . . . . . . . . . . . . . . . . . . .
s6 . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 . . . . . . . . . . . . . . . . . . . .

s1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

s1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
s6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

# Number of top and bottom nodes
top <- length(V(bg)[type==FALSE])
bottom <- length(V(bg)[type==TRUE])

vertices
    name  type
1     s1 FALSE
2     s2 FALSE
3     s3 FALSE
4     s4 FALSE
5     s5 FALSE
6     s6 FALSE
7     s7 FALSE
8     s8 FALSE
9     s9 FALSE
10   s10 FALSE
...
810 s810 FALSE
811 s811 FALSE
812 s812 FALSE
813 s813 FALSE
814 s814 FALSE
815   p1  TRUE
816   p2  TRUE
817   p3  TRUE
818   p4  TRUE
819   p5  TRUE
820   p6  TRUE
821   p7  TRUE
822   p8  TRUE
823   p9  TRUE
824  p10  TRUE
...
929 p115  TRUE
930 p116  TRUE
931 p117  TRUE
932 p118  TRUE
933 p119  TRUE
934 p120  TRUE
935 p121  TRUE
936 p122  TRUE

Function: set_up_for_and_run_marxan

marxan_control_values = set_up_for_and_run_marxan (
                            app_PU_spp_pair_indices,
                            PU_col_name, 
                            spp_col_name, 
                            current_os, 
                            marxan_input_dir, 
                            marxan_output_dir, 
                            parameters, 
                            marxan_IO_dir
                            )

                                                  )
cor_or_app_label:
"cor"
    retVal = list ()
    retVal$marxan_PROP           = marxan_PROP
    retVal$marxan_RANDSEED       = marxan_RANDSEED
    retVal$marxan_NUMREPS        = marxan_NUMREPS
    retVal$marxan_NUMITNS        = marxan_NUMITNS
    retVal$marxan_STARTTEMP      = marxan_STARTTEMP
    retVal$marxan_NUMTEMP        = marxan_NUMTEMP
    retVal$marxan_COSTTHRESH     = marxan_COSTTHRESH
    retVal$marxan_THRESHPEN1     = marxan_THRESHPEN1
    retVal$marxan_THRESHPEN2     = marxan_THRESHPEN2
    retVal$marxan_RUNMODE        = marxan_RUNMODE
    retVal$marxan_MISSLEVEL      = marxan_MISSLEVEL
    retVal$marxan_ITIMPTYPE      = marxan_ITIMPTYPE
    retVal$marxan_HEURTYPE       = marxan_HEURTYPE
    retVal$marxan_CLUMPTYPE      = marxan_CLUMPTYPE

spf_const = write_network_to_marxan_files (
                                        app_PU_spp_pair_indices,
                                        PU_col_name, 
                                        spp_col_name, 
                                        parameters, 
                                        marxan_input_dir, 
                                        marxan_output_dir
                                        ) 

marxan_control_values = 
    set_marxan_controls_and_run_marxan (current_os, 
                                    marxan_input_dir, 
                                    marxan_output_dir, 
                                    parameters, 
                                    marxan_IO_dir) 

create_nodes_data_structure = 
        function (tot_num_nodes, 
                  num_nodes_per_group, 
                  n__num_groups, 
                  num_independent_nodes_per_group)
        #------------------------------------------------------------
        #  Build an overall data frame that shows for each node, 
        #  its node ID and group ID, plus a flag indicating whether 
        #  it's in the dependent set or not.  For example, if there 
        #  are 3 nodes per group:
        #
        #       node_ID     group_ID       dependent_set_member
        #         1            1                 TRUE
        #         2            1                 TRUE
        #         3            1                 FALSE
        #         4            2                 TRUE
        #         5            2                 TRUE
        #         6            2                 FALSE
        #        ...          ...                 ...
        #------------------------------------------------------------

    nodes = data.frame (node_ID = node_IDs,
                        group_ID = group_IDs, 
                        dependent_set_member = dependent_set_members)

gen_single_bdprob = function (parameters, bdpg_error_codes, integerize)
retVal$read_Xu_problem_from_file = read_Xu_problem_from_file
retVal$PU_spp_pair_indices       = PU_spp_pair_indices_sextet$PU_spp_pair_indices 
retVal$PU_col_name               = PU_spp_pair_indices_sextet$PU_col_name
retVal$spp_col_name              = PU_spp_pair_indices_sextet$spp_col_name
retVal$num_PUs                   = PU_spp_pair_indices_sextet$num_PUs
retVal$num_spp                   = PU_spp_pair_indices_sextet$num_spp
retVal$cor_optimum_cost          = PU_spp_pair_indices_sextet$correct_solution_cost
retVal$PU_costs                  = PU_costs
retVal$derived_Xu_params = derived_Xu_params

retVal$prob_is_ok = TRUE
retVal$bpm = bpm    #  0/1 adjacency matrix of spp rows vs PU cols
retVal$nodes = nodes
        num_nodes_per_group                                        = derived_Xu_params$num_nodes_per_group
        num_rounds_of_linking_between_groups                       = derived_Xu_params$num_rounds_of_linking_between_groups
        target_num_links_between_2_groups_per_round                = derived_Xu_params$target_num_links_between_2_groups_per_round
        num_links_within_one_group                                 = derived_Xu_params$num_links_within_one_group
        tot_num_links_inside_groups                                = derived_Xu_params$tot_num_links_inside_groups
        max_possible_num_links_between_groups                      = derived_Xu_params$max_possible_num_links_between_groups
        max_possible_tot_num_links                                 = derived_Xu_params$max_possible_tot_num_links
        max_possible_tot_num_node_link_pairs                       = derived_Xu_params$max_possible_tot_num_node_link_pairs

        n__num_groups                                              = derived_Xu_params$n__num_groups
        alpha__                                                    = derived_Xu_params$alpha__
        p__prop_of_links_between_groups                            = derived_Xu_params$p__prop_of_links_between_groups
        r__density                                                 = derived_Xu_params$r__density
        num_independent_nodes_per_group                            = derived_Xu_params$num_independent_nodes_per_group
        num_independent_set_nodes                                  = derived_Xu_params$num_independent_set_nodes
        tot_num_nodes                                              = derived_Xu_params$tot_num_nodes
        num_dependent_set_nodes                                    = derived_Xu_params$num_dependent_set_nodes
        opt_solution_as_frac_of_tot_num_nodes                      = derived_Xu_params$opt_solution_as_frac_of_tot_num_nodes
        base_for_target_num_links_between_2_groups_per_round       = derived_Xu_params$base_for_target_num_links_between_2_groups_per_round
        at_least_1_for_target_num_links_between_2_groups_per_round = derived_Xu_params$at_least_1_for_target_num_links_between_2_groups_per_round
        nodes = create_nodes_data_structure (tot_num_nodes, 
                                              num_nodes_per_group, 
                                              n__num_groups, 
                                              num_independent_nodes_per_group 
                                             )
        edge_list = 
            create_Xu_graph (num_nodes_per_group, 
                             n__num_groups, 
                             nodes, 
                             max_possible_tot_num_links, 
                             target_num_links_between_2_groups_per_round, 
                             num_rounds_of_linking_between_groups, 
                             DEBUG_LEVEL
                             )
correct_solution_vector_is_known = TRUE
        dependent_node_IDs = get_dependent_node_IDs (nodes)
        num_PUs = get_num_nodes (nodes)
        PU_costs = get_PU_costs (num_PUs)
    #-------------------------------------------------------------    
    #  Combine the information in the nodes and edge_list data 
    #  structures into a single data structure that has one line 
    #  for each species on each planning unit (where species 
    #  are edges and PUs are nodes).
    #-------------------------------------------------------------    

PU_spp_pair_indices_sextet = create_PU_spp_pair_indices (edge_list, 
                                                          nodes, 
                                                          dependent_node_IDs, 
                                                          PU_costs, 
                                                         num_PUs) 

PU_spp_pair_indices  = PU_spp_pair_indices_sextet$PU_spp_pair_indices 
PU_col_name          = PU_spp_pair_indices_sextet$PU_col_name
spp_col_name         = PU_spp_pair_indices_sextet$spp_col_name
num_PUs              = PU_spp_pair_indices_sextet$num_PUs
num_spp              = PU_spp_pair_indices_sextet$num_spp
cor_optimum_cost     = PU_spp_pair_indices_sextet$correct_solution_cost


langfob/bdpg documentation built on Dec. 8, 2022, 5:33 a.m.