Compare commits
10 Commits
feature/co
...
feature/dr
| Author | SHA1 | Date | |
|---|---|---|---|
|
9191474df8
|
|||
|
841fbf16fb
|
|||
|
48bd3c403f
|
|||
| 23b3b33146 | |||
|
da158eb961
|
|||
| e7eec937cb | |||
|
19bec961bd
|
|||
|
8f52c04702
|
|||
|
19a34fb5d2
|
|||
| 92d30460b9 |
2
.github/workflows/test.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
version: ['1.3', '1.4', '1.5', '1.6']
|
||||
version: ['1.6', '1.7', '1.8']
|
||||
os:
|
||||
- ubuntu-latest
|
||||
arch:
|
||||
|
||||
27
CHANGELOG.md
@@ -11,39 +11,50 @@ All notable changes to this project will be documented in this file.
|
||||
[semver]: https://semver.org/spec/v2.0.0.html
|
||||
[pkjjl]: https://pkgdocs.julialang.org/v1/compatibility/#compat-pre-1.0
|
||||
|
||||
# [0.6.0] -- 2022-12-15
|
||||
### Added
|
||||
- Allow RELOG to calculate approximate driving distances, instead of just straight-line distances between points.
|
||||
|
||||
### Fixed
|
||||
- Fix bug that caused building period parameter to be ignored
|
||||
|
||||
## [0.5.2] -- 2022-08-26
|
||||
### Changed
|
||||
- Update to JuMP 1.x
|
||||
|
||||
## [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`)
|
||||
- Add what-if scenarios.
|
||||
- Add products report.
|
||||
|
||||
## [0.5.0] -- 2021-01-06
|
||||
## Added
|
||||
### Added
|
||||
- Allow plants to store input material for processing in later years
|
||||
|
||||
## [0.4.0] -- 2020-09-18
|
||||
## Added
|
||||
### Added
|
||||
- Generate simplified solution reports (CSV)
|
||||
|
||||
## [0.3.3] -- 2020-10-13
|
||||
## Added
|
||||
### Added
|
||||
- Add option to write solution to JSON file in RELOG.solve
|
||||
- Improve error message when instance is infeasible
|
||||
- Make output file more readable
|
||||
|
||||
## [0.3.2] -- 2020-10-07
|
||||
## Added
|
||||
### Added
|
||||
- Add "building period" parameter
|
||||
|
||||
## [0.3.1] -- 2020-07-17
|
||||
## Fixed
|
||||
### Fixed
|
||||
- Fix expansion cost breakdown
|
||||
|
||||
## [0.3.0] -- 2020-06-25
|
||||
## Added
|
||||
### Added
|
||||
- Track emissions and energy (transportation and plants)
|
||||
|
||||
## Changed
|
||||
### Changed
|
||||
- Minor changes to input file format:
|
||||
- Make all dictionary keys lowercase
|
||||
- Rename "outputs (tonne)" to "outputs (tonne/tonne)"
|
||||
|
||||
26
Makefile
@@ -1,25 +1,19 @@
|
||||
JULIA := julia --project=.
|
||||
SRC_FILES := $(wildcard src/*.jl test/*.jl)
|
||||
VERSION := 0.5
|
||||
|
||||
all: docs test
|
||||
|
||||
build/sysimage.so: src/sysimage.jl Project.toml Manifest.toml
|
||||
@$(JULIA) src/sysimage.jl
|
||||
VERSION := 0.6
|
||||
|
||||
clean:
|
||||
rm -rf build/*
|
||||
rm -rfv build Manifest.toml test/Manifest.toml deps/formatter/build deps/formatter/Manifest.toml
|
||||
|
||||
docs:
|
||||
mkdocs build -d ../docs/$(VERSION)/
|
||||
cd docs; julia --project=. make.jl; cd ..
|
||||
rsync -avP --delete-after docs/build/ ../docs/$(VERSION)/
|
||||
|
||||
format:
|
||||
julia -e 'using JuliaFormatter; format(["src", "test"], verbose=true);'
|
||||
cd deps/formatter; ../../juliaw format.jl
|
||||
|
||||
test:
|
||||
@$(JULIA) --sysimage build/sysimage.so test/runtests.jl
|
||||
test: test/Manifest.toml
|
||||
./juliaw test/runtests.jl
|
||||
|
||||
test-watch:
|
||||
bash -c "while true; do make test --quiet; sleep 1; done"
|
||||
test/Manifest.toml: test/Project.toml
|
||||
julia --project=test -e "using Pkg; Pkg.instantiate()"
|
||||
|
||||
.PHONY: docs test
|
||||
.PHONY: docs test format
|
||||
|
||||
31
Project.toml
@@ -1,7 +1,7 @@
|
||||
name = "RELOG"
|
||||
uuid = "a2afcdf7-cf04-4913-85f9-c0d81ddf2008"
|
||||
authors = ["Alinson S Xavier <axavier@anl.gov>"]
|
||||
version = "0.5.1"
|
||||
version = "0.6.0"
|
||||
|
||||
[deps]
|
||||
CRC = "44b605c4-b955-5f2b-9b6d-d2bd01d3d205"
|
||||
@@ -18,8 +18,8 @@ JSONSchema = "7d188eb4-7ad8-530c-ae41-71a32a6d4692"
|
||||
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
|
||||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
|
||||
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
|
||||
NearestNeighbors = "b8a86587-4115-5ab1-83bc-aa920d37bbce"
|
||||
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
|
||||
PackageCompiler = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d"
|
||||
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
|
||||
ProgressBars = "49802e3a-d2f1-5c88-81d8-b72133a6f568"
|
||||
Shapefile = "8e980c4a-a4fe-5da2-b3a7-4b4b0353a2f4"
|
||||
@@ -29,20 +29,19 @@ ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea"
|
||||
|
||||
[compat]
|
||||
CRC = "4"
|
||||
CSV = "0.7"
|
||||
Cbc = "0.6"
|
||||
Clp = "0.8"
|
||||
DataFrames = "0.21"
|
||||
DataStructures = "0.17"
|
||||
CSV = "0.10"
|
||||
Cbc = "1"
|
||||
Clp = "1"
|
||||
DataFrames = "1"
|
||||
DataStructures = "0.18"
|
||||
GZip = "0.5"
|
||||
Geodesy = "0.5"
|
||||
Geodesy = "1"
|
||||
JSON = "0.21"
|
||||
JSONSchema = "0.3"
|
||||
JuMP = "0.21"
|
||||
MathOptInterface = "0.9"
|
||||
OrderedCollections = "1.4"
|
||||
PackageCompiler = "1"
|
||||
ProgressBars = "0.6"
|
||||
Shapefile = "0.7"
|
||||
ZipFile = "0.9"
|
||||
JSONSchema = "1"
|
||||
JuMP = "1"
|
||||
MathOptInterface = "1"
|
||||
OrderedCollections = "1"
|
||||
ProgressBars = "1"
|
||||
Shapefile = "0.8"
|
||||
ZipFile = "0.10"
|
||||
julia = "1"
|
||||
|
||||
17
README.md
@@ -15,19 +15,22 @@
|
||||
|
||||
|
||||
|
||||
<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.6/assets/ex_transportation.png" width="1000px"/>
|
||||
|
||||
### Documentation
|
||||
|
||||
* [Usage](https://anl-ceeesa.github.io/RELOG/0.5/usage)
|
||||
* [Input and Output Data Formats](https://anl-ceeesa.github.io/RELOG/0.5/format)
|
||||
* [Simplified Solution Reports](https://anl-ceeesa.github.io/RELOG/0.5/reports)
|
||||
* [Optimization Model](https://anl-ceeesa.github.io/RELOG/0.5/model)
|
||||
* [Usage](https://anl-ceeesa.github.io/RELOG/0.6/usage)
|
||||
* [Input and Output Data Formats](https://anl-ceeesa.github.io/RELOG/0.6/format)
|
||||
* [Simplified Solution Reports](https://anl-ceeesa.github.io/RELOG/0.6/reports)
|
||||
* [Optimization Model](https://anl-ceeesa.github.io/RELOG/0.6/model)
|
||||
|
||||
### Authors
|
||||
|
||||
* **Alinson S. Xavier,** Argonne National Laboratory <<axavier@anl.gov>>
|
||||
* **Nwike Iloeje,** Argonne National Laboratory <<ciloeje@anl.gov>>
|
||||
* **Alinson S. Xavier** <<axavier@anl.gov>>
|
||||
* **Nwike Iloeje** <<ciloeje@anl.gov>>
|
||||
* **John Atkins**
|
||||
* **Kyle Sun**
|
||||
* **Audrey Gallier**
|
||||
|
||||
### 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,9 +11,10 @@ RELOG accepts as input a JSON file with three sections: `parameters`, `products`
|
||||
The **parameters** section describes details about the simulation itself.
|
||||
|
||||
| Key | Description
|
||||
|:--------------------------|---------------|
|
||||
|:--------------------------|:---------------|
|
||||
|`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. |
|
||||
|`distance metric` | Metric used to compute distances between pairs of locations. Valid options are: `"Euclidean"`, for the straight-line distance between points; or `"driving"` for an approximated driving distance. If not specified, defaults to `"Euclidean"`.
|
||||
|
||||
|
||||
#### Example
|
||||
@@ -21,7 +22,8 @@ The **parameters** section describes details about the simulation itself.
|
||||
{
|
||||
"parameters": {
|
||||
"time horizon (years)": 2,
|
||||
"building period (years)": [1]
|
||||
"building period (years)": [1],
|
||||
"distance metric": "driving",
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -31,18 +33,16 @@ 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:
|
||||
|
||||
| Key | Description
|
||||
|:--------------------------------------|---------------|
|
||||
|:--------------------------------------|:---------------|
|
||||
|`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 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.
|
||||
| `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:
|
||||
|
||||
| Key | Description
|
||||
|:------------------------|---------------|
|
||||
|:------------------------|:---------------|
|
||||
| `latitude (deg)` | The latitude 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.
|
||||
@@ -75,9 +75,7 @@ Each product may have some amount available at the beginning of each time period
|
||||
"transportation emissions (tonne/km/tonne)": {
|
||||
"CO2": [0.052, 0.050],
|
||||
"CH4": [0.003, 0.002]
|
||||
},
|
||||
"disposal cost ($/tonne)": [-10.0, -12.0],
|
||||
"disposal limit (tonne)": [1.0, 1.0],
|
||||
}
|
||||
},
|
||||
"P2": {
|
||||
"transportation cost ($/km/tonne)": [0.022, 0.020]
|
||||
@@ -97,7 +95,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:
|
||||
|
||||
| Key | Description
|
||||
|:------------------------|---------------|
|
||||
|:------------------------|:---------------|
|
||||
| `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.
|
||||
|`energy (GJ/tonne)` | The energy required to process 1 tonne of the input. Must be a time series. Optional.
|
||||
@@ -117,14 +115,14 @@ Each type of plant is associated with a set of potential locations where it can
|
||||
The `storage` dictionary should contain the following keys:
|
||||
|
||||
| Key | Description
|
||||
|:------------------------|---------------|
|
||||
|:------------------------|:---------------|
|
||||
| `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.
|
||||
|
||||
The keys in the `disposal` dictionary should be the names of the products. The values are dictionaries with the following keys:
|
||||
|
||||
| Key | Description
|
||||
|:------------------------|---------------|
|
||||
|:------------------------|:---------------|
|
||||
| `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.
|
||||
|
||||
@@ -132,7 +130,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:
|
||||
|
||||
| Key | Description
|
||||
|:--------------------------------------|---------------|
|
||||
|:--------------------------------------|:---------------|
|
||||
| `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.
|
||||
| `variable operating cost ($/tonne)` | The cost that the plant incurs to process each tonne of input. Must be a time series.
|
||||
@@ -214,7 +212,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:
|
||||
|
||||
Database | Description | Examples
|
||||
---------|-------------|----------
|
||||
:--------|:------------|:---------
|
||||
`us-state`| List of states of the United States. | `us-state:IL` (State of Illinois)
|
||||
`2018-us-county` | List of United States counties, as of 2018. IDs are 5-digit FIPS codes. | `2018-us-county:17043` (DuPage county in Illinois)
|
||||
|
||||
@@ -224,6 +222,7 @@ Database | Description | Examples
|
||||
* Plants can be expanded at any time, even long after they are open.
|
||||
* All material available at the beginning of a time period must be entirely processed by the end of that time period. It is not possible to store unprocessed materials from one time period to the next.
|
||||
* Up to two plant sizes are currently supported. Variable operating costs must be the same for all plant sizes.
|
||||
* Accurate driving distances are only available for the continental United States.
|
||||
|
||||
## Output Data Format (JSON)
|
||||
|
||||
@@ -1,25 +1,29 @@
|
||||
# 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.
|
||||
|
||||
<img src="images/ex_transportation.png" width="1000px"/>
|
||||
```@raw html
|
||||
<center>
|
||||
<img src="assets/ex_transportation.png" width="1000px"/>
|
||||
</center>
|
||||
```
|
||||
|
||||
|
||||
### Table of Contents
|
||||
|
||||
* [Usage](usage.md)
|
||||
* [Input and Output Data Formats](format.md)
|
||||
* [Simplified Solution Reports](reports.md)
|
||||
* [Optimization Model](model.md)
|
||||
```@contents
|
||||
Pages = ["usage.md", "format.md", "reports.md", "model.md"]
|
||||
Depth = 3
|
||||
```
|
||||
|
||||
|
||||
### Source Code
|
||||
|
||||
* [https://github.com/ANL-CEEESA/RELOG](https://github.com/ANL-CEEESA/RELOG)
|
||||
|
||||
### Authors
|
||||
* **Alinson S. Xavier,** Argonne National Laboratory <<axavier@anl.gov>>
|
||||
* **Nwike Iloeje,** Argonne National Laboratory <<ciloeje@anl.gov>>
|
||||
* **Alinson S. Xavier,** Argonne National Laboratory <axavier@anl.gov>
|
||||
* **Nwike Iloeje,** Argonne National Laboratory <ciloeje@anl.gov>
|
||||
|
||||
### License
|
||||
|
||||
@@ -6,53 +6,65 @@ In this page, we describe the precise mathematical optimization model used by RE
|
||||
|
||||
### Sets
|
||||
|
||||
* $L$ - Set of locations holding the original material to be recycled
|
||||
* $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
|
||||
Symbol | Description
|
||||
:-------|:------------
|
||||
$L$ | Set of locations holding the original material to be recycled
|
||||
$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
|
||||
|
||||
**Plants:**
|
||||
#### Plants
|
||||
|
||||
* $c^\text{disp}_{pmt}$ - Cost of disposing one tonne of material $m$ at plant $p$ during time $t$ (`$/tonne/km`)
|
||||
* $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{f-base}_{pt}$ - Fixed cost of keeping plant $p$ open during time period $t$ (`$`)
|
||||
* $c^\text{f-exp}_{pt}$ - Increase in fixed cost for each additional tonne of capacity (`$/tonne`)
|
||||
* $c^\text{var}_{pt}$ - Variable cost of processing one tonne of input at plant $p$ at time $t$ (`$/tonne`)
|
||||
* $c^\text{store}_{pt}$ - Cost of storing one tonne of original material at plant $p$ at time $t$ (`$/tonne`)
|
||||
* $m^\text{min}_p$ - Minimum capacity of plant $p$ (`tonne`)
|
||||
* $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.
|
||||
Symbol | Description | Unit
|
||||
:-------|:------------|:---
|
||||
$c^\text{disp}_{pmt}$ | Cost of disposing one tonne of material $m$ at plant $p$ during time $t$ | \$/tonne/km
|
||||
$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{f-base}_{pt}$ | Fixed cost of keeping plant $p$ open during time period $t$ | $
|
||||
$c^\text{f-exp}_{pt}$ | Increase in fixed cost for each additional tonne of capacity | \$/tonne
|
||||
$c^\text{var}_{pt}$ | Variable cost of processing one tonne of input at plant $p$ at time $t$ | \$/tonne
|
||||
$c^\text{store}_{pt}$ | Cost of storing one tonne of original material at plant $p$ at time $t$ | \$/tonne
|
||||
$m^\text{min}_p$ | Minimum capacity of plant $p$ | tonne
|
||||
$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`)
|
||||
* $m^\text{initial}_{lt}$ - Amount of original material to be recycled at location $l$ during time $t$ (`tonne`)
|
||||
Symbol | Description | Unit
|
||||
:-------|:------------|:---
|
||||
$\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`)
|
||||
* $d_{lp}$ - Distance between plant $p$ and location $l$ (`km`)
|
||||
Symbol | Description | Unit
|
||||
:-------|:------------|:---
|
||||
$c^\text{tr}_{t}$ | Transportation cost during time $t$ | \$/tonne/km
|
||||
$d_{lp}$ | Distance between plant $p$ and location $l$ | km
|
||||
|
||||
|
||||
### 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`)
|
||||
* $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`)
|
||||
* $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`)
|
||||
|
||||
Symbol | Description | Unit
|
||||
:-------|:------------|:---
|
||||
$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$ | Boolean
|
||||
$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$ | Boolean
|
||||
$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
|
||||
|
||||
RELOG minimizes the overall capital, production and transportation costs:
|
||||
|
||||
```math
|
||||
\begin{align*}
|
||||
\text{minimize} \;\; &
|
||||
\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}
|
||||
\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 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:
|
||||
|
||||
\begin{align}
|
||||
```math
|
||||
\begin{align*}
|
||||
& \sum_{p \in P} y_{lpt} = m^\text{initial}_{lt}
|
||||
& \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.
|
||||
|
||||
\begin{align}
|
||||
```math
|
||||
\begin{align*}
|
||||
& \sum_{l \in L} y_{lpt} + z^{\text{store}}_{p,t-1}
|
||||
= z^{\text{proc}}_{pt} + z^{\text{store}}_{p,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 \\
|
||||
& z^{\text{store}}_{p,t^{\max}} = 0
|
||||
& \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:
|
||||
|
||||
\begin{align}
|
||||
```math
|
||||
\begin{align*}
|
||||
& z^{\text{proc}}_{pt} \leq m^\text{min}_p x_p + \sum_{i=1}^t w_p
|
||||
& \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:
|
||||
|
||||
\begin{align}
|
||||
```math
|
||||
\begin{align*}
|
||||
& z^{\text{store}}_{pt} \leq m^\text{store}_p x_p
|
||||
& \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:
|
||||
|
||||
\begin{align}
|
||||
```math
|
||||
\begin{align*}
|
||||
& \sum_{i=1}^t w_p \leq m^\text{max}_p x_p
|
||||
& \forall p \in P, t \in T
|
||||
\end{align}
|
||||
\end{align*}
|
||||
```
|
||||
|
||||
* Amount of recovered material is proportional to amount processed:
|
||||
|
||||
\begin{align}
|
||||
```math
|
||||
\begin{align*}
|
||||
& q_{mpt} = \alpha_{pm} z^{\text{proc}}_{pt}
|
||||
& \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.
|
||||
|
||||
\begin{align}
|
||||
```math
|
||||
\begin{align*}
|
||||
& q_{mpt} = z_{mpt}
|
||||
& \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.
|
||||
|
||||
\begin{align}
|
||||
```math
|
||||
\begin{align*}
|
||||
& x_{pt} = x_{p,t-1} + u_{pt}
|
||||
& \forall p \in P, t \in T \setminus \{1\} \\
|
||||
& x_{p,1} = u_{p,1}
|
||||
& \forall p \in P
|
||||
\end{align}
|
||||
\end{align*}
|
||||
```
|
||||
|
||||
|
||||
* Variable bounds:
|
||||
|
||||
\begin{align}
|
||||
```math
|
||||
\begin{align*}
|
||||
& q_{mpt} \geq 0
|
||||
& \forall m \in M, p \in P, t \in T \\
|
||||
& u_{pt} \in \{0,1\}
|
||||
@@ -162,4 +192,5 @@ In the fourth line, we have the disposal costs.
|
||||
& p \in P, t \in T \\
|
||||
& z^{\text{disp}}_{mpt}, z^{\text{proc}}_{mpt} \geq 0
|
||||
& \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)`.
|
||||
|
||||
| Column | Description
|
||||
|:--------------------------------------|---------------|
|
||||
|:--------------------------------------|:---------------|
|
||||
| `plant type` | Plant type.
|
||||
| `location name` | Location name.
|
||||
| `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());
|
||||
```
|
||||
|
||||
<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):
|
||||
```python
|
||||
@@ -65,8 +67,9 @@ points = gp.points_from_xy(data["longitude (deg)"],
|
||||
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
|
||||
|
||||
@@ -74,7 +77,7 @@ Report showing amount of products produced, sent and disposed of by each plant,
|
||||
|
||||
|
||||
| Column | Description
|
||||
|:--------------------------------------|---------------|
|
||||
|:--------------------------------------|:---------------|
|
||||
| `plant type` | Plant type.
|
||||
| `location name` | Location name.
|
||||
| `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());
|
||||
```
|
||||
|
||||
<img src="../images/ex_amount_produced.png" width="500px"/>
|
||||
```@raw html
|
||||
<img src="../assets/ex_amount_produced.png" width="500px"/>
|
||||
```
|
||||
|
||||
|
||||
## 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)`.
|
||||
|
||||
| Column | Description
|
||||
|:--------------------------------------|---------------|
|
||||
|:--------------------------------------|:---------------|
|
||||
| `plant type` | Plant type.
|
||||
| `location name` | Location name.
|
||||
| `year` | Year.
|
||||
@@ -133,21 +138,22 @@ sns.barplot(x="plant type",
|
||||
.reset_index());
|
||||
```
|
||||
|
||||
<img src="../images/ex_emissions.png" width="500px"/>
|
||||
```@raw html
|
||||
<img src="../assets/ex_emissions.png" width="500px"/>
|
||||
```
|
||||
|
||||
## Products report
|
||||
|
||||
Report showing primary product amounts, locations and marginal costs. Generated by `RELOG.write_products_report(solution, filename)`.
|
||||
|
||||
| Column | Description
|
||||
|:--------------------------------------|---------------|
|
||||
|:--------------------------------------|:---------------|
|
||||
| `product name` | Product name.
|
||||
| `location name` | Name of the collection center.
|
||||
| `latitude (deg)` | Latitude of the collection center.
|
||||
| `longitude (deg)` | Longitude of the collection center.
|
||||
| `year` | What year this row corresponds to. This reports includes one row for each year.
|
||||
| `amount (tonne)` | Amount of product available at this collection center.
|
||||
| `amount disposed (tonne)` | Amount of product disposed of at this collection center.
|
||||
| `marginal cost ($/tonne)` | Cost to process one additional tonne of this product coming from this collection center.
|
||||
|
||||
|
||||
@@ -157,7 +163,7 @@ Report showing amount of product sent from initial locations to plants, and from
|
||||
|
||||
|
||||
| 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 location name` | Name of the location where the product is being shipped from.
|
||||
| `source latitude (deg)` | Latitude of the source location.
|
||||
@@ -191,7 +197,9 @@ sns.barplot(x="product",
|
||||
.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):
|
||||
|
||||
@@ -234,7 +242,9 @@ gp.GeoDataFrame(data, geometry=points).plot(ax=ax,
|
||||
markersize=50);
|
||||
```
|
||||
|
||||
<img src="../images/ex_transportation.png" width="1000px"/>
|
||||
```@raw html
|
||||
<img src="../assets/ex_transportation.png" width="1000px"/>
|
||||
```
|
||||
|
||||
|
||||
## Transportation emissions report
|
||||
@@ -242,7 +252,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)`.
|
||||
|
||||
| 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 location name` | Name of the location where the product is being shipped from.
|
||||
| `source latitude (deg)` | Latitude of the source location.
|
||||
@@ -276,4 +286,6 @@ sns.barplot(x="emission type",
|
||||
.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
|
||||
|
||||
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
|
||||
(@v1.5) pkg> add https://github.com/ANL-CEEESA/RELOG.git
|
||||
```julia
|
||||
using Pkg
|
||||
Pkg.add(name="RELOG", version="0.6")
|
||||
```
|
||||
|
||||
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
|
||||
(@v1.5) 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
|
||||
```julia
|
||||
Pkg.test("RELOG")
|
||||
```
|
||||
|
||||
## 2. Modeling the problem
|
||||
@@ -111,13 +106,17 @@ By default, RELOG internally uses [Cbc](https://github.com/coin-or/Cbc), an open
|
||||
```julia
|
||||
using RELOG, Gurobi, JuMP
|
||||
|
||||
gurobi = optimizer_with_attributes(Gurobi.Optimizer,
|
||||
gurobi = optimizer_with_attributes(
|
||||
Gurobi.Optimizer,
|
||||
"TimeLimit" => 3600,
|
||||
"MIPGap" => 0.001)
|
||||
"MIPGap" => 0.001,
|
||||
)
|
||||
|
||||
RELOG.solve("instance.json",
|
||||
RELOG.solve(
|
||||
"instance.json",
|
||||
output="solution.json",
|
||||
optimizer=gurobi)
|
||||
optimizer=gurobi,
|
||||
)
|
||||
```
|
||||
|
||||
### 5.2 Multi-period heuristics
|
||||
@@ -133,6 +132,8 @@ To solve an instance using this heuristic, use the option `heuristic=true`, as s
|
||||
```julia
|
||||
using RELOG
|
||||
|
||||
solution = RELOG.solve("/home/user/instance.json",
|
||||
heuristic=true)
|
||||
solution = RELOG.solve(
|
||||
"/home/user/instance.json",
|
||||
heuristic=true,
|
||||
)
|
||||
```
|
||||
@@ -1,135 +1,77 @@
|
||||
{
|
||||
"parameters": {
|
||||
"time horizon (years)": 2
|
||||
"time horizon (years)": 2,
|
||||
"distance metric": "driving"
|
||||
},
|
||||
"products": {
|
||||
"P1": {
|
||||
"transportation cost ($/km/tonne)": [
|
||||
0.015,
|
||||
0.015
|
||||
],
|
||||
"transportation energy (J/km/tonne)": [
|
||||
0.12,
|
||||
0.11
|
||||
],
|
||||
"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
|
||||
]
|
||||
"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
|
||||
]
|
||||
"amount (tonne)": [934.56, 934.56]
|
||||
},
|
||||
"C2": {
|
||||
"latitude (deg)": 7.0,
|
||||
"longitude (deg)": 19.0,
|
||||
"amount (tonne)": [
|
||||
198.95,
|
||||
198.95
|
||||
]
|
||||
"amount (tonne)": [198.95, 198.95]
|
||||
},
|
||||
"C3": {
|
||||
"latitude (deg)": 84.0,
|
||||
"longitude (deg)": 76.0,
|
||||
"amount (tonne)": [
|
||||
212.97,
|
||||
212.97
|
||||
]
|
||||
"amount (tonne)": [212.97, 212.97]
|
||||
},
|
||||
"C4": {
|
||||
"latitude (deg)": 21.0,
|
||||
"longitude (deg)": 16.0,
|
||||
"amount (tonne)": [
|
||||
352.19,
|
||||
352.19
|
||||
]
|
||||
"amount (tonne)": [352.19, 352.19]
|
||||
},
|
||||
"C5": {
|
||||
"latitude (deg)": 32.0,
|
||||
"longitude (deg)": 92.0,
|
||||
"amount (tonne)": [
|
||||
510.33,
|
||||
510.33
|
||||
]
|
||||
"amount (tonne)": [510.33, 510.33]
|
||||
},
|
||||
"C6": {
|
||||
"latitude (deg)": 14.0,
|
||||
"longitude (deg)": 62.0,
|
||||
"amount (tonne)": [
|
||||
471.66,
|
||||
471.66
|
||||
]
|
||||
"amount (tonne)": [471.66, 471.66]
|
||||
},
|
||||
"C7": {
|
||||
"latitude (deg)": 30.0,
|
||||
"longitude (deg)": 83.0,
|
||||
"amount (tonne)": [
|
||||
785.21,
|
||||
785.21
|
||||
]
|
||||
"amount (tonne)": [785.21, 785.21]
|
||||
},
|
||||
"C8": {
|
||||
"latitude (deg)": 35.0,
|
||||
"longitude (deg)": 40.0,
|
||||
"amount (tonne)": [
|
||||
706.17,
|
||||
706.17
|
||||
]
|
||||
"amount (tonne)": [706.17, 706.17]
|
||||
},
|
||||
"C9": {
|
||||
"latitude (deg)": 74.0,
|
||||
"longitude (deg)": 52.0,
|
||||
"amount (tonne)": [
|
||||
30.08,
|
||||
30.08
|
||||
]
|
||||
"amount (tonne)": [30.08, 30.08]
|
||||
},
|
||||
"C10": {
|
||||
"latitude (deg)": 22.0,
|
||||
"longitude (deg)": 54.0,
|
||||
"amount (tonne)": [
|
||||
536.52,
|
||||
536.52
|
||||
]
|
||||
"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
|
||||
]
|
||||
"transportation cost ($/km/tonne)": [0.02, 0.02]
|
||||
},
|
||||
"P3": {
|
||||
"transportation cost ($/km/tonne)": [
|
||||
0.0125,
|
||||
0.0125
|
||||
]
|
||||
"transportation cost ($/km/tonne)": [0.0125, 0.0125]
|
||||
},
|
||||
"P4": {
|
||||
"transportation cost ($/km/tonne)": [
|
||||
0.0175,
|
||||
0.0175
|
||||
]
|
||||
"transportation cost ($/km/tonne)": [0.0175, 0.0175]
|
||||
}
|
||||
},
|
||||
"plants": {
|
||||
@@ -139,19 +81,10 @@
|
||||
"P2": 0.2,
|
||||
"P3": 0.5
|
||||
},
|
||||
"energy (GJ/tonne)": [
|
||||
0.12,
|
||||
0.11
|
||||
],
|
||||
"energy (GJ/tonne)": [0.12, 0.11],
|
||||
"emissions (tonne/tonne)": {
|
||||
"CO2": [
|
||||
0.052,
|
||||
0.050
|
||||
],
|
||||
"CH4": [
|
||||
0.003,
|
||||
0.002
|
||||
]
|
||||
"CO2": [0.052, 0.050],
|
||||
"CH4": [0.003, 0.002]
|
||||
},
|
||||
"locations": {
|
||||
"L1": {
|
||||
@@ -159,54 +92,24 @@
|
||||
"longitude (deg)": 0.0,
|
||||
"disposal": {
|
||||
"P2": {
|
||||
"cost ($/tonne)": [
|
||||
-10.0,
|
||||
-10.0
|
||||
],
|
||||
"limit (tonne)": [
|
||||
1.0,
|
||||
1.0
|
||||
]
|
||||
"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
|
||||
]
|
||||
"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
|
||||
]
|
||||
"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
|
||||
]
|
||||
"opening cost ($)": [1250.0, 1250.0],
|
||||
"fixed operating cost ($)": [30.0, 30.0],
|
||||
"variable operating cost ($/tonne)": [30.0, 30.0]
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -215,32 +118,14 @@
|
||||
"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
|
||||
]
|
||||
"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
|
||||
]
|
||||
"opening cost ($)": [10000, 10000],
|
||||
"fixed operating cost ($)": [50.0, 50.0],
|
||||
"variable operating cost ($/tonne)": [50.0, 50.0]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -258,26 +143,14 @@
|
||||
"longitude (deg)": 65.0,
|
||||
"disposal": {
|
||||
"P3": {
|
||||
"cost ($/tonne)": [
|
||||
100.0,
|
||||
100.0
|
||||
]
|
||||
"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
|
||||
]
|
||||
"opening cost ($)": [3000, 3000],
|
||||
"fixed operating cost ($)": [50.0, 50.0],
|
||||
"variable operating cost ($/tonne)": [50.0, 50.0]
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -286,18 +159,9 @@
|
||||
"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
|
||||
]
|
||||
"opening cost ($)": [3000, 3000],
|
||||
"fixed operating cost ($)": [50.0, 50.0],
|
||||
"variable operating cost ($/tonne)": [50.0, 50.0]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -311,18 +175,9 @@
|
||||
"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
|
||||
]
|
||||
"opening cost ($)": [0.0, 0.0],
|
||||
"fixed operating cost ($)": [0.0, 0.0],
|
||||
"variable operating cost ($/tonne)": [-15.0, -15.0]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -336,18 +191,9 @@
|
||||
"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
|
||||
]
|
||||
"opening cost ($)": [0.0, 0.0],
|
||||
"fixed operating cost ($)": [0.0, 0.0],
|
||||
"variable operating cost ($/tonne)": [-15.0, -15.0]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
@@ -5,19 +5,19 @@
|
||||
module RELOG
|
||||
|
||||
include("instance/structs.jl")
|
||||
|
||||
include("graph/structs.jl")
|
||||
|
||||
include("instance/geodb.jl")
|
||||
include("graph/dist.jl")
|
||||
include("graph/build.jl")
|
||||
include("graph/csv.jl")
|
||||
include("instance/compress.jl")
|
||||
include("instance/geodb.jl")
|
||||
include("instance/parse.jl")
|
||||
include("instance/validate.jl")
|
||||
include("model/build.jl")
|
||||
include("model/getsol.jl")
|
||||
include("model/solve.jl")
|
||||
include("model/resolve.jl")
|
||||
include("model/solve.jl")
|
||||
include("reports/plant_emissions.jl")
|
||||
include("reports/plant_outputs.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"]
|
||||
});
|
||||
@@ -2,14 +2,6 @@
|
||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
using Geodesy
|
||||
|
||||
function calculate_distance(source_lat, source_lon, dest_lat, dest_lon)::Float64
|
||||
x = LLA(source_lat, source_lon, 0.0)
|
||||
y = LLA(dest_lat, dest_lon, 0.0)
|
||||
return round(distance(x, y) / 1000.0, digits = 2)
|
||||
end
|
||||
|
||||
function build_graph(instance::Instance)::Graph
|
||||
arcs = []
|
||||
next_index = 0
|
||||
@@ -18,7 +10,6 @@ function build_graph(instance::Instance)::Graph
|
||||
collection_shipping_nodes = ShippingNode[]
|
||||
|
||||
name_to_process_node_map = Dict{Tuple{AbstractString,AbstractString},ProcessNode}()
|
||||
collection_center_to_node = Dict()
|
||||
|
||||
process_nodes_by_input_product =
|
||||
Dict(product => ProcessNode[] for product in instance.products)
|
||||
@@ -28,7 +19,6 @@ function build_graph(instance::Instance)::Graph
|
||||
for center in instance.collection_centers
|
||||
node = ShippingNode(next_index, center, center.product, [], [])
|
||||
next_index += 1
|
||||
collection_center_to_node[center] = node
|
||||
push!(collection_shipping_nodes, node)
|
||||
end
|
||||
|
||||
@@ -52,11 +42,12 @@ function build_graph(instance::Instance)::Graph
|
||||
# Build arcs from collection centers to plants, and from one plant to another
|
||||
for source in [collection_shipping_nodes; plant_shipping_nodes]
|
||||
for dest in process_nodes_by_input_product[source.product]
|
||||
distance = calculate_distance(
|
||||
distance = _calculate_distance(
|
||||
source.location.latitude,
|
||||
source.location.longitude,
|
||||
dest.location.latitude,
|
||||
dest.location.longitude,
|
||||
instance.distance_metric,
|
||||
)
|
||||
values = Dict("distance" => distance)
|
||||
arc = Arc(source, dest, values)
|
||||
@@ -85,7 +76,6 @@ function build_graph(instance::Instance)::Graph
|
||||
collection_shipping_nodes,
|
||||
arcs,
|
||||
name_to_process_node_map,
|
||||
collection_center_to_node,
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
57
src/graph/dist.jl
Normal file
@@ -0,0 +1,57 @@
|
||||
# RELOG: Reverse Logistics Optimization
|
||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
using Geodesy
|
||||
using NearestNeighbors
|
||||
using DataFrames
|
||||
|
||||
function _calculate_distance(
|
||||
source_lat,
|
||||
source_lon,
|
||||
dest_lat,
|
||||
dest_lon,
|
||||
::EuclideanDistance,
|
||||
)::Float64
|
||||
x = LLA(source_lat, source_lon, 0.0)
|
||||
y = LLA(dest_lat, dest_lon, 0.0)
|
||||
return round(euclidean_distance(x, y) / 1000.0, digits = 3)
|
||||
end
|
||||
|
||||
function _calculate_distance(
|
||||
source_lat,
|
||||
source_lon,
|
||||
dest_lat,
|
||||
dest_lon,
|
||||
metric::KnnDrivingDistance,
|
||||
)::Float64
|
||||
if metric.tree === nothing
|
||||
basedir = joinpath(dirname(@__FILE__), "..", "..", "data")
|
||||
csv_filename = joinpath(basedir, "dist_driving.csv")
|
||||
|
||||
# Download pre-computed driving data
|
||||
if !isfile(csv_filename)
|
||||
_download_zip(
|
||||
"https://axavier.org/RELOG/0.6/data/dist_driving_0b9a6ad6.zip",
|
||||
basedir,
|
||||
csv_filename,
|
||||
0x0b9a6ad6,
|
||||
)
|
||||
end
|
||||
|
||||
# Fit kNN model
|
||||
df = DataFrame(CSV.File(csv_filename))
|
||||
coords = Matrix(df[!, [:source_lat, :source_lon, :dest_lat, :dest_lon]])'
|
||||
metric.ratios = Matrix(df[!, [:ratio]])
|
||||
metric.tree = KDTree(coords)
|
||||
end
|
||||
|
||||
# Compute Euclidean distance
|
||||
dist_euclidean =
|
||||
_calculate_distance(source_lat, source_lon, dest_lat, dest_lon, EuclideanDistance())
|
||||
|
||||
# Predict ratio
|
||||
idxs, _ = knn(metric.tree, [source_lat, source_lon, dest_lat, dest_lon], 5)
|
||||
ratio_pred = mean(metric.ratios[idxs])
|
||||
return round(dist_euclidean * ratio_pred, digits = 3)
|
||||
end
|
||||
@@ -33,7 +33,6 @@ mutable struct Graph
|
||||
collection_shipping_nodes::Vector{ShippingNode}
|
||||
arcs::Vector{Arc}
|
||||
name_to_process_node_map::Dict{Tuple{AbstractString,AbstractString},ProcessNode}
|
||||
collection_center_to_node::Dict{CollectionCenter,ShippingNode}
|
||||
end
|
||||
|
||||
function Base.show(io::IO, instance::Graph)
|
||||
|
||||
@@ -23,10 +23,23 @@ function parse(json)::Instance
|
||||
validate(json, Schema(json_schema))
|
||||
|
||||
building_period = [1]
|
||||
if "building period (years)" in keys(json)
|
||||
building_period = json["building period (years)"]
|
||||
if "building period (years)" in keys(json["parameters"])
|
||||
building_period = json["parameters"]["building period (years)"]
|
||||
end
|
||||
|
||||
distance_metric = EuclideanDistance()
|
||||
if "distance metric" in keys(json["parameters"])
|
||||
metric_name = json["parameters"]["distance metric"]
|
||||
if metric_name == "driving"
|
||||
distance_metric = KnnDrivingDistance()
|
||||
elseif metric_name == "Euclidean"
|
||||
# nop
|
||||
else
|
||||
error("Unknown distance metric: $metric_name")
|
||||
end
|
||||
end
|
||||
@show distance_metric
|
||||
|
||||
plants = Plant[]
|
||||
products = Product[]
|
||||
collection_centers = CollectionCenter[]
|
||||
@@ -37,8 +50,6 @@ function parse(json)::Instance
|
||||
cost = product_dict["transportation cost (\$/km/tonne)"]
|
||||
energy = zeros(T)
|
||||
emissions = Dict()
|
||||
disposal_limit = zeros(T)
|
||||
disposal_cost = zeros(T)
|
||||
|
||||
if "transportation energy (J/km/tonne)" in keys(product_dict)
|
||||
energy = product_dict["transportation energy (J/km/tonne)"]
|
||||
@@ -48,25 +59,7 @@ function parse(json)::Instance
|
||||
emissions = product_dict["transportation emissions (tonne/km/tonne)"]
|
||||
end
|
||||
|
||||
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,
|
||||
)
|
||||
product = Product(product_name, cost, energy, emissions)
|
||||
push!(products, product)
|
||||
prod_name_to_product[product_name] = product
|
||||
|
||||
@@ -86,7 +79,6 @@ function parse(json)::Instance
|
||||
product,
|
||||
center_dict["amount (tonne)"],
|
||||
)
|
||||
push!(prod_centers, center)
|
||||
push!(collection_centers, center)
|
||||
end
|
||||
end
|
||||
@@ -197,5 +189,12 @@ function parse(json)::Instance
|
||||
@info @sprintf("%12d collection centers", length(collection_centers))
|
||||
@info @sprintf("%12d candidate plant locations", length(plants))
|
||||
|
||||
return Instance(T, products, collection_centers, plants, building_period)
|
||||
return Instance(
|
||||
T,
|
||||
products,
|
||||
collection_centers,
|
||||
plants,
|
||||
building_period,
|
||||
distance_metric,
|
||||
)
|
||||
end
|
||||
|
||||
@@ -13,9 +13,6 @@ mutable struct Product
|
||||
transportation_cost::Vector{Float64}
|
||||
transportation_energy::Vector{Float64}
|
||||
transportation_emissions::Dict{String,Vector{Float64}}
|
||||
disposal_limit::Vector{Float64}
|
||||
disposal_cost::Vector{Float64}
|
||||
collection_centers::Vector
|
||||
end
|
||||
|
||||
mutable struct CollectionCenter
|
||||
@@ -51,10 +48,21 @@ mutable struct Plant
|
||||
storage_cost::Vector{Float64}
|
||||
end
|
||||
|
||||
|
||||
abstract type DistanceMetric end
|
||||
|
||||
Base.@kwdef mutable struct KnnDrivingDistance <: DistanceMetric
|
||||
tree = nothing
|
||||
ratios = nothing
|
||||
end
|
||||
|
||||
mutable struct EuclideanDistance <: DistanceMetric end
|
||||
|
||||
mutable struct Instance
|
||||
time::Int64
|
||||
products::Vector{Product}
|
||||
collection_centers::Vector{CollectionCenter}
|
||||
plants::Vector{Plant}
|
||||
building_period::Vector{Int64}
|
||||
distance_metric::DistanceMetric
|
||||
end
|
||||
|
||||
@@ -20,17 +20,13 @@ function create_vars!(model::JuMP.Model)
|
||||
graph, T = model[:graph], model[:instance].time
|
||||
model[:flow] =
|
||||
Dict((a, t) => @variable(model, lower_bound = 0) for a in graph.arcs, t = 1:T)
|
||||
model[:plant_dispose] = Dict(
|
||||
model[:dispose] = Dict(
|
||||
(n, t) => @variable(
|
||||
model,
|
||||
lower_bound = 0,
|
||||
upper_bound = n.location.disposal_limit[n.product][t]
|
||||
) for n in values(graph.plant_shipping_nodes), t = 1:T
|
||||
)
|
||||
model[:collection_dispose] = Dict(
|
||||
(n, t) => @variable(model, lower_bound = 0,) for
|
||||
n in values(graph.collection_shipping_nodes), t = 1:T
|
||||
)
|
||||
model[:store] = Dict(
|
||||
(n, t) =>
|
||||
@variable(model, lower_bound = 0, upper_bound = n.location.storage_limit)
|
||||
@@ -135,25 +131,14 @@ function create_objective_function!(model::JuMP.Model)
|
||||
end
|
||||
end
|
||||
|
||||
# Plant shipping node costs
|
||||
# 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[:plant_dispose][n, t],
|
||||
)
|
||||
end
|
||||
|
||||
# Collection shipping node costs
|
||||
for n in values(graph.collection_shipping_nodes), t = 1:T
|
||||
|
||||
# Disposal costs
|
||||
add_to_expression!(
|
||||
obj,
|
||||
n.location.product.disposal_cost[t],
|
||||
model[:collection_dispose][n, t],
|
||||
model[:dispose][n, t],
|
||||
)
|
||||
end
|
||||
|
||||
@@ -169,29 +154,16 @@ function create_shipping_node_constraints!(model::JuMP.Model)
|
||||
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] + model[:collection_dispose][n, t]
|
||||
sum(model[:flow][a, t] for a in n.outgoing_arcs) == n.location.amount[t]
|
||||
)
|
||||
end
|
||||
for prod in model[:instance].products
|
||||
if isempty(prod.collection_centers)
|
||||
continue
|
||||
end
|
||||
expr = AffExpr()
|
||||
for center in prod.collection_centers
|
||||
n = graph.collection_center_to_node[center]
|
||||
add_to_expression!(expr, model[:collection_dispose][n, t])
|
||||
end
|
||||
@constraint(model, expr <= prod.disposal_limit[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[:plant_dispose][n, t]
|
||||
sum(model[:flow][a, t] for a in n.outgoing_arcs) + model[:dispose][n, t]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,25 +39,22 @@ function get_solution(model::JuMP.Model; marginal_costs = true)
|
||||
end
|
||||
|
||||
# Products
|
||||
if marginal_costs
|
||||
for n in graph.collection_shipping_nodes
|
||||
location_dict = OrderedDict{Any,Any}(
|
||||
"Marginal cost (\$/tonne)" => [
|
||||
round(abs(JuMP.shadow_price(model[:eq_balance][n, t])), digits = 2) for t = 1:T
|
||||
],
|
||||
"Latitude (deg)" => n.location.latitude,
|
||||
"Longitude (deg)" => n.location.longitude,
|
||||
"Amount (tonne)" => n.location.amount,
|
||||
"Dispose (tonne)" =>
|
||||
[JuMP.value(model[:collection_dispose][n, t]) for t = 1:T],
|
||||
)
|
||||
if marginal_costs
|
||||
location_dict["Marginal cost (\$/tonne)"] = [
|
||||
round(abs(JuMP.shadow_price(model[:eq_balance][n, t])), digits = 2) for
|
||||
t = 1:T
|
||||
]
|
||||
end
|
||||
if n.product.name ∉ keys(output["Products"])
|
||||
output["Products"][n.product.name] = OrderedDict()
|
||||
end
|
||||
output["Products"][n.product.name][n.location.name] = location_dict
|
||||
end
|
||||
end
|
||||
|
||||
# Plants
|
||||
for plant in instance.plants
|
||||
@@ -181,14 +178,13 @@ function get_solution(model::JuMP.Model; marginal_costs = true)
|
||||
plant_dict["Total output"][product_name] = zeros(T)
|
||||
plant_dict["Output"]["Send"][product_name] = product_dict = OrderedDict()
|
||||
|
||||
disposal_amount =
|
||||
[JuMP.value(model[:plant_dispose][shipping_node, t]) for t = 1:T]
|
||||
disposal_amount = [JuMP.value(model[:dispose][shipping_node, t]) for t = 1:T]
|
||||
if sum(disposal_amount) > 1e-5
|
||||
skip_plant = false
|
||||
plant_dict["Output"]["Dispose"][product_name] =
|
||||
disposal_dict = OrderedDict()
|
||||
disposal_dict["Amount (tonne)"] =
|
||||
[JuMP.value(model[:plant_dispose][shipping_node, t]) for t = 1:T]
|
||||
[JuMP.value(model[:dispose][shipping_node, t]) for t = 1:T]
|
||||
disposal_dict["Cost (\$)"] = [
|
||||
disposal_dict["Amount (tonne)"][t] *
|
||||
plant.disposal_cost[shipping_node.product][t] for t = 1:T
|
||||
|
||||
@@ -13,7 +13,6 @@ function products_report(solution; marginal_costs = true)::DataFrame
|
||||
df."longitude (deg)" = Float64[]
|
||||
df."year" = Int[]
|
||||
df."amount (tonne)" = Float64[]
|
||||
df."amount disposed (tonne)" = Float64[]
|
||||
df."marginal cost (\$/tonne)" = Float64[]
|
||||
T = length(solution["Energy"]["Plants (GJ)"])
|
||||
for (prod_name, prod_dict) in solution["Products"]
|
||||
@@ -23,7 +22,6 @@ function products_report(solution; marginal_costs = true)::DataFrame
|
||||
latitude = round(location_dict["Latitude (deg)"], digits = 6)
|
||||
longitude = round(location_dict["Longitude (deg)"], digits = 6)
|
||||
amount = location_dict["Amount (tonne)"][year]
|
||||
amount_disposed = location_dict["Dispose (tonne)"][year]
|
||||
push!(
|
||||
df,
|
||||
[
|
||||
@@ -34,7 +32,6 @@ function products_report(solution; marginal_costs = true)::DataFrame
|
||||
year,
|
||||
amount,
|
||||
marginal_cost,
|
||||
amount_disposed,
|
||||
],
|
||||
)
|
||||
end
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
"properties": {
|
||||
"time horizon (years)": {
|
||||
"type": "number"
|
||||
},
|
||||
"distance metric": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
@@ -169,12 +172,6 @@
|
||||
},
|
||||
"initial amounts": {
|
||||
"$ref": "#/definitions/InitialAmount"
|
||||
},
|
||||
"disposal limit (tonne)": {
|
||||
"$ref": "#/definitions/TimeSeries"
|
||||
},
|
||||
"disposal cost ($/tonne)": {
|
||||
"$ref": "#/definitions/TimeSeries"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -1,30 +1,15 @@
|
||||
using PackageCompiler
|
||||
using TOML
|
||||
using Logging
|
||||
|
||||
Logging.disable_logging(Logging.Info)
|
||||
using Cbc
|
||||
using Clp
|
||||
using Geodesy
|
||||
using JSON
|
||||
using JSONSchema
|
||||
using JuMP
|
||||
using MathOptInterface
|
||||
using ProgressBars
|
||||
|
||||
mkpath("build")
|
||||
pkg = [:Cbc, :Clp, :Geodesy, :JSON, :JSONSchema, :JuMP, :MathOptInterface, :ProgressBars]
|
||||
|
||||
printstyled("Generating precompilation statements...\n", color = :light_green)
|
||||
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",
|
||||
)
|
||||
@info "Building system image..."
|
||||
create_sysimage(pkg, sysimage_path = "build/sysimage.so")
|
||||
|
||||
@@ -21,7 +21,7 @@ using RELOG
|
||||
@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.location_name == "L1"
|
||||
@test node.outgoing_arcs[1].values["distance"] == 1095.62
|
||||
@test node.outgoing_arcs[1].values["distance"] == 1695.364
|
||||
|
||||
node = process_node_by_location_name["L1"]
|
||||
@test node.location.plant_name == "F1"
|
||||
|
||||
25
test/graph/dist_test.jl
Normal file
@@ -0,0 +1,25 @@
|
||||
# RELOG: Reverse Logistics Optimization
|
||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
using RELOG
|
||||
|
||||
@testset "KnnDrivingDistance" begin
|
||||
# Euclidean distance between Chicago and Indianapolis
|
||||
@test RELOG._calculate_distance(
|
||||
41.866,
|
||||
-87.656,
|
||||
39.764,
|
||||
-86.148,
|
||||
RELOG.EuclideanDistance(),
|
||||
) == 265.818
|
||||
|
||||
# Approximate driving distance between Chicago and Indianapolis
|
||||
@test RELOG._calculate_distance(
|
||||
41.866,
|
||||
-87.656,
|
||||
39.764,
|
||||
-86.148,
|
||||
RELOG.KnnDrivingDistance(),
|
||||
) == 316.43
|
||||
end
|
||||
@@ -40,14 +40,7 @@ using RELOG
|
||||
@test plant.sizes[2].fixed_operating_cost == [30, 30]
|
||||
@test plant.sizes[2].variable_operating_cost == [30, 30]
|
||||
|
||||
p1 = product_name_to_product["P1"]
|
||||
@test p1.disposal_limit == [1.0, 1.0]
|
||||
@test p1.disposal_cost == [-1000.0, -1000.0]
|
||||
|
||||
p2 = product_name_to_product["P2"]
|
||||
@test p2.disposal_limit == [0.0, 0.0]
|
||||
@test p2.disposal_cost == [0.0, 0.0]
|
||||
|
||||
p3 = product_name_to_product["P3"]
|
||||
@test length(plant.output) == 2
|
||||
@test plant.output[p2] == 0.2
|
||||
|
||||
@@ -18,7 +18,7 @@ using RELOG, Cbc, JuMP, Printf, JSON, MathOptInterface.FileFormats
|
||||
)
|
||||
|
||||
@test length(model[:flow]) == 76
|
||||
@test length(model[:plant_dispose]) == 16
|
||||
@test length(model[:dispose]) == 16
|
||||
@test length(model[:open_plant]) == 12
|
||||
@test length(model[:capacity]) == 12
|
||||
@test length(model[:expansion]) == 12
|
||||
@@ -32,7 +32,7 @@ using RELOG, Cbc, JuMP, Printf, JSON, MathOptInterface.FileFormats
|
||||
@test lower_bound(v) == 0.0
|
||||
@test upper_bound(v) == 750.0
|
||||
|
||||
v = model[:plant_dispose][shipping_node_by_loc_and_prod_names["L1", "P2"], 1]
|
||||
v = model[:dispose][shipping_node_by_loc_and_prod_names["L1", "P2"], 1]
|
||||
@test lower_bound(v) == 0.0
|
||||
@test upper_bound(v) == 1.0
|
||||
end
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
|
||||
using RELOG
|
||||
|
||||
basedir = @__DIR__
|
||||
|
||||
@testset "Resolve" begin
|
||||
# Shoud not crash
|
||||
filename = "$basedir/../../instances/s1.json"
|
||||
filename = "$(pwd())/../instances/s1.json"
|
||||
solution_old, model_old = RELOG.solve(filename, return_model = true)
|
||||
solution_new = RELOG.resolve(model_old, filename)
|
||||
end
|
||||
|
||||
@@ -26,15 +26,6 @@ basedir = dirname(@__FILE__)
|
||||
@test "F2" in keys(solution["Plants"])
|
||||
@test "F3" in keys(solution["Plants"])
|
||||
@test "F4" in keys(solution["Plants"])
|
||||
|
||||
@test "Products" in keys(solution)
|
||||
@test "P1" in keys(solution["Products"])
|
||||
@test "C1" in keys(solution["Products"]["P1"])
|
||||
@test "Dispose (tonne)" in keys(solution["Products"]["P1"]["C1"])
|
||||
|
||||
total_disposal =
|
||||
sum([loc["Dispose (tonne)"] for loc in values(solution["Products"]["P1"])])
|
||||
@test total_disposal == [1.0, 1.0]
|
||||
end
|
||||
|
||||
@testset "solve (heuristic)" begin
|
||||
|
||||
@@ -4,11 +4,9 @@
|
||||
|
||||
using RELOG, JSON, GZip
|
||||
|
||||
basedir = @__DIR__
|
||||
|
||||
@testset "Reports" begin
|
||||
@testset "from solve" begin
|
||||
solution = RELOG.solve("$basedir/../instances/s1.json")
|
||||
solution = RELOG.solve("$(pwd())/../instances/s1.json")
|
||||
tmp_filename = tempname()
|
||||
# The following should not crash
|
||||
RELOG.write_plant_emissions_report(solution, tmp_filename)
|
||||
|
||||
@@ -11,6 +11,7 @@ using Test
|
||||
end
|
||||
@testset "Graph" begin
|
||||
include("graph/build_test.jl")
|
||||
include("graph/dist_test.jl")
|
||||
end
|
||||
@testset "Model" begin
|
||||
include("model/build_test.jl")
|
||||
|
||||