From 72e49313c96ccee5a5a65e0bb1769456ac8b9c8d Mon Sep 17 00:00:00 2001 From: "Alinson S. Xavier" Date: Fri, 12 Apr 2024 09:44:14 -0500 Subject: [PATCH] model-3: solve: accept filename and optimizer --- Manifest.toml | 58 +++++++++++++++++++++++++++++++++------------------ Project.toml | 1 + model-3.jl | 22 ++++++++++--------- 3 files changed, 51 insertions(+), 30 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index a032d8c..eba600e 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -1,8 +1,8 @@ # This file is machine-generated - editing it directly is not advised -julia_version = "1.9.0" +julia_version = "1.10.1" manifest_format = "2.0" -project_hash = "6050446040717864eaea84cf3a5f066d959d36dd" +project_hash = "4170463ca454c6921d0f3b304e50e00eea5e30ba" [[deps.ArgTools]] uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" @@ -74,7 +74,7 @@ weakdeps = ["Dates", "LinearAlgebra"] [[deps.CompilerSupportLibraries_jll]] deps = ["Artifacts", "Libdl"] uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" -version = "1.0.2+0" +version = "1.1.0+0" [[deps.CoordinateTransformations]] deps = ["LinearAlgebra", "StaticArrays"] @@ -189,6 +189,18 @@ git-tree-sha1 = "5995b72d385235f3fe55f8f0c4ad61049f867814" uuid = "2e9cd046-0924-5485-92f1-d5272153d98b" version = "1.2.1" +[[deps.HiGHS]] +deps = ["HiGHS_jll", "MathOptInterface", "PrecompileTools", "SparseArrays"] +git-tree-sha1 = "a216e32299172b83abfe699604584f413ffbb045" +uuid = "87dc4568-4c63-4d18-b0c0-bb2238e4078b" +version = "1.9.0" + +[[deps.HiGHS_jll]] +deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Zlib_jll"] +git-tree-sha1 = "9a550d55c49334beb538c5ad9504f07fc29a13dc" +uuid = "8fd58aa0-07eb-5a78-9b36-339c94fd15ea" +version = "1.7.0+0" + [[deps.InlineStrings]] deps = ["Parsers"] git-tree-sha1 = "9cc2baf75c6d09f9da536ddf58eb2f29dedaf461" @@ -256,21 +268,26 @@ uuid = "4af54fe1-eca0-43a8-85a7-787d91b784e3" [[deps.LibCURL]] deps = ["LibCURL_jll", "MozillaCACerts_jll"] uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" -version = "0.6.3" +version = "0.6.4" [[deps.LibCURL_jll]] deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" -version = "7.84.0+0" +version = "8.4.0+0" [[deps.LibGit2]] -deps = ["Base64", "NetworkOptions", "Printf", "SHA"] +deps = ["Base64", "LibGit2_jll", "NetworkOptions", "Printf", "SHA"] uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" +[[deps.LibGit2_jll]] +deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll"] +uuid = "e37daf67-58a4-590a-8e99-b0245dd2ffc5" +version = "1.6.4+0" + [[deps.LibSSH2_jll]] deps = ["Artifacts", "Libdl", "MbedTLS_jll"] uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" -version = "1.10.2+0" +version = "1.11.0+1" [[deps.Libdl]] uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" @@ -323,7 +340,7 @@ version = "1.26.0" [[deps.MbedTLS_jll]] deps = ["Artifacts", "Libdl"] uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" -version = "2.28.2+0" +version = "2.28.2+1" [[deps.Missings]] deps = ["DataAPI"] @@ -336,7 +353,7 @@ uuid = "a63ad114-7e13-5084-954f-fe012c677804" [[deps.MozillaCACerts_jll]] uuid = "14a3606d-f60d-562e-9121-12d972cd8159" -version = "2022.10.11" +version = "2023.1.10" [[deps.MutableArithmetics]] deps = ["LinearAlgebra", "SparseArrays", "Test"] @@ -363,12 +380,12 @@ version = "1.2.0" [[deps.OpenBLAS_jll]] deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"] uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" -version = "0.3.21+4" +version = "0.3.23+4" [[deps.OpenLibm_jll]] deps = ["Artifacts", "Libdl"] uuid = "05823500-19ac-5b8b-9628-191a04bc5112" -version = "0.8.1+0" +version = "0.8.1+2" [[deps.OpenSpecFun_jll]] deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"] @@ -390,7 +407,7 @@ version = "2.8.1" [[deps.Pkg]] deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"] uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" -version = "1.9.0" +version = "1.10.0" [[deps.PooledArrays]] deps = ["DataAPI", "Future"] @@ -429,7 +446,7 @@ deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" [[deps.Random]] -deps = ["SHA", "Serialization"] +deps = ["SHA"] uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" [[deps.Reexport]] @@ -474,6 +491,7 @@ version = "1.2.1" [[deps.SparseArrays]] deps = ["Libdl", "LinearAlgebra", "Random", "Serialization", "SuiteSparse_jll"] uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" +version = "1.10.0" [[deps.SpecialFunctions]] deps = ["IrrationalConstants", "LogExpFunctions", "OpenLibm_jll", "OpenSpecFun_jll"] @@ -509,7 +527,7 @@ version = "1.4.2" [[deps.Statistics]] deps = ["LinearAlgebra", "SparseArrays"] uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" -version = "1.9.0" +version = "1.10.0" [[deps.StatsAPI]] deps = ["LinearAlgebra"] @@ -524,9 +542,9 @@ uuid = "892a3eda-7b42-436c-8928-eab12a02cf0e" version = "0.3.4" [[deps.SuiteSparse_jll]] -deps = ["Artifacts", "Libdl", "Pkg", "libblastrampoline_jll"] +deps = ["Artifacts", "Libdl", "libblastrampoline_jll"] uuid = "bea87d4a-7f5b-5778-9afe-8cc45184846c" -version = "5.10.1+6" +version = "7.2.1+1" [[deps.TOML]] deps = ["Dates"] @@ -590,19 +608,19 @@ version = "0.10.1" [[deps.Zlib_jll]] deps = ["Libdl"] uuid = "83775a58-1f1d-513f-b197-d71354ab007a" -version = "1.2.13+0" +version = "1.2.13+1" [[deps.libblastrampoline_jll]] deps = ["Artifacts", "Libdl"] uuid = "8e850b90-86db-534c-a0d3-1478176c7d93" -version = "5.7.0+0" +version = "5.8.0+1" [[deps.nghttp2_jll]] deps = ["Artifacts", "Libdl"] uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" -version = "1.48.0+0" +version = "1.52.0+1" [[deps.p7zip_jll]] deps = ["Artifacts", "Libdl"] uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" -version = "17.4.0+0" +version = "17.4.0+2" diff --git a/Project.toml b/Project.toml index b0d9bb3..0b343e9 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,7 @@ CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Geodesy = "0ef565a4-170c-5f04-8de2-149903a85f3d" Gurobi = "2e9cd046-0924-5485-92f1-d5272153d98b" +HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b" JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" JuMP = "4076af6c-e467-56ae-b986-b466b2749572" NearestNeighbors = "b8a86587-4115-5ab1-83bc-aa920d37bbce" diff --git a/model-3.jl b/model-3.jl index 59ad962..15d8106 100644 --- a/model-3.jl +++ b/model-3.jl @@ -4,7 +4,6 @@ using CSV using DataFrames -using Gurobi using JSON using JuMP using OrderedCollections @@ -603,9 +602,9 @@ function generate_json() write_json(data, "output-3/case.json") end -function solve() +function solve(filename, optimizer) @info "Reading JSON file" - data = read_json("output-3/case.json") + data = read_json(filename) T = data.T centers = data.centers @@ -613,7 +612,7 @@ function solve() products = data.products emissions = data.emissions - model = Model(Gurobi.Optimizer) + model = Model(optimizer) # Graph # ------------------------------------------------------------------------- @@ -1012,6 +1011,7 @@ function solve() # Report: Transportation # ------------------------------------------------------------------------- + output_dir = dirname(filename) df = DataFrame() df."source" = String[] df."destination" = String[] @@ -1041,7 +1041,7 @@ function solve() ] ) end - CSV.write("output-3/transp.csv", df) + CSV.write("$output_dir/transp.csv", df) # Report: Centers # ------------------------------------------------------------------------- @@ -1079,7 +1079,7 @@ function solve() ] ) end - CSV.write("output-3/centers.csv", df) + CSV.write("$output_dir/centers.csv", df) # Report: Plants # ------------------------------------------------------------------------- @@ -1101,7 +1101,7 @@ function solve() ] ) end - CSV.write("output-3/plants.csv", df) + CSV.write("$output_dir/plants.csv", df) # Report: Plant Outputs # ------------------------------------------------------------------------- @@ -1137,7 +1137,7 @@ function solve() ] ) end - CSV.write("output-3/plant-outputs.csv", df) + CSV.write("$output_dir/plant-outputs.csv", df) # Report: Plant Emissions # ------------------------------------------------------------------------- @@ -1159,7 +1159,7 @@ function solve() ] ) end - CSV.write("output-3/plant-emissions.csv", df) + CSV.write("$output_dir/plant-emissions.csv", df) # Report: Transportation Emissions # ------------------------------------------------------------------------- @@ -1192,6 +1192,8 @@ function solve() ] ) end - CSV.write("output-3/transp-emissions.csv", df) + CSV.write("$output_dir/transp-emissions.csv", df) + + return end