diff --git a/Project.toml b/Project.toml index 1243667..5caf2f0 100644 --- a/Project.toml +++ b/Project.toml @@ -5,9 +5,12 @@ version = "0.1.0" [deps] CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" +DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" +JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" +Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" [compat] julia = "1" diff --git a/data/associations.csv b/data/associations.csv new file mode 100644 index 0000000..6aa282a --- /dev/null +++ b/data/associations.csv @@ -0,0 +1,62 @@ +name,Liliaceae,Ail,Asperge,Ciboulette,Echalote,Oignon,Poireau,Fabaceae,Fève,Haricot,Pois,Apiaceae,Aneth,Carotte,Celeri,Cerfeuil,Fenouil,Panais,Persil,Solanaceae,Aubergine,Poivron,Pomme de terre,Tomate,Brassicaceae,Chou,Chou rave,Chou rouge,Navet,Radis,Cucurbitaceae,Concombre,Cornichon,Courge,Courgette,Melon,Potiron,Artichaut,Basilic,Bette,Betterave,Bourrache,Capucine,Cardon,Chicoree,Cresson,Epinard,Estragon,Fraisier,Laitue,Mâche,Maïs,Menthe,Oeillet d'inde,Sarriette,Sauge,Scorsonère,Souci,Tétragone,Thym,Tournesol +Liliaceae,,,,,,,,-2,,,,1,,,,,,,,-1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +Ail,,,-1,,,1,,-2,,-2,-2,,,1,,,,,,,,,1,1,,-1,,,1,,,1,,,,,,,,,1,,,,,,1,,1,1,1,,,,,,,1,,, +Asperge,,-1,,,-1,-1,1,,0,1,0,,,,,,,,1,,,,,1,,-1,,,,,,1,1,,,,,1,,-1,,,,,,,,,,,,,,,,,,,,, +Ciboulette,,,,,,,,,,,,,,1,,,,,,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,,,,,,,1,,,,,,,,,,,, +Scorsonère,,,,,,1,1,,,,,,,1,,,,,,,,,,,,,1,,,1,,,,,,,,,,,,,,,,,,,,1,,,,,,,,,,, +Souci,,1,,,,1,1,,,,,,,,,,,,,,,,1,1,,,,,,,,,,,,,,,,,,,,,1,,,,,,,,,,,,,,,, +Tétragone,,,,,,,,,,1,,,,,,,,,,,,,,1,,,,,,,,,,,1,,,,,,,,,,,,,,,,,,,,,,,,,, +Thym,,,,,,,,,,,,,,,,,,,,,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, +Tournesol,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,1,,,,,,,,,-1,,,,,-1,,,,,,,,,,, \ No newline at end of file diff --git a/data/classification.json b/data/classification.json new file mode 100644 index 0000000..47d1b6c --- /dev/null +++ b/data/classification.json @@ -0,0 +1,666 @@ +{ + "name": "God", + "type": "Life", + "children": [ + { + "name": "Aizoaceae", + "type": "Family", + "children": [ + { + "name": "Tetragonia", + "type": "Genus", + "children": [ + { + "name": "Tetragone", + "bio": "Tetragonia tetragonioides", + "type": "Species" + } + ] + } + ] + }, + { + "name": "Apiaceae", + "type": "Family", + "children": [ + { + "name": "Anethum", + "type": "Genus", + "children": [ + { + "name": "Aneth", + "type": "Species" + } + ] + }, + { + "name": "Anthriscus", + "type": "Genus", + "children": [ + { + "name": "Cerfeuil", + "type": "Species" + } + ] + }, + { + "name": "Apium", + "type": "Genus", + "children": [ + { + "name": "Celeri", + "type": "Species" + } + ] + }, + { + "name": "Coriandrum", + "type": "Genus", + "children": [ + { + "name": "Coriandre", + "type": "Species" + } + ] + }, + { + "name": "Daucus", + "type": "Genus", + "children": [ + { + "name": "Carotte", + "type": "Species" + } + ] + }, + { + "name": "Foeniculum", + "type": "Genus", + "children": [ + { + "name": "Fenouil", + "type": "Species" + } + ] + }, + { + "name": "Pastinaca", + "type": "Genus", + "children": [ + { + "name": "Panais", + "type": "Species" + } + ] + }, + { + "name": "Petroselinum", + "type": "Genus", + "children": [ + { + "name": "Persil", + "type": "Species" + } + ] + } + ] + }, + { + "name": "Asteraceae", + "type": "Family", + "children": [ + { + "name": "Artemisia", + "type": "Genus", + "children": [ + { + "name": "Estragon", + "bio": "Artemisia dracunculus", + "type": "Species" + } + ] + }, + { + "name": "Calendula", + "type": "Genus", + "children": [ + { + "name": "Souci", + "bio": "Calendula officinalis", + "type": "Species" + } + ] + }, + { + "name": "Chicoree", + "bio": "Cichorium", + "type": "Genus" + }, + { + "name": "Cynara", + "type": "Genus", + "children": [ + { + "name": "Cardon", + "bio": "Cynara cardunculus", + "type": "Species", + "children": [ + { + "name": "Artichaut", + "type": "Variety" + } + ] + } + ] + }, + { + "name": "Helianthus", + "type": "Genus", + "children": [ + { + "name": "Tournesol", + "bio": "Helianthus annuus", + "type": "Species" + } + ] + }, + { + "name": "Lactuca", + "type": "Genus", + "children": [ + { + "name": "Laitue", + "bio": "Lactuca sativa", + "type": "Species", + "children": [ + { + "name": "Batavia", + "type": "Variety" + } + ] + } + ] + }, + { + "name": "Scorsonere", + "bio": "Scorzonera", + "type": "Genus" + }, + { + "name": "Tagetes", + "type": "Genus", + "children": [ + { + "name": "Oeillet d'inde", + "bio": "Tagetes patula", + "type": "Species" + } + ] + } + ] + }, + { + "name": "Boraginaceae", + "type": "Family", + "children": [ + { + "name": "Borago", + "type": "Genus", + "chlidren": [ + { + "name": "Bourrache", + "bio": "Borago officinalis", + "type": "Species" + } + ] + } + ] + }, + { + "name": "Brassicaceae", + "type": "Family", + "children": [ + { + "name": "Brassica", + "type": "Genus", + "children": [ + { + "name": "Chou", + "bio": "Brassica oleracea", + "type": "Species", + "children": [ + { + "name": "Brocoli", + "type": "Variety" + }, + { + "name": "Chou cabus", + "type": "Variety" + } + ] + }, + { + "name": "Brassica rapa", + "type": "Species", + "children": [ + { + "name": "Navet", + "type": "Variety" + } + ] + } + ] + }, + { + "name": "Eruca", + "type": "Genus", + "children": [ + { + "name": "Roquette", + "bio": "Eruca sativa", + "type": "Species" + } + ] + }, + { + "name": "Nasturtium", + "type": "Genus", + "children": [ + { + "name": "Cresson", + "bio": "Nasturtium officinale", + "type": "Species" + } + ] + }, + { + "name": "Raphanus", + "type": "Genus", + "children": [ + { + "name": "Radis", + "type": "Species" + } + ] + }, + { + "name": "Sinapis", + "type": "Genus", + "children": [ + { + "name": "Moutarde", + "bio": "Sinapis alba", + "type": "Species" + } + ] + } + ] + }, + { + "name": "Chenopodiaceae", + "type": "Family", + "children": [ + { + "name": "Atriplex", + "type": "Genus", + "children": [ + { + "name": "Arroche", + "bio": "Atriplex hortensis", + "type": "Species" + } + ] + }, + { + "name": "Beta", + "type": "Genus", + "children": [ + { + "name": "Beta vulgaris", + "type": "Species", + "children": [ + { + "name": "Bette", + "type": "Variety" + }, + { + "name": "Betterave", + "type": "Variety" + } + ] + } + ] + }, + { + "name": "Spinacia", + "type": "Genus", + "children": [ + { + "name": "Epinard", + "type": "Species" + } + ] + } + ] + }, + { + "name": "Cucurbitaceae", + "type": "Family", + "children": [ + { + "name": "Cucumis", + "type": "Genus", + "children": [ + { + "name": "Melon", + "bio": "Cucumis melo", + "type": "Species" + }, + { + "name": "Cucumis sativus", + "type": "Species", + "children": [ + { + "name": "Concombre", + "type": "Variety" + }, + { + "name": "Cornichon", + "type": "Variety" + } + ] + } + ] + }, + { + "name": "Courge", + "bio": "Cucurbita", + "type": "Genus", + "children": [ + { + "name": "Potiron", + "bio": "Cucurbita maxima", + "type": "Species", + "children": [ + { + "name": "Potimarron", + "type": "Variety" + } + ] + }, + { + "name": "Courge musquée", + "bio": "Cucurbita moschata", + "type": "Species", + "children": [ + { + "name": "Butternut", + "type": "Variety" + } + ] + }, + { + "name": "Cucurbita pepo", + "type": "Species", + "children": [ + { + "name": "Courgette", + "type": "Variety" + }, + { + "name": "Patisson", + "bio": "Ovifera", + "type": "Variety" + } + ] + } + ] + } + ] + }, + { + "name": "Fabaceae", + "type": "Family", + "children": [ + { + "name": "Phaseolus", + "type": "Genus", + "children": [ + { + "name": "Haricot", + "type": "Species" + } + ] + }, + { + "name": "Pisum", + "type": "Genus", + "children": [ + { + "name": "Pois", + "type": "Species" + } + ] + }, + { + "name": "Vicia", + "type": "Genus", + "children": [ + { + "name": "Fève", + "type": "Species" + } + ] + } + ] + }, + { + "name": "Lamiaceae", + "type": "Family", + "children": [ + { + "name": "Lavande", + "bio": "Lavandula", + "type": "Genus" + }, + { + "name": "Menthe", + "bio": "Mentha", + "type": "Genus" + }, + { + "name": "Ocimum", + "type": "Genus", + "children": [ + { + "name": "Basilic", + "type": "Species" + } + ] + }, + { + "name": "Salvia", + "type": "Genus", + "children": [ + { + "name": "Sauge", + "bio": "Salvia officinalis", + "type": "Species" + } + ] + }, + { + "name": "Sarriette", + "bio": "Satureja", + "type": "Genus" + }, + { + "name": "Thym", + "bio": "Thymus", + "type": "Genus" + } + ] + }, + { + "name": "Liliaceae", + "type": "Family", + "children": [ + { + "name": "Allium", + "type": "Genus", + "children": [ + { + "name": "Ail", + "type": "Species" + }, + { + "name": "Allium cepa", + "type": "Species", + "children": [ + { + "name": "Echalote", + "type": "Variety" + }, + { + "name": "Oignon", + "type": "Variety", + "children": [ + { + "name": "Oignon blanc", + "type": "Variety" + } + ] + } + ] + }, + { + "name": "Ciboulette", + "type": "Species" + }, + { + "name": "Poireau", + "type": "Species" + } + ] + }, + { + "name": "Asparagus", + "type": "Genus", + "children": [ + { + "name": "Asperge", + "type": "Species" + } + ] + } + ] + }, + { + "name": "Poaceae", + "type": "Family", + "children": [ + { + "name": "Zea", + "type": "Genus", + "children": [ + { + "name": "Mais", + "bio": "Zea mays", + "type": "Species" + } + ] + } + ] + }, + { + "name": "Rosaceae", + "type": "Family", + "children": [ + { + "name": "Fraisier", + "bio": "Fragaria", + "type": "Genus" + } + ] + }, + { + "name": "Solanaceae", + "type": "Family", + "children": [ + { + "name": "Capsicum", + "type": "Genus", + "children": [ + { + "name": "Poivron", + "type": "Species" + } + ] + }, + { + "name": "Solanum", + "type": "Genus", + "children": [ + { + "name": "Aubergine", + "type": "Species" + }, + { + "name": "Pomme de terre", + "type": "Species" + }, + { + "name": "Tomate", + "type": "Species" + } + ] + } + ] + }, + { + "name": "Tropaeolaceae", + "type": "Family", + "children": [ + { + "name": "Tropaeolum", + "type": "Genus", + "children": [ + { + "name": "Capucine", + "bio": "Tropaeolum majus", + "type": "Species" + } + ] + } + ] + }, + { + "name": "Valerianaceae", + "type": "Family", + "children": [ + { + "name": "Valerianella", + "type": "Genus", + "children": [ + { + "name": "Mâche", + "bio": "Valerianella locusta", + "type": "Species" + } + ] + } + ] + }, + { + "name": "Vitaceae", + "type": "Family", + "children": [ + { + "name": "Vigne", + "bio": "Vitis", + "type": "Genus" + } + ] + } + ] +} diff --git a/data/plants.csv b/data/plants.csv new file mode 100644 index 0000000..d1d1fe5 --- /dev/null +++ b/data/plants.csv @@ -0,0 +1,59 @@ +name,count +agretti,2 +ail,0 +aneth,2 +arroche,2 +artichaut,0 +asperge,0 +aubergine,0 +basilic,2 +bette,3 +betterave,3 +capucine,0 +cardon,12 +carotte,6 +celeri,3 +cerfeuil,0 +chicoree,3 +chou rave,0 +chou rouge,0 +chou,6 +ciboulette,0 +concombre,9 +coriandre,2 +cornichon,0 +courgette,16 +cresson,0 +cucurbita,0 +echalote,0 +epinard,0 +fenouil,3 +feve,0 +fraisier,0 +haricot,19 +laitue,12 +lavande,0 +mais,6 +melon,0 +menthe,0 +navet,6 +oeillet d'inde,2 +oignon blanc,3 +oignon,12 +panais,6 +patisson,5 +persil,3 +poireau,12 +pois,12 +poivron,0 +pomme de terre,0 +radis,6 +roquette,2 +sarriette,2 +sauge,0 +scorsonere,3 +souci,2 +tomate,19 +tournesol,2 +tetragone,3 +vigne,0 diff --git a/src/GardenOptim.jl b/src/GardenOptim.jl index 7daf82b..d74f01a 100644 --- a/src/GardenOptim.jl +++ b/src/GardenOptim.jl @@ -1,11 +1,16 @@ module GardenOptim -using DocStringExtensions using Logging +using Unicode + +using DataFrames +using DocStringExtensions using CSV +using JSON using Tables -export loadplants, loadgarden, loadcosts, update!, randomgardenevolution!, outputgarden +export loadclassification, loadplants, loadgarden, loadcosts +export update!, randomgardenevolution!, outputgarden @template (FUNCTIONS, METHODS, MACROS) = """ @@ -13,9 +18,36 @@ export loadplants, loadgarden, loadcosts, update!, randomgardenevolution!, outpu $(DOCSTRING) """ -function loadplants()::Vector{String} - plants = readlines("data/plants.txt") - @info "loaded $(length(plants)) plants" +mutable struct Classification + type::Symbol + name::Symbol + bio::String + children::Vector{Classification} + parent::Classification + + function Classification(classif::Dict{String, Any}) + children = [Classification(d) for d in get(classif, "children", [])] + type = Symbol(Unicode.normalize(classif["type"], casefold=true, stripmark=true)) + name = Symbol(Unicode.normalize(classif["name"], casefold=true, stripmark=true)) + classif = new(type, name, get(classif, "bio", ""), children) + for child in children + child.parent = classif + end + classif + end +end + +function loadclassification() + clf = JSON.parsefile("data/classification.json") + clf = Classification(clf) + @debug "loaded classification of type $(clf.type)" + clf +end + +function loadplants()::DataFrame + plants = CSV.read("data/plants.csv") + @info "loaded $(size(plants, 1)) plants" + plants.name = Symbol.(plants.name) plants end @@ -30,13 +62,67 @@ function loadgarden(plants::Vector{String})::Tuple{Matrix{Int}, Matrix{Bool}} garden, mask end -function loadcosts()::Matrix{Float64} - df = CSV.read("data/costs.csv") - df = coalesce.(df, 0) # replace missing values by 0 - costs = convert(Matrix, df[:, 2:end]) - @info "loaded cost matrix of size $(size(costs))" - # ensure the matrix is symmetric: keep the max of itself and its transpose - costs = Float64.(max.(costs, permutedims(costs))) +function loadcosts()::DataFrame + df = CSV.read("data/associations.csv", copycols=true) + colnames = String.(names(df)) + colnames = Symbol.(Unicode.normalize.(colnames, casefold=true, stripmark=true)) + rename!(df, colnames) + df.name = colnames[2:end] + # df = coalesce.(df, 0.0) + @info "loaded cost matrix for $(size(df, 1)) plants" + df +end + +# function loadcosts()::Matrix{Float64} +# df = CSV.read("data/costs.csv") +# df = coalesce.(df, 0) # replace missing values by 0 +# costs = convert(Matrix, df[:, 2:end]) +# @info "loaded cost matrix of size $(size(costs))" +# # ensure the matrix is symmetric: keep the max of itself and its transpose +# costs = Float64.(max.(costs, permutedims(costs))) +# end + +function getparent(name::Symbol, classification::Classification) + if classification.name == name + return classification.parent + else + for child in classification.children + parent = getparent(name, child) + if !isnothing(parent) + return parent + end + end + end +end + +function computecost(costs::DataFrame, plant1::Symbol, plant2::Symbol, classification::Classification)::Float64 + @debug "$plant1 and $plant2" + if plant1 in names(costs) && plant2 in names(costs) + cost = costs[costs.name .== plant1, plant2][1] + else + @debug "$plant1 and $plant2 not in costs" + cost = missing + end + + if !ismissing(cost) + return cost + end + + @debug "missing" + try + parent1 = getparent(plant1, classification).name + computecost(costs, parent1, plant2, classification) + catch UndefRefError + return missing + end + + try + parent2 = getparent(plant2, classification).name + computecost(costs, plant1, parent2, classification) + catch UndefRefError + return missing + end + end "Return a random index to be filled from the garden mask."