########## 
##########
# Create series of networks to run through simulations
##########
##########
# AUTHOR: Cole B. Brookson
# DATE OF CREATION: 2021-12-04
##########
##########

# set up =======================================================================

# set packages
using DelimitedFiles

include("../01_species_list_creation.jl")

# create different combinations of networks ====================================

# the different values that have different options are:
#   richness shape
#   biomass shape

# set all positional values 
organism_id_pos = 1
organism_type_pos = 2
body_size_pos = 3
lower_prey_limit_pos = 4
upper_prey_limit_pos = 5
habitat_midpoint_pos = 6
habitat_lower_limit_pos = 7
habitat_upper_limit_pos = 8
nutritional_value_pos = 9
biomass_pos = 10
network_id_pos = 11
alive_pos = 12 

# set parameters
n = 50
richness_shape = "top-heavy"
species_list, network = network_draw(n, richness_shape)
# draw species list 
species_list = define_species_list(n, richness_shape)

# test create_interaction_matrix()
interaction_matrix = fill(0, (size(species_list, 1), size(species_list, 1)))
    for i in 1:size(interaction_matrix)[1] #rows
        for j in 1:size(interaction_matrix)[2] #cols
            interaction_matrix[i,j] = determine_interaction(j, i, species_list)
        end
    end
    return interaction_matrix
interaction_matrix = create_interaction_matrix(species_list)
sums = minimum(sum(interaction_matrix, dims = 2) + 
            (sum(interaction_matrix, dims = 1)'))
if sums == 0
    # go through while loop to re-draw until connected
    connect_acomplish = false
    connected_counter = 0
    while connect_acomplish == false
        connected_counter += 1
        # draw species list 
        species_list = define_species_list(n, richness_shape)
        interaction_matrix = create_interaction_matrix(species_list)
        
        # turn into graph
        sums = minimum(sum(interaction_matrix, dims = 2) + 
            (sum(interaction_matrix, dims = 1)'))
        if sums == 0
            continue 
        end 

        if sums > 0 
            connect_acomplish = true 
        end 
    end
end 
return species_list, interaction_matrix