Compare commits
31 Commits
feature/ge
...
feature/st
| Author | SHA1 | Date | |
|---|---|---|---|
|
8231f9da32
|
|||
|
48ccf0d180
|
|||
|
7f475a0914
|
|||
|
4b0fc7327c
|
|||
|
dde0d40282
|
|||
|
74606897cd
|
|||
|
07ca3abb4f
|
|||
|
da158eb961
|
|||
| e7eec937cb | |||
|
19bec961bd
|
|||
|
8f52c04702
|
|||
|
19a34fb5d2
|
|||
| e915a57e58 | |||
| 57b7d09c08 | |||
| a03b9169fd | |||
| ee58af73f0 | |||
| 92d30460b9 | |||
| 9ebb2e49f9 | |||
| 505e3a8e1e | |||
| d4fa75297f | |||
| 881957d6b5 | |||
| 86cf7f5bd9 | |||
| a8c7047e2d | |||
| 099e0fae3a | |||
| 1b8f392852 | |||
| 7a95aa66f6 | |||
| 40d28c727a | |||
| a9ac164833 | |||
| e244ded51d | |||
| 7180651cfa | |||
| 0c9465411f |
2
.github/workflows/test.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
|||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
version: ['1.3', '1.4', '1.5', 'nightly']
|
version: ['1.6', '1.7', '1.8']
|
||||||
os:
|
os:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
arch:
|
arch:
|
||||||
|
|||||||
1
.gitignore
vendored
@@ -12,3 +12,4 @@ Manifest.toml
|
|||||||
data
|
data
|
||||||
build
|
build
|
||||||
benchmark
|
benchmark
|
||||||
|
**/*.log
|
||||||
|
|||||||
52
CHANGELOG.md
@@ -1,28 +1,58 @@
|
|||||||
# Version 0.5.0 (Jan 6, 2021)
|
# Changelog
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
- The format is based on [Keep a Changelog][changelog].
|
||||||
|
- This project adheres to [Semantic Versioning][semver].
|
||||||
|
- For versions before 1.0, we follow the [Pkg.jl convention][pkjjl]
|
||||||
|
that `0.a.b` is compatible with `0.a.c`.
|
||||||
|
|
||||||
|
[changelog]: https://keepachangelog.com/en/1.0.0/
|
||||||
|
[semver]: https://semver.org/spec/v2.0.0.html
|
||||||
|
[pkjjl]: https://pkgdocs.julialang.org/v1/compatibility/#compat-pre-1.0
|
||||||
|
|
||||||
|
## [Unreleased]
|
||||||
|
|
||||||
|
- Allow product disposal at collection centers
|
||||||
|
- Implement stochastic optimization
|
||||||
|
|
||||||
|
## [0.5.2] -- 2022-08-26
|
||||||
|
### Changed
|
||||||
|
- Update to JuMP 1.x
|
||||||
|
|
||||||
|
## [0.5.1] -- 2021-07-23
|
||||||
|
### Added
|
||||||
|
- Allow user to specify locations as unique identifiers, instead of latitude and longitude (e.g. `us-state:IL` or `2018-us-county:17043`)
|
||||||
|
- Add what-if scenarios.
|
||||||
|
- Add products report.
|
||||||
|
|
||||||
|
## [0.5.0] -- 2021-01-06
|
||||||
|
### Added
|
||||||
- Allow plants to store input material for processing in later years
|
- Allow plants to store input material for processing in later years
|
||||||
|
|
||||||
# Version 0.4.0 (Sep 18, 2020)
|
## [0.4.0] -- 2020-09-18
|
||||||
|
### Added
|
||||||
- Generate simplified solution reports (CSV)
|
- Generate simplified solution reports (CSV)
|
||||||
|
|
||||||
# Version 0.3.3 (Aug 13, 2020)
|
## [0.3.3] -- 2020-10-13
|
||||||
|
### Added
|
||||||
- Add option to write solution to JSON file in RELOG.solve
|
- Add option to write solution to JSON file in RELOG.solve
|
||||||
- Improve error message when instance is infeasible
|
- Improve error message when instance is infeasible
|
||||||
- Make output file more readable
|
- Make output file more readable
|
||||||
|
|
||||||
# Version 0.3.2 (Aug 7, 2020)
|
## [0.3.2] -- 2020-10-07
|
||||||
|
### Added
|
||||||
- Add "building period" parameter
|
- Add "building period" parameter
|
||||||
|
|
||||||
# Version 0.3.1 (July 17, 2020)
|
## [0.3.1] -- 2020-07-17
|
||||||
|
### Fixed
|
||||||
- Fix expansion cost breakdown
|
- Fix expansion cost breakdown
|
||||||
|
|
||||||
# Version 0.3.0 (June 25, 2020)
|
## [0.3.0] -- 2020-06-25
|
||||||
|
### Added
|
||||||
- Track emissions and energy (transportation and plants)
|
- Track emissions and energy (transportation and plants)
|
||||||
|
|
||||||
|
### Changed
|
||||||
- Minor changes to input file format:
|
- Minor changes to input file format:
|
||||||
- Make all dictionary keys lowercase
|
- Make all dictionary keys lowercase
|
||||||
- Rename "outputs (tonne)" to "outputs (tonne/tonne)"
|
- Rename "outputs (tonne)" to "outputs (tonne/tonne)"
|
||||||
|
|||||||
27
Makefile
@@ -1,28 +1,19 @@
|
|||||||
JULIA := julia --color=yes --project=@.
|
|
||||||
SRC_FILES := $(wildcard src/*.jl test/*.jl)
|
|
||||||
VERSION := 0.5
|
VERSION := 0.5
|
||||||
|
|
||||||
all: docs test
|
|
||||||
|
|
||||||
build/sysimage.so: src/sysimage.jl Project.toml Manifest.toml
|
|
||||||
mkdir -p build
|
|
||||||
$(JULIA) src/sysimage.jl
|
|
||||||
|
|
||||||
build/test.log: $(SRC_FILES) build/sysimage.so
|
|
||||||
cd test; $(JULIA) --sysimage ../build/sysimage.so runtests.jl
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf build/*
|
rm -rfv build Manifest.toml test/Manifest.toml deps/formatter/build deps/formatter/Manifest.toml
|
||||||
|
|
||||||
docs:
|
docs:
|
||||||
mkdocs build -d ../docs/$(VERSION)/
|
cd docs; julia --project=. make.jl; cd ..
|
||||||
|
rsync -avP --delete-after docs/build/ ../docs/$(VERSION)/
|
||||||
|
|
||||||
format:
|
format:
|
||||||
julia -e 'using JuliaFormatter; format(["src", "test"], verbose=true);'
|
cd deps/formatter; ../../juliaw format.jl
|
||||||
|
|
||||||
test: build/test.log
|
test: test/Manifest.toml
|
||||||
|
./juliaw test/runtests.jl
|
||||||
|
|
||||||
test-watch:
|
test/Manifest.toml: test/Project.toml
|
||||||
bash -c "while true; do make test --quiet; sleep 1; done"
|
julia --project=test -e "using Pkg; Pkg.instantiate()"
|
||||||
|
|
||||||
.PHONY: docs test
|
.PHONY: docs test format
|
||||||
|
|||||||
32
Project.toml
@@ -1,47 +1,45 @@
|
|||||||
name = "RELOG"
|
name = "RELOG"
|
||||||
uuid = "a2afcdf7-cf04-4913-85f9-c0d81ddf2008"
|
uuid = "a2afcdf7-cf04-4913-85f9-c0d81ddf2008"
|
||||||
authors = ["Alinson S Xavier <axavier@anl.gov>"]
|
authors = ["Alinson S Xavier <axavier@anl.gov>"]
|
||||||
version = "0.5.0"
|
version = "0.5.2"
|
||||||
|
|
||||||
[deps]
|
[deps]
|
||||||
CRC = "44b605c4-b955-5f2b-9b6d-d2bd01d3d205"
|
CRC = "44b605c4-b955-5f2b-9b6d-d2bd01d3d205"
|
||||||
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
|
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
|
||||||
Cbc = "9961bab8-2fa3-5c5a-9d89-47fab24efd76"
|
|
||||||
Clp = "e2554f3b-3117-50c0-817c-e040a3ddf72d"
|
|
||||||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
|
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
|
||||||
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
|
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
|
||||||
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
|
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
|
||||||
GZip = "92fee26a-97fe-5a0c-ad85-20a5f3185b63"
|
GZip = "92fee26a-97fe-5a0c-ad85-20a5f3185b63"
|
||||||
Geodesy = "0ef565a4-170c-5f04-8de2-149903a85f3d"
|
Geodesy = "0ef565a4-170c-5f04-8de2-149903a85f3d"
|
||||||
|
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
|
||||||
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
|
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
|
||||||
JSONSchema = "7d188eb4-7ad8-530c-ae41-71a32a6d4692"
|
JSONSchema = "7d188eb4-7ad8-530c-ae41-71a32a6d4692"
|
||||||
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
|
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
|
||||||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
|
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
|
||||||
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
|
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
|
||||||
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
|
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
|
||||||
PackageCompiler = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d"
|
|
||||||
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
|
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
|
||||||
ProgressBars = "49802e3a-d2f1-5c88-81d8-b72133a6f568"
|
ProgressBars = "49802e3a-d2f1-5c88-81d8-b72133a6f568"
|
||||||
|
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
|
||||||
Shapefile = "8e980c4a-a4fe-5da2-b3a7-4b4b0353a2f4"
|
Shapefile = "8e980c4a-a4fe-5da2-b3a7-4b4b0353a2f4"
|
||||||
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
|
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
|
||||||
|
StochasticPrograms = "8b8459f2-c380-502b-8633-9aed2d6c2b35"
|
||||||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
||||||
ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea"
|
ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea"
|
||||||
|
|
||||||
[compat]
|
[compat]
|
||||||
CRC = "4"
|
CRC = "4"
|
||||||
CSV = "0.7"
|
CSV = "0.10"
|
||||||
Cbc = "0.6"
|
DataFrames = "1"
|
||||||
Clp = "0.8"
|
DataStructures = "0.18"
|
||||||
DataFrames = "0.21"
|
|
||||||
DataStructures = "0.17"
|
|
||||||
GZip = "0.5"
|
GZip = "0.5"
|
||||||
Geodesy = "0.5"
|
Geodesy = "1"
|
||||||
JSON = "0.21"
|
JSON = "0.21"
|
||||||
JSONSchema = "0.3"
|
JSONSchema = "1"
|
||||||
JuMP = "0.21"
|
JuMP = "1"
|
||||||
MathOptInterface = "0.9"
|
MathOptInterface = "1"
|
||||||
PackageCompiler = "1"
|
OrderedCollections = "1"
|
||||||
ProgressBars = "0.6"
|
ProgressBars = "1"
|
||||||
Shapefile = "0.7"
|
Shapefile = "0.8"
|
||||||
ZipFile = "0.9"
|
ZipFile = "0.10"
|
||||||
julia = "1"
|
julia = "1"
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
<img src="https://anl-ceeesa.github.io/RELOG/0.5/images/ex_transportation.png" width="1000px"/>
|
<img src="https://anl-ceeesa.github.io/RELOG/0.5/assets/ex_transportation.png" width="1000px"/>
|
||||||
|
|
||||||
### Documentation
|
### Documentation
|
||||||
|
|
||||||
@@ -26,8 +26,10 @@
|
|||||||
|
|
||||||
### Authors
|
### Authors
|
||||||
|
|
||||||
* **Alinson S. Xavier,** Argonne National Laboratory <<axavier@anl.gov>>
|
* **Alinson S. Xavier** <<axavier@anl.gov>>
|
||||||
* **Nwike Iloeje,** Argonne National Laboratory <<ciloeje@anl.gov>>
|
* **Nwike Iloeje** <<ciloeje@anl.gov>>
|
||||||
|
* **John Atkins**
|
||||||
|
* **Kyle Sun**
|
||||||
|
|
||||||
### License
|
### License
|
||||||
|
|
||||||
|
|||||||
5
deps/formatter/Project.toml
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
[deps]
|
||||||
|
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
|
||||||
|
|
||||||
|
[compat]
|
||||||
|
JuliaFormatter = "0.14.4"
|
||||||
8
deps/formatter/format.jl
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using JuliaFormatter
|
||||||
|
format(
|
||||||
|
[
|
||||||
|
"../../src",
|
||||||
|
"../../test",
|
||||||
|
],
|
||||||
|
verbose=true,
|
||||||
|
)
|
||||||
4
docs/Project.toml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
[deps]
|
||||||
|
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
|
||||||
|
RELOG = "a2afcdf7-cf04-4913-85f9-c0d81ddf2008"
|
||||||
|
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
|
||||||
19
docs/make.jl
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using Documenter, RELOG
|
||||||
|
|
||||||
|
function make()
|
||||||
|
makedocs(
|
||||||
|
sitename="RELOG",
|
||||||
|
pages=[
|
||||||
|
"Home" => "index.md",
|
||||||
|
"usage.md",
|
||||||
|
"format.md",
|
||||||
|
"reports.md",
|
||||||
|
"model.md",
|
||||||
|
],
|
||||||
|
format = Documenter.HTML(
|
||||||
|
assets=["assets/custom.css"],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
make()
|
||||||
36
docs/src/assets/custom.css
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
@media screen and (min-width: 1056px) {
|
||||||
|
#documenter .docs-main {
|
||||||
|
max-width: 65rem !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tbody, thead, pre {
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.25);
|
||||||
|
}
|
||||||
|
|
||||||
|
table td, th {
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table p {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
table td code {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
table tr,
|
||||||
|
table th {
|
||||||
|
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
table tr:last-child {
|
||||||
|
border-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
code {
|
||||||
|
background-color: transparent;
|
||||||
|
color: rgb(232, 62, 140);
|
||||||
|
}
|
||||||
|
Before Width: | Height: | Size: 52 KiB After Width: | Height: | Size: 52 KiB |
|
Before Width: | Height: | Size: 37 KiB After Width: | Height: | Size: 37 KiB |
|
Before Width: | Height: | Size: 31 KiB After Width: | Height: | Size: 31 KiB |
|
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 91 KiB |
|
Before Width: | Height: | Size: 586 KiB After Width: | Height: | Size: 586 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
@@ -11,7 +11,7 @@ RELOG accepts as input a JSON file with three sections: `parameters`, `products`
|
|||||||
The **parameters** section describes details about the simulation itself.
|
The **parameters** section describes details about the simulation itself.
|
||||||
|
|
||||||
| Key | Description
|
| Key | Description
|
||||||
|:--------------------------|---------------|
|
|:--------------------------|:---------------|
|
||||||
|`time horizon (years)` | Number of years in the simulation.
|
|`time horizon (years)` | Number of years in the simulation.
|
||||||
|`building period (years)` | List of years in which we are allowed to open new plants. For example, if this parameter is set to `[1,2,3]`, we can only open plants during the first three years. By default, this equals `[1]`; that is, plants can only be opened during the first year. |
|
|`building period (years)` | List of years in which we are allowed to open new plants. For example, if this parameter is set to `[1,2,3]`, we can only open plants during the first three years. By default, this equals `[1]`; that is, plants can only be opened during the first year. |
|
||||||
|
|
||||||
@@ -31,16 +31,18 @@ The **parameters** section describes details about the simulation itself.
|
|||||||
The **products** section describes all products and subproducts in the simulation. The field `instance["Products"]` is a dictionary mapping the name of the product to a dictionary which describes its characteristics. Each product description contains the following keys:
|
The **products** section describes all products and subproducts in the simulation. The field `instance["Products"]` is a dictionary mapping the name of the product to a dictionary which describes its characteristics. Each product description contains the following keys:
|
||||||
|
|
||||||
| Key | Description
|
| Key | Description
|
||||||
|:--------------------------------------|---------------|
|
|:--------------------------------------|:---------------|
|
||||||
|`transportation cost ($/km/tonne)` | The cost to transport this product. Must be a time series.
|
|`transportation cost ($/km/tonne)` | The cost to transport this product. Must be a time series.
|
||||||
|`transportation energy (J/km/tonne)` | The energy required to transport this product. Must be a time series. Optional.
|
|`transportation energy (J/km/tonne)` | The energy required to transport this product. Must be a time series. Optional.
|
||||||
|`transportation emissions (tonne/km/tonne)` | A dictionary mapping the name of each greenhouse gas, produced to transport one tonne of this product along one kilometer, to the amount of gas produced (in tonnes). Must be a time series. Optional.
|
|`transportation emissions (tonne/km/tonne)` | A dictionary mapping the name of each greenhouse gas, produced to transport one tonne of this product along one kilometer, to the amount of gas produced (in tonnes). Must be a time series. Optional.
|
||||||
|`initial amounts` | A dictionary mapping the name of each location to its description (see below). If this product is not initially available, this key may be omitted. Must be a time series.
|
|`initial amounts` | A dictionary mapping the name of each location to its description (see below). If this product is not initially available, this key may be omitted. Must be a time series.
|
||||||
|
| `disposal limit (tonne)` | Total amount of product that can be disposed of across all collection centers. If omitted, all product must be processed. This parameter has no effect on product disposal at plants.
|
||||||
|
| `disposal cost ($/tonne)` | Cost of disposing one tonne of this product at a collection center. If omitted, defaults to zero. This parameter has no effect on product disposal costs at plants.
|
||||||
|
|
||||||
Each product may have some amount available at the beginning of each time period. In this case, the key `initial amounts` maps to a dictionary with the following keys:
|
Each product may have some amount available at the beginning of each time period. In this case, the key `initial amounts` maps to a dictionary with the following keys:
|
||||||
|
|
||||||
| Key | Description
|
| Key | Description
|
||||||
|:------------------------|---------------|
|
|:------------------------|:---------------|
|
||||||
| `latitude (deg)` | The latitude of the location.
|
| `latitude (deg)` | The latitude of the location.
|
||||||
| `longitude (deg)` | The longitude of the location.
|
| `longitude (deg)` | The longitude of the location.
|
||||||
| `amount (tonne)` | The amount of the product initially available at the location. Must be a time series.
|
| `amount (tonne)` | The amount of the product initially available at the location. Must be a time series.
|
||||||
@@ -73,7 +75,9 @@ Each product may have some amount available at the beginning of each time period
|
|||||||
"transportation emissions (tonne/km/tonne)": {
|
"transportation emissions (tonne/km/tonne)": {
|
||||||
"CO2": [0.052, 0.050],
|
"CO2": [0.052, 0.050],
|
||||||
"CH4": [0.003, 0.002]
|
"CH4": [0.003, 0.002]
|
||||||
}
|
},
|
||||||
|
"disposal cost ($/tonne)": [-10.0, -12.0],
|
||||||
|
"disposal limit (tonne)": [1.0, 1.0],
|
||||||
},
|
},
|
||||||
"P2": {
|
"P2": {
|
||||||
"transportation cost ($/km/tonne)": [0.022, 0.020]
|
"transportation cost ($/km/tonne)": [0.022, 0.020]
|
||||||
@@ -93,7 +97,7 @@ Each product may have some amount available at the beginning of each time period
|
|||||||
The **plants** section describes the available types of reverse manufacturing plants, their potential locations and associated costs, as well as their inputs and outputs. The field `instance["Plants"]` is a dictionary mapping the name of the plant to a dictionary with the following keys:
|
The **plants** section describes the available types of reverse manufacturing plants, their potential locations and associated costs, as well as their inputs and outputs. The field `instance["Plants"]` is a dictionary mapping the name of the plant to a dictionary with the following keys:
|
||||||
|
|
||||||
| Key | Description
|
| Key | Description
|
||||||
|:------------------------|---------------|
|
|:------------------------|:---------------|
|
||||||
| `input` | The name of the product that this plant takes as input. Only one input is accepted per plant.
|
| `input` | The name of the product that this plant takes as input. Only one input is accepted per plant.
|
||||||
| `outputs (tonne/tonne)` | A dictionary specifying how many tonnes of each product is produced for each tonnes of input. For example, if the plant outputs 0.5 tonnes of P2 and 0.25 tonnes of P3 for each tonnes of P1 provided, then this entry should be `{"P2": 0.5, "P3": 0.25}`. If the plant does not output anything, this key may be omitted.
|
| `outputs (tonne/tonne)` | A dictionary specifying how many tonnes of each product is produced for each tonnes of input. For example, if the plant outputs 0.5 tonnes of P2 and 0.25 tonnes of P3 for each tonnes of P1 provided, then this entry should be `{"P2": 0.5, "P3": 0.25}`. If the plant does not output anything, this key may be omitted.
|
||||||
|`energy (GJ/tonne)` | The energy required to process 1 tonne of the input. Must be a time series. Optional.
|
|`energy (GJ/tonne)` | The energy required to process 1 tonne of the input. Must be a time series. Optional.
|
||||||
@@ -113,14 +117,14 @@ Each type of plant is associated with a set of potential locations where it can
|
|||||||
The `storage` dictionary should contain the following keys:
|
The `storage` dictionary should contain the following keys:
|
||||||
|
|
||||||
| Key | Description
|
| Key | Description
|
||||||
|:------------------------|---------------|
|
|:------------------------|:---------------|
|
||||||
| `cost ($/tonne)` | The cost to store a tonne of input product for one time period. Must be a time series.
|
| `cost ($/tonne)` | The cost to store a tonne of input product for one time period. Must be a time series.
|
||||||
| `limit (tonne)` | The maximum amount of input product this plant can have in storage at any given time.
|
| `limit (tonne)` | The maximum amount of input product this plant can have in storage at any given time.
|
||||||
|
|
||||||
The keys in the `disposal` dictionary should be the names of the products. The values are dictionaries with the following keys:
|
The keys in the `disposal` dictionary should be the names of the products. The values are dictionaries with the following keys:
|
||||||
|
|
||||||
| Key | Description
|
| Key | Description
|
||||||
|:------------------------|---------------|
|
|:------------------------|:---------------|
|
||||||
| `cost ($/tonne)` | The cost to dispose of the product. Must be a time series.
|
| `cost ($/tonne)` | The cost to dispose of the product. Must be a time series.
|
||||||
| `limit (tonne)` | The maximum amount that can be disposed of. If an unlimited amount can be disposed, this key may be omitted. Must be a time series.
|
| `limit (tonne)` | The maximum amount that can be disposed of. If an unlimited amount can be disposed, this key may be omitted. Must be a time series.
|
||||||
|
|
||||||
@@ -128,7 +132,7 @@ The keys in the `disposal` dictionary should be the names of the products. The v
|
|||||||
The keys in the `capacities (tonne)` dictionary should be the amounts (in tonnes). The values are dictionaries with the following keys:
|
The keys in the `capacities (tonne)` dictionary should be the amounts (in tonnes). The values are dictionaries with the following keys:
|
||||||
|
|
||||||
| Key | Description
|
| Key | Description
|
||||||
|:--------------------------------------|---------------|
|
|:--------------------------------------|:---------------|
|
||||||
| `opening cost ($)` | The cost to open a plant of this size.
|
| `opening cost ($)` | The cost to open a plant of this size.
|
||||||
| `fixed operating cost ($)` | The cost to keep the plant open, even if the plant doesn't process anything. Must be a time series.
|
| `fixed operating cost ($)` | The cost to keep the plant open, even if the plant doesn't process anything. Must be a time series.
|
||||||
| `variable operating cost ($/tonne)` | The cost that the plant incurs to process each tonne of input. Must be a time series.
|
| `variable operating cost ($/tonne)` | The cost that the plant incurs to process each tonne of input. Must be a time series.
|
||||||
@@ -182,6 +186,38 @@ The keys in the `capacities (tonne)` dictionary should be the amounts (in tonnes
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Geographic database
|
||||||
|
|
||||||
|
Instead of specifying locations using latitudes and longitudes, it is also possible to specify them using unique identifiers, such as the name of a US state, or the county FIPS code. This works anywhere `latitude (deg)` and `longitude (deg)` are expected. For example, instead of:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"initial amounts": {
|
||||||
|
"C1": {
|
||||||
|
"latitude (deg)": 37.27182,
|
||||||
|
"longitude (deg)": -119.2704,
|
||||||
|
"amount (tonne)": [934.56, 934.56]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
is is possible to write:
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"initial amounts": {
|
||||||
|
"C1": {
|
||||||
|
"location": "us-state:CA",
|
||||||
|
"amount (tonne)": [934.56, 934.56]
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Location names follow the format `db:id`, where `db` is the name of the database and `id` is the identifier for a specific location. RELOG currently includes the following databases:
|
||||||
|
|
||||||
|
Database | Description | Examples
|
||||||
|
:--------|:------------|:---------
|
||||||
|
`us-state`| List of states of the United States. | `us-state:IL` (State of Illinois)
|
||||||
|
`2018-us-county` | List of United States counties, as of 2018. IDs are 5-digit FIPS codes. | `2018-us-county:17043` (DuPage county in Illinois)
|
||||||
|
|
||||||
### Current limitations
|
### Current limitations
|
||||||
|
|
||||||
* Each plant can only be opened exactly once. After open, the plant remains open until the end of the simulation.
|
* Each plant can only be opened exactly once. After open, the plant remains open until the end of the simulation.
|
||||||
@@ -192,4 +228,3 @@ The keys in the `capacities (tonne)` dictionary should be the amounts (in tonnes
|
|||||||
## Output Data Format (JSON)
|
## Output Data Format (JSON)
|
||||||
|
|
||||||
To be documented.
|
To be documented.
|
||||||
|
|
||||||
@@ -1,25 +1,29 @@
|
|||||||
# RELOG: Reverse Logistics Optimization
|
# RELOG: Reverse Logistics Optimization
|
||||||
|
|
||||||
|
|
||||||
**RELOG** is an open-source supply chain optimization package focusing on reverse logistics and reverse manufacturing. The package uses Mixed-Integer Linear Programming to determine where to build recycling plants, what size should these plants have and which customers should be served by which plants. The package supports custom reverse logistics pipelines, with multiple types of plants, multiple types of product and multiple time periods.
|
**RELOG** is an open-source supply chain optimization package focusing on reverse logistics and reverse manufacturing. The package uses Mixed-Integer Linear Programming to determine where to build recycling plants, what size should these plants have and which customers should be served by which plants. The package supports custom reverse logistics pipelines, with multiple types of plants, multiple types of product and multiple time periods.
|
||||||
|
|
||||||
<img src="images/ex_transportation.png" width="1000px"/>
|
```@raw html
|
||||||
|
<center>
|
||||||
|
<img src="assets/ex_transportation.png" width="1000px"/>
|
||||||
|
</center>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Table of Contents
|
### Table of Contents
|
||||||
|
|
||||||
* [Usage](usage.md)
|
```@contents
|
||||||
* [Input and Output Data Formats](format.md)
|
Pages = ["usage.md", "format.md", "reports.md", "model.md"]
|
||||||
* [Simplified Solution Reports](reports.md)
|
Depth = 3
|
||||||
* [Optimization Model](model.md)
|
```
|
||||||
|
|
||||||
|
|
||||||
### Source Code
|
### Source Code
|
||||||
|
|
||||||
* [https://github.com/ANL-CEEESA/RELOG](https://github.com/ANL-CEEESA/RELOG)
|
* [https://github.com/ANL-CEEESA/RELOG](https://github.com/ANL-CEEESA/RELOG)
|
||||||
|
|
||||||
### Authors
|
### Authors
|
||||||
* **Alinson S. Xavier,** Argonne National Laboratory <<axavier@anl.gov>>
|
* **Alinson S. Xavier,** Argonne National Laboratory <axavier@anl.gov>
|
||||||
* **Nwike Iloeje,** Argonne National Laboratory <<ciloeje@anl.gov>>
|
* **Nwike Iloeje,** Argonne National Laboratory <ciloeje@anl.gov>
|
||||||
|
|
||||||
### License
|
### License
|
||||||
|
|
||||||
@@ -6,53 +6,65 @@ In this page, we describe the precise mathematical optimization model used by RE
|
|||||||
|
|
||||||
### Sets
|
### Sets
|
||||||
|
|
||||||
* $L$ - Set of locations holding the original material to be recycled
|
Symbol | Description
|
||||||
* $M$ - Set of materials recovered during the reverse manufacturing process
|
:-------|:------------
|
||||||
* $P$ - Set of potential plants to open
|
$L$ | Set of locations holding the original material to be recycled
|
||||||
* $T = \{ 1, \ldots, t^{max} \} $ - Set of time periods
|
$M$ | Set of materials recovered during the reverse manufacturing process
|
||||||
|
$P$ | Set of potential plants to open
|
||||||
|
$T = \{ 1, \ldots, t^{max} \}$ | Set of time periods
|
||||||
|
|
||||||
### Constants
|
### Constants
|
||||||
|
|
||||||
**Plants:**
|
#### Plants
|
||||||
|
|
||||||
* $c^\text{disp}_{pmt}$ - Cost of disposing one tonne of material $m$ at plant $p$ during time $t$ (`$/tonne/km`)
|
Symbol | Description | Unit
|
||||||
* $c^\text{exp}_{pt}$ - Cost of adding one tonne of capacity to plant $p$ at time $t$ (`$/tonne`)
|
:-------|:------------|:---
|
||||||
* $c^\text{open}_{pt}$ - Cost of opening plant $p$ at time $t$, at minimum capacity (`$`)
|
$c^\text{disp}_{pmt}$ | Cost of disposing one tonne of material $m$ at plant $p$ during time $t$ | \$/tonne/km
|
||||||
* $c^\text{f-base}_{pt}$ - Fixed cost of keeping plant $p$ open during time period $t$ (`$`)
|
$c^\text{exp}_{pt}$ | Cost of adding one tonne of capacity to plant $p$ at time $t$ | \$/tonne
|
||||||
* $c^\text{f-exp}_{pt}$ - Increase in fixed cost for each additional tonne of capacity (`$/tonne`)
|
$c^\text{open}_{pt}$ | Cost of opening plant $p$ at time $t$, at minimum capacity | $
|
||||||
* $c^\text{var}_{pt}$ - Variable cost of processing one tonne of input at plant $p$ at time $t$ (`$/tonne`)
|
$c^\text{f-base}_{pt}$ | Fixed cost of keeping plant $p$ open during time period $t$ | $
|
||||||
* $c^\text{store}_{pt}$ - Cost of storing one tonne of original material at plant $p$ at time $t$ (`$/tonne`)
|
$c^\text{f-exp}_{pt}$ | Increase in fixed cost for each additional tonne of capacity | \$/tonne
|
||||||
* $m^\text{min}_p$ - Minimum capacity of plant $p$ (`tonne`)
|
$c^\text{var}_{pt}$ | Variable cost of processing one tonne of input at plant $p$ at time $t$ | \$/tonne
|
||||||
* $m^\text{max}_p$ - Maximum capacity of plant $p$ (`tonne`)
|
$c^\text{store}_{pt}$ | Cost of storing one tonne of original material at plant $p$ at time $t$ | \$/tonne
|
||||||
* $m^\text{disp}_{pmt}$ - Maximum amount of material $m$ that plant $p$ can dispose of during time $t$ (`tonne`)
|
$m^\text{min}_p$ | Minimum capacity of plant $p$ | tonne
|
||||||
* $m^\text{store}_p$ - Maximum amount of original material that plant $p$ can store for later processing.
|
$m^\text{max}_p$ | Maximum capacity of plant $p$ | tonne
|
||||||
|
$m^\text{disp}_{pmt}$ | Maximum amount of material $m$ that plant $p$ can dispose of during time $t$ | tonne
|
||||||
|
$m^\text{store}_p$ | Maximum amount of original material that plant $p$ can store for later processing. | tonne
|
||||||
|
|
||||||
**Products:**
|
#### Products
|
||||||
|
|
||||||
* $\alpha_{pm}$ - Amount of material $m$ recovered by plant $t$ for each tonne of original material (`tonne/tonne`)
|
Symbol | Description | Unit
|
||||||
* $m^\text{initial}_{lt}$ - Amount of original material to be recycled at location $l$ during time $t$ (`tonne`)
|
:-------|:------------|:---
|
||||||
|
$\alpha_{pm}$ | Amount of material $m$ recovered by plant $t$ for each tonne of original material | tonne/tonne
|
||||||
|
$m^\text{initial}_{lt}$ | Amount of original material to be recycled at location $l$ during time $t$ | tonne
|
||||||
|
|
||||||
**Transportation:**
|
#### Transportation
|
||||||
|
|
||||||
* $c^\text{tr}_{t}$ - Transportation cost during time $t$ (`$/tonne/km`)
|
Symbol | Description | Unit
|
||||||
* $d_{lp}$ - Distance between plant $p$ and location $l$ (`km`)
|
:-------|:------------|:---
|
||||||
|
$c^\text{tr}_{t}$ | Transportation cost during time $t$ | \$/tonne/km
|
||||||
|
$d_{lp}$ | Distance between plant $p$ and location $l$ | km
|
||||||
|
|
||||||
|
|
||||||
### Decision variables
|
### Decision variables
|
||||||
* $q_{mpt}$ - Amount of material $m$ recovered by plant $p$ during time $t$ (`tonne`)
|
|
||||||
* $u_{pt}$ - Binary variable that equals 1 if plant $p$ starts operating at time $t$ (`bool`)
|
Symbol | Description | Unit
|
||||||
* $w_{pt}$ - Extra capacity (amount above the minimum) added to plant $p$ during time $t$ (`tonne`)
|
:-------|:------------|:---
|
||||||
* $x_{pt}$ - Binary variable that equals 1 if plant $p$ is operational at time $t$ (`bool`)
|
$q_{mpt}$ | Amount of material $m$ recovered by plant $p$ during time $t$ | tonne
|
||||||
* $y_{lpt}$ - Amount of product sent from location $l$ to plant $p$ during time $t$ (`tonne`)
|
$u_{pt}$ | Binary variable that equals 1 if plant $p$ starts operating at time $t$ | Boolean
|
||||||
* $z^{\text{disp}}_{mpt}$ - Amount of material $m$ disposed of by plant $p$ during time $t$ (`tonne`)
|
$w_{pt}$ | Extra capacity (amount above the minimum) added to plant $p$ during time $t$ | tonne
|
||||||
* $z^{\text{store}}_{pt}$ - Amount of original material in storage at plant $p$ by the end of time period $t$ (`tonne`)
|
$x_{pt}$ | Binary variable that equals 1 if plant $p$ is operational at time $t$ | Boolean
|
||||||
* $z^{\text{proc}}_{mpt}$ - Amount of original material processed by plant $p$ during time period $t$ (`tonne`)
|
$y_{lpt}$ | Amount of product sent from location $l$ to plant $p$ during time $t$ | tonne
|
||||||
|
$z^{\text{disp}}_{mpt}$ | Amount of material $m$ disposed of by plant $p$ during time $t$ | tonne
|
||||||
|
$z^{\text{store}}_{pt}$ | Amount of original material in storage at plant $p$ by the end of time period $t$ | tonne
|
||||||
|
$z^{\text{proc}}_{mpt}$ | Amount of original material processed by plant $p$ during time period $t$ | tonne
|
||||||
|
|
||||||
|
|
||||||
### Objective function
|
### Objective function
|
||||||
|
|
||||||
RELOG minimizes the overall capital, production and transportation costs:
|
RELOG minimizes the overall capital, production and transportation costs:
|
||||||
|
|
||||||
|
```math
|
||||||
\begin{align*}
|
\begin{align*}
|
||||||
\text{minimize} \;\; &
|
\text{minimize} \;\; &
|
||||||
\sum_{t \in T} \sum_{p \in P} \left[
|
\sum_{t \in T} \sum_{p \in P} \left[
|
||||||
@@ -73,6 +85,7 @@ RELOG minimizes the overall capital, production and transportation costs:
|
|||||||
&
|
&
|
||||||
\sum_{t \in T} \sum_{p \in P} \sum_{m \in M} c^{\text{disp}}_{pmt} z_{pmt}
|
\sum_{t \in T} \sum_{p \in P} \sum_{m \in M} c^{\text{disp}}_{pmt} z_{pmt}
|
||||||
\end{align*}
|
\end{align*}
|
||||||
|
```
|
||||||
|
|
||||||
In the first line, we have (i) opening costs, if plant starts operating at time $t$, (ii) fixed operating costs, if plant is operational, (iii) additional fixed operating costs coming from expansion performed in all previous time periods up to the current one, and finally (iv) the expansion costs during the current time period.
|
In the first line, we have (i) opening costs, if plant starts operating at time $t$, (ii) fixed operating costs, if plant is operational, (iii) additional fixed operating costs coming from expansion performed in all previous time periods up to the current one, and finally (iv) the expansion costs during the current time period.
|
||||||
In the second line, we have storage and variable processing costs.
|
In the second line, we have storage and variable processing costs.
|
||||||
@@ -83,14 +96,17 @@ In the fourth line, we have the disposal costs.
|
|||||||
|
|
||||||
* All original materials must be sent to a plant:
|
* All original materials must be sent to a plant:
|
||||||
|
|
||||||
\begin{align}
|
```math
|
||||||
|
\begin{align*}
|
||||||
& \sum_{p \in P} y_{lpt} = m^\text{initial}_{lt}
|
& \sum_{p \in P} y_{lpt} = m^\text{initial}_{lt}
|
||||||
& \forall l \in L, t \in T
|
& \forall l \in L, t \in T
|
||||||
\end{align}
|
\end{align*}
|
||||||
|
```
|
||||||
|
|
||||||
* Amount received equals amount processed plus stored. Furthermore, all original material should be processed by the end of the simulation.
|
* Amount received equals amount processed plus stored. Furthermore, all original material should be processed by the end of the simulation.
|
||||||
|
|
||||||
\begin{align}
|
```math
|
||||||
|
\begin{align*}
|
||||||
& \sum_{l \in L} y_{lpt} + z^{\text{store}}_{p,t-1}
|
& \sum_{l \in L} y_{lpt} + z^{\text{store}}_{p,t-1}
|
||||||
= z^{\text{proc}}_{pt} + z^{\text{store}}_{p,t}
|
= z^{\text{proc}}_{pt} + z^{\text{store}}_{p,t}
|
||||||
& \forall p \in P, t \in T \\
|
& \forall p \in P, t \in T \\
|
||||||
@@ -98,56 +114,70 @@ In the fourth line, we have the disposal costs.
|
|||||||
& \forall p \in P \\
|
& \forall p \in P \\
|
||||||
& z^{\text{store}}_{p,t^{\max}} = 0
|
& z^{\text{store}}_{p,t^{\max}} = 0
|
||||||
& \forall p \in P
|
& \forall p \in P
|
||||||
\end{align}
|
\end{align*}
|
||||||
|
```
|
||||||
|
|
||||||
* Plants have a limited processing capacity. Furthermore, if a plant is closed, it has zero processing capacity:
|
* Plants have a limited processing capacity. Furthermore, if a plant is closed, it has zero processing capacity:
|
||||||
|
|
||||||
\begin{align}
|
```math
|
||||||
|
\begin{align*}
|
||||||
& z^{\text{proc}}_{pt} \leq m^\text{min}_p x_p + \sum_{i=1}^t w_p
|
& z^{\text{proc}}_{pt} \leq m^\text{min}_p x_p + \sum_{i=1}^t w_p
|
||||||
& \forall p \in P, t \in T
|
& \forall p \in P, t \in T
|
||||||
\end{align}
|
\end{align*}
|
||||||
|
```
|
||||||
|
|
||||||
* Plants have limited storage capacity. Furthermore, if a plant is closed, is has zero storage capacity:
|
* Plants have limited storage capacity. Furthermore, if a plant is closed, is has zero storage capacity:
|
||||||
|
|
||||||
\begin{align}
|
```math
|
||||||
|
\begin{align*}
|
||||||
& z^{\text{store}}_{pt} \leq m^\text{store}_p x_p
|
& z^{\text{store}}_{pt} \leq m^\text{store}_p x_p
|
||||||
& \forall p \in P, t \in T
|
& \forall p \in P, t \in T
|
||||||
\end{align}
|
\end{align*}
|
||||||
|
```
|
||||||
|
|
||||||
* Plants can only be expanded up to their maximum capacity. Furthermore, if a plant is closed, it cannot be expanded:
|
* Plants can only be expanded up to their maximum capacity. Furthermore, if a plant is closed, it cannot be expanded:
|
||||||
|
|
||||||
\begin{align}
|
```math
|
||||||
|
\begin{align*}
|
||||||
& \sum_{i=1}^t w_p \leq m^\text{max}_p x_p
|
& \sum_{i=1}^t w_p \leq m^\text{max}_p x_p
|
||||||
& \forall p \in P, t \in T
|
& \forall p \in P, t \in T
|
||||||
\end{align}
|
\end{align*}
|
||||||
|
```
|
||||||
|
|
||||||
* Amount of recovered material is proportional to amount processed:
|
* Amount of recovered material is proportional to amount processed:
|
||||||
|
|
||||||
\begin{align}
|
```math
|
||||||
|
\begin{align*}
|
||||||
& q_{mpt} = \alpha_{pm} z^{\text{proc}}_{pt}
|
& q_{mpt} = \alpha_{pm} z^{\text{proc}}_{pt}
|
||||||
& \forall m \in M, p \in P, t \in T
|
& \forall m \in M, p \in P, t \in T
|
||||||
\end{align}
|
\end{align*}
|
||||||
|
```
|
||||||
|
|
||||||
* Because we only consider a single type of plant, all recovered material must be immediately disposed of. In RELOG's full model, recovered materials may be sent to another plant for further processing.
|
* Because we only consider a single type of plant, all recovered material must be immediately disposed of. In RELOG's full model, recovered materials may be sent to another plant for further processing.
|
||||||
|
|
||||||
\begin{align}
|
```math
|
||||||
|
\begin{align*}
|
||||||
& q_{mpt} = z_{mpt}
|
& q_{mpt} = z_{mpt}
|
||||||
& \forall m \in M, p \in P, t \in T
|
& \forall m \in M, p \in P, t \in T
|
||||||
\end{align}
|
\end{align*}
|
||||||
|
```
|
||||||
|
|
||||||
* A plant is operational at time $t$ if it was operational at time $t-1$ or it was built at time $t$. This constraint also prevents a plant from being built multiple times.
|
* A plant is operational at time $t$ if it was operational at time $t-1$ or it was built at time $t$. This constraint also prevents a plant from being built multiple times.
|
||||||
|
|
||||||
\begin{align}
|
```math
|
||||||
|
\begin{align*}
|
||||||
& x_{pt} = x_{p,t-1} + u_{pt}
|
& x_{pt} = x_{p,t-1} + u_{pt}
|
||||||
& \forall p \in P, t \in T \setminus \{1\} \\
|
& \forall p \in P, t \in T \setminus \{1\} \\
|
||||||
& x_{p,1} = u_{p,1}
|
& x_{p,1} = u_{p,1}
|
||||||
& \forall p \in P
|
& \forall p \in P
|
||||||
\end{align}
|
\end{align*}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
* Variable bounds:
|
* Variable bounds:
|
||||||
|
|
||||||
\begin{align}
|
```math
|
||||||
|
\begin{align*}
|
||||||
& q_{mpt} \geq 0
|
& q_{mpt} \geq 0
|
||||||
& \forall m \in M, p \in P, t \in T \\
|
& \forall m \in M, p \in P, t \in T \\
|
||||||
& u_{pt} \in \{0,1\}
|
& u_{pt} \in \{0,1\}
|
||||||
@@ -162,4 +192,5 @@ In the fourth line, we have the disposal costs.
|
|||||||
& p \in P, t \in T \\
|
& p \in P, t \in T \\
|
||||||
& z^{\text{disp}}_{mpt}, z^{\text{proc}}_{mpt} \geq 0
|
& z^{\text{disp}}_{mpt}, z^{\text{proc}}_{mpt} \geq 0
|
||||||
& \forall m \in M, p \in P, t \in T
|
& \forall m \in M, p \in P, t \in T
|
||||||
\end{align}
|
\end{align*}
|
||||||
|
```
|
||||||
@@ -6,15 +6,13 @@ In this page, we also illustrate what types of charts and visualizations can be
|
|||||||
|
|
||||||
## Plants report
|
## Plants report
|
||||||
|
|
||||||
Report showing plant costs, capacities, energy expenditure and utilization factors.
|
Report showing plant costs, capacities, energy expenditure and utilization factors. Generated by `RELOG.write_plants_report(solution, filename)`.
|
||||||
|
|
||||||
Generated by `RELOG.write_plants_report(solution, filename)`. For a concrete example, see [nimh_plants.csv](https://github.com/ANL-CEEESA/RELOG/blob/master/test/fixtures/nimh_plants.csv).
|
|
||||||
|
|
||||||
| Column | Description
|
| Column | Description
|
||||||
|:--------------------------------------|---------------|
|
|:--------------------------------------|:---------------|
|
||||||
| `plant type` | Plant type.
|
| `plant type` | Plant type.
|
||||||
| `location name` | Location name.
|
| `location name` | Location name.
|
||||||
| `year` | What year this row corresponds to. This reports includes one row for each year in the simulation.
|
| `year` | What year this row corresponds to. This reports includes one row for each year.
|
||||||
| `latitude (deg)` | Latitude of the plant.
|
| `latitude (deg)` | Latitude of the plant.
|
||||||
| `longitude (deg)` | Longitude of the plant.
|
| `longitude (deg)` | Longitude of the plant.
|
||||||
| `capacity (tonne)` | Capacity of the plant at this point in time.
|
| `capacity (tonne)` | Capacity of the plant at this point in time.
|
||||||
@@ -47,7 +45,9 @@ sns.barplot(x="year",
|
|||||||
.reset_index());
|
.reset_index());
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="../images/ex_plant_cost_per_year.png" width="500px"/>
|
```@raw html
|
||||||
|
<img src="../assets/ex_plant_cost_per_year.png" width="500px"/>
|
||||||
|
```
|
||||||
|
|
||||||
* Map showing plant locations (in Python):
|
* Map showing plant locations (in Python):
|
||||||
```python
|
```python
|
||||||
@@ -67,21 +67,20 @@ points = gp.points_from_xy(data["longitude (deg)"],
|
|||||||
gp.GeoDataFrame(data, geometry=points).plot(ax=ax);
|
gp.GeoDataFrame(data, geometry=points).plot(ax=ax);
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="../images/ex_plant_locations.png" width="1000px"/>
|
```@raw html
|
||||||
|
<img src="../assets/ex_plant_locations.png" width="1000px"/>
|
||||||
|
```
|
||||||
|
|
||||||
## Plant outputs report
|
## Plant outputs report
|
||||||
|
|
||||||
Report showing amount of products produced, sent and disposed of by each plant, as well as disposal costs.
|
Report showing amount of products produced, sent and disposed of by each plant, as well as disposal costs. Generated by `RELOG.write_plant_outputs_report(solution, filename)`.
|
||||||
|
|
||||||
Generated by `RELOG.write_plant_outputs_report(solution, filename)`. For a concrete example, see [nimh_plant_outputs.csv](https://github.com/ANL-CEEESA/RELOG/blob/master/test/fixtures/nimh_plant_outputs.csv).
|
|
||||||
|
|
||||||
|
|
||||||
| Column | Description
|
| Column | Description
|
||||||
|:--------------------------------------|---------------|
|
|:--------------------------------------|:---------------|
|
||||||
| `plant type` | Plant type.
|
| `plant type` | Plant type.
|
||||||
| `location name` | Location name.
|
| `location name` | Location name.
|
||||||
| `year` | What year this row corresponds to. This reports includes one row for each year in the simulation.
|
| `year` | What year this row corresponds to. This reports includes one row for each year.
|
||||||
| `product name` | Product being produced.
|
| `product name` | Product being produced.
|
||||||
| `amount produced (tonne)` | Amount of product produced this year.
|
| `amount produced (tonne)` | Amount of product produced this year.
|
||||||
| `amount sent (tonne)` | Amount of product produced by this plant and sent to another plant for further processing this year.
|
| `amount sent (tonne)` | Amount of product produced by this plant and sent to another plant for further processing this year.
|
||||||
@@ -105,17 +104,17 @@ sns.barplot(x="amount produced (tonne)",
|
|||||||
.reset_index());
|
.reset_index());
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="../images/ex_amount_produced.png" width="500px"/>
|
```@raw html
|
||||||
|
<img src="../assets/ex_amount_produced.png" width="500px"/>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Plant emissions report
|
## Plant emissions report
|
||||||
|
|
||||||
Report showing amount of emissions produced by each plant.
|
Report showing amount of emissions produced by each plant. Generated by `RELOG.write_plant_emissions_report(solution, filename)`.
|
||||||
|
|
||||||
Generated by `RELOG.write_plant_emissions_report(solution, filename)`. For a concrete example, see [nimh_plant_emissions.csv](https://github.com/ANL-CEEESA/RELOG/blob/master/test/fixtures/nimh_plant_emissions.csv).
|
|
||||||
|
|
||||||
| Column | Description
|
| Column | Description
|
||||||
|:--------------------------------------|---------------|
|
|:--------------------------------------|:---------------|
|
||||||
| `plant type` | Plant type.
|
| `plant type` | Plant type.
|
||||||
| `location name` | Location name.
|
| `location name` | Location name.
|
||||||
| `year` | Year.
|
| `year` | Year.
|
||||||
@@ -139,17 +138,33 @@ sns.barplot(x="plant type",
|
|||||||
.reset_index());
|
.reset_index());
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="../images/ex_emissions.png" width="500px"/>
|
```@raw html
|
||||||
|
<img src="../assets/ex_emissions.png" width="500px"/>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Products report
|
||||||
|
|
||||||
|
Report showing primary product amounts, locations and marginal costs. Generated by `RELOG.write_products_report(solution, filename)`.
|
||||||
|
|
||||||
|
| Column | Description
|
||||||
|
|:--------------------------------------|:---------------|
|
||||||
|
| `product name` | Product name.
|
||||||
|
| `location name` | Name of the collection center.
|
||||||
|
| `latitude (deg)` | Latitude of the collection center.
|
||||||
|
| `longitude (deg)` | Longitude of the collection center.
|
||||||
|
| `year` | What year this row corresponds to. This reports includes one row for each year.
|
||||||
|
| `amount (tonne)` | Amount of product available at this collection center.
|
||||||
|
| `amount disposed (tonne)` | Amount of product disposed of at this collection center.
|
||||||
|
| `marginal cost ($/tonne)` | Cost to process one additional tonne of this product coming from this collection center.
|
||||||
|
|
||||||
|
|
||||||
## Transportation report
|
## Transportation report
|
||||||
|
|
||||||
Report showing amount of product sent from initial locations to plants, and from one plant to another. Includes the distance between each pair of locations, amount-distance shipped, transportation costs and energy expenditure.
|
Report showing amount of product sent from initial locations to plants, and from one plant to another. Includes the distance between each pair of locations, amount-distance shipped, transportation costs and energy expenditure. Generated by `RELOG.write_transportation_report(solution, filename)`.
|
||||||
|
|
||||||
Generated by `RELOG.write_transportation_report(solution, filename)`. For a concrete example, see [nimh_transportation.csv](https://github.com/ANL-CEEESA/RELOG/blob/master/test/fixtures/nimh_transportation.csv).
|
|
||||||
|
|
||||||
|
|
||||||
| Column | Description
|
| Column | Description
|
||||||
|:--------------------------------------|---------------|
|
|:--------------------------------------|:---------------|
|
||||||
| `source type` | If product is being shipped from an initial location, equals `Origin`. If product is being shipped from a plant, equals plant type.
|
| `source type` | If product is being shipped from an initial location, equals `Origin`. If product is being shipped from a plant, equals plant type.
|
||||||
| `source location name` | Name of the location where the product is being shipped from.
|
| `source location name` | Name of the location where the product is being shipped from.
|
||||||
| `source latitude (deg)` | Latitude of the source location.
|
| `source latitude (deg)` | Latitude of the source location.
|
||||||
@@ -183,7 +198,9 @@ sns.barplot(x="product",
|
|||||||
.reset_index());
|
.reset_index());
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="../images/ex_transportation_amount_distance.png" width="500px"/>
|
```@raw html
|
||||||
|
<img src="../assets/ex_transportation_amount_distance.png" width="500px"/>
|
||||||
|
```
|
||||||
|
|
||||||
* Map of transportation lines (in Python):
|
* Map of transportation lines (in Python):
|
||||||
|
|
||||||
@@ -226,17 +243,17 @@ gp.GeoDataFrame(data, geometry=points).plot(ax=ax,
|
|||||||
markersize=50);
|
markersize=50);
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="../images/ex_transportation.png" width="1000px"/>
|
```@raw html
|
||||||
|
<img src="../assets/ex_transportation.png" width="1000px"/>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Transportation emissions report
|
## Transportation emissions report
|
||||||
|
|
||||||
Report showing emissions for each trip between initial locations and plants, and between pairs of plants.
|
Report showing emissions for each trip between initial locations and plants, and between pairs of plants. Generated by `RELOG.write_transportation_emissions_report(solution, filename)`.
|
||||||
|
|
||||||
Generated by `RELOG.write_transportation_emissions_report(solution, filename)`. For a concrete example, see [nimh_transportation_emissions.csv](https://github.com/ANL-CEEESA/RELOG/blob/master/test/fixtures/nimh_transportation_emissions.csv).
|
|
||||||
|
|
||||||
| Column | Description
|
| Column | Description
|
||||||
|:--------------------------------------|---------------|
|
|:--------------------------------------|:---------------|
|
||||||
| `source type` | If product is being shipped from an initial location, equals `Origin`. If product is being shipped from a plant, equals plant type.
|
| `source type` | If product is being shipped from an initial location, equals `Origin`. If product is being shipped from a plant, equals plant type.
|
||||||
| `source location name` | Name of the location where the product is being shipped from.
|
| `source location name` | Name of the location where the product is being shipped from.
|
||||||
| `source latitude (deg)` | Latitude of the source location.
|
| `source latitude (deg)` | Latitude of the source location.
|
||||||
@@ -270,4 +287,6 @@ sns.barplot(x="emission type",
|
|||||||
.reset_index());
|
.reset_index());
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="../images/ex_transportation_emissions.png" width="500px"/>
|
```@raw html
|
||||||
|
<img src="../assets/ex_transportation_emissions.png" width="500px"/>
|
||||||
|
```
|
||||||
@@ -3,22 +3,17 @@ Usage
|
|||||||
|
|
||||||
## 1. Installation
|
## 1. Installation
|
||||||
|
|
||||||
To use RELOG, the first step is to install the [Julia programming language](https://julialang.org/) on your machine. Note that RELOG was developed and tested with Julia 1.5 and may not be compatible with newer versions. After Julia is installed, launch the Julia console, type `]` to switch to package manger mode, then run:
|
To use RELOG, the first step is to install the [Julia programming language](https://julialang.org/) on your machine. Note that RELOG was developed and tested with Julia 1.8 and may not be compatible with newer versions. After Julia is installed, launch the Julia console, then run:
|
||||||
|
|
||||||
```text
|
```julia
|
||||||
(@v1.5) pkg> add https://github.com/ANL-CEEESA/RELOG.git
|
using Pkg
|
||||||
|
Pkg.add(name="RELOG", version="0.5")
|
||||||
```
|
```
|
||||||
|
|
||||||
After the package and all its dependencies have been installed, please run the RELOG test suite, as shown below, to make sure that the package has been correctly installed:
|
After the package and all its dependencies have been installed, please run the RELOG test suite, as shown below, to make sure that the package has been correctly installed:
|
||||||
|
|
||||||
```text
|
```julia
|
||||||
(@v1.5) pkg> test RELOG
|
Pkg.test("RELOG")
|
||||||
```
|
|
||||||
|
|
||||||
To update the package to a newer version, type `]` to enter the package manager mode, then run:
|
|
||||||
|
|
||||||
```text
|
|
||||||
(@v1.5) pkg> update RELOG
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 2. Modeling the problem
|
## 2. Modeling the problem
|
||||||
@@ -66,25 +61,65 @@ RELOG.write_transportation_report(solution, "transportation.csv")
|
|||||||
|
|
||||||
For a complete description of the file formats above, and for a complete list of available reports, see the [data format page](format.md).
|
For a complete description of the file formats above, and for a complete list of available reports, see the [data format page](format.md).
|
||||||
|
|
||||||
## 4. Advanced options
|
## 4. What-If Analysis
|
||||||
|
|
||||||
### 4.1 Changing the solver
|
Fundamentally, RELOG decides when and where to build plants based on a deterministic optimization problem that minimizes costs for a particular input file provided by the user. In practical situations, it may not be possible to perfectly estimate some (or most) entries in this input file in advance, such as costs, demands and emissions. In this situation, it may be interesting to evaluate how well does the facility location plan produced by RELOG work if costs, demands and emissions turn out to be different.
|
||||||
|
|
||||||
|
To simplify this what-if analysis, RELOG provides the `resolve` method, which updates a previous solution based on a new scenario, but keeps some of the previous decisions fixed. More precisely, given an optimal solution produced by RELOG and a new input file describing the new scenario, the `resolve` method reoptimizes the supply chain and produces a new solution which still builds the same set of plants as before, in exactly the same locations and with the same capacities, but that may now utilize the plants differently, based on the new data. For example, in the new solution, plants that were previously used at full capacity may now be utilized at half-capacity instead. As another example, regions that were previously served by a certain plant may now be served by a different one.
|
||||||
|
|
||||||
|
The following snippet shows how to use the method:
|
||||||
|
|
||||||
|
```julia
|
||||||
|
# Import package
|
||||||
|
using RELOG
|
||||||
|
|
||||||
|
# Optimize for the average scenario
|
||||||
|
solution_avg, model_avg = RELOG.solve("input_avg.json", return_model=true)
|
||||||
|
|
||||||
|
# Write reports for the average scenario
|
||||||
|
RELOG.write_plants_report(solution_avg, "plants_avg.csv")
|
||||||
|
RELOG.write_transportation_report(solution_avg, "transportation_avg.csv")
|
||||||
|
|
||||||
|
# Re-optimize for the high-demand scenario, keeping plants fixed
|
||||||
|
solution_high = RELOG.resolve(model_avg, "input_high.json")
|
||||||
|
|
||||||
|
# Write reports for the high-demand scenario
|
||||||
|
RELOG.write_plants_report(solution_high, "plants_high.csv")
|
||||||
|
RELOG.write_transportation_report(solution_high, "transportation_high.csv")
|
||||||
|
```
|
||||||
|
|
||||||
|
To use the `resolve` method, the new input file should be very similar to the original one. Only the following entries are allowed to change:
|
||||||
|
|
||||||
|
- **Products:** Transportation costs, energy, emissions and initial amounts (latitude, longitude and amount).
|
||||||
|
- **Plants:** Energy and emissions.
|
||||||
|
- **Plant's location:** Latitude and longitude.
|
||||||
|
- **Plant's storage:** Cost.
|
||||||
|
- **Plant's capacity:** Opening cost, fixed operating cost and variable operating cost.
|
||||||
|
|
||||||
|
|
||||||
|
## 5. Advanced options
|
||||||
|
|
||||||
|
### 5.1 Changing the solver
|
||||||
|
|
||||||
By default, RELOG internally uses [Cbc](https://github.com/coin-or/Cbc), an open-source and freely-available Mixed-Integer Linear Programming solver developed by the [COIN-OR Project](https://www.coin-or.org/). For larger-scale test cases, a commercial solver such as Gurobi, CPLEX or XPRESS is recommended. The following snippet shows how to switch from Cbc to Gurobi, for example:
|
By default, RELOG internally uses [Cbc](https://github.com/coin-or/Cbc), an open-source and freely-available Mixed-Integer Linear Programming solver developed by the [COIN-OR Project](https://www.coin-or.org/). For larger-scale test cases, a commercial solver such as Gurobi, CPLEX or XPRESS is recommended. The following snippet shows how to switch from Cbc to Gurobi, for example:
|
||||||
|
|
||||||
```julia
|
```julia
|
||||||
using RELOG, Gurobi, JuMP
|
using RELOG, Gurobi, JuMP
|
||||||
|
|
||||||
gurobi = optimizer_with_attributes(Gurobi.Optimizer,
|
gurobi = optimizer_with_attributes(
|
||||||
"TimeLimit" => 3600,
|
Gurobi.Optimizer,
|
||||||
"MIPGap" => 0.001)
|
"TimeLimit" => 3600,
|
||||||
|
"MIPGap" => 0.001,
|
||||||
|
)
|
||||||
|
|
||||||
RELOG.solve("instance.json",
|
RELOG.solve(
|
||||||
output="solution.json",
|
"instance.json",
|
||||||
optimizer=gurobi)
|
output="solution.json",
|
||||||
|
optimizer=gurobi,
|
||||||
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
### 4.2 Multi-period heuristics
|
### 5.2 Multi-period heuristics
|
||||||
|
|
||||||
For large-scale instances, it may be too time-consuming to find an exact optimal solution to the multi-period version of the problem. For these situations, RELOG includes a heuristic solution method, which proceeds as follows:
|
For large-scale instances, it may be too time-consuming to find an exact optimal solution to the multi-period version of the problem. For these situations, RELOG includes a heuristic solution method, which proceeds as follows:
|
||||||
|
|
||||||
@@ -97,6 +132,8 @@ To solve an instance using this heuristic, use the option `heuristic=true`, as s
|
|||||||
```julia
|
```julia
|
||||||
using RELOG
|
using RELOG
|
||||||
|
|
||||||
solution = RELOG.solve("/home/user/instance.json",
|
solution = RELOG.solve(
|
||||||
heuristic=true)
|
"/home/user/instance.json",
|
||||||
|
heuristic=true,
|
||||||
|
)
|
||||||
```
|
```
|
||||||
@@ -1,202 +0,0 @@
|
|||||||
{
|
|
||||||
"parameters": {
|
|
||||||
"time horizon (years)": 2
|
|
||||||
},
|
|
||||||
"products": {
|
|
||||||
"P1": {
|
|
||||||
"transportation cost ($/km/tonne)": [0.015, 0.015],
|
|
||||||
"transportation energy (J/km/tonne)": [0.12, 0.11],
|
|
||||||
"transportation emissions (tonne/km/tonne)": {
|
|
||||||
"CO2": [0.052, 0.050],
|
|
||||||
"CH4": [0.003, 0.002]
|
|
||||||
},
|
|
||||||
"initial amounts": {
|
|
||||||
"C1": {
|
|
||||||
"latitude (deg)": 7.0,
|
|
||||||
"longitude (deg)": 7.0,
|
|
||||||
"amount (tonne)": [934.56, 934.56]
|
|
||||||
},
|
|
||||||
"C2": {
|
|
||||||
"latitude (deg)": 7.0,
|
|
||||||
"longitude (deg)": 19.0,
|
|
||||||
"amount (tonne)": [198.95, 198.95]
|
|
||||||
},
|
|
||||||
"C3": {
|
|
||||||
"latitude (deg)": 84.0,
|
|
||||||
"longitude (deg)": 76.0,
|
|
||||||
"amount (tonne)": [212.97, 212.97]
|
|
||||||
},
|
|
||||||
"C4": {
|
|
||||||
"latitude (deg)": 21.0,
|
|
||||||
"longitude (deg)": 16.0,
|
|
||||||
"amount (tonne)": [352.19, 352.19]
|
|
||||||
},
|
|
||||||
"C5": {
|
|
||||||
"latitude (deg)": 32.0,
|
|
||||||
"longitude (deg)": 92.0,
|
|
||||||
"amount (tonne)": [510.33, 510.33]
|
|
||||||
},
|
|
||||||
"C6": {
|
|
||||||
"latitude (deg)": 14.0,
|
|
||||||
"longitude (deg)": 62.0,
|
|
||||||
"amount (tonne)": [471.66, 471.66]
|
|
||||||
},
|
|
||||||
"C7": {
|
|
||||||
"latitude (deg)": 30.0,
|
|
||||||
"longitude (deg)": 83.0,
|
|
||||||
"amount (tonne)": [785.21, 785.21]
|
|
||||||
},
|
|
||||||
"C8": {
|
|
||||||
"latitude (deg)": 35.0,
|
|
||||||
"longitude (deg)": 40.0,
|
|
||||||
"amount (tonne)": [706.17, 706.17]
|
|
||||||
},
|
|
||||||
"C9": {
|
|
||||||
"latitude (deg)": 74.0,
|
|
||||||
"longitude (deg)": 52.0,
|
|
||||||
"amount (tonne)": [30.08, 30.08]
|
|
||||||
},
|
|
||||||
"C10": {
|
|
||||||
"latitude (deg)": 22.0,
|
|
||||||
"longitude (deg)": 54.0,
|
|
||||||
"amount (tonne)": [536.52, 536.52]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"P2": {
|
|
||||||
"transportation cost ($/km/tonne)": [0.02, 0.02]
|
|
||||||
},
|
|
||||||
"P3": {
|
|
||||||
"transportation cost ($/km/tonne)": [0.0125, 0.0125]
|
|
||||||
},
|
|
||||||
"P4": {
|
|
||||||
"transportation cost ($/km/tonne)": [0.0175, 0.0175]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"plants": {
|
|
||||||
"F1": {
|
|
||||||
"input": "P1",
|
|
||||||
"outputs (tonne/tonne)": {
|
|
||||||
"P2": 0.2,
|
|
||||||
"P3": 0.5
|
|
||||||
},
|
|
||||||
"energy (GJ/tonne)": [0.12, 0.11],
|
|
||||||
"emissions (tonne/tonne)": {
|
|
||||||
"CO2": [0.052, 0.050],
|
|
||||||
"CH4": [0.003, 0.002]
|
|
||||||
},
|
|
||||||
"locations": {
|
|
||||||
"L1": {
|
|
||||||
"latitude (deg)": 0.0,
|
|
||||||
"longitude (deg)": 0.0,
|
|
||||||
"disposal": {
|
|
||||||
"P2": {
|
|
||||||
"cost ($/tonne)": [-10.0, -10.0],
|
|
||||||
"limit (tonne)": [1.0, 1.0]
|
|
||||||
},
|
|
||||||
"P3": {
|
|
||||||
"cost ($/tonne)": [-10.0, -10.0],
|
|
||||||
"limit (tonne)": [1.0, 1.0]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"capacities (tonne)": {
|
|
||||||
"250.0": {
|
|
||||||
"opening cost ($)": [500.0, 500.0],
|
|
||||||
"fixed operating cost ($)": [30.0, 30.0],
|
|
||||||
"variable operating cost ($/tonne)": [30.0, 30.0]
|
|
||||||
},
|
|
||||||
"1000.0": {
|
|
||||||
"opening cost ($)": [1250.0, 1250.0],
|
|
||||||
"fixed operating cost ($)": [30.0, 30.0],
|
|
||||||
"variable operating cost ($/tonne)": [30.0, 30.0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"L2": {
|
|
||||||
"latitude (deg)": 0.5,
|
|
||||||
"longitude (deg)": 0.5,
|
|
||||||
"capacities (tonne)": {
|
|
||||||
"0.0": {
|
|
||||||
"opening cost ($)": [1000, 1000],
|
|
||||||
"fixed operating cost ($)": [50.0, 50.0],
|
|
||||||
"variable operating cost ($/tonne)": [50.0, 50.0]
|
|
||||||
},
|
|
||||||
"10000.0": {
|
|
||||||
"opening cost ($)": [10000, 10000],
|
|
||||||
"fixed operating cost ($)": [50.0, 50.0],
|
|
||||||
"variable operating cost ($/tonne)": [50.0, 50.0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"F2": {
|
|
||||||
"input": "P2",
|
|
||||||
"outputs (tonne/tonne)": {
|
|
||||||
"P3": 0.05,
|
|
||||||
"P4": 0.80
|
|
||||||
},
|
|
||||||
"locations": {
|
|
||||||
"L3": {
|
|
||||||
"latitude (deg)": 25.0,
|
|
||||||
"longitude (deg)": 65.0,
|
|
||||||
"disposal": {
|
|
||||||
"P3": {
|
|
||||||
"cost ($/tonne)": [100.0, 100.0]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"capacities (tonne)": {
|
|
||||||
"1000.0": {
|
|
||||||
"opening cost ($)": [3000, 3000],
|
|
||||||
"fixed operating cost ($)": [50.0, 50.0],
|
|
||||||
"variable operating cost ($/tonne)": [50.0, 50.0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"L4": {
|
|
||||||
"latitude (deg)": 0.75,
|
|
||||||
"longitude (deg)": 0.20,
|
|
||||||
"capacities (tonne)": {
|
|
||||||
"10000": {
|
|
||||||
"opening cost ($)": [3000, 3000],
|
|
||||||
"fixed operating cost ($)": [50.0, 50.0],
|
|
||||||
"variable operating cost ($/tonne)": [50.0, 50.0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"F3": {
|
|
||||||
"input": "P4",
|
|
||||||
"locations": {
|
|
||||||
"L5": {
|
|
||||||
"latitude (deg)": 100.0,
|
|
||||||
"longitude (deg)": 100.0,
|
|
||||||
"capacities (tonne)": {
|
|
||||||
"15000": {
|
|
||||||
"opening cost ($)": [0.0, 0.0],
|
|
||||||
"fixed operating cost ($)": [0.0, 0.0],
|
|
||||||
"variable operating cost ($/tonne)": [-15.0, -15.0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"F4": {
|
|
||||||
"input": "P3",
|
|
||||||
"locations": {
|
|
||||||
"L6": {
|
|
||||||
"latitude (deg)": 50.0,
|
|
||||||
"longitude (deg)": 50.0,
|
|
||||||
"capacities (tonne)": {
|
|
||||||
"10000": {
|
|
||||||
"opening cost ($)": [0.0, 0.0],
|
|
||||||
"fixed operating cost ($)": [0.0, 0.0],
|
|
||||||
"variable operating cost ($/tonne)": [-15.0, -15.0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
[ Info: Reading s1.json...
|
|
||||||
[ Info: Building graph...
|
|
||||||
[ Info: 2 time periods
|
|
||||||
[ Info: 6 process nodes
|
|
||||||
[ Info: 8 shipping nodes (plant)
|
|
||||||
[ Info: 10 shipping nodes (collection)
|
|
||||||
[ Info: 38 arcs
|
|
||||||
[ Info: Building optimization model...
|
|
||||||
[ Info: Optimizing MILP...
|
|
||||||
[ Info: Re-optimizing with integer variables fixed...
|
|
||||||
[ Info: Extracting solution...
|
|
||||||
75
juliaw
Executable file
@@ -0,0 +1,75 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
|
||||||
|
# Copyright (C) 2020-2021, UChicago Argonne, LLC. All rights reserved.
|
||||||
|
# Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
|
||||||
|
if [ ! -e Project.toml ]; then
|
||||||
|
echo "juliaw: Project.toml not found"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -e Manifest.toml ]; then
|
||||||
|
julia --project=. -e 'using Pkg; Pkg.instantiate()' || exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -e build/sysimage.so -o Project.toml -nt build/sysimage.so ]; then
|
||||||
|
echo "juliaw: rebuilding system image..."
|
||||||
|
|
||||||
|
# Generate temporary project folder
|
||||||
|
rm -rf $HOME/.juliaw
|
||||||
|
mkdir -p $HOME/.juliaw/src
|
||||||
|
cp Project.toml Manifest.toml $HOME/.juliaw
|
||||||
|
NAME=$(julia -e 'using TOML; toml = TOML.parsefile("Project.toml"); "name" in keys(toml) && print(toml["name"])')
|
||||||
|
if [ ! -z $NAME ]; then
|
||||||
|
cat > $HOME/.juliaw/src/$NAME.jl << EOF
|
||||||
|
module $NAME
|
||||||
|
end
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Add PackageCompiler dependencies to temporary project
|
||||||
|
julia --project=$HOME/.juliaw -e 'using Pkg; Pkg.add(["PackageCompiler", "TOML", "Logging"])'
|
||||||
|
|
||||||
|
# Generate system image scripts
|
||||||
|
cat > $HOME/.juliaw/sysimage.jl << EOF
|
||||||
|
using PackageCompiler
|
||||||
|
using TOML
|
||||||
|
using Logging
|
||||||
|
|
||||||
|
Logging.disable_logging(Logging.Info)
|
||||||
|
mkpath("$PWD/build")
|
||||||
|
|
||||||
|
println("juliaw: generating precompilation statements...")
|
||||||
|
run(\`julia --project="$PWD" --trace-compile="$PWD"/build/precompile.jl \$(ARGS)\`)
|
||||||
|
|
||||||
|
println("juliaw: finding dependencies...")
|
||||||
|
project = TOML.parsefile("Project.toml")
|
||||||
|
manifest = TOML.parsefile("Manifest.toml")
|
||||||
|
deps = Symbol[]
|
||||||
|
for dep in keys(project["deps"])
|
||||||
|
if dep in keys(manifest)
|
||||||
|
# Up to Julia 1.6
|
||||||
|
dep_entry = manifest[dep][1]
|
||||||
|
else
|
||||||
|
# Julia 1.7+
|
||||||
|
dep_entry = manifest["deps"][dep][1]
|
||||||
|
end
|
||||||
|
if "path" in keys(dep_entry)
|
||||||
|
println(" - \$(dep) [skip]")
|
||||||
|
else
|
||||||
|
println(" - \$(dep)")
|
||||||
|
push!(deps, Symbol(dep))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
println("juliaw: building system image...")
|
||||||
|
create_sysimage(
|
||||||
|
deps,
|
||||||
|
precompile_statements_file = "$PWD/build/precompile.jl",
|
||||||
|
sysimage_path = "$PWD/build/sysimage.so",
|
||||||
|
)
|
||||||
|
EOF
|
||||||
|
julia --project=$HOME/.juliaw $HOME/.juliaw/sysimage.jl $*
|
||||||
|
else
|
||||||
|
julia --project=. --sysimage build/sysimage.so $*
|
||||||
|
fi
|
||||||
@@ -20,6 +20,7 @@ include("model/solve.jl")
|
|||||||
include("reports/plant_emissions.jl")
|
include("reports/plant_emissions.jl")
|
||||||
include("reports/plant_outputs.jl")
|
include("reports/plant_outputs.jl")
|
||||||
include("reports/plants.jl")
|
include("reports/plants.jl")
|
||||||
|
include("reports/products.jl")
|
||||||
include("reports/tr_emissions.jl")
|
include("reports/tr_emissions.jl")
|
||||||
include("reports/tr.jl")
|
include("reports/tr.jl")
|
||||||
include("reports/write.jl")
|
include("reports/write.jl")
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
.navbar-default {
|
|
||||||
border-bottom: 0px;
|
|
||||||
background-color: #fff;
|
|
||||||
box-shadow: 0px 0px 15px rgba(0, 0, 0, 0.2);
|
|
||||||
}
|
|
||||||
|
|
||||||
a, .navbar-default a {
|
|
||||||
color: #06a !important;
|
|
||||||
font-weight: normal;
|
|
||||||
}
|
|
||||||
|
|
||||||
.disabled > a {
|
|
||||||
color: #999 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.navbar-default a:hover,
|
|
||||||
.navbar-default .active,
|
|
||||||
.active > a {
|
|
||||||
background-color: #f0f0f0 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.icon-bar {
|
|
||||||
background-color: #666 !important;
|
|
||||||
}
|
|
||||||
|
|
||||||
.navbar-collapse {
|
|
||||||
border-color: #fff !important;
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
MathJax.Hub.Config({
|
|
||||||
"tex2jax": { inlineMath: [ [ '$', '$' ] ] }
|
|
||||||
});
|
|
||||||
MathJax.Hub.Config({
|
|
||||||
config: ["MMLorHTML.js"],
|
|
||||||
jax: ["input/TeX", "output/HTML-CSS", "output/NativeMML"],
|
|
||||||
extensions: ["MathMenu.js", "MathZoom.js"]
|
|
||||||
});
|
|
||||||
@@ -7,7 +7,7 @@ using Geodesy
|
|||||||
function calculate_distance(source_lat, source_lon, dest_lat, dest_lon)::Float64
|
function calculate_distance(source_lat, source_lon, dest_lat, dest_lon)::Float64
|
||||||
x = LLA(source_lat, source_lon, 0.0)
|
x = LLA(source_lat, source_lon, 0.0)
|
||||||
y = LLA(dest_lat, dest_lon, 0.0)
|
y = LLA(dest_lat, dest_lon, 0.0)
|
||||||
return round(distance(x, y) / 1000.0, digits = 2)
|
return round(euclidean_distance(x, y) / 1000.0, digits = 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
function build_graph(instance::Instance)::Graph
|
function build_graph(instance::Instance)::Graph
|
||||||
@@ -17,6 +17,9 @@ function build_graph(instance::Instance)::Graph
|
|||||||
plant_shipping_nodes = ShippingNode[]
|
plant_shipping_nodes = ShippingNode[]
|
||||||
collection_shipping_nodes = ShippingNode[]
|
collection_shipping_nodes = ShippingNode[]
|
||||||
|
|
||||||
|
name_to_process_node_map = Dict{Tuple{AbstractString,AbstractString},ProcessNode}()
|
||||||
|
collection_center_to_node = Dict()
|
||||||
|
|
||||||
process_nodes_by_input_product =
|
process_nodes_by_input_product =
|
||||||
Dict(product => ProcessNode[] for product in instance.products)
|
Dict(product => ProcessNode[] for product in instance.products)
|
||||||
shipping_nodes_by_plant = Dict(plant => [] for plant in instance.plants)
|
shipping_nodes_by_plant = Dict(plant => [] for plant in instance.plants)
|
||||||
@@ -25,6 +28,7 @@ function build_graph(instance::Instance)::Graph
|
|||||||
for center in instance.collection_centers
|
for center in instance.collection_centers
|
||||||
node = ShippingNode(next_index, center, center.product, [], [])
|
node = ShippingNode(next_index, center, center.product, [], [])
|
||||||
next_index += 1
|
next_index += 1
|
||||||
|
collection_center_to_node[center] = node
|
||||||
push!(collection_shipping_nodes, node)
|
push!(collection_shipping_nodes, node)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -35,6 +39,8 @@ function build_graph(instance::Instance)::Graph
|
|||||||
push!(process_nodes, pn)
|
push!(process_nodes, pn)
|
||||||
push!(process_nodes_by_input_product[plant.input], pn)
|
push!(process_nodes_by_input_product[plant.input], pn)
|
||||||
|
|
||||||
|
name_to_process_node_map[(plant.plant_name, plant.location_name)] = pn
|
||||||
|
|
||||||
for product in keys(plant.output)
|
for product in keys(plant.output)
|
||||||
sn = ShippingNode(next_index, plant, product, [], [])
|
sn = ShippingNode(next_index, plant, product, [], [])
|
||||||
next_index += 1
|
next_index += 1
|
||||||
@@ -53,7 +59,7 @@ function build_graph(instance::Instance)::Graph
|
|||||||
dest.location.longitude,
|
dest.location.longitude,
|
||||||
)
|
)
|
||||||
values = Dict("distance" => distance)
|
values = Dict("distance" => distance)
|
||||||
arc = Arc(source, dest, values)
|
arc = Arc(length(arcs) + 1, source, dest, values)
|
||||||
push!(source.outgoing_arcs, arc)
|
push!(source.outgoing_arcs, arc)
|
||||||
push!(dest.incoming_arcs, arc)
|
push!(dest.incoming_arcs, arc)
|
||||||
push!(arcs, arc)
|
push!(arcs, arc)
|
||||||
@@ -66,12 +72,32 @@ function build_graph(instance::Instance)::Graph
|
|||||||
for dest in shipping_nodes_by_plant[plant]
|
for dest in shipping_nodes_by_plant[plant]
|
||||||
weight = plant.output[dest.product]
|
weight = plant.output[dest.product]
|
||||||
values = Dict("weight" => weight)
|
values = Dict("weight" => weight)
|
||||||
arc = Arc(source, dest, values)
|
arc = Arc(length(arcs) + 1, source, dest, values)
|
||||||
push!(source.outgoing_arcs, arc)
|
push!(source.outgoing_arcs, arc)
|
||||||
push!(dest.incoming_arcs, arc)
|
push!(dest.incoming_arcs, arc)
|
||||||
push!(arcs, arc)
|
push!(arcs, arc)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return Graph(process_nodes, plant_shipping_nodes, collection_shipping_nodes, arcs)
|
return Graph(
|
||||||
|
process_nodes,
|
||||||
|
plant_shipping_nodes,
|
||||||
|
collection_shipping_nodes,
|
||||||
|
arcs,
|
||||||
|
name_to_process_node_map,
|
||||||
|
collection_center_to_node,
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function print_graph_stats(instance::Instance, graph::Graph)::Nothing
|
||||||
|
@info @sprintf(" %12d time periods", instance.time)
|
||||||
|
@info @sprintf(" %12d process nodes", length(graph.process_nodes))
|
||||||
|
@info @sprintf(" %12d shipping nodes (plant)", length(graph.plant_shipping_nodes))
|
||||||
|
@info @sprintf(
|
||||||
|
" %12d shipping nodes (collection)",
|
||||||
|
length(graph.collection_shipping_nodes)
|
||||||
|
)
|
||||||
|
@info @sprintf(" %12d arcs", length(graph.arcs))
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using Geodesy
|
|||||||
abstract type Node end
|
abstract type Node end
|
||||||
|
|
||||||
mutable struct Arc
|
mutable struct Arc
|
||||||
|
index::Int
|
||||||
source::Node
|
source::Node
|
||||||
dest::Node
|
dest::Node
|
||||||
values::Dict{String,Float64}
|
values::Dict{String,Float64}
|
||||||
@@ -32,4 +33,14 @@ mutable struct Graph
|
|||||||
plant_shipping_nodes::Vector{ShippingNode}
|
plant_shipping_nodes::Vector{ShippingNode}
|
||||||
collection_shipping_nodes::Vector{ShippingNode}
|
collection_shipping_nodes::Vector{ShippingNode}
|
||||||
arcs::Vector{Arc}
|
arcs::Vector{Arc}
|
||||||
|
name_to_process_node_map::Dict{Tuple{AbstractString,AbstractString},ProcessNode}
|
||||||
|
collection_center_to_node::Dict{CollectionCenter,ShippingNode}
|
||||||
|
end
|
||||||
|
|
||||||
|
function Base.show(io::IO, instance::Graph)
|
||||||
|
print(io, "RELOG graph with ")
|
||||||
|
print(io, "$(length(instance.process_nodes)) process nodes, ")
|
||||||
|
print(io, "$(length(instance.plant_shipping_nodes)) plant shipping nodes, ")
|
||||||
|
print(io, "$(length(instance.collection_shipping_nodes)) collection shipping nodes, ")
|
||||||
|
print(io, "$(length(instance.arcs)) arcs")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ function _compress(instance::Instance)::Instance
|
|||||||
for (emission_name, emission_value) in p.transportation_emissions
|
for (emission_name, emission_value) in p.transportation_emissions
|
||||||
p.transportation_emissions[emission_name] = [mean(emission_value)]
|
p.transportation_emissions[emission_name] = [mean(emission_value)]
|
||||||
end
|
end
|
||||||
|
p.disposal_limit = [maximum(p.disposal_limit) * T]
|
||||||
|
p.disposal_cost = [mean(p.disposal_cost)]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Compress collection centers
|
# Compress collection centers
|
||||||
@@ -58,3 +60,42 @@ function _compress(instance::Instance)::Instance
|
|||||||
|
|
||||||
return compressed
|
return compressed
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function _slice(instance::Instance, T::UnitRange)::Instance
|
||||||
|
sliced = deepcopy(instance)
|
||||||
|
sliced.time = length(T)
|
||||||
|
|
||||||
|
for p in sliced.products
|
||||||
|
p.transportation_cost = p.transportation_cost[T]
|
||||||
|
p.transportation_energy = p.transportation_energy[T]
|
||||||
|
for (emission_name, emission_value) in p.transportation_emissions
|
||||||
|
p.transportation_emissions[emission_name] = emission_value[T]
|
||||||
|
end
|
||||||
|
p.disposal_limit = p.disposal_limit[T]
|
||||||
|
p.disposal_cost = p.disposal_cost[T]
|
||||||
|
end
|
||||||
|
|
||||||
|
for c in sliced.collection_centers
|
||||||
|
c.amount = c.amount[T]
|
||||||
|
end
|
||||||
|
|
||||||
|
for plant in sliced.plants
|
||||||
|
plant.energy = plant.energy[T]
|
||||||
|
for (emission_name, emission_value) in plant.emissions
|
||||||
|
plant.emissions[emission_name] = emission_value[T]
|
||||||
|
end
|
||||||
|
for s in plant.sizes
|
||||||
|
s.variable_operating_cost = s.variable_operating_cost[T]
|
||||||
|
s.opening_cost = s.opening_cost[T]
|
||||||
|
s.fixed_operating_cost = s.fixed_operating_cost[T]
|
||||||
|
end
|
||||||
|
for (prod_name, disp_limit) in plant.disposal_limit
|
||||||
|
plant.disposal_limit[prod_name] = disp_limit[T]
|
||||||
|
end
|
||||||
|
for (prod_name, disp_cost) in plant.disposal_cost
|
||||||
|
plant.disposal_cost[prod_name] = disp_cost[T]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return sliced
|
||||||
|
end
|
||||||
@@ -42,7 +42,7 @@ function centroid(geom::Shapefile.Polygon)::GeoPoint
|
|||||||
return GeoPoint(round(y_center, digits = 5), round(x_center, digits = 5))
|
return GeoPoint(round(y_center, digits = 5), round(x_center, digits = 5))
|
||||||
end
|
end
|
||||||
|
|
||||||
function _download(url, output, expected_crc32)::Nothing
|
function _download_file(url, output, expected_crc32)::Nothing
|
||||||
if isfile(output)
|
if isfile(output)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -55,13 +55,13 @@ function _download(url, output, expected_crc32)::Nothing
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
function _download_zip(url, outputdir, expected_crc32)::Nothing
|
function _download_zip(url, outputdir, expected_output_file, expected_crc32)::Nothing
|
||||||
if isdir(outputdir)
|
if isfile(expected_output_file)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
mkpath(outputdir)
|
mkpath(outputdir)
|
||||||
@info "Downloading: $url"
|
@info "Downloading: $url"
|
||||||
zip_filename = _download(url)
|
zip_filename = download(url)
|
||||||
actual_crc32 = open(crc32, zip_filename)
|
actual_crc32 = open(crc32, zip_filename)
|
||||||
expected_crc32 == actual_crc32 || error("CRC32 mismatch")
|
expected_crc32 == actual_crc32 || error("CRC32 mismatch")
|
||||||
open(zip_filename) do zip_file
|
open(zip_filename) do zip_file
|
||||||
@@ -91,8 +91,8 @@ function _geodb_load_gov_census(;
|
|||||||
csv_filename = "$basedir/locations.csv"
|
csv_filename = "$basedir/locations.csv"
|
||||||
if !isfile(csv_filename)
|
if !isfile(csv_filename)
|
||||||
# Download required files
|
# Download required files
|
||||||
_download(population_url, "$basedir/population.csv", population_crc32)
|
_download_zip(shp_url, basedir, joinpath(basedir, shp_filename), shp_crc32)
|
||||||
_download_zip(shp_url, basedir, shp_crc32)
|
_download_file(population_url, "$basedir/population.csv", population_crc32)
|
||||||
|
|
||||||
# Read shapefile
|
# Read shapefile
|
||||||
@info "Processing: $shp_filename"
|
@info "Processing: $shp_filename"
|
||||||
@@ -140,12 +140,15 @@ end
|
|||||||
|
|
||||||
# 2018 US counties
|
# 2018 US counties
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
function _extract_cols_2018_us_county(table::Shapefile.Table, i::Int)::OrderedDict{String,Any}
|
function _extract_cols_2018_us_county(
|
||||||
|
table::Shapefile.Table,
|
||||||
|
i::Int,
|
||||||
|
)::OrderedDict{String,Any}
|
||||||
return OrderedDict(
|
return OrderedDict(
|
||||||
"id" => table.STATEFP[i] * table.COUNTYFP[i],
|
"id" => table.STATEFP[i] * table.COUNTYFP[i],
|
||||||
"statefp" => table.STATEFP[i],
|
"statefp" => table.STATEFP[i],
|
||||||
"countyfp" => table.COUNTYFP[i],
|
"countyfp" => table.COUNTYFP[i],
|
||||||
"name" => table.NAME[i]
|
"name" => table.NAME[i],
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -168,25 +171,6 @@ function _geodb_load_2018_us_county()::Dict{String,GeoRegion}
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
# # 2018 US ZIP codes
|
|
||||||
# # -----------------------------------------------------------------------------
|
|
||||||
# function _extract_cols_2018_us_zcta(table::Shapefile.Table, i::Int)::OrderedDict{String,Any}
|
|
||||||
# return OrderedDict("id" => table.ZCTA5CE10[i])
|
|
||||||
# end
|
|
||||||
|
|
||||||
# function _geodb_load_2018_us_zcta()::Dict{String,GeoRegion}
|
|
||||||
# return _geodb_load_gov_census(
|
|
||||||
# db_name = "2018-us-zcta",
|
|
||||||
# extract_cols = _extract_cols_2018_us_zcta,
|
|
||||||
# shp_crc32 = 0x6391f5fc,
|
|
||||||
# shp_filename = "cb_2018_us_zcta510_500k.shp",
|
|
||||||
# shp_url = "https://www2.census.gov/geo/tiger/GENZ2018/shp/cb_2018_us_zcta510_500k.zip",
|
|
||||||
# population_url = "http://www2.census.gov/programs-surveys/popest/datasets/2010-2019/national/totals/nst-est2019-alldata.csv",
|
|
||||||
# population_crc32 = 0x191cc64c,
|
|
||||||
# population_col = "POPESTIMATE2019",
|
|
||||||
# )
|
|
||||||
# end
|
|
||||||
|
|
||||||
# US States
|
# US States
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
function _extract_cols_us_state(table::Shapefile.Table, i::Int)::OrderedDict{String,Any}
|
function _extract_cols_us_state(table::Shapefile.Table, i::Int)::OrderedDict{String,Any}
|
||||||
@@ -218,7 +202,6 @@ end
|
|||||||
|
|
||||||
function geodb_load(db_name::AbstractString)::Dict{String,GeoRegion}
|
function geodb_load(db_name::AbstractString)::Dict{String,GeoRegion}
|
||||||
db_name == "2018-us-county" && return _geodb_load_2018_us_county()
|
db_name == "2018-us-county" && return _geodb_load_2018_us_county()
|
||||||
db_name == "2018-us-zcta" && return _geodb_load_2018_us_zcta()
|
|
||||||
db_name == "us-state" && return _geodb_load_us_state()
|
db_name == "us-state" && return _geodb_load_us_state()
|
||||||
error("Unknown database: $db_name")
|
error("Unknown database: $db_name")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -37,6 +37,8 @@ function parse(json)::Instance
|
|||||||
cost = product_dict["transportation cost (\$/km/tonne)"]
|
cost = product_dict["transportation cost (\$/km/tonne)"]
|
||||||
energy = zeros(T)
|
energy = zeros(T)
|
||||||
emissions = Dict()
|
emissions = Dict()
|
||||||
|
disposal_limit = zeros(T)
|
||||||
|
disposal_cost = zeros(T)
|
||||||
|
|
||||||
if "transportation energy (J/km/tonne)" in keys(product_dict)
|
if "transportation energy (J/km/tonne)" in keys(product_dict)
|
||||||
energy = product_dict["transportation energy (J/km/tonne)"]
|
energy = product_dict["transportation energy (J/km/tonne)"]
|
||||||
@@ -46,7 +48,25 @@ function parse(json)::Instance
|
|||||||
emissions = product_dict["transportation emissions (tonne/km/tonne)"]
|
emissions = product_dict["transportation emissions (tonne/km/tonne)"]
|
||||||
end
|
end
|
||||||
|
|
||||||
product = Product(product_name, cost, energy, emissions)
|
if "disposal limit (tonne)" in keys(product_dict)
|
||||||
|
disposal_limit = product_dict["disposal limit (tonne)"]
|
||||||
|
end
|
||||||
|
|
||||||
|
if "disposal cost (\$/tonne)" in keys(product_dict)
|
||||||
|
disposal_cost = product_dict["disposal cost (\$/tonne)"]
|
||||||
|
end
|
||||||
|
|
||||||
|
prod_centers = []
|
||||||
|
|
||||||
|
product = Product(
|
||||||
|
product_name,
|
||||||
|
cost,
|
||||||
|
energy,
|
||||||
|
emissions,
|
||||||
|
disposal_limit,
|
||||||
|
disposal_cost,
|
||||||
|
prod_centers,
|
||||||
|
)
|
||||||
push!(products, product)
|
push!(products, product)
|
||||||
prod_name_to_product[product_name] = product
|
prod_name_to_product[product_name] = product
|
||||||
|
|
||||||
@@ -66,6 +86,7 @@ function parse(json)::Instance
|
|||||||
product,
|
product,
|
||||||
center_dict["amount (tonne)"],
|
center_dict["amount (tonne)"],
|
||||||
)
|
)
|
||||||
|
push!(prod_centers, center)
|
||||||
push!(collection_centers, center)
|
push!(collection_centers, center)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -100,6 +121,13 @@ function parse(json)::Instance
|
|||||||
disposal_limit = Dict(p => [0.0 for t = 1:T] for p in keys(output))
|
disposal_limit = Dict(p => [0.0 for t = 1:T] for p in keys(output))
|
||||||
disposal_cost = Dict(p => [0.0 for t = 1:T] for p in keys(output))
|
disposal_cost = Dict(p => [0.0 for t = 1:T] for p in keys(output))
|
||||||
|
|
||||||
|
# GeoDB
|
||||||
|
if "location" in keys(location_dict)
|
||||||
|
region = geodb_query(location_dict["location"])
|
||||||
|
location_dict["latitude (deg)"] = region.centroid.lat
|
||||||
|
location_dict["longitude (deg)"] = region.centroid.lon
|
||||||
|
end
|
||||||
|
|
||||||
# Disposal
|
# Disposal
|
||||||
if "disposal" in keys(location_dict)
|
if "disposal" in keys(location_dict)
|
||||||
for (product_name, disposal_dict) in location_dict["disposal"]
|
for (product_name, disposal_dict) in location_dict["disposal"]
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ mutable struct Product
|
|||||||
transportation_cost::Vector{Float64}
|
transportation_cost::Vector{Float64}
|
||||||
transportation_energy::Vector{Float64}
|
transportation_energy::Vector{Float64}
|
||||||
transportation_emissions::Dict{String,Vector{Float64}}
|
transportation_emissions::Dict{String,Vector{Float64}}
|
||||||
|
disposal_limit::Vector{Float64}
|
||||||
|
disposal_cost::Vector{Float64}
|
||||||
|
collection_centers::Vector
|
||||||
end
|
end
|
||||||
|
|
||||||
mutable struct CollectionCenter
|
mutable struct CollectionCenter
|
||||||
|
|||||||
@@ -12,14 +12,10 @@ function validate(json, schema)
|
|||||||
result = JSONSchema.validate(json, schema)
|
result = JSONSchema.validate(json, schema)
|
||||||
if result !== nothing
|
if result !== nothing
|
||||||
if result isa JSONSchema.SingleIssue
|
if result isa JSONSchema.SingleIssue
|
||||||
path = join(result.path, " → ")
|
msg = "$(result.reason) in $(result.path)"
|
||||||
if length(path) == 0
|
|
||||||
path = "root"
|
|
||||||
end
|
|
||||||
msg = "$(result.msg) in $(path)"
|
|
||||||
else
|
else
|
||||||
msg = convert(String, result)
|
msg = convert(String, result)
|
||||||
end
|
end
|
||||||
throw(msg)
|
throw("Error parsing input file: $(msg)")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,63 +2,346 @@
|
|||||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||||
# Released under the modified BSD license. See COPYING.md for more details.
|
# Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
|
||||||
using JuMP, LinearAlgebra, Geodesy, Cbc, Clp, ProgressBars, Printf, DataStructures
|
using JuMP, LinearAlgebra, Geodesy, ProgressBars, Printf, DataStructures, StochasticPrograms
|
||||||
|
|
||||||
|
function build_model(
|
||||||
function build_model(instance::Instance, graph::Graph, optimizer)::JuMP.Model
|
instance::Instance,
|
||||||
model = Model(optimizer)
|
graph::Graph,
|
||||||
model[:instance] = instance
|
optimizer,
|
||||||
model[:graph] = graph
|
)
|
||||||
create_vars!(model)
|
return build_model(
|
||||||
create_objective_function!(model)
|
instance,
|
||||||
create_shipping_node_constraints!(model)
|
[graph],
|
||||||
create_process_node_constraints!(model)
|
[1.0],
|
||||||
return model
|
optimizer=optimizer,
|
||||||
|
method=:ef,
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function build_model(
|
||||||
|
instance::Instance,
|
||||||
|
graphs::Vector{Graph},
|
||||||
|
probs::Vector{Float64};
|
||||||
|
optimizer,
|
||||||
|
method=:ef,
|
||||||
|
tol=0.1,
|
||||||
|
)
|
||||||
|
T = instance.time
|
||||||
|
|
||||||
function create_vars!(model::JuMP.Model)
|
@stochastic_model model begin
|
||||||
graph, T = model[:graph], model[:instance].time
|
# Stage 1: Build plants
|
||||||
model[:flow] =
|
# =====================================================================
|
||||||
Dict((a, t) => @variable(model, lower_bound = 0) for a in graph.arcs, t = 1:T)
|
@stage 1 begin
|
||||||
model[:dispose] = Dict(
|
pn = graphs[1].process_nodes
|
||||||
(n, t) => @variable(
|
PN = length(pn)
|
||||||
model,
|
|
||||||
lower_bound = 0,
|
# Var: open_plant
|
||||||
upper_bound = n.location.disposal_limit[n.product][t]
|
@decision(
|
||||||
) for n in values(graph.plant_shipping_nodes), t = 1:T
|
model,
|
||||||
)
|
open_plant[n in 1:PN, t in 1:T],
|
||||||
model[:store] = Dict(
|
binary = true,
|
||||||
(n, t) =>
|
)
|
||||||
@variable(model, lower_bound = 0, upper_bound = n.location.storage_limit)
|
|
||||||
for n in values(graph.process_nodes), t = 1:T
|
# Var: is_open
|
||||||
)
|
@decision(
|
||||||
model[:process] = Dict(
|
model,
|
||||||
(n, t) => @variable(model, lower_bound = 0) for
|
is_open[n in 1:PN, t in 1:T],
|
||||||
n in values(graph.process_nodes), t = 1:T
|
binary = true,
|
||||||
)
|
)
|
||||||
model[:open_plant] = Dict(
|
|
||||||
(n, t) => @variable(model, binary = true) for n in values(graph.process_nodes),
|
# Objective function
|
||||||
t = 1:T
|
@objective(
|
||||||
)
|
model,
|
||||||
model[:is_open] = Dict(
|
Min,
|
||||||
(n, t) => @variable(model, binary = true) for n in values(graph.process_nodes),
|
|
||||||
t = 1:T
|
# Opening, fixed operating costs
|
||||||
)
|
sum(
|
||||||
model[:capacity] = Dict(
|
pn[n].location.sizes[1].opening_cost[t] * open_plant[n, t] +
|
||||||
(n, t) => @variable(
|
pn[n].location.sizes[1].fixed_operating_cost[t] * is_open[n, t]
|
||||||
model,
|
for n in 1:PN
|
||||||
lower_bound = 0,
|
for t in 1:T
|
||||||
upper_bound = n.location.sizes[2].capacity
|
),
|
||||||
) for n in values(graph.process_nodes), t = 1:T
|
)
|
||||||
)
|
|
||||||
model[:expansion] = Dict(
|
for t = 1:T, n in 1:PN
|
||||||
(n, t) => @variable(
|
# Plant is currently open if it was already open in the previous time period or
|
||||||
model,
|
# if it was built just now
|
||||||
lower_bound = 0,
|
if t > 1
|
||||||
upper_bound = n.location.sizes[2].capacity - n.location.sizes[1].capacity
|
@constraint(
|
||||||
) for n in values(graph.process_nodes), t = 1:T
|
model,
|
||||||
)
|
is_open[n, t] == is_open[n, t-1] + open_plant[n, t]
|
||||||
|
)
|
||||||
|
else
|
||||||
|
@constraint(model, is_open[n, t] == open_plant[n, t])
|
||||||
|
end
|
||||||
|
|
||||||
|
# Plant can only be opened during building period
|
||||||
|
if t ∉ instance.building_period
|
||||||
|
@constraint(model, open_plant[n, t] == 0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Stage 2: Flows, disposal, capacity & storage
|
||||||
|
# =====================================================================
|
||||||
|
@stage 2 begin
|
||||||
|
@uncertain graph
|
||||||
|
pn = graph.process_nodes
|
||||||
|
psn = graph.plant_shipping_nodes
|
||||||
|
csn = graph.collection_shipping_nodes
|
||||||
|
arcs = graph.arcs
|
||||||
|
|
||||||
|
A = length(arcs)
|
||||||
|
PN = length(pn)
|
||||||
|
CSN = length(csn)
|
||||||
|
PSN = length(psn)
|
||||||
|
|
||||||
|
# Var: flow
|
||||||
|
@recourse(
|
||||||
|
model,
|
||||||
|
flow[a in 1:A, t in 1:T],
|
||||||
|
lower_bound = 0,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Var: plant_dispose
|
||||||
|
@recourse(
|
||||||
|
model,
|
||||||
|
plant_dispose[n in 1:PSN, t in 1:T],
|
||||||
|
lower_bound = 0,
|
||||||
|
upper_bound = psn[n].location.disposal_limit[psn[n].product][t],
|
||||||
|
)
|
||||||
|
|
||||||
|
# Var: collection_dispose
|
||||||
|
@recourse(
|
||||||
|
model,
|
||||||
|
collection_dispose[n in 1:CSN, t in 1:T],
|
||||||
|
lower_bound = 0,
|
||||||
|
upper_bound = graph.collection_shipping_nodes[n].location.amount[t],
|
||||||
|
)
|
||||||
|
|
||||||
|
# Var: collection_shortfall
|
||||||
|
@recourse(
|
||||||
|
model,
|
||||||
|
collection_shortfall[n in 1:CSN, t in 1:T],
|
||||||
|
lower_bound = 0,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Var: store
|
||||||
|
@recourse(
|
||||||
|
model,
|
||||||
|
store[
|
||||||
|
n in 1:PN,
|
||||||
|
t in 1:T,
|
||||||
|
],
|
||||||
|
lower_bound = 0,
|
||||||
|
upper_bound = pn[n].location.storage_limit,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Var: process
|
||||||
|
@recourse(
|
||||||
|
model,
|
||||||
|
process[
|
||||||
|
n in 1:PN,
|
||||||
|
t in 1:T,
|
||||||
|
],
|
||||||
|
lower_bound = 0,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Var: capacity
|
||||||
|
@recourse(
|
||||||
|
model,
|
||||||
|
capacity[
|
||||||
|
n in 1:PN,
|
||||||
|
t in 1:T,
|
||||||
|
],
|
||||||
|
lower_bound = 0,
|
||||||
|
upper_bound = pn[n].location.sizes[2].capacity,
|
||||||
|
)
|
||||||
|
|
||||||
|
# Var: expansion
|
||||||
|
@recourse(
|
||||||
|
model,
|
||||||
|
expansion[
|
||||||
|
n in 1:PN,
|
||||||
|
t in 1:T,
|
||||||
|
],
|
||||||
|
lower_bound = 0,
|
||||||
|
upper_bound = (
|
||||||
|
pn[n].location.sizes[2].capacity -
|
||||||
|
pn[n].location.sizes[1].capacity
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
# Objective function
|
||||||
|
@objective(
|
||||||
|
model,
|
||||||
|
Min,
|
||||||
|
sum(
|
||||||
|
# Transportation costs
|
||||||
|
pn[n].location.input.transportation_cost[t] *
|
||||||
|
a.values["distance"] *
|
||||||
|
flow[a.index,t]
|
||||||
|
|
||||||
|
for n in 1:PN
|
||||||
|
for a in pn[n].incoming_arcs
|
||||||
|
for t in 1:T
|
||||||
|
) + sum(
|
||||||
|
# Fixed operating costs (expansion)
|
||||||
|
slope_fix_oper_cost(pn[n].location, t) * expansion[n, t] +
|
||||||
|
|
||||||
|
# Processing costs
|
||||||
|
pn[n].location.sizes[1].variable_operating_cost[t] * process[n, t] +
|
||||||
|
|
||||||
|
# Storage costs
|
||||||
|
pn[n].location.storage_cost[t] * store[n, t] +
|
||||||
|
|
||||||
|
# Expansion costs
|
||||||
|
(
|
||||||
|
t < T ? (
|
||||||
|
(
|
||||||
|
slope_open(pn[n].location, t) -
|
||||||
|
slope_open(pn[n].location, t + 1)
|
||||||
|
) * expansion[n, t]
|
||||||
|
) : slope_open(pn[n].location, t) * expansion[n, t]
|
||||||
|
)
|
||||||
|
|
||||||
|
for n in 1:PN
|
||||||
|
for t in 1:T
|
||||||
|
) + sum(
|
||||||
|
# Disposal costs (plants)
|
||||||
|
psn[n].location.disposal_cost[psn[n].product][t] * plant_dispose[n, t]
|
||||||
|
for n in 1:PSN
|
||||||
|
for t in 1:T
|
||||||
|
) + sum(
|
||||||
|
# Disposal costs (collection centers)
|
||||||
|
csn[n].location.product.disposal_cost[t] * collection_dispose[n, t]
|
||||||
|
for n in 1:CSN
|
||||||
|
for t in 1:T
|
||||||
|
) + sum(
|
||||||
|
# Collection shortfall
|
||||||
|
1e4 * collection_shortfall[n, t]
|
||||||
|
for n in 1:CSN
|
||||||
|
for t in 1:T
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Process node constraints
|
||||||
|
for t = 1:T, n in 1:PN
|
||||||
|
node = pn[n]
|
||||||
|
|
||||||
|
# Output amount is implied by amount processed
|
||||||
|
for arc in node.outgoing_arcs
|
||||||
|
@constraint(
|
||||||
|
model,
|
||||||
|
flow[arc.index, t] == arc.values["weight"] * process[n, t]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
# If plant is closed, capacity is zero
|
||||||
|
@constraint(
|
||||||
|
model,
|
||||||
|
capacity[n, t] <= node.location.sizes[2].capacity * is_open[n, t]
|
||||||
|
)
|
||||||
|
|
||||||
|
# If plant is open, capacity is greater than base
|
||||||
|
@constraint(
|
||||||
|
model,
|
||||||
|
capacity[n, t] >= node.location.sizes[1].capacity * is_open[n, t]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Capacity is linked to expansion
|
||||||
|
@constraint(
|
||||||
|
model,
|
||||||
|
capacity[n, t] <=
|
||||||
|
node.location.sizes[1].capacity + expansion[n, t]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Can only process up to capacity
|
||||||
|
@constraint(model, process[n, t] <= capacity[n, t])
|
||||||
|
|
||||||
|
if t > 1
|
||||||
|
# Plant capacity can only increase over time
|
||||||
|
@constraint(model, capacity[n, t] >= capacity[n, t-1])
|
||||||
|
@constraint(model, expansion[n, t] >= expansion[n, t-1])
|
||||||
|
end
|
||||||
|
|
||||||
|
# Amount received equals amount processed plus stored
|
||||||
|
store_in = 0
|
||||||
|
if t > 1
|
||||||
|
store_in = store[n, t-1]
|
||||||
|
end
|
||||||
|
if t == T
|
||||||
|
@constraint(model, store[n, t] == 0)
|
||||||
|
end
|
||||||
|
@constraint(
|
||||||
|
model,
|
||||||
|
sum(
|
||||||
|
flow[arc.index, t]
|
||||||
|
for arc in node.incoming_arcs
|
||||||
|
) + store_in == store[n, t] + process[n, t]
|
||||||
|
)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
# Material flow at collection shipping nodes
|
||||||
|
@constraint(
|
||||||
|
model,
|
||||||
|
eq_balance_centers[
|
||||||
|
n in 1:CSN,
|
||||||
|
t in 1:T,
|
||||||
|
],
|
||||||
|
sum(
|
||||||
|
flow[arc.index, t]
|
||||||
|
for arc in csn[n].outgoing_arcs
|
||||||
|
) == csn[n].location.amount[t] - collection_dispose[n, t] - collection_shortfall[n, t]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Material flow at plant shipping nodes
|
||||||
|
@constraint(
|
||||||
|
model,
|
||||||
|
eq_balance_plant[
|
||||||
|
n in 1:PSN,
|
||||||
|
t in 1:T,
|
||||||
|
],
|
||||||
|
sum(flow[a.index, t] for a in psn[n].incoming_arcs) ==
|
||||||
|
sum(flow[a.index, t] for a in psn[n].outgoing_arcs) +
|
||||||
|
plant_dispose[n, t]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Enforce product disposal limit at collection centers
|
||||||
|
for t in 1:T, prod in instance.products
|
||||||
|
if isempty(prod.collection_centers)
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
@constraint(
|
||||||
|
model,
|
||||||
|
sum(
|
||||||
|
collection_dispose[n, t]
|
||||||
|
for n in 1:CSN
|
||||||
|
if csn[n].product.name == prod.name
|
||||||
|
) <= prod.disposal_limit[t]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ξ = [
|
||||||
|
@scenario graph = graphs[i] probability = probs[i]
|
||||||
|
for i in 1:length(graphs)
|
||||||
|
]
|
||||||
|
|
||||||
|
if method == :ef
|
||||||
|
sp = instantiate(model, ξ; optimizer=optimizer)
|
||||||
|
elseif method == :lshaped
|
||||||
|
sp = instantiate(model, ξ; optimizer=LShaped.Optimizer)
|
||||||
|
set_optimizer_attribute(sp, MasterOptimizer(), optimizer)
|
||||||
|
set_optimizer_attribute(sp, SubProblemOptimizer(), optimizer)
|
||||||
|
set_optimizer_attribute(sp, RelativeTolerance(), tol)
|
||||||
|
else
|
||||||
|
error("unknown method: $method")
|
||||||
|
end
|
||||||
|
|
||||||
|
return sp
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -79,172 +362,3 @@ function slope_fix_oper_cost(plant, t)
|
|||||||
(plant.sizes[2].capacity - plant.sizes[1].capacity)
|
(plant.sizes[2].capacity - plant.sizes[1].capacity)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function create_objective_function!(model::JuMP.Model)
|
|
||||||
graph, T = model[:graph], model[:instance].time
|
|
||||||
obj = AffExpr(0.0)
|
|
||||||
|
|
||||||
# Process node costs
|
|
||||||
for n in values(graph.process_nodes), t = 1:T
|
|
||||||
|
|
||||||
# Transportation and variable operating costs
|
|
||||||
for a in n.incoming_arcs
|
|
||||||
c = n.location.input.transportation_cost[t] * a.values["distance"]
|
|
||||||
add_to_expression!(obj, c, model[:flow][a, t])
|
|
||||||
end
|
|
||||||
|
|
||||||
# Opening costs
|
|
||||||
add_to_expression!(
|
|
||||||
obj,
|
|
||||||
n.location.sizes[1].opening_cost[t],
|
|
||||||
model[:open_plant][n, t],
|
|
||||||
)
|
|
||||||
|
|
||||||
# Fixed operating costs (base)
|
|
||||||
add_to_expression!(
|
|
||||||
obj,
|
|
||||||
n.location.sizes[1].fixed_operating_cost[t],
|
|
||||||
model[:is_open][n, t],
|
|
||||||
)
|
|
||||||
|
|
||||||
# Fixed operating costs (expansion)
|
|
||||||
add_to_expression!(obj, slope_fix_oper_cost(n.location, t), model[:expansion][n, t])
|
|
||||||
|
|
||||||
# Processing costs
|
|
||||||
add_to_expression!(
|
|
||||||
obj,
|
|
||||||
n.location.sizes[1].variable_operating_cost[t],
|
|
||||||
model[:process][n, t],
|
|
||||||
)
|
|
||||||
|
|
||||||
# Storage costs
|
|
||||||
add_to_expression!(obj, n.location.storage_cost[t], model[:store][n, t])
|
|
||||||
|
|
||||||
# Expansion costs
|
|
||||||
if t < T
|
|
||||||
add_to_expression!(
|
|
||||||
obj,
|
|
||||||
slope_open(n.location, t) - slope_open(n.location, t + 1),
|
|
||||||
model[:expansion][n, t],
|
|
||||||
)
|
|
||||||
else
|
|
||||||
add_to_expression!(obj, slope_open(n.location, t), model[:expansion][n, t])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Shipping node costs
|
|
||||||
for n in values(graph.plant_shipping_nodes), t = 1:T
|
|
||||||
|
|
||||||
# Disposal costs
|
|
||||||
add_to_expression!(
|
|
||||||
obj,
|
|
||||||
n.location.disposal_cost[n.product][t],
|
|
||||||
model[:dispose][n, t],
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
@objective(model, Min, obj)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function create_shipping_node_constraints!(model::JuMP.Model)
|
|
||||||
graph, T = model[:graph], model[:instance].time
|
|
||||||
model[:eq_balance] = OrderedDict()
|
|
||||||
for t = 1:T
|
|
||||||
# Collection centers
|
|
||||||
for n in graph.collection_shipping_nodes
|
|
||||||
model[:eq_balance][n, t] = @constraint(
|
|
||||||
model,
|
|
||||||
sum(model[:flow][a, t] for a in n.outgoing_arcs) == n.location.amount[t]
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Plants
|
|
||||||
for n in graph.plant_shipping_nodes
|
|
||||||
@constraint(
|
|
||||||
model,
|
|
||||||
sum(model[:flow][a, t] for a in n.incoming_arcs) ==
|
|
||||||
sum(model[:flow][a, t] for a in n.outgoing_arcs) + model[:dispose][n, t]
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
function create_process_node_constraints!(model::JuMP.Model)
|
|
||||||
graph, T = model[:graph], model[:instance].time
|
|
||||||
|
|
||||||
for t = 1:T, n in graph.process_nodes
|
|
||||||
input_sum = AffExpr(0.0)
|
|
||||||
for a in n.incoming_arcs
|
|
||||||
add_to_expression!(input_sum, 1.0, model[:flow][a, t])
|
|
||||||
end
|
|
||||||
|
|
||||||
# Output amount is implied by amount processed
|
|
||||||
for a in n.outgoing_arcs
|
|
||||||
@constraint(
|
|
||||||
model,
|
|
||||||
model[:flow][a, t] == a.values["weight"] * model[:process][n, t]
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
# If plant is closed, capacity is zero
|
|
||||||
@constraint(
|
|
||||||
model,
|
|
||||||
model[:capacity][n, t] <= n.location.sizes[2].capacity * model[:is_open][n, t]
|
|
||||||
)
|
|
||||||
|
|
||||||
# If plant is open, capacity is greater than base
|
|
||||||
@constraint(
|
|
||||||
model,
|
|
||||||
model[:capacity][n, t] >= n.location.sizes[1].capacity * model[:is_open][n, t]
|
|
||||||
)
|
|
||||||
|
|
||||||
# Capacity is linked to expansion
|
|
||||||
@constraint(
|
|
||||||
model,
|
|
||||||
model[:capacity][n, t] <=
|
|
||||||
n.location.sizes[1].capacity + model[:expansion][n, t]
|
|
||||||
)
|
|
||||||
|
|
||||||
# Can only process up to capacity
|
|
||||||
@constraint(model, model[:process][n, t] <= model[:capacity][n, t])
|
|
||||||
|
|
||||||
if t > 1
|
|
||||||
# Plant capacity can only increase over time
|
|
||||||
@constraint(model, model[:capacity][n, t] >= model[:capacity][n, t-1])
|
|
||||||
@constraint(model, model[:expansion][n, t] >= model[:expansion][n, t-1])
|
|
||||||
end
|
|
||||||
|
|
||||||
# Amount received equals amount processed plus stored
|
|
||||||
store_in = 0
|
|
||||||
if t > 1
|
|
||||||
store_in = model[:store][n, t-1]
|
|
||||||
end
|
|
||||||
if t == T
|
|
||||||
@constraint(model, model[:store][n, t] == 0)
|
|
||||||
end
|
|
||||||
@constraint(
|
|
||||||
model,
|
|
||||||
input_sum + store_in == model[:store][n, t] + model[:process][n, t]
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
# Plant is currently open if it was already open in the previous time period or
|
|
||||||
# if it was built just now
|
|
||||||
if t > 1
|
|
||||||
@constraint(
|
|
||||||
model,
|
|
||||||
model[:is_open][n, t] == model[:is_open][n, t-1] + model[:open_plant][n, t]
|
|
||||||
)
|
|
||||||
else
|
|
||||||
@constraint(model, model[:is_open][n, t] == model[:open_plant][n, t])
|
|
||||||
end
|
|
||||||
|
|
||||||
# Plant can only be opened during building period
|
|
||||||
if t ∉ model[:instance].building_period
|
|
||||||
@constraint(model, model[:open_plant][n, t] == 0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|||||||
@@ -2,12 +2,33 @@
|
|||||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||||
# Released under the modified BSD license. See COPYING.md for more details.
|
# Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
|
||||||
using JuMP, LinearAlgebra, Geodesy, Cbc, Clp, ProgressBars, Printf, DataStructures
|
using JuMP, LinearAlgebra, Geodesy, ProgressBars, Printf, DataStructures
|
||||||
|
|
||||||
|
function get_solution(
|
||||||
|
instance,
|
||||||
|
graph,
|
||||||
|
model,
|
||||||
|
scenario_index::Int=1;
|
||||||
|
marginal_costs=false,
|
||||||
|
)
|
||||||
|
value(x) = StochasticPrograms.value(x, scenario_index)
|
||||||
|
ivalue(x) = StochasticPrograms.value(x)
|
||||||
|
shadow_price(x) = StochasticPrograms.shadow_price(x, scenario_index)
|
||||||
|
|
||||||
function get_solution(model::JuMP.Model; marginal_costs = true)
|
|
||||||
graph, instance = model[:graph], model[:instance]
|
|
||||||
T = instance.time
|
T = instance.time
|
||||||
|
|
||||||
|
pn = graph.process_nodes
|
||||||
|
psn = graph.plant_shipping_nodes
|
||||||
|
csn = graph.collection_shipping_nodes
|
||||||
|
arcs = graph.arcs
|
||||||
|
|
||||||
|
A = length(arcs)
|
||||||
|
PN = length(pn)
|
||||||
|
CSN = length(csn)
|
||||||
|
PSN = length(psn)
|
||||||
|
|
||||||
|
flow = model[2, :flow]
|
||||||
|
|
||||||
output = OrderedDict(
|
output = OrderedDict(
|
||||||
"Plants" => OrderedDict(),
|
"Plants" => OrderedDict(),
|
||||||
"Products" => OrderedDict(),
|
"Products" => OrderedDict(),
|
||||||
@@ -29,34 +50,52 @@ function get_solution(model::JuMP.Model; marginal_costs = true)
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
plant_to_process_node = OrderedDict(n.location => n for n in graph.process_nodes)
|
pn = graph.process_nodes
|
||||||
plant_to_shipping_nodes = OrderedDict()
|
psn = graph.plant_shipping_nodes
|
||||||
for p in instance.plants
|
|
||||||
plant_to_shipping_nodes[p] = []
|
plant_to_process_node_index = OrderedDict(
|
||||||
for a in plant_to_process_node[p].outgoing_arcs
|
pn[n].location => n
|
||||||
push!(plant_to_shipping_nodes[p], a.dest)
|
for n in 1:length(pn)
|
||||||
end
|
)
|
||||||
|
|
||||||
|
plant_to_shipping_node_indices = OrderedDict(p => [] for p in instance.plants)
|
||||||
|
for n in 1:length(psn)
|
||||||
|
push!(plant_to_shipping_node_indices[psn[n].location], n)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Products
|
# Products
|
||||||
if marginal_costs
|
for n in 1:CSN
|
||||||
for n in graph.collection_shipping_nodes
|
node = csn[n]
|
||||||
location_dict = OrderedDict{Any,Any}(
|
location_dict = OrderedDict{Any,Any}(
|
||||||
"Marginal cost (\$/tonne)" => [
|
"Latitude (deg)" => node.location.latitude,
|
||||||
round(abs(JuMP.shadow_price(model[:eq_balance][n, t])), digits = 2) for t = 1:T
|
"Longitude (deg)" => node.location.longitude,
|
||||||
],
|
"Amount (tonne)" => node.location.amount,
|
||||||
)
|
"Dispose (tonne)" => [
|
||||||
if n.product.name ∉ keys(output["Products"])
|
value(model[2, :collection_dispose][n, t])
|
||||||
output["Products"][n.product.name] = OrderedDict()
|
for t = 1:T
|
||||||
end
|
],
|
||||||
output["Products"][n.product.name][n.location.name] = location_dict
|
"Disposal cost (\$)" => [
|
||||||
|
value(model[2, :collection_dispose][n, t]) *
|
||||||
|
node.location.product.disposal_cost[t]
|
||||||
|
for t = 1:T
|
||||||
|
]
|
||||||
|
)
|
||||||
|
if marginal_costs
|
||||||
|
location_dict["Marginal cost (\$/tonne)"] = [
|
||||||
|
round(abs(shadow_price(model[2, :eq_balance_centers][n, t])), digits=2) for t = 1:T
|
||||||
|
]
|
||||||
end
|
end
|
||||||
|
if node.product.name ∉ keys(output["Products"])
|
||||||
|
output["Products"][node.product.name] = OrderedDict()
|
||||||
|
end
|
||||||
|
output["Products"][node.product.name][node.location.name] = location_dict
|
||||||
end
|
end
|
||||||
|
|
||||||
# Plants
|
# Plants
|
||||||
for plant in instance.plants
|
for plant in instance.plants
|
||||||
skip_plant = true
|
skip_plant = true
|
||||||
process_node = plant_to_process_node[plant]
|
n = plant_to_process_node_index[plant]
|
||||||
|
process_node = pn[n]
|
||||||
plant_dict = OrderedDict{Any,Any}(
|
plant_dict = OrderedDict{Any,Any}(
|
||||||
"Input" => OrderedDict(),
|
"Input" => OrderedDict(),
|
||||||
"Output" =>
|
"Output" =>
|
||||||
@@ -67,39 +106,39 @@ function get_solution(model::JuMP.Model; marginal_costs = true)
|
|||||||
"Latitude (deg)" => plant.latitude,
|
"Latitude (deg)" => plant.latitude,
|
||||||
"Longitude (deg)" => plant.longitude,
|
"Longitude (deg)" => plant.longitude,
|
||||||
"Capacity (tonne)" =>
|
"Capacity (tonne)" =>
|
||||||
[JuMP.value(model[:capacity][process_node, t]) for t = 1:T],
|
[value(model[2, :capacity][n, t]) for t = 1:T],
|
||||||
"Opening cost (\$)" => [
|
"Opening cost (\$)" => [
|
||||||
JuMP.value(model[:open_plant][process_node, t]) *
|
ivalue(model[1, :open_plant][n, t]) *
|
||||||
plant.sizes[1].opening_cost[t] for t = 1:T
|
plant.sizes[1].opening_cost[t] for t = 1:T
|
||||||
],
|
],
|
||||||
"Fixed operating cost (\$)" => [
|
"Fixed operating cost (\$)" => [
|
||||||
JuMP.value(model[:is_open][process_node, t]) *
|
ivalue(model[1, :is_open][n, t]) *
|
||||||
plant.sizes[1].fixed_operating_cost[t] +
|
plant.sizes[1].fixed_operating_cost[t] +
|
||||||
JuMP.value(model[:expansion][process_node, t]) *
|
value(model[2, :expansion][n, t]) *
|
||||||
slope_fix_oper_cost(plant, t) for t = 1:T
|
slope_fix_oper_cost(plant, t) for t = 1:T
|
||||||
],
|
],
|
||||||
"Expansion cost (\$)" => [
|
"Expansion cost (\$)" => [
|
||||||
(
|
(
|
||||||
if t == 1
|
if t == 1
|
||||||
slope_open(plant, t) * JuMP.value(model[:expansion][process_node, t])
|
slope_open(plant, t) * value(model[2, :expansion][n, t])
|
||||||
else
|
else
|
||||||
slope_open(plant, t) * (
|
slope_open(plant, t) * (
|
||||||
JuMP.value(model[:expansion][process_node, t]) -
|
value(model[2, :expansion][n, t]) -
|
||||||
JuMP.value(model[:expansion][process_node, t-1])
|
value(model[2, :expansion][n, t-1])
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
) for t = 1:T
|
) for t = 1:T
|
||||||
],
|
],
|
||||||
"Process (tonne)" =>
|
"Process (tonne)" =>
|
||||||
[JuMP.value(model[:process][process_node, t]) for t = 1:T],
|
[value(model[2, :process][n, t]) for t = 1:T],
|
||||||
"Variable operating cost (\$)" => [
|
"Variable operating cost (\$)" => [
|
||||||
JuMP.value(model[:process][process_node, t]) *
|
value(model[2, :process][n, t]) *
|
||||||
plant.sizes[1].variable_operating_cost[t] for t = 1:T
|
plant.sizes[1].variable_operating_cost[t] for t = 1:T
|
||||||
],
|
],
|
||||||
"Storage (tonne)" =>
|
"Storage (tonne)" =>
|
||||||
[JuMP.value(model[:store][process_node, t]) for t = 1:T],
|
[value(model[2, :store][n, t]) for t = 1:T],
|
||||||
"Storage cost (\$)" => [
|
"Storage cost (\$)" => [
|
||||||
JuMP.value(model[:store][process_node, t]) * plant.storage_cost[t]
|
value(model[2, :store][n, t]) * plant.storage_cost[t]
|
||||||
for t = 1:T
|
for t = 1:T
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@@ -112,7 +151,7 @@ function get_solution(model::JuMP.Model; marginal_costs = true)
|
|||||||
|
|
||||||
# Inputs
|
# Inputs
|
||||||
for a in process_node.incoming_arcs
|
for a in process_node.incoming_arcs
|
||||||
vals = [JuMP.value(model[:flow][a, t]) for t = 1:T]
|
vals = [value(flow[a.index, t]) for t = 1:T]
|
||||||
if sum(vals) <= 1e-3
|
if sum(vals) <= 1e-3
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
@@ -170,18 +209,20 @@ function get_solution(model::JuMP.Model; marginal_costs = true)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Outputs
|
# Outputs
|
||||||
for shipping_node in plant_to_shipping_nodes[plant]
|
for n2 in plant_to_shipping_node_indices[plant]
|
||||||
|
shipping_node = psn[n2]
|
||||||
product_name = shipping_node.product.name
|
product_name = shipping_node.product.name
|
||||||
plant_dict["Total output"][product_name] = zeros(T)
|
plant_dict["Total output"][product_name] = zeros(T)
|
||||||
plant_dict["Output"]["Send"][product_name] = product_dict = OrderedDict()
|
plant_dict["Output"]["Send"][product_name] = product_dict = OrderedDict()
|
||||||
|
|
||||||
disposal_amount = [JuMP.value(model[:dispose][shipping_node, t]) for t = 1:T]
|
disposal_amount =
|
||||||
|
[value(model[2, :plant_dispose][n2, t]) for t = 1:T]
|
||||||
if sum(disposal_amount) > 1e-5
|
if sum(disposal_amount) > 1e-5
|
||||||
skip_plant = false
|
skip_plant = false
|
||||||
plant_dict["Output"]["Dispose"][product_name] =
|
plant_dict["Output"]["Dispose"][product_name] =
|
||||||
disposal_dict = OrderedDict()
|
disposal_dict = OrderedDict()
|
||||||
disposal_dict["Amount (tonne)"] =
|
disposal_dict["Amount (tonne)"] =
|
||||||
[JuMP.value(model[:dispose][shipping_node, t]) for t = 1:T]
|
[value(model[2, :plant_dispose][n2, t]) for t = 1:T]
|
||||||
disposal_dict["Cost (\$)"] = [
|
disposal_dict["Cost (\$)"] = [
|
||||||
disposal_dict["Amount (tonne)"][t] *
|
disposal_dict["Amount (tonne)"][t] *
|
||||||
plant.disposal_cost[shipping_node.product][t] for t = 1:T
|
plant.disposal_cost[shipping_node.product][t] for t = 1:T
|
||||||
@@ -191,7 +232,7 @@ function get_solution(model::JuMP.Model; marginal_costs = true)
|
|||||||
end
|
end
|
||||||
|
|
||||||
for a in shipping_node.outgoing_arcs
|
for a in shipping_node.outgoing_arcs
|
||||||
vals = [JuMP.value(model[:flow][a, t]) for t = 1:T]
|
vals = [value(flow[a.index, t]) for t = 1:T]
|
||||||
if sum(vals) <= 1e-3
|
if sum(vals) <= 1e-3
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,26 +2,18 @@
|
|||||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||||
# Released under the modified BSD license. See COPYING.md for more details.
|
# Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
|
||||||
using JuMP, LinearAlgebra, Geodesy, Cbc, Clp, ProgressBars, Printf, DataStructures
|
using JuMP, LinearAlgebra, Geodesy, HiGHS, ProgressBars, Printf, DataStructures
|
||||||
|
|
||||||
default_milp_optimizer = optimizer_with_attributes(Cbc.Optimizer, "logLevel" => 0)
|
function _get_default_milp_optimizer()
|
||||||
default_lp_optimizer = optimizer_with_attributes(Clp.Optimizer, "LogLevel" => 0)
|
return optimizer_with_attributes(HiGHS.Optimizer)
|
||||||
|
end
|
||||||
|
|
||||||
function solve(
|
function _get_default_lp_optimizer()
|
||||||
instance::Instance;
|
return optimizer_with_attributes(HiGHS.Optimizer)
|
||||||
optimizer = nothing,
|
end
|
||||||
output = nothing,
|
|
||||||
marginal_costs = true,
|
|
||||||
)
|
|
||||||
|
|
||||||
milp_optimizer = lp_optimizer = optimizer
|
|
||||||
if optimizer == nothing
|
|
||||||
milp_optimizer = default_milp_optimizer
|
|
||||||
lp_optimizer = default_lp_optimizer
|
|
||||||
end
|
|
||||||
|
|
||||||
@info "Building graph..."
|
function _print_graph_stats(instance::Instance, graph::Graph)::Nothing
|
||||||
graph = RELOG.build_graph(instance)
|
|
||||||
@info @sprintf(" %12d time periods", instance.time)
|
@info @sprintf(" %12d time periods", instance.time)
|
||||||
@info @sprintf(" %12d process nodes", length(graph.process_nodes))
|
@info @sprintf(" %12d process nodes", length(graph.process_nodes))
|
||||||
@info @sprintf(" %12d shipping nodes (plant)", length(graph.plant_shipping_nodes))
|
@info @sprintf(" %12d shipping nodes (plant)", length(graph.plant_shipping_nodes))
|
||||||
@@ -30,49 +22,100 @@ function solve(
|
|||||||
length(graph.collection_shipping_nodes)
|
length(graph.collection_shipping_nodes)
|
||||||
)
|
)
|
||||||
@info @sprintf(" %12d arcs", length(graph.arcs))
|
@info @sprintf(" %12d arcs", length(graph.arcs))
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
@info "Building optimization model..."
|
function solve_stochastic(;
|
||||||
model = RELOG.build_model(instance, graph, milp_optimizer)
|
scenarios::Vector{String},
|
||||||
|
probs::Vector{Float64},
|
||||||
|
optimizer,
|
||||||
|
method=:ef,
|
||||||
|
tol=0.1,
|
||||||
|
)
|
||||||
|
@info "Reading instance files..."
|
||||||
|
instances = [parsefile(sc) for sc in scenarios]
|
||||||
|
|
||||||
@info "Optimizing MILP..."
|
@info "Building graphs..."
|
||||||
JuMP.optimize!(model)
|
graphs = [build_graph(inst) for inst in instances]
|
||||||
|
|
||||||
|
@info "Building stochastic model..."
|
||||||
|
sp = RELOG.build_model(instances[1], graphs, probs; optimizer, method, tol)
|
||||||
|
|
||||||
|
@info "Optimizing stochastic model..."
|
||||||
|
optimize!(sp)
|
||||||
|
|
||||||
|
@info "Extracting solution..."
|
||||||
|
solutions = [
|
||||||
|
get_solution(instances[i], graphs[i], sp, i)
|
||||||
|
for i in 1:length(instances)
|
||||||
|
]
|
||||||
|
|
||||||
|
return solutions
|
||||||
|
end
|
||||||
|
|
||||||
|
function solve(
|
||||||
|
instance::Instance;
|
||||||
|
optimizer=HiGHS.Optimizer,
|
||||||
|
marginal_costs=true,
|
||||||
|
return_model=false
|
||||||
|
)
|
||||||
|
@info "Building graph..."
|
||||||
|
graph = RELOG.build_graph(instance)
|
||||||
|
_print_graph_stats(instance, graph)
|
||||||
|
|
||||||
|
@info "Building model..."
|
||||||
|
model = RELOG.build_model(instance, [graph], [1.0]; optimizer)
|
||||||
|
|
||||||
|
@info "Optimizing model..."
|
||||||
|
optimize!(model)
|
||||||
if !has_values(model)
|
if !has_values(model)
|
||||||
@warn "No solution available"
|
error("No solution available")
|
||||||
return OrderedDict()
|
|
||||||
end
|
|
||||||
|
|
||||||
if marginal_costs
|
|
||||||
@info "Re-optimizing with integer variables fixed..."
|
|
||||||
all_vars = JuMP.all_variables(model)
|
|
||||||
vals = OrderedDict(var => JuMP.value(var) for var in all_vars)
|
|
||||||
JuMP.set_optimizer(model, lp_optimizer)
|
|
||||||
for var in all_vars
|
|
||||||
if JuMP.is_binary(var)
|
|
||||||
JuMP.unset_binary(var)
|
|
||||||
JuMP.fix(var, vals[var])
|
|
||||||
end
|
|
||||||
end
|
|
||||||
JuMP.optimize!(model)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@info "Extracting solution..."
|
@info "Extracting solution..."
|
||||||
solution = get_solution(model, marginal_costs = marginal_costs)
|
solution = get_solution(instance, graph, model, 1)
|
||||||
|
|
||||||
if output != nothing
|
if marginal_costs
|
||||||
write(solution, output)
|
@info "Re-optimizing with integer variables fixed..."
|
||||||
|
open_plant_vals = value.(model[1, :open_plant])
|
||||||
|
is_open_vals = value.(model[1, :is_open])
|
||||||
|
|
||||||
|
for n in 1:length(graph.process_nodes), t in 1:instance.time
|
||||||
|
unset_binary(model[1, :open_plant][n, t])
|
||||||
|
unset_binary(model[1, :is_open][n, t])
|
||||||
|
fix(
|
||||||
|
model[1, :open_plant][n, t],
|
||||||
|
open_plant_vals[n, t]
|
||||||
|
)
|
||||||
|
fix(
|
||||||
|
model[1, :is_open][n, t],
|
||||||
|
is_open_vals[n, t]
|
||||||
|
)
|
||||||
|
|
||||||
|
end
|
||||||
|
optimize!(model)
|
||||||
|
if has_values(model)
|
||||||
|
@info "Extracting solution..."
|
||||||
|
solution = get_solution(instance, graph, model, 1, marginal_costs=true)
|
||||||
|
else
|
||||||
|
@warn "Error computing marginal costs. Ignoring."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return solution
|
if return_model
|
||||||
|
return solution, model
|
||||||
|
else
|
||||||
|
return solution
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function solve(filename::AbstractString; heuristic = false, kwargs...)
|
function solve(filename::AbstractString; heuristic=false, kwargs...)
|
||||||
@info "Reading $filename..."
|
@info "Reading $filename..."
|
||||||
instance = RELOG.parsefile(filename)
|
instance = RELOG.parsefile(filename)
|
||||||
if heuristic && instance.time > 1
|
if heuristic && instance.time > 1
|
||||||
@info "Solving single-period version..."
|
@info "Solving single-period version..."
|
||||||
compressed = _compress(instance)
|
compressed = _compress(instance)
|
||||||
csol = solve(compressed; output = nothing, marginal_costs = false, kwargs...)
|
csol, model = solve(compressed; marginal_costs=false, return_model=true, kwargs...)
|
||||||
@info "Filtering candidate locations..."
|
@info "Filtering candidate locations..."
|
||||||
selected_pairs = []
|
selected_pairs = []
|
||||||
for (plant_name, plant_dict) in csol["Plants"]
|
for (plant_name, plant_dict) in csol["Plants"]
|
||||||
|
|||||||
52
src/reports/products.jl
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
# RELOG: Reverse Logistics Optimization
|
||||||
|
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||||
|
# Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
|
||||||
|
using DataFrames
|
||||||
|
using CSV
|
||||||
|
|
||||||
|
function products_report(solution)::DataFrame
|
||||||
|
df = DataFrame()
|
||||||
|
df."product name" = String[]
|
||||||
|
df."location name" = String[]
|
||||||
|
df."latitude (deg)" = Float64[]
|
||||||
|
df."longitude (deg)" = Float64[]
|
||||||
|
df."year" = Int[]
|
||||||
|
df."amount (tonne)" = Float64[]
|
||||||
|
df."marginal cost (\$/tonne)" = Float64[]
|
||||||
|
df."amount disposed (tonne)" = Float64[]
|
||||||
|
df."disposal cost (\$)" = Float64[]
|
||||||
|
T = length(solution["Energy"]["Plants (GJ)"])
|
||||||
|
for (prod_name, prod_dict) in solution["Products"]
|
||||||
|
for (location_name, location_dict) in prod_dict
|
||||||
|
for year = 1:T
|
||||||
|
marginal_cost = NaN
|
||||||
|
if "Marginal cost (\$/tonne)" in keys(location_dict)
|
||||||
|
marginal_cost = location_dict["Marginal cost (\$/tonne)"][year]
|
||||||
|
end
|
||||||
|
latitude = round(location_dict["Latitude (deg)"], digits = 6)
|
||||||
|
longitude = round(location_dict["Longitude (deg)"], digits = 6)
|
||||||
|
amount = location_dict["Amount (tonne)"][year]
|
||||||
|
amount_disposed = location_dict["Dispose (tonne)"][year]
|
||||||
|
disposal_cost = location_dict["Disposal cost (\$)"][year]
|
||||||
|
push!(
|
||||||
|
df,
|
||||||
|
[
|
||||||
|
prod_name,
|
||||||
|
location_name,
|
||||||
|
latitude,
|
||||||
|
longitude,
|
||||||
|
year,
|
||||||
|
amount,
|
||||||
|
marginal_cost,
|
||||||
|
amount_disposed,
|
||||||
|
disposal_cost,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return df
|
||||||
|
end
|
||||||
|
|
||||||
|
write_products_report(solution, filename) = CSV.write(filename, products_report(solution))
|
||||||
@@ -169,6 +169,12 @@
|
|||||||
},
|
},
|
||||||
"initial amounts": {
|
"initial amounts": {
|
||||||
"$ref": "#/definitions/InitialAmount"
|
"$ref": "#/definitions/InitialAmount"
|
||||||
|
},
|
||||||
|
"disposal limit (tonne)": {
|
||||||
|
"$ref": "#/definitions/TimeSeries"
|
||||||
|
},
|
||||||
|
"disposal cost ($/tonne)": {
|
||||||
|
"$ref": "#/definitions/TimeSeries"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
|
|||||||
@@ -1,15 +1,30 @@
|
|||||||
using PackageCompiler
|
using PackageCompiler
|
||||||
|
using TOML
|
||||||
|
using Logging
|
||||||
|
|
||||||
using Cbc
|
Logging.disable_logging(Logging.Info)
|
||||||
using Clp
|
|
||||||
using Geodesy
|
|
||||||
using JSON
|
|
||||||
using JSONSchema
|
|
||||||
using JuMP
|
|
||||||
using MathOptInterface
|
|
||||||
using ProgressBars
|
|
||||||
|
|
||||||
pkg = [:Cbc, :Clp, :Geodesy, :JSON, :JSONSchema, :JuMP, :MathOptInterface, :ProgressBars]
|
mkpath("build")
|
||||||
|
|
||||||
@info "Building system image..."
|
printstyled("Generating precompilation statements...\n", color = :light_green)
|
||||||
create_sysimage(pkg, sysimage_path = "build/sysimage.so")
|
run(`julia --project=. --trace-compile=build/precompile.jl $ARGS`)
|
||||||
|
|
||||||
|
printstyled("Finding dependencies...\n", color = :light_green)
|
||||||
|
project = TOML.parsefile("Project.toml")
|
||||||
|
manifest = TOML.parsefile("Manifest.toml")
|
||||||
|
deps = Symbol[]
|
||||||
|
for dep in keys(project["deps"])
|
||||||
|
if "path" in keys(manifest[dep][1])
|
||||||
|
printstyled(" skip $(dep)\n", color = :light_black)
|
||||||
|
else
|
||||||
|
println(" add $(dep)")
|
||||||
|
push!(deps, Symbol(dep))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
printstyled("Building system image...\n", color = :light_green)
|
||||||
|
create_sysimage(
|
||||||
|
deps,
|
||||||
|
precompile_statements_file = "build/precompile.jl",
|
||||||
|
sysimage_path = "build/sysimage.so",
|
||||||
|
)
|
||||||
|
|||||||
4406
test/fixtures/instances/case3_p010_s1.00.json
vendored
Normal file
4406
test/fixtures/instances/case3_p010_s1.25.json
vendored
Normal file
357
test/fixtures/instances/s1.json
vendored
Normal file
@@ -0,0 +1,357 @@
|
|||||||
|
{
|
||||||
|
"parameters": {
|
||||||
|
"time horizon (years)": 2
|
||||||
|
},
|
||||||
|
"products": {
|
||||||
|
"P1": {
|
||||||
|
"transportation cost ($/km/tonne)": [
|
||||||
|
0.015,
|
||||||
|
0.015
|
||||||
|
],
|
||||||
|
"transportation energy (J/km/tonne)": [
|
||||||
|
0.12,
|
||||||
|
0.11
|
||||||
|
],
|
||||||
|
"transportation emissions (tonne/km/tonne)": {
|
||||||
|
"CO2": [
|
||||||
|
0.052,
|
||||||
|
0.050
|
||||||
|
],
|
||||||
|
"CH4": [
|
||||||
|
0.003,
|
||||||
|
0.002
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"initial amounts": {
|
||||||
|
"C1": {
|
||||||
|
"latitude (deg)": 7.0,
|
||||||
|
"longitude (deg)": 7.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
934.56,
|
||||||
|
934.56
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"C2": {
|
||||||
|
"latitude (deg)": 7.0,
|
||||||
|
"longitude (deg)": 19.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
198.95,
|
||||||
|
198.95
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"C3": {
|
||||||
|
"latitude (deg)": 84.0,
|
||||||
|
"longitude (deg)": 76.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
212.97,
|
||||||
|
212.97
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"C4": {
|
||||||
|
"latitude (deg)": 21.0,
|
||||||
|
"longitude (deg)": 16.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
352.19,
|
||||||
|
352.19
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"C5": {
|
||||||
|
"latitude (deg)": 32.0,
|
||||||
|
"longitude (deg)": 92.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
510.33,
|
||||||
|
510.33
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"C6": {
|
||||||
|
"latitude (deg)": 14.0,
|
||||||
|
"longitude (deg)": 62.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
471.66,
|
||||||
|
471.66
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"C7": {
|
||||||
|
"latitude (deg)": 30.0,
|
||||||
|
"longitude (deg)": 83.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
785.21,
|
||||||
|
785.21
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"C8": {
|
||||||
|
"latitude (deg)": 35.0,
|
||||||
|
"longitude (deg)": 40.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
706.17,
|
||||||
|
706.17
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"C9": {
|
||||||
|
"latitude (deg)": 74.0,
|
||||||
|
"longitude (deg)": 52.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
30.08,
|
||||||
|
30.08
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"C10": {
|
||||||
|
"latitude (deg)": 22.0,
|
||||||
|
"longitude (deg)": 54.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
536.52,
|
||||||
|
536.52
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"disposal limit (tonne)": [
|
||||||
|
1.0,
|
||||||
|
1.0
|
||||||
|
],
|
||||||
|
"disposal cost ($/tonne)": [
|
||||||
|
-1000,
|
||||||
|
-1000
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"P2": {
|
||||||
|
"transportation cost ($/km/tonne)": [
|
||||||
|
0.02,
|
||||||
|
0.02
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"P3": {
|
||||||
|
"transportation cost ($/km/tonne)": [
|
||||||
|
0.0125,
|
||||||
|
0.0125
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"P4": {
|
||||||
|
"transportation cost ($/km/tonne)": [
|
||||||
|
0.0175,
|
||||||
|
0.0175
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"plants": {
|
||||||
|
"F1": {
|
||||||
|
"input": "P1",
|
||||||
|
"outputs (tonne/tonne)": {
|
||||||
|
"P2": 0.2,
|
||||||
|
"P3": 0.5
|
||||||
|
},
|
||||||
|
"energy (GJ/tonne)": [
|
||||||
|
0.12,
|
||||||
|
0.11
|
||||||
|
],
|
||||||
|
"emissions (tonne/tonne)": {
|
||||||
|
"CO2": [
|
||||||
|
0.052,
|
||||||
|
0.050
|
||||||
|
],
|
||||||
|
"CH4": [
|
||||||
|
0.003,
|
||||||
|
0.002
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locations": {
|
||||||
|
"L1": {
|
||||||
|
"latitude (deg)": 0.0,
|
||||||
|
"longitude (deg)": 0.0,
|
||||||
|
"disposal": {
|
||||||
|
"P2": {
|
||||||
|
"cost ($/tonne)": [
|
||||||
|
-10.0,
|
||||||
|
-10.0
|
||||||
|
],
|
||||||
|
"limit (tonne)": [
|
||||||
|
1.0,
|
||||||
|
1.0
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"P3": {
|
||||||
|
"cost ($/tonne)": [
|
||||||
|
-10.0,
|
||||||
|
-10.0
|
||||||
|
],
|
||||||
|
"limit (tonne)": [
|
||||||
|
1.0,
|
||||||
|
1.0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"capacities (tonne)": {
|
||||||
|
"250.0": {
|
||||||
|
"opening cost ($)": [
|
||||||
|
500.0,
|
||||||
|
500.0
|
||||||
|
],
|
||||||
|
"fixed operating cost ($)": [
|
||||||
|
30.0,
|
||||||
|
30.0
|
||||||
|
],
|
||||||
|
"variable operating cost ($/tonne)": [
|
||||||
|
30.0,
|
||||||
|
30.0
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1000.0": {
|
||||||
|
"opening cost ($)": [
|
||||||
|
1250.0,
|
||||||
|
1250.0
|
||||||
|
],
|
||||||
|
"fixed operating cost ($)": [
|
||||||
|
30.0,
|
||||||
|
30.0
|
||||||
|
],
|
||||||
|
"variable operating cost ($/tonne)": [
|
||||||
|
30.0,
|
||||||
|
30.0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"L2": {
|
||||||
|
"latitude (deg)": 0.5,
|
||||||
|
"longitude (deg)": 0.5,
|
||||||
|
"capacities (tonne)": {
|
||||||
|
"0.0": {
|
||||||
|
"opening cost ($)": [
|
||||||
|
1000,
|
||||||
|
1000
|
||||||
|
],
|
||||||
|
"fixed operating cost ($)": [
|
||||||
|
50.0,
|
||||||
|
50.0
|
||||||
|
],
|
||||||
|
"variable operating cost ($/tonne)": [
|
||||||
|
50.0,
|
||||||
|
50.0
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"10000.0": {
|
||||||
|
"opening cost ($)": [
|
||||||
|
10000,
|
||||||
|
10000
|
||||||
|
],
|
||||||
|
"fixed operating cost ($)": [
|
||||||
|
50.0,
|
||||||
|
50.0
|
||||||
|
],
|
||||||
|
"variable operating cost ($/tonne)": [
|
||||||
|
50.0,
|
||||||
|
50.0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"F2": {
|
||||||
|
"input": "P2",
|
||||||
|
"outputs (tonne/tonne)": {
|
||||||
|
"P3": 0.05,
|
||||||
|
"P4": 0.80
|
||||||
|
},
|
||||||
|
"locations": {
|
||||||
|
"L3": {
|
||||||
|
"latitude (deg)": 25.0,
|
||||||
|
"longitude (deg)": 65.0,
|
||||||
|
"disposal": {
|
||||||
|
"P3": {
|
||||||
|
"cost ($/tonne)": [
|
||||||
|
100.0,
|
||||||
|
100.0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"capacities (tonne)": {
|
||||||
|
"1000.0": {
|
||||||
|
"opening cost ($)": [
|
||||||
|
3000,
|
||||||
|
3000
|
||||||
|
],
|
||||||
|
"fixed operating cost ($)": [
|
||||||
|
50.0,
|
||||||
|
50.0
|
||||||
|
],
|
||||||
|
"variable operating cost ($/tonne)": [
|
||||||
|
50.0,
|
||||||
|
50.0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"L4": {
|
||||||
|
"latitude (deg)": 0.75,
|
||||||
|
"longitude (deg)": 0.20,
|
||||||
|
"capacities (tonne)": {
|
||||||
|
"10000": {
|
||||||
|
"opening cost ($)": [
|
||||||
|
3000,
|
||||||
|
3000
|
||||||
|
],
|
||||||
|
"fixed operating cost ($)": [
|
||||||
|
50.0,
|
||||||
|
50.0
|
||||||
|
],
|
||||||
|
"variable operating cost ($/tonne)": [
|
||||||
|
50.0,
|
||||||
|
50.0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"F3": {
|
||||||
|
"input": "P4",
|
||||||
|
"locations": {
|
||||||
|
"L5": {
|
||||||
|
"latitude (deg)": 100.0,
|
||||||
|
"longitude (deg)": 100.0,
|
||||||
|
"capacities (tonne)": {
|
||||||
|
"15000": {
|
||||||
|
"opening cost ($)": [
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"fixed operating cost ($)": [
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"variable operating cost ($/tonne)": [
|
||||||
|
-15.0,
|
||||||
|
-15.0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"F4": {
|
||||||
|
"input": "P3",
|
||||||
|
"locations": {
|
||||||
|
"L6": {
|
||||||
|
"latitude (deg)": 50.0,
|
||||||
|
"longitude (deg)": 50.0,
|
||||||
|
"capacities (tonne)": {
|
||||||
|
"10000": {
|
||||||
|
"opening cost ($)": [
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"fixed operating cost ($)": [
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"variable operating cost ($/tonne)": [
|
||||||
|
-15.0,
|
||||||
|
-15.0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -202,8 +202,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"L2": {
|
"L2": {
|
||||||
"latitude (deg)": 0.5,
|
"location": "2018-us-county:17043",
|
||||||
"longitude (deg)": 0.5,
|
|
||||||
"capacities (tonne)": {
|
"capacities (tonne)": {
|
||||||
"0.0": {
|
"0.0": {
|
||||||
"opening cost ($)": [
|
"opening cost ($)": [
|
||||||
@@ -3,37 +3,38 @@
|
|||||||
|
|
||||||
using RELOG
|
using RELOG
|
||||||
|
|
||||||
@testset "build_graph" begin
|
function graph_build_test()
|
||||||
basedir = dirname(@__FILE__)
|
@testset "build_graph" begin
|
||||||
instance = RELOG.parsefile("$basedir/../../instances/s1.json")
|
instance = RELOG.parsefile(fixture("instances/s1.json"))
|
||||||
graph = RELOG.build_graph(instance)
|
graph = RELOG.build_graph(instance)
|
||||||
process_node_by_location_name =
|
process_node_by_location_name =
|
||||||
Dict(n.location.location_name => n for n in graph.process_nodes)
|
Dict(n.location.location_name => n for n in graph.process_nodes)
|
||||||
|
|
||||||
@test length(graph.plant_shipping_nodes) == 8
|
@test length(graph.plant_shipping_nodes) == 8
|
||||||
@test length(graph.collection_shipping_nodes) == 10
|
@test length(graph.collection_shipping_nodes) == 10
|
||||||
@test length(graph.process_nodes) == 6
|
@test length(graph.process_nodes) == 6
|
||||||
|
|
||||||
node = graph.collection_shipping_nodes[1]
|
node = graph.collection_shipping_nodes[1]
|
||||||
@test node.location.name == "C1"
|
@test node.location.name == "C1"
|
||||||
@test length(node.incoming_arcs) == 0
|
@test length(node.incoming_arcs) == 0
|
||||||
@test length(node.outgoing_arcs) == 2
|
@test length(node.outgoing_arcs) == 2
|
||||||
@test node.outgoing_arcs[1].source.location.name == "C1"
|
@test node.outgoing_arcs[1].source.location.name == "C1"
|
||||||
@test node.outgoing_arcs[1].dest.location.plant_name == "F1"
|
@test node.outgoing_arcs[1].dest.location.plant_name == "F1"
|
||||||
@test node.outgoing_arcs[1].dest.location.location_name == "L1"
|
@test node.outgoing_arcs[1].dest.location.location_name == "L1"
|
||||||
@test node.outgoing_arcs[1].values["distance"] == 1095.62
|
@test node.outgoing_arcs[1].values["distance"] == 1095.62
|
||||||
|
|
||||||
node = process_node_by_location_name["L1"]
|
node = process_node_by_location_name["L1"]
|
||||||
@test node.location.plant_name == "F1"
|
@test node.location.plant_name == "F1"
|
||||||
@test node.location.location_name == "L1"
|
@test node.location.location_name == "L1"
|
||||||
@test length(node.incoming_arcs) == 10
|
@test length(node.incoming_arcs) == 10
|
||||||
@test length(node.outgoing_arcs) == 2
|
@test length(node.outgoing_arcs) == 2
|
||||||
|
|
||||||
node = process_node_by_location_name["L3"]
|
node = process_node_by_location_name["L3"]
|
||||||
@test node.location.plant_name == "F2"
|
@test node.location.plant_name == "F2"
|
||||||
@test node.location.location_name == "L3"
|
@test node.location.location_name == "L3"
|
||||||
@test length(node.incoming_arcs) == 2
|
@test length(node.incoming_arcs) == 2
|
||||||
@test length(node.outgoing_arcs) == 2
|
@test length(node.outgoing_arcs) == 2
|
||||||
|
|
||||||
@test length(graph.arcs) == 38
|
@test length(graph.arcs) == 38
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -3,51 +3,52 @@
|
|||||||
|
|
||||||
using RELOG
|
using RELOG
|
||||||
|
|
||||||
@testset "compress" begin
|
function compress_test()
|
||||||
basedir = dirname(@__FILE__)
|
@testset "compress" begin
|
||||||
instance = RELOG.parsefile("$basedir/../../instances/s1.json")
|
instance = RELOG.parsefile(fixture("instances/s1.json"))
|
||||||
compressed = RELOG._compress(instance)
|
compressed = RELOG._compress(instance)
|
||||||
|
|
||||||
product_name_to_product = Dict(p.name => p for p in compressed.products)
|
product_name_to_product = Dict(p.name => p for p in compressed.products)
|
||||||
location_name_to_facility = Dict()
|
location_name_to_facility = Dict()
|
||||||
for p in compressed.plants
|
for p in compressed.plants
|
||||||
location_name_to_facility[p.location_name] = p
|
location_name_to_facility[p.location_name] = p
|
||||||
|
end
|
||||||
|
for c in compressed.collection_centers
|
||||||
|
location_name_to_facility[c.name] = c
|
||||||
|
end
|
||||||
|
|
||||||
|
p1 = product_name_to_product["P1"]
|
||||||
|
p2 = product_name_to_product["P2"]
|
||||||
|
p3 = product_name_to_product["P3"]
|
||||||
|
c1 = location_name_to_facility["C1"]
|
||||||
|
l1 = location_name_to_facility["L1"]
|
||||||
|
|
||||||
|
@test compressed.time == 1
|
||||||
|
@test compressed.building_period == [1]
|
||||||
|
|
||||||
|
@test p1.name == "P1"
|
||||||
|
@test p1.transportation_cost ≈ [0.015]
|
||||||
|
@test p1.transportation_energy ≈ [0.115]
|
||||||
|
@test p1.transportation_emissions["CO2"] ≈ [0.051]
|
||||||
|
@test p1.transportation_emissions["CH4"] ≈ [0.0025]
|
||||||
|
|
||||||
|
@test c1.name == "C1"
|
||||||
|
@test c1.amount ≈ [1869.12]
|
||||||
|
|
||||||
|
@test l1.plant_name == "F1"
|
||||||
|
@test l1.location_name == "L1"
|
||||||
|
@test l1.energy ≈ [0.115]
|
||||||
|
@test l1.emissions["CO2"] ≈ [0.051]
|
||||||
|
@test l1.emissions["CH4"] ≈ [0.0025]
|
||||||
|
@test l1.sizes[1].opening_cost ≈ [500]
|
||||||
|
@test l1.sizes[2].opening_cost ≈ [1250]
|
||||||
|
@test l1.sizes[1].fixed_operating_cost ≈ [60]
|
||||||
|
@test l1.sizes[2].fixed_operating_cost ≈ [60]
|
||||||
|
@test l1.sizes[1].variable_operating_cost ≈ [30]
|
||||||
|
@test l1.sizes[2].variable_operating_cost ≈ [30]
|
||||||
|
@test l1.disposal_limit[p2] ≈ [2.0]
|
||||||
|
@test l1.disposal_limit[p3] ≈ [2.0]
|
||||||
|
@test l1.disposal_cost[p2] ≈ [-10.0]
|
||||||
|
@test l1.disposal_cost[p3] ≈ [-10.0]
|
||||||
end
|
end
|
||||||
for c in compressed.collection_centers
|
|
||||||
location_name_to_facility[c.name] = c
|
|
||||||
end
|
|
||||||
|
|
||||||
p1 = product_name_to_product["P1"]
|
|
||||||
p2 = product_name_to_product["P2"]
|
|
||||||
p3 = product_name_to_product["P3"]
|
|
||||||
c1 = location_name_to_facility["C1"]
|
|
||||||
l1 = location_name_to_facility["L1"]
|
|
||||||
|
|
||||||
@test compressed.time == 1
|
|
||||||
@test compressed.building_period == [1]
|
|
||||||
|
|
||||||
@test p1.name == "P1"
|
|
||||||
@test p1.transportation_cost ≈ [0.015]
|
|
||||||
@test p1.transportation_energy ≈ [0.115]
|
|
||||||
@test p1.transportation_emissions["CO2"] ≈ [0.051]
|
|
||||||
@test p1.transportation_emissions["CH4"] ≈ [0.0025]
|
|
||||||
|
|
||||||
@test c1.name == "C1"
|
|
||||||
@test c1.amount ≈ [1869.12]
|
|
||||||
|
|
||||||
@test l1.plant_name == "F1"
|
|
||||||
@test l1.location_name == "L1"
|
|
||||||
@test l1.energy ≈ [0.115]
|
|
||||||
@test l1.emissions["CO2"] ≈ [0.051]
|
|
||||||
@test l1.emissions["CH4"] ≈ [0.0025]
|
|
||||||
@test l1.sizes[1].opening_cost ≈ [500]
|
|
||||||
@test l1.sizes[2].opening_cost ≈ [1250]
|
|
||||||
@test l1.sizes[1].fixed_operating_cost ≈ [60]
|
|
||||||
@test l1.sizes[2].fixed_operating_cost ≈ [60]
|
|
||||||
@test l1.sizes[1].variable_operating_cost ≈ [30]
|
|
||||||
@test l1.sizes[2].variable_operating_cost ≈ [30]
|
|
||||||
@test l1.disposal_limit[p2] ≈ [2.0]
|
|
||||||
@test l1.disposal_limit[p3] ≈ [2.0]
|
|
||||||
@test l1.disposal_cost[p2] ≈ [-10.0]
|
|
||||||
@test l1.disposal_cost[p3] ≈ [-10.0]
|
|
||||||
end
|
end
|
||||||
@@ -4,22 +4,24 @@
|
|||||||
|
|
||||||
using RELOG
|
using RELOG
|
||||||
|
|
||||||
@testset "geodb_query (2018-us-county)" begin
|
function geodb_test()
|
||||||
region = RELOG.geodb_query("2018-us-county:17043")
|
@testset "geodb_query (2018-us-county)" begin
|
||||||
@test region.centroid.lat == 41.83956
|
region = RELOG.geodb_query("2018-us-county:17043")
|
||||||
@test region.centroid.lon == -88.08857
|
@test region.centroid.lat == 41.83956
|
||||||
@test region.population == 922_921
|
@test region.centroid.lon == -88.08857
|
||||||
end
|
@test region.population == 922_921
|
||||||
|
end
|
||||||
|
|
||||||
# @testset "geodb_query (2018-us-zcta)" begin
|
# @testset "geodb_query (2018-us-zcta)" begin
|
||||||
# region = RELOG.geodb_query("2018-us-zcta:60439")
|
# region = RELOG.geodb_query("2018-us-zcta:60439")
|
||||||
# @test region.centroid.lat == 41.68241
|
# @test region.centroid.lat == 41.68241
|
||||||
# @test region.centroid.lon == -87.98954
|
# @test region.centroid.lon == -87.98954
|
||||||
# end
|
# end
|
||||||
|
|
||||||
@testset "geodb_query (us-state)" begin
|
@testset "geodb_query (us-state)" begin
|
||||||
region = RELOG.geodb_query("us-state:IL")
|
region = RELOG.geodb_query("us-state:IL")
|
||||||
@test region.centroid.lat == 39.73939
|
@test region.centroid.lat == 39.73939
|
||||||
@test region.centroid.lon == -89.50414
|
@test region.centroid.lon == -89.50414
|
||||||
@test region.population == 12_671_821
|
@test region.population == 12_671_821
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -3,84 +3,90 @@
|
|||||||
|
|
||||||
using RELOG
|
using RELOG
|
||||||
|
|
||||||
@testset "parse" begin
|
function parse_test()
|
||||||
basedir = dirname(@__FILE__)
|
@testset "parse" begin
|
||||||
instance = RELOG.parsefile("$basedir/../../instances/s1.json")
|
instance = RELOG.parsefile(fixture("instances/s1.json"))
|
||||||
|
|
||||||
centers = instance.collection_centers
|
centers = instance.collection_centers
|
||||||
plants = instance.plants
|
plants = instance.plants
|
||||||
products = instance.products
|
products = instance.products
|
||||||
location_name_to_plant = Dict(p.location_name => p for p in plants)
|
location_name_to_plant = Dict(p.location_name => p for p in plants)
|
||||||
product_name_to_product = Dict(p.name => p for p in products)
|
product_name_to_product = Dict(p.name => p for p in products)
|
||||||
|
|
||||||
@test length(centers) == 10
|
@test length(centers) == 10
|
||||||
@test centers[1].name == "C1"
|
@test centers[1].name == "C1"
|
||||||
@test centers[1].latitude == 7
|
@test centers[1].latitude == 7
|
||||||
@test centers[1].latitude == 7
|
@test centers[1].latitude == 7
|
||||||
@test centers[1].longitude == 7
|
@test centers[1].longitude == 7
|
||||||
@test centers[1].amount == [934.56, 934.56]
|
@test centers[1].amount == [934.56, 934.56]
|
||||||
@test centers[1].product.name == "P1"
|
@test centers[1].product.name == "P1"
|
||||||
|
|
||||||
@test length(plants) == 6
|
@test length(plants) == 6
|
||||||
|
|
||||||
plant = location_name_to_plant["L1"]
|
plant = location_name_to_plant["L1"]
|
||||||
@test plant.plant_name == "F1"
|
@test plant.plant_name == "F1"
|
||||||
@test plant.location_name == "L1"
|
@test plant.location_name == "L1"
|
||||||
@test plant.input.name == "P1"
|
@test plant.input.name == "P1"
|
||||||
@test plant.latitude == 0
|
@test plant.latitude == 0
|
||||||
@test plant.longitude == 0
|
@test plant.longitude == 0
|
||||||
|
|
||||||
@test length(plant.sizes) == 2
|
@test length(plant.sizes) == 2
|
||||||
@test plant.sizes[1].capacity == 250
|
@test plant.sizes[1].capacity == 250
|
||||||
@test plant.sizes[1].opening_cost == [500, 500]
|
@test plant.sizes[1].opening_cost == [500, 500]
|
||||||
@test plant.sizes[1].fixed_operating_cost == [30, 30]
|
@test plant.sizes[1].fixed_operating_cost == [30, 30]
|
||||||
@test plant.sizes[1].variable_operating_cost == [30, 30]
|
@test plant.sizes[1].variable_operating_cost == [30, 30]
|
||||||
@test plant.sizes[2].capacity == 1000
|
@test plant.sizes[2].capacity == 1000
|
||||||
@test plant.sizes[2].opening_cost == [1250, 1250]
|
@test plant.sizes[2].opening_cost == [1250, 1250]
|
||||||
@test plant.sizes[2].fixed_operating_cost == [30, 30]
|
@test plant.sizes[2].fixed_operating_cost == [30, 30]
|
||||||
@test plant.sizes[2].variable_operating_cost == [30, 30]
|
@test plant.sizes[2].variable_operating_cost == [30, 30]
|
||||||
|
|
||||||
p2 = product_name_to_product["P2"]
|
p1 = product_name_to_product["P1"]
|
||||||
p3 = product_name_to_product["P3"]
|
@test p1.disposal_limit == [1.0, 1.0]
|
||||||
@test length(plant.output) == 2
|
@test p1.disposal_cost == [-1000.0, -1000.0]
|
||||||
@test plant.output[p2] == 0.2
|
|
||||||
@test plant.output[p3] == 0.5
|
|
||||||
@test plant.disposal_limit[p2] == [1, 1]
|
|
||||||
@test plant.disposal_limit[p3] == [1, 1]
|
|
||||||
@test plant.disposal_cost[p2] == [-10, -10]
|
|
||||||
@test plant.disposal_cost[p3] == [-10, -10]
|
|
||||||
|
|
||||||
plant = location_name_to_plant["L3"]
|
p2 = product_name_to_product["P2"]
|
||||||
@test plant.location_name == "L3"
|
@test p2.disposal_limit == [0.0, 0.0]
|
||||||
@test plant.input.name == "P2"
|
@test p2.disposal_cost == [0.0, 0.0]
|
||||||
@test plant.latitude == 25
|
|
||||||
@test plant.longitude == 65
|
|
||||||
|
|
||||||
@test length(plant.sizes) == 2
|
p3 = product_name_to_product["P3"]
|
||||||
@test plant.sizes[1].capacity == 1000.0
|
@test length(plant.output) == 2
|
||||||
@test plant.sizes[1].opening_cost == [3000, 3000]
|
@test plant.output[p2] == 0.2
|
||||||
@test plant.sizes[1].fixed_operating_cost == [50, 50]
|
@test plant.output[p3] == 0.5
|
||||||
@test plant.sizes[1].variable_operating_cost == [50, 50]
|
@test plant.disposal_limit[p2] == [1, 1]
|
||||||
@test plant.sizes[1] == plant.sizes[2]
|
@test plant.disposal_limit[p3] == [1, 1]
|
||||||
|
@test plant.disposal_cost[p2] == [-10, -10]
|
||||||
|
@test plant.disposal_cost[p3] == [-10, -10]
|
||||||
|
|
||||||
p4 = product_name_to_product["P4"]
|
plant = location_name_to_plant["L3"]
|
||||||
@test plant.output[p3] == 0.05
|
@test plant.location_name == "L3"
|
||||||
@test plant.output[p4] == 0.8
|
@test plant.input.name == "P2"
|
||||||
@test plant.disposal_limit[p3] == [1e8, 1e8]
|
@test plant.latitude == 25
|
||||||
@test plant.disposal_limit[p4] == [0, 0]
|
@test plant.longitude == 65
|
||||||
|
|
||||||
|
@test length(plant.sizes) == 2
|
||||||
|
@test plant.sizes[1].capacity == 1000.0
|
||||||
|
@test plant.sizes[1].opening_cost == [3000, 3000]
|
||||||
|
@test plant.sizes[1].fixed_operating_cost == [50, 50]
|
||||||
|
@test plant.sizes[1].variable_operating_cost == [50, 50]
|
||||||
|
@test plant.sizes[1] == plant.sizes[2]
|
||||||
|
|
||||||
|
p4 = product_name_to_product["P4"]
|
||||||
|
@test plant.output[p3] == 0.05
|
||||||
|
@test plant.output[p4] == 0.8
|
||||||
|
@test plant.disposal_limit[p3] == [1e8, 1e8]
|
||||||
|
@test plant.disposal_limit[p4] == [0, 0]
|
||||||
|
end
|
||||||
|
|
||||||
|
@testset "parse (geodb)" begin
|
||||||
|
instance = RELOG.parsefile(fixture("instances/s2.json"))
|
||||||
|
|
||||||
|
centers = instance.collection_centers
|
||||||
|
@test centers[1].name == "C1"
|
||||||
|
@test centers[1].latitude == 41.83956
|
||||||
|
@test centers[1].longitude == -88.08857
|
||||||
|
end
|
||||||
|
|
||||||
|
# @testset "parse (invalid)" begin
|
||||||
|
# @test_throws ErrorException RELOG.parsefile(fixture("s1-wrong-length.json"))
|
||||||
|
# end
|
||||||
end
|
end
|
||||||
|
|
||||||
@testset "parse (geodb)" begin
|
|
||||||
basedir = dirname(@__FILE__)
|
|
||||||
instance = RELOG.parsefile("$basedir/../../instances/s2.json")
|
|
||||||
|
|
||||||
centers = instance.collection_centers
|
|
||||||
@test centers[1].name == "C1"
|
|
||||||
@test centers[1].latitude == 41.83956
|
|
||||||
@test centers[1].longitude == -88.08857
|
|
||||||
end
|
|
||||||
|
|
||||||
# @testset "parse (invalid)" begin
|
|
||||||
# basedir = dirname(@__FILE__)
|
|
||||||
# @test_throws ErrorException RELOG.parsefile("$basedir/../fixtures/s1-wrong-length.json")
|
|
||||||
# end
|
|
||||||
|
|||||||
@@ -1,38 +1,38 @@
|
|||||||
# Copyright (C) 2020 Argonne National Laboratory
|
# Copyright (C) 2020 Argonne National Laboratory
|
||||||
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
||||||
|
|
||||||
using RELOG, Cbc, JuMP, Printf, JSON, MathOptInterface.FileFormats
|
using RELOG, HiGHS, JuMP, Printf, JSON, MathOptInterface.FileFormats
|
||||||
|
|
||||||
@testset "build" begin
|
function model_build_test()
|
||||||
basedir = dirname(@__FILE__)
|
@testset "build" begin
|
||||||
instance = RELOG.parsefile("$basedir/../../instances/s1.json")
|
instance = RELOG.parsefile(fixture("instances/s1.json"))
|
||||||
graph = RELOG.build_graph(instance)
|
graph = RELOG.build_graph(instance)
|
||||||
model = RELOG.build_model(instance, graph, Cbc.Optimizer)
|
model = RELOG.build_model(instance, graph, HiGHS.Optimizer)
|
||||||
set_optimizer_attribute(model, "logLevel", 0)
|
|
||||||
|
|
||||||
process_node_by_location_name =
|
process_node_by_location_name =
|
||||||
Dict(n.location.location_name => n for n in graph.process_nodes)
|
Dict(n.location.location_name => n for n in graph.process_nodes)
|
||||||
|
|
||||||
shipping_node_by_loc_and_prod_names = Dict(
|
shipping_node_by_loc_and_prod_names = Dict(
|
||||||
(n.location.location_name, n.product.name) => n for n in graph.plant_shipping_nodes
|
(n.location.location_name, n.product.name) => n for n in graph.plant_shipping_nodes
|
||||||
)
|
)
|
||||||
|
|
||||||
@test length(model[:flow]) == 76
|
@test length(model[1, :open_plant]) == 12
|
||||||
@test length(model[:dispose]) == 16
|
@test length(model[2, :flow]) == 76
|
||||||
@test length(model[:open_plant]) == 12
|
@test length(model[2, :plant_dispose]) == 16
|
||||||
@test length(model[:capacity]) == 12
|
@test length(model[2, :capacity]) == 12
|
||||||
@test length(model[:expansion]) == 12
|
@test length(model[2, :expansion]) == 12
|
||||||
|
|
||||||
l1 = process_node_by_location_name["L1"]
|
# l1 = process_node_by_location_name["L1"]
|
||||||
v = model[:capacity][l1, 1]
|
# v = model[2, :capacity][l1.index, 1]
|
||||||
@test lower_bound(v) == 0.0
|
# @test lower_bound(v) == 0.0
|
||||||
@test upper_bound(v) == 1000.0
|
# @test upper_bound(v) == 1000.0
|
||||||
|
|
||||||
v = model[:expansion][l1, 1]
|
# v = model[2, :expansion][l1.index, 1]
|
||||||
@test lower_bound(v) == 0.0
|
# @test lower_bound(v) == 0.0
|
||||||
@test upper_bound(v) == 750.0
|
# @test upper_bound(v) == 750.0
|
||||||
|
|
||||||
v = model[:dispose][shipping_node_by_loc_and_prod_names["L1", "P2"], 1]
|
# v = model[2, :plant_dispose][shipping_node_by_loc_and_prod_names["L1", "P2"].index, 1]
|
||||||
@test lower_bound(v) == 0.0
|
# @test lower_bound(v) == 0.0
|
||||||
@test upper_bound(v) == 1.0
|
# @test upper_bound(v) == 1.0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@@ -1,61 +1,85 @@
|
|||||||
# Copyright (C) 2020 Argonne National Laboratory
|
# Copyright (C) 2020 Argonne National Laboratory
|
||||||
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
||||||
|
|
||||||
using RELOG, Cbc, JuMP, Printf, JSON, MathOptInterface.FileFormats
|
using RELOG, JuMP, Printf, JSON, MathOptInterface.FileFormats
|
||||||
|
|
||||||
basedir = dirname(@__FILE__)
|
basedir = dirname(@__FILE__)
|
||||||
|
|
||||||
@testset "solve (exact)" begin
|
function model_solve_test()
|
||||||
solution_filename_a = tempname()
|
@testset "solve (exact)" begin
|
||||||
solution_filename_b = tempname()
|
solution = RELOG.solve(fixture("instances/s1.json"))
|
||||||
solution = RELOG.solve("$basedir/../../instances/s1.json", output = solution_filename_a)
|
|
||||||
|
|
||||||
@test isfile(solution_filename_a)
|
solution_filename = tempname()
|
||||||
|
RELOG.write(solution, solution_filename)
|
||||||
|
@test isfile(solution_filename)
|
||||||
|
|
||||||
RELOG.write(solution, solution_filename_b)
|
@test "Costs" in keys(solution)
|
||||||
@test isfile(solution_filename_b)
|
@test "Fixed operating (\$)" in keys(solution["Costs"])
|
||||||
|
@test "Transportation (\$)" in keys(solution["Costs"])
|
||||||
|
@test "Variable operating (\$)" in keys(solution["Costs"])
|
||||||
|
@test "Total (\$)" in keys(solution["Costs"])
|
||||||
|
|
||||||
@test "Costs" in keys(solution)
|
@test "Plants" in keys(solution)
|
||||||
@test "Fixed operating (\$)" in keys(solution["Costs"])
|
@test "F1" in keys(solution["Plants"])
|
||||||
@test "Transportation (\$)" in keys(solution["Costs"])
|
@test "F2" in keys(solution["Plants"])
|
||||||
@test "Variable operating (\$)" in keys(solution["Costs"])
|
@test "F3" in keys(solution["Plants"])
|
||||||
@test "Total (\$)" in keys(solution["Costs"])
|
@test "F4" in keys(solution["Plants"])
|
||||||
|
|
||||||
@test "Plants" in keys(solution)
|
@test "Products" in keys(solution)
|
||||||
@test "F1" in keys(solution["Plants"])
|
@test "P1" in keys(solution["Products"])
|
||||||
@test "F2" in keys(solution["Plants"])
|
@test "C1" in keys(solution["Products"]["P1"])
|
||||||
@test "F3" in keys(solution["Plants"])
|
@test "Dispose (tonne)" in keys(solution["Products"]["P1"]["C1"])
|
||||||
@test "F4" in keys(solution["Plants"])
|
|
||||||
end
|
|
||||||
|
|
||||||
@testset "solve (heuristic)" begin
|
total_disposal =
|
||||||
# Should not crash
|
sum([loc["Dispose (tonne)"] for loc in values(solution["Products"]["P1"])])
|
||||||
solution = RELOG.solve("$basedir/../../instances/s1.json", heuristic = true)
|
@test total_disposal == [1.0, 1.0]
|
||||||
end
|
end
|
||||||
|
|
||||||
@testset "solve (infeasible)" begin
|
@testset "solve (heuristic)" begin
|
||||||
json = JSON.parsefile("$basedir/../../instances/s1.json")
|
# Should not crash
|
||||||
for (location_name, location_dict) in json["products"]["P1"]["initial amounts"]
|
solution = RELOG.solve(fixture("instances/s1.json"), heuristic = true)
|
||||||
location_dict["amount (tonne)"] *= 1000
|
end
|
||||||
|
|
||||||
|
# @testset "solve (infeasible)" begin
|
||||||
|
# json = JSON.parsefile(fixture("instances/s1.json"))
|
||||||
|
# for (location_name, location_dict) in json["products"]["P1"]["initial amounts"]
|
||||||
|
# location_dict["amount (tonne)"] *= 1000
|
||||||
|
# end
|
||||||
|
# @test_throws ErrorException("No solution available") RELOG.solve(RELOG.parse(json))
|
||||||
|
# end
|
||||||
|
|
||||||
|
@testset "solve (with storage)" begin
|
||||||
|
basedir = dirname(@__FILE__)
|
||||||
|
filename = "$basedir/../fixtures/storage.json"
|
||||||
|
instance = RELOG.parsefile(filename)
|
||||||
|
@test instance.plants[1].storage_limit == 50.0
|
||||||
|
@test instance.plants[1].storage_cost == [2.0, 1.5, 1.0]
|
||||||
|
|
||||||
|
solution = RELOG.solve(filename)
|
||||||
|
plant_dict = solution["Plants"]["mega plant"]["Chicago"]
|
||||||
|
@test plant_dict["Variable operating cost (\$)"] == [500.0, 0.0, 100.0]
|
||||||
|
@test plant_dict["Process (tonne)"] == [50.0, 0.0, 50.0]
|
||||||
|
@test plant_dict["Storage (tonne)"] == [50.0, 50.0, 0.0]
|
||||||
|
@test plant_dict["Storage cost (\$)"] == [100.0, 75.0, 0.0]
|
||||||
|
|
||||||
|
@test solution["Costs"]["Variable operating (\$)"] == [500.0, 0.0, 100.0]
|
||||||
|
@test solution["Costs"]["Storage (\$)"] == [100.0, 75.0, 0.0]
|
||||||
|
@test solution["Costs"]["Total (\$)"] == [600.0, 75.0, 100.0]
|
||||||
|
end
|
||||||
|
|
||||||
|
@testset "solve (stochastic)" begin
|
||||||
|
# Should not crash
|
||||||
|
solutions = RELOG.solve_stochastic(
|
||||||
|
scenarios=[
|
||||||
|
fixture("instances/case3_p010_s1.00.json"),
|
||||||
|
fixture("instances/case3_p010_s1.25.json"),
|
||||||
|
],
|
||||||
|
probs=[0.5, 0.5],
|
||||||
|
optimizer=optimizer_with_attributes(
|
||||||
|
HiGHS.Optimizer,
|
||||||
|
"log_to_console" => false,
|
||||||
|
),
|
||||||
|
method=:lshaped,
|
||||||
|
)
|
||||||
end
|
end
|
||||||
RELOG.solve(RELOG.parse(json))
|
|
||||||
end
|
|
||||||
|
|
||||||
@testset "solve (with storage)" begin
|
|
||||||
basedir = dirname(@__FILE__)
|
|
||||||
filename = "$basedir/../fixtures/storage.json"
|
|
||||||
instance = RELOG.parsefile(filename)
|
|
||||||
@test instance.plants[1].storage_limit == 50.0
|
|
||||||
@test instance.plants[1].storage_cost == [2.0, 1.5, 1.0]
|
|
||||||
|
|
||||||
solution = RELOG.solve(filename)
|
|
||||||
plant_dict = solution["Plants"]["mega plant"]["Chicago"]
|
|
||||||
@test plant_dict["Variable operating cost (\$)"] == [500.0, 0.0, 100.0]
|
|
||||||
@test plant_dict["Process (tonne)"] == [50.0, 0.0, 50.0]
|
|
||||||
@test plant_dict["Storage (tonne)"] == [50.0, 50.0, 0.0]
|
|
||||||
@test plant_dict["Storage cost (\$)"] == [100.0, 75.0, 0.0]
|
|
||||||
|
|
||||||
@test solution["Costs"]["Variable operating (\$)"] == [500.0, 0.0, 100.0]
|
|
||||||
@test solution["Costs"]["Storage (\$)"] == [100.0, 75.0, 0.0]
|
|
||||||
@test solution["Costs"]["Total (\$)"] == [600.0, 75.0, 100.0]
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -4,15 +4,20 @@
|
|||||||
|
|
||||||
using RELOG, JSON, GZip
|
using RELOG, JSON, GZip
|
||||||
|
|
||||||
@testset "Reports" begin
|
basedir = @__DIR__
|
||||||
@testset "from solve" begin
|
|
||||||
solution = RELOG.solve("$(pwd())/../instances/s1.json")
|
function reports_test()
|
||||||
tmp_filename = tempname()
|
@testset "Reports" begin
|
||||||
# The following should not crash
|
@testset "from solve" begin
|
||||||
RELOG.write_plants_report(solution, tmp_filename)
|
solution = RELOG.solve(fixture("instances/s1.json"))
|
||||||
RELOG.write_plant_outputs_report(solution, tmp_filename)
|
tmp_filename = tempname()
|
||||||
RELOG.write_plant_emissions_report(solution, tmp_filename)
|
# The following should not crash
|
||||||
RELOG.write_transportation_report(solution, tmp_filename)
|
RELOG.write_plant_emissions_report(solution, tmp_filename)
|
||||||
RELOG.write_transportation_emissions_report(solution, tmp_filename)
|
RELOG.write_plant_outputs_report(solution, tmp_filename)
|
||||||
|
RELOG.write_plants_report(solution, tmp_filename)
|
||||||
|
RELOG.write_products_report(solution, tmp_filename)
|
||||||
|
RELOG.write_transportation_emissions_report(solution, tmp_filename)
|
||||||
|
RELOG.write_transportation_report(solution, tmp_filename)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -2,19 +2,46 @@
|
|||||||
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
||||||
|
|
||||||
using Test
|
using Test
|
||||||
|
using RELOG
|
||||||
|
using Revise
|
||||||
|
|
||||||
@testset "RELOG" begin
|
includet("instance/compress_test.jl")
|
||||||
@testset "Instance" begin
|
includet("instance/geodb_test.jl")
|
||||||
include("instance/compress_test.jl")
|
includet("instance/parse_test.jl")
|
||||||
include("instance/geodb_test.jl")
|
includet("graph/build_test.jl")
|
||||||
include("instance/parse_test.jl")
|
includet("model/build_test.jl")
|
||||||
|
includet("model/solve_test.jl")
|
||||||
|
includet("reports_test.jl")
|
||||||
|
|
||||||
|
function fixture(path)
|
||||||
|
for candidate in [
|
||||||
|
"fixtures/$path",
|
||||||
|
"test/fixtures/$path"
|
||||||
|
]
|
||||||
|
if isfile(candidate)
|
||||||
|
return candidate
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@testset "Graph" begin
|
error("Fixture not found: $path")
|
||||||
include("graph/build_test.jl")
|
|
||||||
end
|
|
||||||
@testset "Model" begin
|
|
||||||
include("model/build_test.jl")
|
|
||||||
include("model/solve_test.jl")
|
|
||||||
end
|
|
||||||
include("reports_test.jl")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function runtests()
|
||||||
|
@testset "RELOG" begin
|
||||||
|
@testset "Instance" begin
|
||||||
|
compress_test()
|
||||||
|
geodb_test()
|
||||||
|
parse_test()
|
||||||
|
end
|
||||||
|
@testset "Graph" begin
|
||||||
|
graph_build_test()
|
||||||
|
end
|
||||||
|
@testset "Model" begin
|
||||||
|
model_build_test()
|
||||||
|
model_solve_test()
|
||||||
|
end
|
||||||
|
reports_test()
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
runtests()
|
||||||
|
|||||||