From 426707af1f7c39662172f7d3f2e0ccf271271ba6 Mon Sep 17 00:00:00 2001 From: louis-gautier Date: Thu, 14 Apr 2022 10:19:26 -0400 Subject: [PATCH 1/3] Fixed error "failed to convert from nohing to real" when storedata is called --- src/metrics/basicmetrics/dataframes.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/metrics/basicmetrics/dataframes.jl b/src/metrics/basicmetrics/dataframes.jl index 27640c3..be0767a 100644 --- a/src/metrics/basicmetrics/dataframes.jl +++ b/src/metrics/basicmetrics/dataframes.jl @@ -26,15 +26,15 @@ function storedata(metrics::AbstractMetrics; filename::String="") :Nodes => metrics.meanNodeVisitedUntilEnd[i], :Time => metrics.timeneeded[i], :Score => missing, - :Reward => isnothing(metrics.totalReward) ? missing : metrics.totalReward[i], - :Loss => isnothing(metrics.loss) ? missing : metrics.loss[i] + :Reward => isnothing(metrics.totalReward) || isnothing(metrics.totalReward[i]) ? missing : metrics.totalReward[i], + :Loss => isnothing(metrics.loss) || isnothing(metrics.loss[i]) ? missing : metrics.loss[i] ) push!(df, episodeData) for j = 1:length(metrics.nodeVisited[i]) solutionData = copy(episodeData) solutionData[:Solution] = j solutionData[:Nodes] = metrics.nodeVisited[i][j] - solutionData[:Score] = isnothing(metrics.scores) ? missing : metrics.scores[i][j] + solutionData[:Score] = isnothing(metrics.scores) || isnothing(metrics.scores[i]) || isnothing(metrics.scores[i][j]) ? missing : metrics.scores[i][j] push!(df, solutionData) end end @@ -62,15 +62,15 @@ function storedata(metrics::Vector{<:AbstractMetrics}; filename::String="") :Nodes => metrics[j].meanNodeVisitedUntilEnd[i], :Time => metrics[j].timeneeded[i], :Score => missing, - :Reward => isnothing(metrics[j].totalReward) ? missing : metrics[j].totalReward[i], - :Loss => isnothing(metrics[j].loss) ? missing : metrics[j].loss[i] + :Reward => isnothing(metrics[j].totalReward) || isnothing(metrics[j].totalReward[i]) ? missing : metrics[j].totalReward[i], + :Loss => isnothing(metrics[j].loss) || isnothing(metrics[j].loss[i]) ? missing : metrics[j].loss[i] ) push!(df, episodeData) for k = 1:length(metrics[j].nodeVisited[i]) solutionData = copy(episodeData) solutionData[:Solution] = k solutionData[:Nodes] = metrics[j].nodeVisited[i][k] - solutionData[:Score] = isnothing(metrics[j].scores) ? missing : metrics[j].scores[i][k] + solutionData[:Score] = isnothing(metrics[j].scores) || isnothing(metrics[j].scores[i]) || isnothing(metrics[j].scores[i][k]) ? missing : metrics[j].scores[i][k] push!(df, solutionData) end end From e2c7dff04b33b9e5f784540584b5c77ff88f79eb Mon Sep 17 00:00:00 2001 From: louis-gautier Date: Tue, 3 May 2022 17:38:17 -0400 Subject: [PATCH 2/3] Made tripartite graph plot functional again --- Project.toml | 9 ++++--- .../tripartite/tripartite.jl | 25 ++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/Project.toml b/Project.toml index e3d5682..3263166 100644 --- a/Project.toml +++ b/Project.toml @@ -1,18 +1,21 @@ name = "SeaPearlExtras" uuid = "90978a9a-af5e-4113-9033-e3aa0a1ac968" -authors = ["PierreTsr ","3rdCore "] +authors = ["PierreTsr ", "3rdCore "] version = "0.1.0" - [deps] BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0" CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" +Cairo = "159f3aea-2a34-519c-b102-8c37f9878175" +Compose = "a81c6b42-2e10-5240-aca2-a61377ecd94b" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4" GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71" GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231" +Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6" +LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" SeaPearl = "c13076dc-bdcd-48ba-bc88-4b44c2587ab3" [compat] -julia = "1.6 - 1.7" \ No newline at end of file +julia = "1.6 - 1.7" diff --git a/src/staterepresentation/tripartite/tripartite.jl b/src/staterepresentation/tripartite/tripartite.jl index 9bd770b..c7657c0 100644 --- a/src/staterepresentation/tripartite/tripartite.jl +++ b/src/staterepresentation/tripartite/tripartite.jl @@ -1,16 +1,29 @@ -using SeaPearl: DefaultStateRepresentation, VariableVertex, ValueVertex +using SeaPearl: DefaultStateRepresentation, VariableVertex, ValueVertex, adjacency_matrix +using Graphs +using Cairo, Compose function plottripartite(sr::DefaultStateRepresentation) cpmodel = sr.cplayergraph + am = Matrix(adjacency_matrix(cpmodel)) n = cpmodel.totalLength nodefillc = [] + label = [] for id in 1:n v = cpmodel.idToNode[id] - if isa(v, VariableVertex) push!(nodefillc,"red") - elseif isa(v, ValueVertex) push!(nodefillc,"blue") - else push!(nodefillc,"black") end + if isa(v, VariableVertex) + push!(nodefillc,"red") + push!(label,v.variable.id) + elseif isa(v, ValueVertex) + push!(nodefillc,"blue") + push!(label,v.value) + else + push!(nodefillc,"black") + push!(label,typeof(v.constraint)) + end + end - gplot(cpmodel;nodefillc=nodefillc) + draw(PDF("test.pdf", 16cm, 16cm), gplot(Graphs.Graph(am); nodefillc=nodefillc, nodelabel=label)) + error("Your plot is ready") end -export plottripartite +export plottripartite, plottripartite2 \ No newline at end of file From 1651a141a9ba5d493d902fceecc6034147f231a8 Mon Sep 17 00:00:00 2001 From: louis-gautier Date: Wed, 18 May 2022 17:48:24 -0400 Subject: [PATCH 3/3] Update plottripartite util --- src/staterepresentation/tripartite/tripartite.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/staterepresentation/tripartite/tripartite.jl b/src/staterepresentation/tripartite/tripartite.jl index c7657c0..71955eb 100644 --- a/src/staterepresentation/tripartite/tripartite.jl +++ b/src/staterepresentation/tripartite/tripartite.jl @@ -1,8 +1,8 @@ -using SeaPearl: DefaultStateRepresentation, VariableVertex, ValueVertex, adjacency_matrix +using SeaPearl: DefaultStateRepresentation, VariableVertex, ValueVertex, adjacency_matrix, HeterogeneousStateRepresentation using Graphs using Cairo, Compose -function plottripartite(sr::DefaultStateRepresentation) +function plottripartite(sr::Union{DefaultStateRepresentation, HeterogeneousStateRepresentation}) cpmodel = sr.cplayergraph am = Matrix(adjacency_matrix(cpmodel)) n = cpmodel.totalLength @@ -17,7 +17,7 @@ function plottripartite(sr::DefaultStateRepresentation) push!(nodefillc,"blue") push!(label,v.value) else - push!(nodefillc,"black") + push!(nodefillc,"black") push!(label,typeof(v.constraint)) end