Compare commits
18 Commits
v0.5.1
...
feature/st
| Author | SHA1 | Date | |
|---|---|---|---|
|
8231f9da32
|
|||
|
48ccf0d180
|
|||
|
7f475a0914
|
|||
|
4b0fc7327c
|
|||
|
dde0d40282
|
|||
|
74606897cd
|
|||
|
07ca3abb4f
|
|||
|
da158eb961
|
|||
| e7eec937cb | |||
|
19bec961bd
|
|||
|
8f52c04702
|
|||
|
19a34fb5d2
|
|||
| e915a57e58 | |||
| 57b7d09c08 | |||
| a03b9169fd | |||
| ee58af73f0 | |||
| 92d30460b9 | |||
| 9ebb2e49f9 |
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', '1.6']
|
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
|
||||||
|
|||||||
25
CHANGELOG.md
@@ -11,39 +11,48 @@ All notable changes to this project will be documented in this file.
|
|||||||
[semver]: https://semver.org/spec/v2.0.0.html
|
[semver]: https://semver.org/spec/v2.0.0.html
|
||||||
[pkjjl]: https://pkgdocs.julialang.org/v1/compatibility/#compat-pre-1.0
|
[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
|
## [0.5.1] -- 2021-07-23
|
||||||
## Added
|
### Added
|
||||||
- Allow user to specify locations as unique identifiers, instead of latitude and longitude (e.g. `us-state:IL` or `2018-us-county:17043`)
|
- 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 what-if scenarios.
|
||||||
- Add products report.
|
- Add products report.
|
||||||
|
|
||||||
## [0.5.0] -- 2021-01-06
|
## [0.5.0] -- 2021-01-06
|
||||||
## Added
|
### Added
|
||||||
- Allow plants to store input material for processing in later years
|
- Allow plants to store input material for processing in later years
|
||||||
|
|
||||||
## [0.4.0] -- 2020-09-18
|
## [0.4.0] -- 2020-09-18
|
||||||
## Added
|
### Added
|
||||||
- Generate simplified solution reports (CSV)
|
- Generate simplified solution reports (CSV)
|
||||||
|
|
||||||
## [0.3.3] -- 2020-10-13
|
## [0.3.3] -- 2020-10-13
|
||||||
## Added
|
### 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
|
||||||
|
|
||||||
## [0.3.2] -- 2020-10-07
|
## [0.3.2] -- 2020-10-07
|
||||||
## Added
|
### Added
|
||||||
- Add "building period" parameter
|
- Add "building period" parameter
|
||||||
|
|
||||||
## [0.3.1] -- 2020-07-17
|
## [0.3.1] -- 2020-07-17
|
||||||
## Fixed
|
### Fixed
|
||||||
- Fix expansion cost breakdown
|
- Fix expansion cost breakdown
|
||||||
|
|
||||||
## [0.3.0] -- 2020-06-25
|
## [0.3.0] -- 2020-06-25
|
||||||
## Added
|
### Added
|
||||||
- Track emissions and energy (transportation and plants)
|
- Track emissions and energy (transportation and plants)
|
||||||
|
|
||||||
## Changed
|
### 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
|
||||||
|
|||||||
33
Project.toml
@@ -1,48 +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.1"
|
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"
|
||||||
OrderedCollections = "1.4"
|
OrderedCollections = "1"
|
||||||
PackageCompiler = "1"
|
ProgressBars = "1"
|
||||||
ProgressBars = "0.6"
|
Shapefile = "0.8"
|
||||||
Shapefile = "0.7"
|
ZipFile = "0.10"
|
||||||
ZipFile = "0.9"
|
|
||||||
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.
|
||||||
@@ -210,7 +214,7 @@ is is possible to write:
|
|||||||
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:
|
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
|
Database | Description | Examples
|
||||||
---------|-------------|----------
|
:--------|:------------|:---------
|
||||||
`us-state`| List of states of the United States. | `us-state:IL` (State of Illinois)
|
`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)
|
`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)
|
||||||
|
|
||||||
@@ -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*}
|
||||||
|
```
|
||||||
@@ -9,7 +9,7 @@ In this page, we also illustrate what types of charts and visualizations can be
|
|||||||
Report showing plant costs, capacities, energy expenditure and utilization factors. Generated by `RELOG.write_plants_report(solution, filename)`.
|
Report showing plant costs, capacities, energy expenditure and utilization factors. Generated by `RELOG.write_plants_report(solution, filename)`.
|
||||||
|
|
||||||
| 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.
|
| `year` | What year this row corresponds to. This reports includes one row for each year.
|
||||||
@@ -45,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
|
||||||
@@ -65,8 +67,9 @@ 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
|
||||||
|
|
||||||
@@ -74,7 +77,7 @@ Report showing amount of products produced, sent and disposed of by each plant,
|
|||||||
|
|
||||||
|
|
||||||
| 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.
|
| `year` | What year this row corresponds to. This reports includes one row for each year.
|
||||||
@@ -101,7 +104,9 @@ 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
|
||||||
@@ -109,7 +114,7 @@ sns.barplot(x="amount produced (tonne)",
|
|||||||
Report showing amount of emissions produced by each plant. Generated by `RELOG.write_plant_emissions_report(solution, filename)`.
|
Report showing amount of emissions produced by each plant. Generated by `RELOG.write_plant_emissions_report(solution, filename)`.
|
||||||
|
|
||||||
| Column | Description
|
| Column | Description
|
||||||
|:--------------------------------------|---------------|
|
|:--------------------------------------|:---------------|
|
||||||
| `plant type` | Plant type.
|
| `plant type` | Plant type.
|
||||||
| `location name` | Location name.
|
| `location name` | Location name.
|
||||||
| `year` | Year.
|
| `year` | Year.
|
||||||
@@ -133,20 +138,23 @@ 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
|
## Products report
|
||||||
|
|
||||||
Report showing primary product amounts, locations and marginal costs. Generated by `RELOG.write_products_report(solution, filename)`.
|
Report showing primary product amounts, locations and marginal costs. Generated by `RELOG.write_products_report(solution, filename)`.
|
||||||
|
|
||||||
| Column | Description
|
| Column | Description
|
||||||
|:--------------------------------------|---------------|
|
|:--------------------------------------|:---------------|
|
||||||
| `product name` | Product name.
|
| `product name` | Product name.
|
||||||
| `location name` | Name of the collection center.
|
| `location name` | Name of the collection center.
|
||||||
| `latitude (deg)` | Latitude of the collection center.
|
| `latitude (deg)` | Latitude of the collection center.
|
||||||
| `longitude (deg)` | Longitude 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.
|
| `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 (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.
|
| `marginal cost ($/tonne)` | Cost to process one additional tonne of this product coming from this collection center.
|
||||||
|
|
||||||
|
|
||||||
@@ -156,7 +164,7 @@ Report showing amount of product sent from initial locations to plants, and from
|
|||||||
|
|
||||||
|
|
||||||
| 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.
|
||||||
@@ -190,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):
|
||||||
|
|
||||||
@@ -233,7 +243,9 @@ 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
|
||||||
@@ -241,7 +253,7 @@ gp.GeoDataFrame(data, geometry=points).plot(ax=ax,
|
|||||||
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)`.
|
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)`.
|
||||||
|
|
||||||
| 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.
|
||||||
@@ -275,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
|
||||||
@@ -111,13 +106,17 @@ By default, RELOG internally uses [Cbc](https://github.com/coin-or/Cbc), an open
|
|||||||
```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,
|
||||||
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
### 5.2 Multi-period heuristics
|
### 5.2 Multi-period heuristics
|
||||||
@@ -133,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
|
||||||
@@ -17,7 +17,6 @@ include("instance/validate.jl")
|
|||||||
include("model/build.jl")
|
include("model/build.jl")
|
||||||
include("model/getsol.jl")
|
include("model/getsol.jl")
|
||||||
include("model/solve.jl")
|
include("model/solve.jl")
|
||||||
include("model/resolve.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")
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -18,6 +18,7 @@ function build_graph(instance::Instance)::Graph
|
|||||||
collection_shipping_nodes = ShippingNode[]
|
collection_shipping_nodes = ShippingNode[]
|
||||||
|
|
||||||
name_to_process_node_map = Dict{Tuple{AbstractString,AbstractString},ProcessNode}()
|
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)
|
||||||
@@ -27,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
|
||||||
|
|
||||||
@@ -57,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)
|
||||||
@@ -70,7 +72,7 @@ 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)
|
||||||
@@ -83,6 +85,7 @@ function build_graph(instance::Instance)::Graph
|
|||||||
collection_shipping_nodes,
|
collection_shipping_nodes,
|
||||||
arcs,
|
arcs,
|
||||||
name_to_process_node_map,
|
name_to_process_node_map,
|
||||||
|
collection_center_to_node,
|
||||||
)
|
)
|
||||||
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}
|
||||||
@@ -33,6 +34,7 @@ mutable struct Graph
|
|||||||
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}
|
name_to_process_node_map::Dict{Tuple{AbstractString,AbstractString},ProcessNode}
|
||||||
|
collection_center_to_node::Dict{CollectionCenter,ShippingNode}
|
||||||
end
|
end
|
||||||
|
|
||||||
function Base.show(io::IO, instance::Graph)
|
function Base.show(io::IO, instance::Graph)
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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,62 +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(instance::Instance, graph::Graph, optimizer)::JuMP.Model
|
function build_model(
|
||||||
model = Model(optimizer)
|
instance::Instance,
|
||||||
model[:instance] = instance
|
graph::Graph,
|
||||||
model[:graph] = graph
|
optimizer,
|
||||||
create_vars!(model)
|
)
|
||||||
create_objective_function!(model)
|
return build_model(
|
||||||
create_shipping_node_constraints!(model)
|
instance,
|
||||||
create_process_node_constraints!(model)
|
[graph],
|
||||||
return model
|
[1.0],
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
@@ -78,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,37 +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,
|
||||||
"Latitude (deg)" => n.location.latitude,
|
"Dispose (tonne)" => [
|
||||||
"Longitude (deg)" => n.location.longitude,
|
value(model[2, :collection_dispose][n, t])
|
||||||
"Amount (tonne)" => n.location.amount,
|
for t = 1:T
|
||||||
)
|
],
|
||||||
if n.product.name ∉ keys(output["Products"])
|
"Disposal cost (\$)" => [
|
||||||
output["Products"][n.product.name] = OrderedDict()
|
value(model[2, :collection_dispose][n, t]) *
|
||||||
end
|
node.location.product.disposal_cost[t]
|
||||||
output["Products"][n.product.name][n.location.name] = location_dict
|
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" =>
|
||||||
@@ -70,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
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@@ -115,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
|
||||||
@@ -173,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
|
||||||
@@ -194,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
|
||||||
|
|||||||
@@ -1,97 +0,0 @@
|
|||||||
# RELOG: Reverse Logistics Optimization
|
|
||||||
# Copyright (C) 2020-2021, UChicago Argonne, LLC. All rights reserved.
|
|
||||||
# Released under the modified BSD license. See COPYING.md for more details.
|
|
||||||
|
|
||||||
using JuMP
|
|
||||||
|
|
||||||
function resolve(model_old, filename::AbstractString; kwargs...)::OrderedDict
|
|
||||||
@info "Reading $filename..."
|
|
||||||
instance = RELOG.parsefile(filename)
|
|
||||||
return resolve(model_old, instance; kwargs...)
|
|
||||||
end
|
|
||||||
|
|
||||||
function resolve(model_old, instance::Instance; optimizer = nothing)::OrderedDict
|
|
||||||
milp_optimizer = lp_optimizer = optimizer
|
|
||||||
if optimizer === nothing
|
|
||||||
milp_optimizer = _get_default_milp_optimizer()
|
|
||||||
lp_optimizer = _get_default_lp_optimizer()
|
|
||||||
end
|
|
||||||
|
|
||||||
@info "Building new graph..."
|
|
||||||
graph = build_graph(instance)
|
|
||||||
_print_graph_stats(instance, graph)
|
|
||||||
|
|
||||||
@info "Building new optimization model..."
|
|
||||||
model_new = RELOG.build_model(instance, graph, milp_optimizer)
|
|
||||||
|
|
||||||
@info "Fixing decision variables..."
|
|
||||||
_fix_plants!(model_old, model_new)
|
|
||||||
JuMP.set_optimizer(model_new, lp_optimizer)
|
|
||||||
|
|
||||||
@info "Optimizing MILP..."
|
|
||||||
JuMP.optimize!(model_new)
|
|
||||||
|
|
||||||
if !has_values(model_new)
|
|
||||||
@warn("No solution available")
|
|
||||||
return OrderedDict()
|
|
||||||
end
|
|
||||||
|
|
||||||
@info "Extracting solution..."
|
|
||||||
solution = get_solution(model_new, marginal_costs = true)
|
|
||||||
|
|
||||||
return solution
|
|
||||||
end
|
|
||||||
|
|
||||||
function _fix_plants!(model_old, model_new)::Nothing
|
|
||||||
T = model_new[:instance].time
|
|
||||||
|
|
||||||
# Fix open_plant variables
|
|
||||||
for ((node_old, t), var_old) in model_old[:open_plant]
|
|
||||||
value_old = JuMP.value(var_old)
|
|
||||||
node_new = model_new[:graph].name_to_process_node_map[(
|
|
||||||
node_old.location.plant_name,
|
|
||||||
node_old.location.location_name,
|
|
||||||
)]
|
|
||||||
var_new = model_new[:open_plant][node_new, t]
|
|
||||||
JuMP.unset_binary(var_new)
|
|
||||||
JuMP.fix(var_new, value_old)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Fix is_open variables
|
|
||||||
for ((node_old, t), var_old) in model_old[:is_open]
|
|
||||||
value_old = JuMP.value(var_old)
|
|
||||||
node_new = model_new[:graph].name_to_process_node_map[(
|
|
||||||
node_old.location.plant_name,
|
|
||||||
node_old.location.location_name,
|
|
||||||
)]
|
|
||||||
var_new = model_new[:is_open][node_new, t]
|
|
||||||
JuMP.unset_binary(var_new)
|
|
||||||
JuMP.fix(var_new, value_old)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Fix plant capacities
|
|
||||||
for ((node_old, t), var_old) in model_old[:capacity]
|
|
||||||
value_old = JuMP.value(var_old)
|
|
||||||
node_new = model_new[:graph].name_to_process_node_map[(
|
|
||||||
node_old.location.plant_name,
|
|
||||||
node_old.location.location_name,
|
|
||||||
)]
|
|
||||||
var_new = model_new[:capacity][node_new, t]
|
|
||||||
JuMP.delete_lower_bound(var_new)
|
|
||||||
JuMP.delete_upper_bound(var_new)
|
|
||||||
JuMP.fix(var_new, value_old)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Fix plant expansion
|
|
||||||
for ((node_old, t), var_old) in model_old[:expansion]
|
|
||||||
value_old = JuMP.value(var_old)
|
|
||||||
node_new = model_new[:graph].name_to_process_node_map[(
|
|
||||||
node_old.location.plant_name,
|
|
||||||
node_old.location.location_name,
|
|
||||||
)]
|
|
||||||
var_new = model_new[:expansion][node_new, t]
|
|
||||||
JuMP.delete_lower_bound(var_new)
|
|
||||||
JuMP.delete_upper_bound(var_new)
|
|
||||||
JuMP.fix(var_new, value_old)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -2,14 +2,14 @@
|
|||||||
# 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
|
||||||
|
|
||||||
function _get_default_milp_optimizer()
|
function _get_default_milp_optimizer()
|
||||||
return optimizer_with_attributes(Cbc.Optimizer, "logLevel" => 0)
|
return optimizer_with_attributes(HiGHS.Optimizer)
|
||||||
end
|
end
|
||||||
|
|
||||||
function _get_default_lp_optimizer()
|
function _get_default_lp_optimizer()
|
||||||
return optimizer_with_attributes(Clp.Optimizer, "LogLevel" => 0)
|
return optimizer_with_attributes(HiGHS.Optimizer)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -25,53 +25,81 @@ function _print_graph_stats(instance::Instance, graph::Graph)::Nothing
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function solve_stochastic(;
|
||||||
|
scenarios::Vector{String},
|
||||||
|
probs::Vector{Float64},
|
||||||
|
optimizer,
|
||||||
|
method=:ef,
|
||||||
|
tol=0.1,
|
||||||
|
)
|
||||||
|
@info "Reading instance files..."
|
||||||
|
instances = [parsefile(sc) for sc in scenarios]
|
||||||
|
|
||||||
|
@info "Building graphs..."
|
||||||
|
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(
|
function solve(
|
||||||
instance::Instance;
|
instance::Instance;
|
||||||
optimizer = nothing,
|
optimizer=HiGHS.Optimizer,
|
||||||
output = nothing,
|
marginal_costs=true,
|
||||||
marginal_costs = true,
|
return_model=false
|
||||||
return_model = false,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
milp_optimizer = lp_optimizer = optimizer
|
|
||||||
if optimizer == nothing
|
|
||||||
milp_optimizer = _get_default_milp_optimizer()
|
|
||||||
lp_optimizer = _get_default_lp_optimizer()
|
|
||||||
end
|
|
||||||
|
|
||||||
@info "Building graph..."
|
@info "Building graph..."
|
||||||
graph = RELOG.build_graph(instance)
|
graph = RELOG.build_graph(instance)
|
||||||
_print_graph_stats(instance, graph)
|
_print_graph_stats(instance, graph)
|
||||||
|
|
||||||
@info "Building optimization model..."
|
@info "Building model..."
|
||||||
model = RELOG.build_model(instance, graph, milp_optimizer)
|
model = RELOG.build_model(instance, [graph], [1.0]; optimizer)
|
||||||
|
|
||||||
@info "Optimizing MILP..."
|
|
||||||
JuMP.optimize!(model)
|
|
||||||
|
|
||||||
|
@info "Optimizing model..."
|
||||||
|
optimize!(model)
|
||||||
if !has_values(model)
|
if !has_values(model)
|
||||||
error("No solution available")
|
error("No solution available")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@info "Extracting solution..."
|
||||||
|
solution = get_solution(instance, graph, model, 1)
|
||||||
|
|
||||||
if marginal_costs
|
if marginal_costs
|
||||||
@info "Re-optimizing with integer variables fixed..."
|
@info "Re-optimizing with integer variables fixed..."
|
||||||
all_vars = JuMP.all_variables(model)
|
open_plant_vals = value.(model[1, :open_plant])
|
||||||
vals = OrderedDict(var => JuMP.value(var) for var in all_vars)
|
is_open_vals = value.(model[1, :is_open])
|
||||||
JuMP.set_optimizer(model, lp_optimizer)
|
|
||||||
for var in all_vars
|
for n in 1:length(graph.process_nodes), t in 1:instance.time
|
||||||
if JuMP.is_binary(var)
|
unset_binary(model[1, :open_plant][n, t])
|
||||||
JuMP.unset_binary(var)
|
unset_binary(model[1, :is_open][n, t])
|
||||||
JuMP.fix(var, vals[var])
|
fix(
|
||||||
end
|
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
|
||||||
JuMP.optimize!(model)
|
|
||||||
end
|
|
||||||
|
|
||||||
@info "Extracting solution..."
|
|
||||||
solution = get_solution(model, marginal_costs = marginal_costs)
|
|
||||||
|
|
||||||
if output != nothing
|
|
||||||
write(solution, output)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if return_model
|
if return_model
|
||||||
@@ -81,13 +109,13 @@ function solve(
|
|||||||
end
|
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"]
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
using DataFrames
|
using DataFrames
|
||||||
using CSV
|
using CSV
|
||||||
|
|
||||||
function products_report(solution; marginal_costs = true)::DataFrame
|
function products_report(solution)::DataFrame
|
||||||
df = DataFrame()
|
df = DataFrame()
|
||||||
df."product name" = String[]
|
df."product name" = String[]
|
||||||
df."location name" = String[]
|
df."location name" = String[]
|
||||||
@@ -14,14 +14,21 @@ function products_report(solution; marginal_costs = true)::DataFrame
|
|||||||
df."year" = Int[]
|
df."year" = Int[]
|
||||||
df."amount (tonne)" = Float64[]
|
df."amount (tonne)" = Float64[]
|
||||||
df."marginal cost (\$/tonne)" = Float64[]
|
df."marginal cost (\$/tonne)" = Float64[]
|
||||||
|
df."amount disposed (tonne)" = Float64[]
|
||||||
|
df."disposal cost (\$)" = Float64[]
|
||||||
T = length(solution["Energy"]["Plants (GJ)"])
|
T = length(solution["Energy"]["Plants (GJ)"])
|
||||||
for (prod_name, prod_dict) in solution["Products"]
|
for (prod_name, prod_dict) in solution["Products"]
|
||||||
for (location_name, location_dict) in prod_dict
|
for (location_name, location_dict) in prod_dict
|
||||||
for year = 1:T
|
for year = 1:T
|
||||||
marginal_cost = location_dict["Marginal cost (\$/tonne)"][year]
|
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)
|
latitude = round(location_dict["Latitude (deg)"], digits = 6)
|
||||||
longitude = round(location_dict["Longitude (deg)"], digits = 6)
|
longitude = round(location_dict["Longitude (deg)"], digits = 6)
|
||||||
amount = location_dict["Amount (tonne)"][year]
|
amount = location_dict["Amount (tonne)"][year]
|
||||||
|
amount_disposed = location_dict["Dispose (tonne)"][year]
|
||||||
|
disposal_cost = location_dict["Disposal cost (\$)"][year]
|
||||||
push!(
|
push!(
|
||||||
df,
|
df,
|
||||||
[
|
[
|
||||||
@@ -32,6 +39,8 @@ function products_report(solution; marginal_costs = true)::DataFrame
|
|||||||
year,
|
year,
|
||||||
amount,
|
amount,
|
||||||
marginal_cost,
|
marginal_cost,
|
||||||
|
amount_disposed,
|
||||||
|
disposal_cost,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,11 +0,0 @@
|
|||||||
# Copyright (C) 2020 Argonne National Laboratory
|
|
||||||
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
|
||||||
|
|
||||||
using RELOG
|
|
||||||
|
|
||||||
@testset "Resolve" begin
|
|
||||||
# Shoud not crash
|
|
||||||
filename = "$(pwd())/../instances/s1.json"
|
|
||||||
solution_old, model_old = RELOG.solve(filename, return_model = true)
|
|
||||||
solution_new = RELOG.resolve(model_old, filename)
|
|
||||||
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
|
||||||
@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
|
end
|
||||||
|
|||||||
@@ -4,16 +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_plant_emissions_report(solution, tmp_filename)
|
solution = RELOG.solve(fixture("instances/s1.json"))
|
||||||
RELOG.write_plant_outputs_report(solution, tmp_filename)
|
tmp_filename = tempname()
|
||||||
RELOG.write_plants_report(solution, tmp_filename)
|
# The following should not crash
|
||||||
RELOG.write_products_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_transportation_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,20 +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")
|
|
||||||
include("model/resolve_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()
|
||||||
|
|||||||