mirror of
https://github.com/ANL-CEEESA/RELOG.git
synced 2025-12-06 15:48:51 -06:00
Compare commits
16 Commits
feature/ge
...
feature/co
| Author | SHA1 | Date | |
|---|---|---|---|
| a03b9169fd | |||
| ee58af73f0 | |||
| 9ebb2e49f9 | |||
| 505e3a8e1e | |||
| d4fa75297f | |||
| 881957d6b5 | |||
| 86cf7f5bd9 | |||
| a8c7047e2d | |||
| 099e0fae3a | |||
| 1b8f392852 | |||
| 7a95aa66f6 | |||
| 40d28c727a | |||
| a9ac164833 | |||
| e244ded51d | |||
| 7180651cfa | |||
| 0c9465411f |
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
version: ['1.3', '1.4', '1.5', 'nightly']
|
||||
version: ['1.3', '1.4', '1.5', '1.6']
|
||||
os:
|
||||
- ubuntu-latest
|
||||
arch:
|
||||
|
||||
43
CHANGELOG.md
43
CHANGELOG.md
@@ -1,28 +1,49 @@
|
||||
# Version 0.5.0 (Jan 6, 2021)
|
||||
# Changelog
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
- The format is based on [Keep a Changelog][changelog].
|
||||
- This project adheres to [Semantic Versioning][semver].
|
||||
- For versions before 1.0, we follow the [Pkg.jl convention][pkjjl]
|
||||
that `0.a.b` is compatible with `0.a.c`.
|
||||
|
||||
[changelog]: https://keepachangelog.com/en/1.0.0/
|
||||
[semver]: https://semver.org/spec/v2.0.0.html
|
||||
[pkjjl]: https://pkgdocs.julialang.org/v1/compatibility/#compat-pre-1.0
|
||||
|
||||
## [0.5.1] -- 2021-07-23
|
||||
## Added
|
||||
- Allow user to specify locations as unique identifiers, instead of latitude and longitude (e.g. `us-state:IL` or `2018-us-county:17043`)
|
||||
- Add what-if scenarios.
|
||||
- Add products report.
|
||||
|
||||
## [0.5.0] -- 2021-01-06
|
||||
## Added
|
||||
- Allow plants to store input material for processing in later years
|
||||
|
||||
# Version 0.4.0 (Sep 18, 2020)
|
||||
|
||||
## [0.4.0] -- 2020-09-18
|
||||
## Added
|
||||
- Generate simplified solution reports (CSV)
|
||||
|
||||
# Version 0.3.3 (Aug 13, 2020)
|
||||
|
||||
## [0.3.3] -- 2020-10-13
|
||||
## Added
|
||||
- Add option to write solution to JSON file in RELOG.solve
|
||||
- Improve error message when instance is infeasible
|
||||
- Make output file more readable
|
||||
|
||||
# Version 0.3.2 (Aug 7, 2020)
|
||||
|
||||
## [0.3.2] -- 2020-10-07
|
||||
## Added
|
||||
- Add "building period" parameter
|
||||
|
||||
# Version 0.3.1 (July 17, 2020)
|
||||
|
||||
## [0.3.1] -- 2020-07-17
|
||||
## Fixed
|
||||
- Fix expansion cost breakdown
|
||||
|
||||
# Version 0.3.0 (June 25, 2020)
|
||||
|
||||
## [0.3.0] -- 2020-06-25
|
||||
## Added
|
||||
- Track emissions and energy (transportation and plants)
|
||||
|
||||
## Changed
|
||||
- Minor changes to input file format:
|
||||
- Make all dictionary keys lowercase
|
||||
- Rename "outputs (tonne)" to "outputs (tonne/tonne)"
|
||||
|
||||
11
Makefile
11
Makefile
@@ -1,15 +1,11 @@
|
||||
JULIA := julia --color=yes --project=@.
|
||||
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
|
||||
mkdir -p build
|
||||
$(JULIA) src/sysimage.jl
|
||||
|
||||
build/test.log: $(SRC_FILES) build/sysimage.so
|
||||
cd test; $(JULIA) --sysimage ../build/sysimage.so runtests.jl
|
||||
@$(JULIA) src/sysimage.jl
|
||||
|
||||
clean:
|
||||
rm -rf build/*
|
||||
@@ -20,7 +16,8 @@ docs:
|
||||
format:
|
||||
julia -e 'using JuliaFormatter; format(["src", "test"], verbose=true);'
|
||||
|
||||
test: build/test.log
|
||||
test:
|
||||
@$(JULIA) --sysimage build/sysimage.so test/runtests.jl
|
||||
|
||||
test-watch:
|
||||
bash -c "while true; do make test --quiet; sleep 1; done"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
name = "RELOG"
|
||||
uuid = "a2afcdf7-cf04-4913-85f9-c0d81ddf2008"
|
||||
authors = ["Alinson S Xavier <axavier@anl.gov>"]
|
||||
version = "0.5.0"
|
||||
version = "0.5.1"
|
||||
|
||||
[deps]
|
||||
CRC = "44b605c4-b955-5f2b-9b6d-d2bd01d3d205"
|
||||
@@ -40,6 +40,7 @@ JSON = "0.21"
|
||||
JSONSchema = "0.3"
|
||||
JuMP = "0.21"
|
||||
MathOptInterface = "0.9"
|
||||
OrderedCollections = "1.4"
|
||||
PackageCompiler = "1"
|
||||
ProgressBars = "0.6"
|
||||
Shapefile = "0.7"
|
||||
|
||||
@@ -4,73 +4,132 @@
|
||||
},
|
||||
"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": {
|
||||
@@ -80,10 +139,19 @@
|
||||
"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": {
|
||||
@@ -91,24 +159,54 @@
|
||||
"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
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -117,14 +215,32 @@
|
||||
"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
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,14 +258,26 @@
|
||||
"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
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -158,9 +286,18 @@
|
||||
"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
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -174,9 +311,18 @@
|
||||
"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
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -190,9 +336,18 @@
|
||||
"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
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,8 +202,7 @@
|
||||
}
|
||||
},
|
||||
"L2": {
|
||||
"latitude (deg)": 0.5,
|
||||
"longitude (deg)": 0.5,
|
||||
"location": "2018-us-county:17043",
|
||||
"capacities (tonne)": {
|
||||
"0.0": {
|
||||
"opening cost ($)": [
|
||||
|
||||
@@ -17,9 +17,11 @@ include("instance/validate.jl")
|
||||
include("model/build.jl")
|
||||
include("model/getsol.jl")
|
||||
include("model/solve.jl")
|
||||
include("model/resolve.jl")
|
||||
include("reports/plant_emissions.jl")
|
||||
include("reports/plant_outputs.jl")
|
||||
include("reports/plants.jl")
|
||||
include("reports/products.jl")
|
||||
include("reports/tr_emissions.jl")
|
||||
include("reports/tr.jl")
|
||||
include("reports/write.jl")
|
||||
|
||||
@@ -36,6 +36,8 @@ The **products** section describes all products and subproducts in the simulatio
|
||||
|`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:
|
||||
|
||||
@@ -73,7 +75,9 @@ 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]
|
||||
@@ -182,6 +186,38 @@ The keys in the `capacities (tonne)` dictionary should be the amounts (in tonnes
|
||||
}
|
||||
```
|
||||
|
||||
### Geographic database
|
||||
|
||||
Instead of specifying locations using latitudes and longitudes, it is also possible to specify them using unique identifiers, such as the name of a US state, or the county FIPS code. This works anywhere `latitude (deg)` and `longitude (deg)` are expected. For example, instead of:
|
||||
```json
|
||||
{
|
||||
"initial amounts": {
|
||||
"C1": {
|
||||
"latitude (deg)": 37.27182,
|
||||
"longitude (deg)": -119.2704,
|
||||
"amount (tonne)": [934.56, 934.56]
|
||||
},
|
||||
}
|
||||
}
|
||||
```
|
||||
is is possible to write:
|
||||
```json
|
||||
{
|
||||
"initial amounts": {
|
||||
"C1": {
|
||||
"location": "us-state:CA",
|
||||
"amount (tonne)": [934.56, 934.56]
|
||||
},
|
||||
}
|
||||
}
|
||||
```
|
||||
Location names follow the format `db:id`, where `db` is the name of the database and `id` is the identifier for a specific location. RELOG currently includes the following databases:
|
||||
|
||||
Database | Description | Examples
|
||||
---------|-------------|----------
|
||||
`us-state`| List of states of the United States. | `us-state:IL` (State of Illinois)
|
||||
`2018-us-county` | List of United States counties, as of 2018. IDs are 5-digit FIPS codes. | `2018-us-county:17043` (DuPage county in Illinois)
|
||||
|
||||
### Current limitations
|
||||
|
||||
* Each plant can only be opened exactly once. After open, the plant remains open until the end of the simulation.
|
||||
@@ -192,4 +228,3 @@ The keys in the `capacities (tonne)` dictionary should be the amounts (in tonnes
|
||||
## Output Data Format (JSON)
|
||||
|
||||
To be documented.
|
||||
|
||||
|
||||
@@ -6,15 +6,13 @@ In this page, we also illustrate what types of charts and visualizations can be
|
||||
|
||||
## Plants report
|
||||
|
||||
Report showing plant costs, capacities, energy expenditure and utilization factors.
|
||||
|
||||
Generated by `RELOG.write_plants_report(solution, filename)`. For a concrete example, see [nimh_plants.csv](https://github.com/ANL-CEEESA/RELOG/blob/master/test/fixtures/nimh_plants.csv).
|
||||
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 in the simulation.
|
||||
| `year` | What year this row corresponds to. This reports includes one row for each year.
|
||||
| `latitude (deg)` | Latitude of the plant.
|
||||
| `longitude (deg)` | Longitude of the plant.
|
||||
| `capacity (tonne)` | Capacity of the plant at this point in time.
|
||||
@@ -72,16 +70,14 @@ gp.GeoDataFrame(data, geometry=points).plot(ax=ax);
|
||||
|
||||
## Plant outputs report
|
||||
|
||||
Report showing amount of products produced, sent and disposed of by each plant, as well as disposal costs.
|
||||
|
||||
Generated by `RELOG.write_plant_outputs_report(solution, filename)`. For a concrete example, see [nimh_plant_outputs.csv](https://github.com/ANL-CEEESA/RELOG/blob/master/test/fixtures/nimh_plant_outputs.csv).
|
||||
Report showing amount of products produced, sent and disposed of by each plant, as well as disposal costs. Generated by `RELOG.write_plant_outputs_report(solution, filename)`.
|
||||
|
||||
|
||||
| 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 in the simulation.
|
||||
| `year` | What year this row corresponds to. This reports includes one row for each year.
|
||||
| `product name` | Product being produced.
|
||||
| `amount produced (tonne)` | Amount of product produced this year.
|
||||
| `amount sent (tonne)` | Amount of product produced by this plant and sent to another plant for further processing this year.
|
||||
@@ -110,9 +106,7 @@ sns.barplot(x="amount produced (tonne)",
|
||||
|
||||
## Plant emissions report
|
||||
|
||||
Report showing amount of emissions produced by each plant.
|
||||
|
||||
Generated by `RELOG.write_plant_emissions_report(solution, filename)`. For a concrete example, see [nimh_plant_emissions.csv](https://github.com/ANL-CEEESA/RELOG/blob/master/test/fixtures/nimh_plant_emissions.csv).
|
||||
Report showing amount of emissions produced by each plant. Generated by `RELOG.write_plant_emissions_report(solution, filename)`.
|
||||
|
||||
| Column | Description
|
||||
|:--------------------------------------|---------------|
|
||||
@@ -141,11 +135,25 @@ sns.barplot(x="plant type",
|
||||
|
||||
<img src="../images/ex_emissions.png" width="500px"/>
|
||||
|
||||
## Products report
|
||||
|
||||
Report showing primary product amounts, locations and marginal costs. Generated by `RELOG.write_products_report(solution, filename)`.
|
||||
|
||||
| Column | Description
|
||||
|:--------------------------------------|---------------|
|
||||
| `product name` | Product name.
|
||||
| `location name` | Name of the collection center.
|
||||
| `latitude (deg)` | Latitude of the collection center.
|
||||
| `longitude (deg)` | Longitude of the collection center.
|
||||
| `year` | What year this row corresponds to. This reports includes one row for each year.
|
||||
| `amount (tonne)` | Amount of product available at this collection center.
|
||||
| `amount disposed (tonne)` | Amount of product disposed of at this collection center.
|
||||
| `marginal cost ($/tonne)` | Cost to process one additional tonne of this product coming from this collection center.
|
||||
|
||||
|
||||
## Transportation report
|
||||
|
||||
Report showing amount of product sent from initial locations to plants, and from one plant to another. Includes the distance between each pair of locations, amount-distance shipped, transportation costs and energy expenditure.
|
||||
|
||||
Generated by `RELOG.write_transportation_report(solution, filename)`. For a concrete example, see [nimh_transportation.csv](https://github.com/ANL-CEEESA/RELOG/blob/master/test/fixtures/nimh_transportation.csv).
|
||||
Report showing amount of product sent from initial locations to plants, and from one plant to another. Includes the distance between each pair of locations, amount-distance shipped, transportation costs and energy expenditure. Generated by `RELOG.write_transportation_report(solution, filename)`.
|
||||
|
||||
|
||||
| Column | Description
|
||||
@@ -231,9 +239,7 @@ gp.GeoDataFrame(data, geometry=points).plot(ax=ax,
|
||||
|
||||
## Transportation emissions report
|
||||
|
||||
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)`. For a concrete example, see [nimh_transportation_emissions.csv](https://github.com/ANL-CEEESA/RELOG/blob/master/test/fixtures/nimh_transportation_emissions.csv).
|
||||
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
|
||||
|:--------------------------------------|---------------|
|
||||
|
||||
@@ -66,9 +66,45 @@ RELOG.write_transportation_report(solution, "transportation.csv")
|
||||
|
||||
For a complete description of the file formats above, and for a complete list of available reports, see the [data format page](format.md).
|
||||
|
||||
## 4. Advanced options
|
||||
## 4. What-If Analysis
|
||||
|
||||
### 4.1 Changing the solver
|
||||
Fundamentally, RELOG decides when and where to build plants based on a deterministic optimization problem that minimizes costs for a particular input file provided by the user. In practical situations, it may not be possible to perfectly estimate some (or most) entries in this input file in advance, such as costs, demands and emissions. In this situation, it may be interesting to evaluate how well does the facility location plan produced by RELOG work if costs, demands and emissions turn out to be different.
|
||||
|
||||
To simplify this what-if analysis, RELOG provides the `resolve` method, which updates a previous solution based on a new scenario, but keeps some of the previous decisions fixed. More precisely, given an optimal solution produced by RELOG and a new input file describing the new scenario, the `resolve` method reoptimizes the supply chain and produces a new solution which still builds the same set of plants as before, in exactly the same locations and with the same capacities, but that may now utilize the plants differently, based on the new data. For example, in the new solution, plants that were previously used at full capacity may now be utilized at half-capacity instead. As another example, regions that were previously served by a certain plant may now be served by a different one.
|
||||
|
||||
The following snippet shows how to use the method:
|
||||
|
||||
```julia
|
||||
# Import package
|
||||
using RELOG
|
||||
|
||||
# Optimize for the average scenario
|
||||
solution_avg, model_avg = RELOG.solve("input_avg.json", return_model=true)
|
||||
|
||||
# Write reports for the average scenario
|
||||
RELOG.write_plants_report(solution_avg, "plants_avg.csv")
|
||||
RELOG.write_transportation_report(solution_avg, "transportation_avg.csv")
|
||||
|
||||
# Re-optimize for the high-demand scenario, keeping plants fixed
|
||||
solution_high = RELOG.resolve(model_avg, "input_high.json")
|
||||
|
||||
# Write reports for the high-demand scenario
|
||||
RELOG.write_plants_report(solution_high, "plants_high.csv")
|
||||
RELOG.write_transportation_report(solution_high, "transportation_high.csv")
|
||||
```
|
||||
|
||||
To use the `resolve` method, the new input file should be very similar to the original one. Only the following entries are allowed to change:
|
||||
|
||||
- **Products:** Transportation costs, energy, emissions and initial amounts (latitude, longitude and amount).
|
||||
- **Plants:** Energy and emissions.
|
||||
- **Plant's location:** Latitude and longitude.
|
||||
- **Plant's storage:** Cost.
|
||||
- **Plant's capacity:** Opening cost, fixed operating cost and variable operating cost.
|
||||
|
||||
|
||||
## 5. Advanced options
|
||||
|
||||
### 5.1 Changing the solver
|
||||
|
||||
By default, RELOG internally uses [Cbc](https://github.com/coin-or/Cbc), an open-source and freely-available Mixed-Integer Linear Programming solver developed by the [COIN-OR Project](https://www.coin-or.org/). For larger-scale test cases, a commercial solver such as Gurobi, CPLEX or XPRESS is recommended. The following snippet shows how to switch from Cbc to Gurobi, for example:
|
||||
|
||||
@@ -84,7 +120,7 @@ RELOG.solve("instance.json",
|
||||
optimizer=gurobi)
|
||||
```
|
||||
|
||||
### 4.2 Multi-period heuristics
|
||||
### 5.2 Multi-period heuristics
|
||||
|
||||
For large-scale instances, it may be too time-consuming to find an exact optimal solution to the multi-period version of the problem. For these situations, RELOG includes a heuristic solution method, which proceeds as follows:
|
||||
|
||||
|
||||
@@ -17,6 +17,9 @@ function build_graph(instance::Instance)::Graph
|
||||
plant_shipping_nodes = ShippingNode[]
|
||||
collection_shipping_nodes = ShippingNode[]
|
||||
|
||||
name_to_process_node_map = Dict{Tuple{AbstractString,AbstractString},ProcessNode}()
|
||||
collection_center_to_node = Dict()
|
||||
|
||||
process_nodes_by_input_product =
|
||||
Dict(product => ProcessNode[] for product in instance.products)
|
||||
shipping_nodes_by_plant = Dict(plant => [] for plant in instance.plants)
|
||||
@@ -25,6 +28,7 @@ function build_graph(instance::Instance)::Graph
|
||||
for center in instance.collection_centers
|
||||
node = ShippingNode(next_index, center, center.product, [], [])
|
||||
next_index += 1
|
||||
collection_center_to_node[center] = node
|
||||
push!(collection_shipping_nodes, node)
|
||||
end
|
||||
|
||||
@@ -35,6 +39,8 @@ function build_graph(instance::Instance)::Graph
|
||||
push!(process_nodes, pn)
|
||||
push!(process_nodes_by_input_product[plant.input], pn)
|
||||
|
||||
name_to_process_node_map[(plant.plant_name, plant.location_name)] = pn
|
||||
|
||||
for product in keys(plant.output)
|
||||
sn = ShippingNode(next_index, plant, product, [], [])
|
||||
next_index += 1
|
||||
@@ -73,5 +79,25 @@ function build_graph(instance::Instance)::Graph
|
||||
end
|
||||
end
|
||||
|
||||
return Graph(process_nodes, plant_shipping_nodes, collection_shipping_nodes, arcs)
|
||||
return Graph(
|
||||
process_nodes,
|
||||
plant_shipping_nodes,
|
||||
collection_shipping_nodes,
|
||||
arcs,
|
||||
name_to_process_node_map,
|
||||
collection_center_to_node,
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
function print_graph_stats(instance::Instance, graph::Graph)::Nothing
|
||||
@info @sprintf(" %12d time periods", instance.time)
|
||||
@info @sprintf(" %12d process nodes", length(graph.process_nodes))
|
||||
@info @sprintf(" %12d shipping nodes (plant)", length(graph.plant_shipping_nodes))
|
||||
@info @sprintf(
|
||||
" %12d shipping nodes (collection)",
|
||||
length(graph.collection_shipping_nodes)
|
||||
)
|
||||
@info @sprintf(" %12d arcs", length(graph.arcs))
|
||||
return
|
||||
end
|
||||
|
||||
@@ -32,4 +32,14 @@ mutable struct Graph
|
||||
plant_shipping_nodes::Vector{ShippingNode}
|
||||
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)
|
||||
print(io, "RELOG graph with ")
|
||||
print(io, "$(length(instance.process_nodes)) process nodes, ")
|
||||
print(io, "$(length(instance.plant_shipping_nodes)) plant shipping nodes, ")
|
||||
print(io, "$(length(instance.collection_shipping_nodes)) collection shipping nodes, ")
|
||||
print(io, "$(length(instance.arcs)) arcs")
|
||||
end
|
||||
|
||||
@@ -42,7 +42,7 @@ function centroid(geom::Shapefile.Polygon)::GeoPoint
|
||||
return GeoPoint(round(y_center, digits = 5), round(x_center, digits = 5))
|
||||
end
|
||||
|
||||
function _download(url, output, expected_crc32)::Nothing
|
||||
function _download_file(url, output, expected_crc32)::Nothing
|
||||
if isfile(output)
|
||||
return
|
||||
end
|
||||
@@ -55,13 +55,13 @@ function _download(url, output, expected_crc32)::Nothing
|
||||
return
|
||||
end
|
||||
|
||||
function _download_zip(url, outputdir, expected_crc32)::Nothing
|
||||
if isdir(outputdir)
|
||||
function _download_zip(url, outputdir, expected_output_file, expected_crc32)::Nothing
|
||||
if isfile(expected_output_file)
|
||||
return
|
||||
end
|
||||
mkpath(outputdir)
|
||||
@info "Downloading: $url"
|
||||
zip_filename = _download(url)
|
||||
zip_filename = download(url)
|
||||
actual_crc32 = open(crc32, zip_filename)
|
||||
expected_crc32 == actual_crc32 || error("CRC32 mismatch")
|
||||
open(zip_filename) do zip_file
|
||||
@@ -91,8 +91,8 @@ function _geodb_load_gov_census(;
|
||||
csv_filename = "$basedir/locations.csv"
|
||||
if !isfile(csv_filename)
|
||||
# Download required files
|
||||
_download(population_url, "$basedir/population.csv", population_crc32)
|
||||
_download_zip(shp_url, basedir, shp_crc32)
|
||||
_download_zip(shp_url, basedir, joinpath(basedir, shp_filename), shp_crc32)
|
||||
_download_file(population_url, "$basedir/population.csv", population_crc32)
|
||||
|
||||
# Read shapefile
|
||||
@info "Processing: $shp_filename"
|
||||
@@ -140,12 +140,15 @@ end
|
||||
|
||||
# 2018 US counties
|
||||
# -----------------------------------------------------------------------------
|
||||
function _extract_cols_2018_us_county(table::Shapefile.Table, i::Int)::OrderedDict{String,Any}
|
||||
function _extract_cols_2018_us_county(
|
||||
table::Shapefile.Table,
|
||||
i::Int,
|
||||
)::OrderedDict{String,Any}
|
||||
return OrderedDict(
|
||||
"id" => table.STATEFP[i] * table.COUNTYFP[i],
|
||||
"statefp" => table.STATEFP[i],
|
||||
"countyfp" => table.COUNTYFP[i],
|
||||
"name" => table.NAME[i]
|
||||
"name" => table.NAME[i],
|
||||
)
|
||||
end
|
||||
|
||||
@@ -168,25 +171,6 @@ function _geodb_load_2018_us_county()::Dict{String,GeoRegion}
|
||||
)
|
||||
end
|
||||
|
||||
# # 2018 US ZIP codes
|
||||
# # -----------------------------------------------------------------------------
|
||||
# function _extract_cols_2018_us_zcta(table::Shapefile.Table, i::Int)::OrderedDict{String,Any}
|
||||
# return OrderedDict("id" => table.ZCTA5CE10[i])
|
||||
# end
|
||||
|
||||
# function _geodb_load_2018_us_zcta()::Dict{String,GeoRegion}
|
||||
# return _geodb_load_gov_census(
|
||||
# db_name = "2018-us-zcta",
|
||||
# extract_cols = _extract_cols_2018_us_zcta,
|
||||
# shp_crc32 = 0x6391f5fc,
|
||||
# shp_filename = "cb_2018_us_zcta510_500k.shp",
|
||||
# shp_url = "https://www2.census.gov/geo/tiger/GENZ2018/shp/cb_2018_us_zcta510_500k.zip",
|
||||
# population_url = "http://www2.census.gov/programs-surveys/popest/datasets/2010-2019/national/totals/nst-est2019-alldata.csv",
|
||||
# population_crc32 = 0x191cc64c,
|
||||
# population_col = "POPESTIMATE2019",
|
||||
# )
|
||||
# end
|
||||
|
||||
# US States
|
||||
# -----------------------------------------------------------------------------
|
||||
function _extract_cols_us_state(table::Shapefile.Table, i::Int)::OrderedDict{String,Any}
|
||||
@@ -218,7 +202,6 @@ end
|
||||
|
||||
function geodb_load(db_name::AbstractString)::Dict{String,GeoRegion}
|
||||
db_name == "2018-us-county" && return _geodb_load_2018_us_county()
|
||||
db_name == "2018-us-zcta" && return _geodb_load_2018_us_zcta()
|
||||
db_name == "us-state" && return _geodb_load_us_state()
|
||||
error("Unknown database: $db_name")
|
||||
end
|
||||
|
||||
@@ -37,6 +37,8 @@ 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)"]
|
||||
@@ -46,7 +48,25 @@ function parse(json)::Instance
|
||||
emissions = product_dict["transportation emissions (tonne/km/tonne)"]
|
||||
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)
|
||||
prod_name_to_product[product_name] = product
|
||||
|
||||
@@ -66,6 +86,7 @@ function parse(json)::Instance
|
||||
product,
|
||||
center_dict["amount (tonne)"],
|
||||
)
|
||||
push!(prod_centers, center)
|
||||
push!(collection_centers, center)
|
||||
end
|
||||
end
|
||||
@@ -100,6 +121,13 @@ function parse(json)::Instance
|
||||
disposal_limit = Dict(p => [0.0 for t = 1:T] for p in keys(output))
|
||||
disposal_cost = Dict(p => [0.0 for t = 1:T] for p in keys(output))
|
||||
|
||||
# GeoDB
|
||||
if "location" in keys(location_dict)
|
||||
region = geodb_query(location_dict["location"])
|
||||
location_dict["latitude (deg)"] = region.centroid.lat
|
||||
location_dict["longitude (deg)"] = region.centroid.lon
|
||||
end
|
||||
|
||||
# Disposal
|
||||
if "disposal" in keys(location_dict)
|
||||
for (product_name, disposal_dict) in location_dict["disposal"]
|
||||
|
||||
@@ -13,6 +13,9 @@ 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
|
||||
|
||||
@@ -12,14 +12,10 @@ function validate(json, schema)
|
||||
result = JSONSchema.validate(json, schema)
|
||||
if result !== nothing
|
||||
if result isa JSONSchema.SingleIssue
|
||||
path = join(result.path, " → ")
|
||||
if length(path) == 0
|
||||
path = "root"
|
||||
end
|
||||
msg = "$(result.msg) in $(path)"
|
||||
msg = "$(result.reason) in $(result.path)"
|
||||
else
|
||||
msg = convert(String, result)
|
||||
end
|
||||
throw(msg)
|
||||
throw("Error parsing input file: $(msg)")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
|
||||
using JuMP, LinearAlgebra, Geodesy, Cbc, Clp, ProgressBars, Printf, DataStructures
|
||||
|
||||
|
||||
function build_model(instance::Instance, graph::Graph, optimizer)::JuMP.Model
|
||||
model = Model(optimizer)
|
||||
model[:instance] = instance
|
||||
@@ -21,13 +20,17 @@ 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[:dispose] = Dict(
|
||||
model[:plant_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)
|
||||
@@ -132,14 +135,25 @@ function create_objective_function!(model::JuMP.Model)
|
||||
end
|
||||
end
|
||||
|
||||
# Shipping node costs
|
||||
# Plant 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],
|
||||
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],
|
||||
)
|
||||
end
|
||||
|
||||
@@ -155,16 +169,29 @@ 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]
|
||||
sum(model[:flow][a, t] for a in n.outgoing_arcs) ==
|
||||
n.location.amount[t] + model[:collection_dispose][n, 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[:dispose][n, t]
|
||||
sum(model[:flow][a, t] for a in n.outgoing_arcs) +
|
||||
model[:plant_dispose][n, t]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -39,18 +39,24 @@ 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
|
||||
],
|
||||
)
|
||||
if n.product.name ∉ keys(output["Products"])
|
||||
output["Products"][n.product.name] = OrderedDict()
|
||||
end
|
||||
output["Products"][n.product.name][n.location.name] = location_dict
|
||||
for n in graph.collection_shipping_nodes
|
||||
location_dict = OrderedDict{Any,Any}(
|
||||
"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
|
||||
|
||||
# Plants
|
||||
@@ -175,13 +181,14 @@ 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[:dispose][shipping_node, t]) for t = 1:T]
|
||||
disposal_amount =
|
||||
[JuMP.value(model[:plant_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[:dispose][shipping_node, t]) for t = 1:T]
|
||||
[JuMP.value(model[:plant_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
|
||||
|
||||
97
src/model/resolve.jl
Normal file
97
src/model/resolve.jl
Normal file
@@ -0,0 +1,97 @@
|
||||
# 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
|
||||
@@ -4,24 +4,16 @@
|
||||
|
||||
using JuMP, LinearAlgebra, Geodesy, Cbc, Clp, ProgressBars, Printf, DataStructures
|
||||
|
||||
default_milp_optimizer = optimizer_with_attributes(Cbc.Optimizer, "logLevel" => 0)
|
||||
default_lp_optimizer = optimizer_with_attributes(Clp.Optimizer, "LogLevel" => 0)
|
||||
function _get_default_milp_optimizer()
|
||||
return optimizer_with_attributes(Cbc.Optimizer, "logLevel" => 0)
|
||||
end
|
||||
|
||||
function solve(
|
||||
instance::Instance;
|
||||
optimizer = nothing,
|
||||
output = nothing,
|
||||
marginal_costs = true,
|
||||
)
|
||||
function _get_default_lp_optimizer()
|
||||
return optimizer_with_attributes(Clp.Optimizer, "LogLevel" => 0)
|
||||
end
|
||||
|
||||
milp_optimizer = lp_optimizer = optimizer
|
||||
if optimizer == nothing
|
||||
milp_optimizer = default_milp_optimizer
|
||||
lp_optimizer = default_lp_optimizer
|
||||
end
|
||||
|
||||
@info "Building graph..."
|
||||
graph = RELOG.build_graph(instance)
|
||||
function _print_graph_stats(instance::Instance, graph::Graph)::Nothing
|
||||
@info @sprintf(" %12d time periods", instance.time)
|
||||
@info @sprintf(" %12d process nodes", length(graph.process_nodes))
|
||||
@info @sprintf(" %12d shipping nodes (plant)", length(graph.plant_shipping_nodes))
|
||||
@@ -30,6 +22,26 @@ function solve(
|
||||
length(graph.collection_shipping_nodes)
|
||||
)
|
||||
@info @sprintf(" %12d arcs", length(graph.arcs))
|
||||
return
|
||||
end
|
||||
|
||||
function solve(
|
||||
instance::Instance;
|
||||
optimizer = nothing,
|
||||
output = nothing,
|
||||
marginal_costs = true,
|
||||
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..."
|
||||
graph = RELOG.build_graph(instance)
|
||||
_print_graph_stats(instance, graph)
|
||||
|
||||
@info "Building optimization model..."
|
||||
model = RELOG.build_model(instance, graph, milp_optimizer)
|
||||
@@ -38,8 +50,7 @@ function solve(
|
||||
JuMP.optimize!(model)
|
||||
|
||||
if !has_values(model)
|
||||
@warn "No solution available"
|
||||
return OrderedDict()
|
||||
error("No solution available")
|
||||
end
|
||||
|
||||
if marginal_costs
|
||||
@@ -63,7 +74,11 @@ function solve(
|
||||
write(solution, output)
|
||||
end
|
||||
|
||||
return solution
|
||||
if return_model
|
||||
return solution, model
|
||||
else
|
||||
return solution
|
||||
end
|
||||
end
|
||||
|
||||
function solve(filename::AbstractString; heuristic = false, kwargs...)
|
||||
|
||||
46
src/reports/products.jl
Normal file
46
src/reports/products.jl
Normal file
@@ -0,0 +1,46 @@
|
||||
# RELOG: Reverse Logistics Optimization
|
||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||
# Released under the modified BSD license. See COPYING.md for more details.
|
||||
|
||||
using DataFrames
|
||||
using CSV
|
||||
|
||||
function products_report(solution; marginal_costs = true)::DataFrame
|
||||
df = DataFrame()
|
||||
df."product name" = String[]
|
||||
df."location name" = String[]
|
||||
df."latitude (deg)" = Float64[]
|
||||
df."longitude (deg)" = Float64[]
|
||||
df."year" = Int[]
|
||||
df."amount (tonne)" = Float64[]
|
||||
df."amount disposed (tonne)" = Float64[]
|
||||
df."marginal cost (\$/tonne)" = Float64[]
|
||||
T = length(solution["Energy"]["Plants (GJ)"])
|
||||
for (prod_name, prod_dict) in solution["Products"]
|
||||
for (location_name, location_dict) in prod_dict
|
||||
for year = 1:T
|
||||
marginal_cost = location_dict["Marginal cost (\$/tonne)"][year]
|
||||
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,
|
||||
[
|
||||
prod_name,
|
||||
location_name,
|
||||
latitude,
|
||||
longitude,
|
||||
year,
|
||||
amount,
|
||||
marginal_cost,
|
||||
amount_disposed,
|
||||
],
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
return df
|
||||
end
|
||||
|
||||
write_products_report(solution, filename) = CSV.write(filename, products_report(solution))
|
||||
@@ -169,6 +169,12 @@
|
||||
},
|
||||
"initial amounts": {
|
||||
"$ref": "#/definitions/InitialAmount"
|
||||
},
|
||||
"disposal limit (tonne)": {
|
||||
"$ref": "#/definitions/TimeSeries"
|
||||
},
|
||||
"disposal cost ($/tonne)": {
|
||||
"$ref": "#/definitions/TimeSeries"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
||||
@@ -1,15 +1,30 @@
|
||||
using PackageCompiler
|
||||
using TOML
|
||||
using Logging
|
||||
|
||||
using Cbc
|
||||
using Clp
|
||||
using Geodesy
|
||||
using JSON
|
||||
using JSONSchema
|
||||
using JuMP
|
||||
using MathOptInterface
|
||||
using ProgressBars
|
||||
Logging.disable_logging(Logging.Info)
|
||||
|
||||
pkg = [:Cbc, :Clp, :Geodesy, :JSON, :JSONSchema, :JuMP, :MathOptInterface, :ProgressBars]
|
||||
mkpath("build")
|
||||
|
||||
@info "Building system image..."
|
||||
create_sysimage(pkg, sysimage_path = "build/sysimage.so")
|
||||
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",
|
||||
)
|
||||
|
||||
@@ -40,7 +40,14 @@ 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[:dispose]) == 16
|
||||
@test length(model[:plant_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[:dispose][shipping_node_by_loc_and_prod_names["L1", "P2"], 1]
|
||||
v = model[:plant_dispose][shipping_node_by_loc_and_prod_names["L1", "P2"], 1]
|
||||
@test lower_bound(v) == 0.0
|
||||
@test upper_bound(v) == 1.0
|
||||
end
|
||||
|
||||
13
test/model/resolve_test.jl
Normal file
13
test/model/resolve_test.jl
Normal file
@@ -0,0 +1,13 @@
|
||||
# Copyright (C) 2020 Argonne National Laboratory
|
||||
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
||||
|
||||
using RELOG
|
||||
|
||||
basedir = @__DIR__
|
||||
|
||||
@testset "Resolve" begin
|
||||
# Shoud not crash
|
||||
filename = "$basedir/../../instances/s1.json"
|
||||
solution_old, model_old = RELOG.solve(filename, return_model = true)
|
||||
solution_new = RELOG.resolve(model_old, filename)
|
||||
end
|
||||
@@ -26,6 +26,15 @@ 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
|
||||
@@ -38,7 +47,7 @@ end
|
||||
for (location_name, location_dict) in json["products"]["P1"]["initial amounts"]
|
||||
location_dict["amount (tonne)"] *= 1000
|
||||
end
|
||||
RELOG.solve(RELOG.parse(json))
|
||||
@test_throws ErrorException("No solution available") RELOG.solve(RELOG.parse(json))
|
||||
end
|
||||
|
||||
@testset "solve (with storage)" begin
|
||||
|
||||
@@ -4,15 +4,18 @@
|
||||
|
||||
using RELOG, JSON, GZip
|
||||
|
||||
basedir = @__DIR__
|
||||
|
||||
@testset "Reports" begin
|
||||
@testset "from solve" begin
|
||||
solution = RELOG.solve("$(pwd())/../instances/s1.json")
|
||||
solution = RELOG.solve("$basedir/../instances/s1.json")
|
||||
tmp_filename = tempname()
|
||||
# The following should not crash
|
||||
RELOG.write_plants_report(solution, tmp_filename)
|
||||
RELOG.write_plant_outputs_report(solution, tmp_filename)
|
||||
RELOG.write_plant_emissions_report(solution, tmp_filename)
|
||||
RELOG.write_transportation_report(solution, tmp_filename)
|
||||
RELOG.write_plant_outputs_report(solution, tmp_filename)
|
||||
RELOG.write_plants_report(solution, tmp_filename)
|
||||
RELOG.write_products_report(solution, tmp_filename)
|
||||
RELOG.write_transportation_emissions_report(solution, tmp_filename)
|
||||
RELOG.write_transportation_report(solution, tmp_filename)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -15,6 +15,7 @@ using Test
|
||||
@testset "Model" begin
|
||||
include("model/build_test.jl")
|
||||
include("model/solve_test.jl")
|
||||
include("model/resolve_test.jl")
|
||||
end
|
||||
include("reports_test.jl")
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user