Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- 'nightly'
- '1.10'
os:
- ubuntu-latest
arch:
Expand All @@ -33,10 +32,4 @@ jobs:
- uses: julia-actions/cache@v1
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v2
with:
files: lcov.info
- uses: julia-actions/julia-uploadcoveralls@v1
env:
COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }}

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ using Plots
using JuMP
using Test

using BARON
#using BARON

#exportall(CompHENS)

Expand Down Expand Up @@ -43,13 +43,13 @@ obj_func = CostScaledPaterson()
base_cost, cost_coeff, scaling_coeff = 4000, 500, 0.83

# 7.i. Commercial using BARON:
optimizer = optimizer_with_attributes(BARON.Optimizer, "MaxTime" => 20.0, "AbsConFeasTol" => 1)
#= optimizer = optimizer_with_attributes(BARON.Optimizer, "MaxTime" => 20.0, "AbsConFeasTol" => 1)
results_df = generate_network!(prob, EMAT; optimizer = optimizer, obj_func = obj_func, verbose = true, cost_coeff = cost_coeff, scaling_coeff = scaling_coeff, base_cost = base_cost, save_model = true)

model = prob.results_dict[:network_gen_model]
file_name = "/home/avinash/Desktop/COMPHENS/CompHENS.jl/Examples/XLSX_interface/ClassicHENSProblem/Gundersen_4_stream/Gundersen_4_stream.pdf"

plot_HEN_streamwise(prob, model, overall_network, file_name; digits = 1)
plot_HEN_streamwise(prob, model, overall_network, file_name; digits = 1) =#

#=Trials
#CompHENS.
Expand Down
15 changes: 9 additions & 6 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ authors = ["Avinash Subramanian"]
version = "0.1.4"

[deps]
BARON = "2e2ca445-9e14-5b13-8677-4410f177f82b"
Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Expand All @@ -15,11 +14,16 @@ Kwonly = "18d08c8c-0732-55ee-a446-91a51d7b4206"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
NamedArrays = "86f7a689-2022-50b4-a561-43c23ac3c673"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
XLSX = "fdbf4ff8-1666-58a4-91e7-1b58723a45e0"

[weakdeps]
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"

[extensions]
CompHENSNetworkXPlotsExt = "PyCall"

[compat]
BARON = "0.8"
Conda = "1"
DataFrames = "1"
DocStringExtensions = "0.9"
HiGHS = "1"
Expand All @@ -29,10 +33,9 @@ Kwonly = "0.1"
MathOptInterface = "1"
NamedArrays = "0.9"
Plots = "1"
XLSX = "0.8, 0.9"
julia = "1.6"
PyCall = "1"
Conda = "1"
XLSX = "0.8, 0.9"
julia = "1.10"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
156 changes: 156 additions & 0 deletions ext/CompHENSNetworkXPlotsExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
module CompHENSNetworkXPlotsExt

using CompHENS
using PyCall
using Conda

const nx = PyNULL()
const plt = PyNULL()
const back_pdf = PyNULL()


function __init__()
copy!(nx, pyimport_conda("networkx", "networkx"))
copy!(plt, pyimport_conda("matplotlib.pyplot", "matplotlib"))
copy!(back_pdf, pyimport_conda("matplotlib.backends.backend_pdf", "matplotlib"))
end

"""
$(TYPEDSIGNATURES)
The visualization tools for the HEN uses the Python `NetworkX` and `MatPlotlib` packages.
By default, OS-X and Windows users should PyCall configured to use the Miniconda environment installed at `.julia/conda/` (this can be attained by calling `Conda.ROOTENV`).
For Linux users: By default the default system installation is used, and it is necessary to over-ride this as follows:
- Set
```
ENV["PYTHON"]=""
using Pkg
Pkg.build("PyCall")
```
Then **restart** the Julia process.
"""
function CompHENS.plot_HEN_streamwise(prob::ClassicHENSProblem, model::AbstractModel, overall_network::Dict{String, AbstractSuperstructure}, file_name; digits = 1)
__init__()
pdf = CompHENS.back_pdf.PdfPages(file_name)
for stream in prob.all_names
plt.close()
(g, edge_labels, node_labels, position, node_size) = get_stream_graph(prob.all_dict[stream], prob, model, overall_network[stream]; digits = digits)
nx.draw_networkx(g, position, node_size = node_size, with_labels=false, arrowstyle="->", node_shape = "s")
nx.draw_networkx_labels(g, position, labels = node_labels, font_size = 3, horizontalalignment = "left", verticalalignment = "top")
nx.draw_networkx_edge_labels(g, position, edge_labels = edge_labels, horizontalalignment = "center", verticalalignment = "center", font_size = 2, rotate=false)
pdf.savefig()
end
pdf.close()
end

"""


Gets a NetworkX Digraph for each stream
Returns: (g, edge_labels, node_labels, position, node_size)
"""
function CompHENS.get_stream_graph(stream::AbstractStream, prob::ClassicHENSProblem, model::AbstractModel, superstructure::AbstractSplitSuperstructure; digits = 1)
g = nx.DiGraph()
edge_labels = Dict()
node_labels = Dict()

# Add nodes to NetworkX graph
for node in superstructure.nodes
g.add_node(node.name)
if node isa HX
match = node.match
if stream isa HotStream
node_labels[node.name] = "match: $(match), Q = $(round((prob.results_dict[:Q][match, stream.name]), digits = digits))"
elseif stream isa ColdStream
node_labels[node.name] = "match: $(match), Q = $(round((prob.results_dict[:Q][stream.name, match]), digits = digits))"
end
end
end

# Only add edges if f_edge is greater than 0
for edge in superstructure.edges
if value(model[:f][(stream.name, edge)]) > 0.0
g.add_edge(edge.in.name, edge.out.name)
edge_labels[(edge.in.name, edge.out.name)] = "m: $(round(value(model[:f][(stream.name, edge)]); digits = digits)) T: $(round(value(model[:t][(stream.name, edge)]); digits = digits))"
end
end

num_matches = length(prob.results_dict[:HLD_list][stream.name])
# Copied from SeqHENS.jl
# Setting the coordinates of the nodes
position = Dict()
coordinates = [] # Array to keep pushing paired coordinates to, will then go through and assign to dictionary
bfix = 0.4 # Determines the vertical spacing

push!(coordinates, (0,0))
push!(coordinates, (1,0))
for e in 1:num_matches
push!(coordinates,(2,0-(bfix*(e-1))))
push!(coordinates,(5,0-(bfix*(e-1))))
push!(coordinates,(9,0-(bfix*(e-1))))
end
push!(coordinates,(10,0))
push!(coordinates,(11,0))

i = 0 # hack for now
for node in superstructure.nodes
i += 1
position[node.name] = coordinates[i]
end

node_size = fill(1.0, length(superstructure.nodes))
return(g, edge_labels, node_labels, position, node_size)
end

function CompHENS.get_stream_graph(stream::AbstractUtility, prob::ClassicHENSProblem, model::AbstractModel, superstructure::AbstractSplitSuperstructure; digits = 1)
g = nx.DiGraph()
edge_labels = Dict()
node_labels = Dict()

# Add nodes to NetworkX graph
for node in superstructure.nodes
g.add_node(node.name)
if node isa HX
match = node.match
if stream isa HotStream
node_labels[node.name] = "o: $(match), Q = $(round((prob.results_dict[:Q][match, stream.name]), digits = digits))"
elseif stream isa ColdStream
node_labels[node.name] = "o: $(match), Q = $(round((prob.results_dict[:Q][stream.name, match]), digits = digits))"
end
end
end

# Only add edges if f_edge is greater than 0
for edge in superstructure.edges
if edge.in isa HX || edge.out isa HX # Only care about edges attached to HX
g.add_edge(edge.in.name, edge.out.name)
edge_labels[(edge.in.name, edge.out.name)] = "T: $(round(value(model[:t][(stream.name, edge)]); digits = digits))"
end
end

num_matches = length(prob.results_dict[:HLD_list][stream.name])
# Copied from SeqHENS.jl
# Setting the coordinates of the nodes
position = Dict()
coordinates = [] # Array to keep pushing paired coordinates to, will then go through and assign to dictionary
bfix = 0.4 # Determines the vertical spacing

push!(coordinates, (0,0))
push!(coordinates, (1,0))
for e in 1:num_matches
push!(coordinates,(2,0-(bfix*(e-1))))
push!(coordinates,(5,0-(bfix*(e-1))))
push!(coordinates,(9,0-(bfix*(e-1))))
end
push!(coordinates,(10,0))
push!(coordinates,(11,0))

i = 0 # hack for now
for node in superstructure.nodes
i += 1
position[node.name] = coordinates[i]
end

node_size = fill(1.0, length(superstructure.nodes))
return(g, edge_labels, node_labels, position, node_size)
end
end
2 changes: 1 addition & 1 deletion src/CompHENS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ include("Superstructures/ParallelSplit.jl")
export generate_network!, postprocess_network!, plot_HEN_streamwise, print_stream_results, get_design_area, AreaArithmeticMean, AreaPaterson, CostScaledPaterson, get_stream_graph
include("SubProblems/Network_generation/network_generator_JuMP.jl")
include("SubProblems/Network_generation/network_postprocess.jl")
include("SubProblems/Network_generation/conda_networkx_plots.jl")
#include("SubProblems/Network_generation/conda_networkx_plots.jl")



Expand Down
1 change: 1 addition & 0 deletions src/Streams/streams.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ mutable struct ColdStream <: AbstractStream
T_in <= T_out || error("Supply and Target temperature don't match stream type")
mcp >= 0.0 || error("mcp values negative") # Can be zero if stream doesn't exist in one period.
h > smallest_value || error("values infeasible")
push!(add_user_data, "Working Terminal T" => T_out)
new(name, Float64(T_in), Float64(T_out), Float64(mcp), Float64(h), add_user_data, calc)
end
end
Expand Down
Loading