Compare commits
44 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
7bce105428
|
|||
|
1aa01b7b2b
|
|||
|
e86ae0f818
|
|||
|
22d73c9ded
|
|||
|
a8e4491ea3
|
|||
|
50d53f628f
|
|||
|
79748e3c13
|
|||
| d1f6796c96 | |||
|
51ff8eb130
|
|||
|
9191474df8
|
|||
|
841fbf16fb
|
|||
|
48bd3c403f
|
|||
| 23b3b33146 | |||
|
86dee7558b
|
|||
|
d84b74a8a7
|
|||
|
bae39a4ff4
|
|||
|
da158eb961
|
|||
| e7eec937cb | |||
|
19bec961bd
|
|||
|
8f52c04702
|
|||
|
19a34fb5d2
|
|||
|
8bf2baf809
|
|||
|
027ffcd94c
|
|||
| 84cf4ddcd9 | |||
| 8bce7c047b | |||
| ee767b9ebd | |||
| 9112d9fde5 | |||
| 3d03dfc722 | |||
| 01a4c6626d | |||
| 310f5c389e | |||
| 1273110419 | |||
| e797cb98e0 | |||
| 0beb30800e | |||
| 02a81e5fdd | |||
| 096d95a1aa | |||
| 01452441dc | |||
| 56b673fb9e | |||
| af2a8b67be | |||
| 524299a3c2 | |||
| 0e53a4334e | |||
| a03b9169fd | |||
| ee58af73f0 | |||
| 92d30460b9 | |||
| 9ebb2e49f9 |
4
.dockerignore
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
build
|
||||||
|
jobs
|
||||||
|
relog-web/node_modules
|
||||||
|
relog-web/build
|
||||||
4
.github/workflows/lint.yml
vendored
@@ -14,10 +14,10 @@ jobs:
|
|||||||
shell: julia --color=yes {0}
|
shell: julia --color=yes {0}
|
||||||
run: |
|
run: |
|
||||||
using Pkg
|
using Pkg
|
||||||
Pkg.add(PackageSpec(name="JuliaFormatter", version="0.14.4"))
|
Pkg.add(PackageSpec(name="JuliaFormatter", version="1"))
|
||||||
using JuliaFormatter
|
using JuliaFormatter
|
||||||
format("src", verbose=true)
|
format("src", verbose=true)
|
||||||
format("test", verbose=true)
|
format("test/src", verbose=true)
|
||||||
out = String(read(Cmd(`git diff`)))
|
out = String(read(Cmd(`git diff`)))
|
||||||
if isempty(out)
|
if isempty(out)
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|||||||
16
.github/workflows/test.yml
vendored
@@ -10,7 +10,7 @@ jobs:
|
|||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
version: ['1.3', '1.4', '1.5', '1.6']
|
version: ['1.6', '1.7', '1.8']
|
||||||
os:
|
os:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
arch:
|
arch:
|
||||||
@@ -21,5 +21,15 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
version: ${{ matrix.version }}
|
version: ${{ matrix.version }}
|
||||||
arch: ${{ matrix.arch }}
|
arch: ${{ matrix.arch }}
|
||||||
- uses: julia-actions/julia-buildpkg@v1
|
- name: Run tests
|
||||||
- uses: julia-actions/julia-runtest@v1
|
shell: julia --color=yes --project=test {0}
|
||||||
|
run: |
|
||||||
|
using Pkg
|
||||||
|
Pkg.develop(path=".")
|
||||||
|
Pkg.update()
|
||||||
|
using RELOGT
|
||||||
|
try
|
||||||
|
runtests()
|
||||||
|
catch
|
||||||
|
exit(1)
|
||||||
|
end
|
||||||
|
|||||||
4
.gitignore
vendored
@@ -12,3 +12,7 @@ Manifest.toml
|
|||||||
data
|
data
|
||||||
build
|
build
|
||||||
benchmark
|
benchmark
|
||||||
|
run.jl
|
||||||
|
relog-web-legacy
|
||||||
|
.vscode
|
||||||
|
jobs
|
||||||
|
|||||||
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
|
[semver]: https://semver.org/spec/v2.0.0.html
|
||||||
[pkjjl]: https://pkgdocs.julialang.org/v1/compatibility/#compat-pre-1.0
|
[pkjjl]: https://pkgdocs.julialang.org/v1/compatibility/#compat-pre-1.0
|
||||||
|
|
||||||
|
## [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
|
## [0.5.1] -- 2021-07-23
|
||||||
## Added
|
### Added
|
||||||
- Allow user to specify locations as unique identifiers, instead of latitude and longitude (e.g. `us-state:IL` or `2018-us-county:17043`)
|
- Allow user to specify locations as unique identifiers, instead of latitude and longitude (e.g. `us-state:IL` or `2018-us-county:17043`)
|
||||||
- Add what-if scenarios.
|
- Add what-if scenarios.
|
||||||
- Add products report.
|
- Add products report.
|
||||||
|
|
||||||
## [0.5.0] -- 2021-01-06
|
## [0.5.0] -- 2021-01-06
|
||||||
## Added
|
### Added
|
||||||
- Allow plants to store input material for processing in later years
|
- Allow plants to store input material for processing in later years
|
||||||
|
|
||||||
## [0.4.0] -- 2020-09-18
|
## [0.4.0] -- 2020-09-18
|
||||||
## Added
|
### Added
|
||||||
- Generate simplified solution reports (CSV)
|
- Generate simplified solution reports (CSV)
|
||||||
|
|
||||||
## [0.3.3] -- 2020-10-13
|
## [0.3.3] -- 2020-10-13
|
||||||
## Added
|
### Added
|
||||||
- Add option to write solution to JSON file in RELOG.solve
|
- Add option to write solution to JSON file in RELOG.solve
|
||||||
- Improve error message when instance is infeasible
|
- Improve error message when instance is infeasible
|
||||||
- Make output file more readable
|
- Make output file more readable
|
||||||
|
|
||||||
## [0.3.2] -- 2020-10-07
|
## [0.3.2] -- 2020-10-07
|
||||||
## Added
|
### Added
|
||||||
- Add "building period" parameter
|
- Add "building period" parameter
|
||||||
|
|
||||||
## [0.3.1] -- 2020-07-17
|
## [0.3.1] -- 2020-07-17
|
||||||
## Fixed
|
### Fixed
|
||||||
- Fix expansion cost breakdown
|
- Fix expansion cost breakdown
|
||||||
|
|
||||||
## [0.3.0] -- 2020-06-25
|
## [0.3.0] -- 2020-06-25
|
||||||
## Added
|
### Added
|
||||||
- Track emissions and energy (transportation and plants)
|
- Track emissions and energy (transportation and plants)
|
||||||
|
|
||||||
## Changed
|
### Changed
|
||||||
- Minor changes to input file format:
|
- Minor changes to input file format:
|
||||||
- Make all dictionary keys lowercase
|
- Make all dictionary keys lowercase
|
||||||
- Rename "outputs (tonne)" to "outputs (tonne/tonne)"
|
- Rename "outputs (tonne)" to "outputs (tonne/tonne)"
|
||||||
|
|||||||
29
Dockerfile
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
FROM julia:1.7-buster
|
||||||
|
|
||||||
|
ENV RELOG_TIME_LIMIT_SEC=3600
|
||||||
|
|
||||||
|
# Install Node.js & zip
|
||||||
|
RUN apt-get update -yq && \
|
||||||
|
apt-get -yq install curl gnupg ca-certificates && \
|
||||||
|
curl -L https://deb.nodesource.com/setup_18.x | bash && \
|
||||||
|
apt-get update -yq && \
|
||||||
|
apt-get install -yq nodejs zip
|
||||||
|
|
||||||
|
# Install Julia dependencies
|
||||||
|
ADD Project.toml /app/
|
||||||
|
ADD src/RELOG.jl /app/src/
|
||||||
|
RUN julia --project=/app -e 'using Pkg; Pkg.update()'
|
||||||
|
|
||||||
|
# Install JS dependencies
|
||||||
|
ADD relog-web/package*.json /app/relog-web/
|
||||||
|
RUN cd /app/relog-web && npm install
|
||||||
|
|
||||||
|
# Copy source code
|
||||||
|
ADD . /app
|
||||||
|
RUN julia --project=/app -e 'using Pkg; Pkg.precompile()'
|
||||||
|
|
||||||
|
# Build JS app
|
||||||
|
RUN cd /app/relog-web && npm run build
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
CMD julia --project=/app -e 'import RELOG; RELOG.web("0.0.0.0")'
|
||||||
41
Makefile
@@ -1,28 +1,31 @@
|
|||||||
JULIA := julia --color=yes --project=@.
|
VERSION := 0.6
|
||||||
SRC_FILES := $(wildcard src/*.jl test/*.jl)
|
PKG := ghcr.io/anl-ceeesa/relog-web
|
||||||
VERSION := 0.5
|
|
||||||
|
|
||||||
all: docs test
|
|
||||||
|
|
||||||
build/sysimage.so: src/sysimage.jl Project.toml Manifest.toml
|
|
||||||
mkdir -p build
|
|
||||||
$(JULIA) src/sysimage.jl
|
|
||||||
|
|
||||||
build/test.log: $(SRC_FILES) build/sysimage.so
|
|
||||||
cd test; $(JULIA) --sysimage ../build/sysimage.so runtests.jl
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf build/*
|
rm -rfv build Manifest.toml test/Manifest.toml deps/formatter/build deps/formatter/Manifest.toml
|
||||||
|
|
||||||
docs:
|
docs:
|
||||||
mkdocs build -d ../docs/$(VERSION)/
|
cd docs; julia --project=. make.jl; cd ..
|
||||||
|
rsync -avP --delete-after docs/build/ ../docs/$(VERSION)/
|
||||||
|
|
||||||
|
docker-build:
|
||||||
|
docker build --tag $(PKG):$(VERSION) .
|
||||||
|
docker build --tag $(PKG):latest .
|
||||||
|
|
||||||
|
docker-push:
|
||||||
|
docker push $(PKG):$(VERSION)
|
||||||
|
docker push $(PKG):latest
|
||||||
|
|
||||||
|
docker-run:
|
||||||
|
docker run -it --rm --name relog --volume $(PWD)/jobs:/app/jobs --publish 8000:8080 $(PKG):$(VERSION)
|
||||||
|
|
||||||
format:
|
format:
|
||||||
julia -e 'using JuliaFormatter; format(["src", "test"], verbose=true);'
|
cd deps/formatter; ../../juliaw format.jl
|
||||||
|
|
||||||
test: build/test.log
|
test: test/Manifest.toml
|
||||||
|
./juliaw test/runtests.jl
|
||||||
|
|
||||||
test-watch:
|
test/Manifest.toml: test/Project.toml
|
||||||
bash -c "while true; do make test --quiet; sleep 1; done"
|
julia --project=test -e "using Pkg; Pkg.instantiate()"
|
||||||
|
|
||||||
.PHONY: docs test
|
.PHONY: docs test format
|
||||||
|
|||||||
38
Project.toml
@@ -1,27 +1,30 @@
|
|||||||
name = "RELOG"
|
name = "RELOG"
|
||||||
uuid = "a2afcdf7-cf04-4913-85f9-c0d81ddf2008"
|
uuid = "a2afcdf7-cf04-4913-85f9-c0d81ddf2008"
|
||||||
authors = ["Alinson S Xavier <axavier@anl.gov>"]
|
authors = ["Alinson S Xavier <axavier@anl.gov>"]
|
||||||
version = "0.5.1"
|
version = "0.6.0"
|
||||||
|
|
||||||
[deps]
|
[deps]
|
||||||
CRC = "44b605c4-b955-5f2b-9b6d-d2bd01d3d205"
|
CRC = "44b605c4-b955-5f2b-9b6d-d2bd01d3d205"
|
||||||
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
|
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
|
||||||
Cbc = "9961bab8-2fa3-5c5a-9d89-47fab24efd76"
|
|
||||||
Clp = "e2554f3b-3117-50c0-817c-e040a3ddf72d"
|
|
||||||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
|
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
|
||||||
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
|
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
|
||||||
|
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
|
||||||
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
|
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
|
||||||
GZip = "92fee26a-97fe-5a0c-ad85-20a5f3185b63"
|
GZip = "92fee26a-97fe-5a0c-ad85-20a5f3185b63"
|
||||||
Geodesy = "0ef565a4-170c-5f04-8de2-149903a85f3d"
|
Geodesy = "0ef565a4-170c-5f04-8de2-149903a85f3d"
|
||||||
|
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
|
||||||
|
HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b"
|
||||||
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
|
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
|
||||||
JSONSchema = "7d188eb4-7ad8-530c-ae41-71a32a6d4692"
|
JSONSchema = "7d188eb4-7ad8-530c-ae41-71a32a6d4692"
|
||||||
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
|
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
|
||||||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
|
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
|
||||||
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
|
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
|
||||||
|
NearestNeighbors = "b8a86587-4115-5ab1-83bc-aa920d37bbce"
|
||||||
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
|
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
|
||||||
PackageCompiler = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d"
|
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
|
||||||
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
|
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
|
||||||
ProgressBars = "49802e3a-d2f1-5c88-81d8-b72133a6f568"
|
ProgressBars = "49802e3a-d2f1-5c88-81d8-b72133a6f568"
|
||||||
|
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
|
||||||
Shapefile = "8e980c4a-a4fe-5da2-b3a7-4b4b0353a2f4"
|
Shapefile = "8e980c4a-a4fe-5da2-b3a7-4b4b0353a2f4"
|
||||||
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
|
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
|
||||||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
||||||
@@ -29,20 +32,19 @@ ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea"
|
|||||||
|
|
||||||
[compat]
|
[compat]
|
||||||
CRC = "4"
|
CRC = "4"
|
||||||
CSV = "0.7"
|
CSV = "0.10"
|
||||||
Cbc = "0.6"
|
DataFrames = "1"
|
||||||
Clp = "0.8"
|
DataStructures = "0.18"
|
||||||
DataFrames = "0.21"
|
|
||||||
DataStructures = "0.17"
|
|
||||||
GZip = "0.5"
|
GZip = "0.5"
|
||||||
Geodesy = "0.5"
|
Geodesy = "1"
|
||||||
|
HTTP = "0.9"
|
||||||
JSON = "0.21"
|
JSON = "0.21"
|
||||||
JSONSchema = "0.3"
|
JSONSchema = "1"
|
||||||
JuMP = "0.21"
|
JuMP = "1"
|
||||||
MathOptInterface = "0.9"
|
MathOptInterface = "1"
|
||||||
OrderedCollections = "1.4"
|
NearestNeighbors = "0.4"
|
||||||
PackageCompiler = "1"
|
OrderedCollections = "1"
|
||||||
ProgressBars = "0.6"
|
ProgressBars = "1"
|
||||||
Shapefile = "0.7"
|
Shapefile = "0.8"
|
||||||
ZipFile = "0.9"
|
ZipFile = "0.10"
|
||||||
julia = "1"
|
julia = "1"
|
||||||
|
|||||||
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
|
### Documentation
|
||||||
|
|
||||||
* [Usage](https://anl-ceeesa.github.io/RELOG/0.5/usage)
|
* [Usage](https://anl-ceeesa.github.io/RELOG/0.6/usage)
|
||||||
* [Input and Output Data Formats](https://anl-ceeesa.github.io/RELOG/0.5/format)
|
* [Input and Output Data Formats](https://anl-ceeesa.github.io/RELOG/0.6/format)
|
||||||
* [Simplified Solution Reports](https://anl-ceeesa.github.io/RELOG/0.5/reports)
|
* [Simplified Solution Reports](https://anl-ceeesa.github.io/RELOG/0.6/reports)
|
||||||
* [Optimization Model](https://anl-ceeesa.github.io/RELOG/0.5/model)
|
* [Optimization Model](https://anl-ceeesa.github.io/RELOG/0.6/model)
|
||||||
|
|
||||||
### Authors
|
### Authors
|
||||||
|
|
||||||
* **Alinson S. Xavier,** Argonne National Laboratory <<axavier@anl.gov>>
|
* **Alinson S. Xavier** <<axavier@anl.gov>>
|
||||||
* **Nwike Iloeje,** Argonne National Laboratory <<ciloeje@anl.gov>>
|
* **Nwike Iloeje** <<ciloeje@anl.gov>>
|
||||||
|
* **John Atkins**
|
||||||
|
* **Kyle Sun**
|
||||||
|
* **Audrey Gallier**
|
||||||
|
|
||||||
### License
|
### License
|
||||||
|
|
||||||
|
|||||||
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.
|
The **parameters** section describes details about the simulation itself.
|
||||||
|
|
||||||
| Key | Description
|
| Key | Description
|
||||||
|:--------------------------|---------------|
|
|:--------------------------|:---------------|
|
||||||
|`time horizon (years)` | Number of years in the simulation.
|
|`time horizon (years)` | Number of years in the simulation.
|
||||||
|`building period (years)` | List of years in which we are allowed to open new plants. For example, if this parameter is set to `[1,2,3]`, we can only open plants during the first three years. By default, this equals `[1]`; that is, plants can only be opened during the first year. |
|
|`building period (years)` | List of years in which we are allowed to open new plants. For example, if this parameter is set to `[1,2,3]`, we can only open plants during the first three years. By default, this equals `[1]`; that is, plants can only be opened during the first year. |
|
||||||
|
|`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
|
#### Example
|
||||||
@@ -21,7 +22,8 @@ The **parameters** section describes details about the simulation itself.
|
|||||||
{
|
{
|
||||||
"parameters": {
|
"parameters": {
|
||||||
"time horizon (years)": 2,
|
"time horizon (years)": 2,
|
||||||
"building period (years)": [1]
|
"building period (years)": [1],
|
||||||
|
"distance metric": "driving",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -31,16 +33,18 @@ The **parameters** section describes details about the simulation itself.
|
|||||||
The **products** section describes all products and subproducts in the simulation. The field `instance["Products"]` is a dictionary mapping the name of the product to a dictionary which describes its characteristics. Each product description contains the following keys:
|
The **products** section describes all products and subproducts in the simulation. The field `instance["Products"]` is a dictionary mapping the name of the product to a dictionary which describes its characteristics. Each product description contains the following keys:
|
||||||
|
|
||||||
| Key | Description
|
| Key | Description
|
||||||
|:--------------------------------------|---------------|
|
|:--------------------------------------|:---------------|
|
||||||
|`transportation cost ($/km/tonne)` | The cost to transport this product. Must be a time series.
|
|`transportation cost ($/km/tonne)` | The cost to transport this product. Must be a time series.
|
||||||
|`transportation energy (J/km/tonne)` | The energy required to transport this product. Must be a time series. Optional.
|
|`transportation energy (J/km/tonne)` | The energy required to transport this product. Must be a time series. Optional.
|
||||||
|`transportation emissions (tonne/km/tonne)` | A dictionary mapping the name of each greenhouse gas, produced to transport one tonne of this product along one kilometer, to the amount of gas produced (in tonnes). Must be a time series. Optional.
|
|`transportation emissions (tonne/km/tonne)` | A dictionary mapping the name of each greenhouse gas, produced to transport one tonne of this product along one kilometer, to the amount of gas produced (in tonnes). Must be a time series. Optional.
|
||||||
|`initial amounts` | A dictionary mapping the name of each location to its description (see below). If this product is not initially available, this key may be omitted. Must be a time series.
|
|`initial amounts` | A dictionary mapping the name of each location to its description (see below). If this product is not initially available, this key may be omitted. Must be a time series.
|
||||||
|
| `disposal limit (tonne)` | Total amount of product that can be disposed of across all collection centers. If omitted, all product must be processed. This parameter has no effect on product disposal at plants.
|
||||||
|
| `disposal cost ($/tonne)` | Cost of disposing one tonne of this product at a collection center. If omitted, defaults to zero. This parameter has no effect on product disposal costs at plants.
|
||||||
|
|
||||||
Each product may have some amount available at the beginning of each time period. In this case, the key `initial amounts` maps to a dictionary with the following keys:
|
Each product may have some amount available at the beginning of each time period. In this case, the key `initial amounts` maps to a dictionary with the following keys:
|
||||||
|
|
||||||
| Key | Description
|
| Key | Description
|
||||||
|:------------------------|---------------|
|
|:------------------------|:---------------|
|
||||||
| `latitude (deg)` | The latitude of the location.
|
| `latitude (deg)` | The latitude of the location.
|
||||||
| `longitude (deg)` | The longitude of the location.
|
| `longitude (deg)` | The longitude of the location.
|
||||||
| `amount (tonne)` | The amount of the product initially available at the location. Must be a time series.
|
| `amount (tonne)` | The amount of the product initially available at the location. Must be a time series.
|
||||||
@@ -73,7 +77,9 @@ Each product may have some amount available at the beginning of each time period
|
|||||||
"transportation emissions (tonne/km/tonne)": {
|
"transportation emissions (tonne/km/tonne)": {
|
||||||
"CO2": [0.052, 0.050],
|
"CO2": [0.052, 0.050],
|
||||||
"CH4": [0.003, 0.002]
|
"CH4": [0.003, 0.002]
|
||||||
}
|
},
|
||||||
|
"disposal cost ($/tonne)": [-10.0, -12.0],
|
||||||
|
"disposal limit (tonne)": [1.0, 1.0],
|
||||||
},
|
},
|
||||||
"P2": {
|
"P2": {
|
||||||
"transportation cost ($/km/tonne)": [0.022, 0.020]
|
"transportation cost ($/km/tonne)": [0.022, 0.020]
|
||||||
@@ -93,7 +99,7 @@ Each product may have some amount available at the beginning of each time period
|
|||||||
The **plants** section describes the available types of reverse manufacturing plants, their potential locations and associated costs, as well as their inputs and outputs. The field `instance["Plants"]` is a dictionary mapping the name of the plant to a dictionary with the following keys:
|
The **plants** section describes the available types of reverse manufacturing plants, their potential locations and associated costs, as well as their inputs and outputs. The field `instance["Plants"]` is a dictionary mapping the name of the plant to a dictionary with the following keys:
|
||||||
|
|
||||||
| Key | Description
|
| Key | Description
|
||||||
|:------------------------|---------------|
|
|:------------------------|:---------------|
|
||||||
| `input` | The name of the product that this plant takes as input. Only one input is accepted per plant.
|
| `input` | The name of the product that this plant takes as input. Only one input is accepted per plant.
|
||||||
| `outputs (tonne/tonne)` | A dictionary specifying how many tonnes of each product is produced for each tonnes of input. For example, if the plant outputs 0.5 tonnes of P2 and 0.25 tonnes of P3 for each tonnes of P1 provided, then this entry should be `{"P2": 0.5, "P3": 0.25}`. If the plant does not output anything, this key may be omitted.
|
| `outputs (tonne/tonne)` | A dictionary specifying how many tonnes of each product is produced for each tonnes of input. For example, if the plant outputs 0.5 tonnes of P2 and 0.25 tonnes of P3 for each tonnes of P1 provided, then this entry should be `{"P2": 0.5, "P3": 0.25}`. If the plant does not output anything, this key may be omitted.
|
||||||
|`energy (GJ/tonne)` | The energy required to process 1 tonne of the input. Must be a time series. Optional.
|
|`energy (GJ/tonne)` | The energy required to process 1 tonne of the input. Must be a time series. Optional.
|
||||||
@@ -113,14 +119,14 @@ Each type of plant is associated with a set of potential locations where it can
|
|||||||
The `storage` dictionary should contain the following keys:
|
The `storage` dictionary should contain the following keys:
|
||||||
|
|
||||||
| Key | Description
|
| Key | Description
|
||||||
|:------------------------|---------------|
|
|:------------------------|:---------------|
|
||||||
| `cost ($/tonne)` | The cost to store a tonne of input product for one time period. Must be a time series.
|
| `cost ($/tonne)` | The cost to store a tonne of input product for one time period. Must be a time series.
|
||||||
| `limit (tonne)` | The maximum amount of input product this plant can have in storage at any given time.
|
| `limit (tonne)` | The maximum amount of input product this plant can have in storage at any given time.
|
||||||
|
|
||||||
The keys in the `disposal` dictionary should be the names of the products. The values are dictionaries with the following keys:
|
The keys in the `disposal` dictionary should be the names of the products. The values are dictionaries with the following keys:
|
||||||
|
|
||||||
| Key | Description
|
| Key | Description
|
||||||
|:------------------------|---------------|
|
|:------------------------|:---------------|
|
||||||
| `cost ($/tonne)` | The cost to dispose of the product. Must be a time series.
|
| `cost ($/tonne)` | The cost to dispose of the product. Must be a time series.
|
||||||
| `limit (tonne)` | The maximum amount that can be disposed of. If an unlimited amount can be disposed, this key may be omitted. Must be a time series.
|
| `limit (tonne)` | The maximum amount that can be disposed of. If an unlimited amount can be disposed, this key may be omitted. Must be a time series.
|
||||||
|
|
||||||
@@ -128,7 +134,7 @@ The keys in the `disposal` dictionary should be the names of the products. The v
|
|||||||
The keys in the `capacities (tonne)` dictionary should be the amounts (in tonnes). The values are dictionaries with the following keys:
|
The keys in the `capacities (tonne)` dictionary should be the amounts (in tonnes). The values are dictionaries with the following keys:
|
||||||
|
|
||||||
| Key | Description
|
| Key | Description
|
||||||
|:--------------------------------------|---------------|
|
|:--------------------------------------|:---------------|
|
||||||
| `opening cost ($)` | The cost to open a plant of this size.
|
| `opening cost ($)` | The cost to open a plant of this size.
|
||||||
| `fixed operating cost ($)` | The cost to keep the plant open, even if the plant doesn't process anything. Must be a time series.
|
| `fixed operating cost ($)` | The cost to keep the plant open, even if the plant doesn't process anything. Must be a time series.
|
||||||
| `variable operating cost ($/tonne)` | The cost that the plant incurs to process each tonne of input. Must be a time series.
|
| `variable operating cost ($/tonne)` | The cost that the plant incurs to process each tonne of input. Must be a time series.
|
||||||
@@ -210,7 +216,7 @@ is is possible to write:
|
|||||||
Location names follow the format `db:id`, where `db` is the name of the database and `id` is the identifier for a specific location. RELOG currently includes the following databases:
|
Location names follow the format `db:id`, where `db` is the name of the database and `id` is the identifier for a specific location. RELOG currently includes the following databases:
|
||||||
|
|
||||||
Database | Description | Examples
|
Database | Description | Examples
|
||||||
---------|-------------|----------
|
:--------|:------------|:---------
|
||||||
`us-state`| List of states of the United States. | `us-state:IL` (State of Illinois)
|
`us-state`| List of states of the United States. | `us-state:IL` (State of Illinois)
|
||||||
`2018-us-county` | List of United States counties, as of 2018. IDs are 5-digit FIPS codes. | `2018-us-county:17043` (DuPage county in Illinois)
|
`2018-us-county` | List of United States counties, as of 2018. IDs are 5-digit FIPS codes. | `2018-us-county:17043` (DuPage county in Illinois)
|
||||||
|
|
||||||
@@ -220,6 +226,7 @@ Database | Description | Examples
|
|||||||
* Plants can be expanded at any time, even long after they are open.
|
* 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.
|
* 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.
|
* 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)
|
## Output Data Format (JSON)
|
||||||
|
|
||||||
@@ -1,25 +1,29 @@
|
|||||||
# RELOG: Reverse Logistics Optimization
|
# RELOG: Reverse Logistics Optimization
|
||||||
|
|
||||||
|
|
||||||
**RELOG** is an open-source supply chain optimization package focusing on reverse logistics and reverse manufacturing. The package uses Mixed-Integer Linear Programming to determine where to build recycling plants, what size should these plants have and which customers should be served by which plants. The package supports custom reverse logistics pipelines, with multiple types of plants, multiple types of product and multiple time periods.
|
**RELOG** is an open-source supply chain optimization package focusing on reverse logistics and reverse manufacturing. The package uses Mixed-Integer Linear Programming to determine where to build recycling plants, what size should these plants have and which customers should be served by which plants. The package supports custom reverse logistics pipelines, with multiple types of plants, multiple types of product and multiple time periods.
|
||||||
|
|
||||||
<img src="images/ex_transportation.png" width="1000px"/>
|
```@raw html
|
||||||
|
<center>
|
||||||
|
<img src="assets/ex_transportation.png" width="1000px"/>
|
||||||
|
</center>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Table of Contents
|
### Table of Contents
|
||||||
|
|
||||||
* [Usage](usage.md)
|
```@contents
|
||||||
* [Input and Output Data Formats](format.md)
|
Pages = ["usage.md", "format.md", "reports.md", "model.md"]
|
||||||
* [Simplified Solution Reports](reports.md)
|
Depth = 3
|
||||||
* [Optimization Model](model.md)
|
```
|
||||||
|
|
||||||
|
|
||||||
### Source Code
|
### Source Code
|
||||||
|
|
||||||
* [https://github.com/ANL-CEEESA/RELOG](https://github.com/ANL-CEEESA/RELOG)
|
* [https://github.com/ANL-CEEESA/RELOG](https://github.com/ANL-CEEESA/RELOG)
|
||||||
|
|
||||||
### Authors
|
### Authors
|
||||||
* **Alinson S. Xavier,** Argonne National Laboratory <<axavier@anl.gov>>
|
* **Alinson S. Xavier,** Argonne National Laboratory <axavier@anl.gov>
|
||||||
* **Nwike Iloeje,** Argonne National Laboratory <<ciloeje@anl.gov>>
|
* **Nwike Iloeje,** Argonne National Laboratory <ciloeje@anl.gov>
|
||||||
|
|
||||||
### License
|
### License
|
||||||
|
|
||||||
@@ -6,53 +6,65 @@ In this page, we describe the precise mathematical optimization model used by RE
|
|||||||
|
|
||||||
### Sets
|
### Sets
|
||||||
|
|
||||||
* $L$ - Set of locations holding the original material to be recycled
|
Symbol | Description
|
||||||
* $M$ - Set of materials recovered during the reverse manufacturing process
|
:-------|:------------
|
||||||
* $P$ - Set of potential plants to open
|
$L$ | Set of locations holding the original material to be recycled
|
||||||
* $T = \{ 1, \ldots, t^{max} \} $ - Set of time periods
|
$M$ | Set of materials recovered during the reverse manufacturing process
|
||||||
|
$P$ | Set of potential plants to open
|
||||||
|
$T = \{ 1, \ldots, t^{max} \}$ | Set of time periods
|
||||||
|
|
||||||
### Constants
|
### Constants
|
||||||
|
|
||||||
**Plants:**
|
#### Plants
|
||||||
|
|
||||||
* $c^\text{disp}_{pmt}$ - Cost of disposing one tonne of material $m$ at plant $p$ during time $t$ (`$/tonne/km`)
|
Symbol | Description | Unit
|
||||||
* $c^\text{exp}_{pt}$ - Cost of adding one tonne of capacity to plant $p$ at time $t$ (`$/tonne`)
|
:-------|:------------|:---
|
||||||
* $c^\text{open}_{pt}$ - Cost of opening plant $p$ at time $t$, at minimum capacity (`$`)
|
$c^\text{disp}_{pmt}$ | Cost of disposing one tonne of material $m$ at plant $p$ during time $t$ | \$/tonne/km
|
||||||
* $c^\text{f-base}_{pt}$ - Fixed cost of keeping plant $p$ open during time period $t$ (`$`)
|
$c^\text{exp}_{pt}$ | Cost of adding one tonne of capacity to plant $p$ at time $t$ | \$/tonne
|
||||||
* $c^\text{f-exp}_{pt}$ - Increase in fixed cost for each additional tonne of capacity (`$/tonne`)
|
$c^\text{open}_{pt}$ | Cost of opening plant $p$ at time $t$, at minimum capacity | $
|
||||||
* $c^\text{var}_{pt}$ - Variable cost of processing one tonne of input at plant $p$ at time $t$ (`$/tonne`)
|
$c^\text{f-base}_{pt}$ | Fixed cost of keeping plant $p$ open during time period $t$ | $
|
||||||
* $c^\text{store}_{pt}$ - Cost of storing one tonne of original material at plant $p$ at time $t$ (`$/tonne`)
|
$c^\text{f-exp}_{pt}$ | Increase in fixed cost for each additional tonne of capacity | \$/tonne
|
||||||
* $m^\text{min}_p$ - Minimum capacity of plant $p$ (`tonne`)
|
$c^\text{var}_{pt}$ | Variable cost of processing one tonne of input at plant $p$ at time $t$ | \$/tonne
|
||||||
* $m^\text{max}_p$ - Maximum capacity of plant $p$ (`tonne`)
|
$c^\text{store}_{pt}$ | Cost of storing one tonne of original material at plant $p$ at time $t$ | \$/tonne
|
||||||
* $m^\text{disp}_{pmt}$ - Maximum amount of material $m$ that plant $p$ can dispose of during time $t$ (`tonne`)
|
$m^\text{min}_p$ | Minimum capacity of plant $p$ | tonne
|
||||||
* $m^\text{store}_p$ - Maximum amount of original material that plant $p$ can store for later processing.
|
$m^\text{max}_p$ | Maximum capacity of plant $p$ | tonne
|
||||||
|
$m^\text{disp}_{pmt}$ | Maximum amount of material $m$ that plant $p$ can dispose of during time $t$ | tonne
|
||||||
|
$m^\text{store}_p$ | Maximum amount of original material that plant $p$ can store for later processing. | tonne
|
||||||
|
|
||||||
**Products:**
|
#### Products
|
||||||
|
|
||||||
* $\alpha_{pm}$ - Amount of material $m$ recovered by plant $t$ for each tonne of original material (`tonne/tonne`)
|
Symbol | Description | Unit
|
||||||
* $m^\text{initial}_{lt}$ - Amount of original material to be recycled at location $l$ during time $t$ (`tonne`)
|
:-------|:------------|:---
|
||||||
|
$\alpha_{pm}$ | Amount of material $m$ recovered by plant $t$ for each tonne of original material | tonne/tonne
|
||||||
|
$m^\text{initial}_{lt}$ | Amount of original material to be recycled at location $l$ during time $t$ | tonne
|
||||||
|
|
||||||
**Transportation:**
|
#### Transportation
|
||||||
|
|
||||||
* $c^\text{tr}_{t}$ - Transportation cost during time $t$ (`$/tonne/km`)
|
Symbol | Description | Unit
|
||||||
* $d_{lp}$ - Distance between plant $p$ and location $l$ (`km`)
|
:-------|:------------|:---
|
||||||
|
$c^\text{tr}_{t}$ | Transportation cost during time $t$ | \$/tonne/km
|
||||||
|
$d_{lp}$ | Distance between plant $p$ and location $l$ | km
|
||||||
|
|
||||||
|
|
||||||
### Decision variables
|
### Decision variables
|
||||||
* $q_{mpt}$ - Amount of material $m$ recovered by plant $p$ during time $t$ (`tonne`)
|
|
||||||
* $u_{pt}$ - Binary variable that equals 1 if plant $p$ starts operating at time $t$ (`bool`)
|
Symbol | Description | Unit
|
||||||
* $w_{pt}$ - Extra capacity (amount above the minimum) added to plant $p$ during time $t$ (`tonne`)
|
:-------|:------------|:---
|
||||||
* $x_{pt}$ - Binary variable that equals 1 if plant $p$ is operational at time $t$ (`bool`)
|
$q_{mpt}$ | Amount of material $m$ recovered by plant $p$ during time $t$ | tonne
|
||||||
* $y_{lpt}$ - Amount of product sent from location $l$ to plant $p$ during time $t$ (`tonne`)
|
$u_{pt}$ | Binary variable that equals 1 if plant $p$ starts operating at time $t$ | Boolean
|
||||||
* $z^{\text{disp}}_{mpt}$ - Amount of material $m$ disposed of by plant $p$ during time $t$ (`tonne`)
|
$w_{pt}$ | Extra capacity (amount above the minimum) added to plant $p$ during time $t$ | tonne
|
||||||
* $z^{\text{store}}_{pt}$ - Amount of original material in storage at plant $p$ by the end of time period $t$ (`tonne`)
|
$x_{pt}$ | Binary variable that equals 1 if plant $p$ is operational at time $t$ | Boolean
|
||||||
* $z^{\text{proc}}_{mpt}$ - Amount of original material processed by plant $p$ during time period $t$ (`tonne`)
|
$y_{lpt}$ | Amount of product sent from location $l$ to plant $p$ during time $t$ | tonne
|
||||||
|
$z^{\text{disp}}_{mpt}$ | Amount of material $m$ disposed of by plant $p$ during time $t$ | tonne
|
||||||
|
$z^{\text{store}}_{pt}$ | Amount of original material in storage at plant $p$ by the end of time period $t$ | tonne
|
||||||
|
$z^{\text{proc}}_{mpt}$ | Amount of original material processed by plant $p$ during time period $t$ | tonne
|
||||||
|
|
||||||
|
|
||||||
### Objective function
|
### Objective function
|
||||||
|
|
||||||
RELOG minimizes the overall capital, production and transportation costs:
|
RELOG minimizes the overall capital, production and transportation costs:
|
||||||
|
|
||||||
|
```math
|
||||||
\begin{align*}
|
\begin{align*}
|
||||||
\text{minimize} \;\; &
|
\text{minimize} \;\; &
|
||||||
\sum_{t \in T} \sum_{p \in P} \left[
|
\sum_{t \in T} \sum_{p \in P} \left[
|
||||||
@@ -73,6 +85,7 @@ RELOG minimizes the overall capital, production and transportation costs:
|
|||||||
&
|
&
|
||||||
\sum_{t \in T} \sum_{p \in P} \sum_{m \in M} c^{\text{disp}}_{pmt} z_{pmt}
|
\sum_{t \in T} \sum_{p \in P} \sum_{m \in M} c^{\text{disp}}_{pmt} z_{pmt}
|
||||||
\end{align*}
|
\end{align*}
|
||||||
|
```
|
||||||
|
|
||||||
In the first line, we have (i) opening costs, if plant starts operating at time $t$, (ii) fixed operating costs, if plant is operational, (iii) additional fixed operating costs coming from expansion performed in all previous time periods up to the current one, and finally (iv) the expansion costs during the current time period.
|
In the first line, we have (i) opening costs, if plant starts operating at time $t$, (ii) fixed operating costs, if plant is operational, (iii) additional fixed operating costs coming from expansion performed in all previous time periods up to the current one, and finally (iv) the expansion costs during the current time period.
|
||||||
In the second line, we have storage and variable processing costs.
|
In the second line, we have storage and variable processing costs.
|
||||||
@@ -83,14 +96,17 @@ In the fourth line, we have the disposal costs.
|
|||||||
|
|
||||||
* All original materials must be sent to a plant:
|
* All original materials must be sent to a plant:
|
||||||
|
|
||||||
\begin{align}
|
```math
|
||||||
|
\begin{align*}
|
||||||
& \sum_{p \in P} y_{lpt} = m^\text{initial}_{lt}
|
& \sum_{p \in P} y_{lpt} = m^\text{initial}_{lt}
|
||||||
& \forall l \in L, t \in T
|
& \forall l \in L, t \in T
|
||||||
\end{align}
|
\end{align*}
|
||||||
|
```
|
||||||
|
|
||||||
* Amount received equals amount processed plus stored. Furthermore, all original material should be processed by the end of the simulation.
|
* Amount received equals amount processed plus stored. Furthermore, all original material should be processed by the end of the simulation.
|
||||||
|
|
||||||
\begin{align}
|
```math
|
||||||
|
\begin{align*}
|
||||||
& \sum_{l \in L} y_{lpt} + z^{\text{store}}_{p,t-1}
|
& \sum_{l \in L} y_{lpt} + z^{\text{store}}_{p,t-1}
|
||||||
= z^{\text{proc}}_{pt} + z^{\text{store}}_{p,t}
|
= z^{\text{proc}}_{pt} + z^{\text{store}}_{p,t}
|
||||||
& \forall p \in P, t \in T \\
|
& \forall p \in P, t \in T \\
|
||||||
@@ -98,56 +114,70 @@ In the fourth line, we have the disposal costs.
|
|||||||
& \forall p \in P \\
|
& \forall p \in P \\
|
||||||
& z^{\text{store}}_{p,t^{\max}} = 0
|
& z^{\text{store}}_{p,t^{\max}} = 0
|
||||||
& \forall p \in P
|
& \forall p \in P
|
||||||
\end{align}
|
\end{align*}
|
||||||
|
```
|
||||||
|
|
||||||
* Plants have a limited processing capacity. Furthermore, if a plant is closed, it has zero processing capacity:
|
* Plants have a limited processing capacity. Furthermore, if a plant is closed, it has zero processing capacity:
|
||||||
|
|
||||||
\begin{align}
|
```math
|
||||||
|
\begin{align*}
|
||||||
& z^{\text{proc}}_{pt} \leq m^\text{min}_p x_p + \sum_{i=1}^t w_p
|
& z^{\text{proc}}_{pt} \leq m^\text{min}_p x_p + \sum_{i=1}^t w_p
|
||||||
& \forall p \in P, t \in T
|
& \forall p \in P, t \in T
|
||||||
\end{align}
|
\end{align*}
|
||||||
|
```
|
||||||
|
|
||||||
* Plants have limited storage capacity. Furthermore, if a plant is closed, is has zero storage capacity:
|
* Plants have limited storage capacity. Furthermore, if a plant is closed, is has zero storage capacity:
|
||||||
|
|
||||||
\begin{align}
|
```math
|
||||||
|
\begin{align*}
|
||||||
& z^{\text{store}}_{pt} \leq m^\text{store}_p x_p
|
& z^{\text{store}}_{pt} \leq m^\text{store}_p x_p
|
||||||
& \forall p \in P, t \in T
|
& \forall p \in P, t \in T
|
||||||
\end{align}
|
\end{align*}
|
||||||
|
```
|
||||||
|
|
||||||
* Plants can only be expanded up to their maximum capacity. Furthermore, if a plant is closed, it cannot be expanded:
|
* Plants can only be expanded up to their maximum capacity. Furthermore, if a plant is closed, it cannot be expanded:
|
||||||
|
|
||||||
\begin{align}
|
```math
|
||||||
|
\begin{align*}
|
||||||
& \sum_{i=1}^t w_p \leq m^\text{max}_p x_p
|
& \sum_{i=1}^t w_p \leq m^\text{max}_p x_p
|
||||||
& \forall p \in P, t \in T
|
& \forall p \in P, t \in T
|
||||||
\end{align}
|
\end{align*}
|
||||||
|
```
|
||||||
|
|
||||||
* Amount of recovered material is proportional to amount processed:
|
* Amount of recovered material is proportional to amount processed:
|
||||||
|
|
||||||
\begin{align}
|
```math
|
||||||
|
\begin{align*}
|
||||||
& q_{mpt} = \alpha_{pm} z^{\text{proc}}_{pt}
|
& q_{mpt} = \alpha_{pm} z^{\text{proc}}_{pt}
|
||||||
& \forall m \in M, p \in P, t \in T
|
& \forall m \in M, p \in P, t \in T
|
||||||
\end{align}
|
\end{align*}
|
||||||
|
```
|
||||||
|
|
||||||
* Because we only consider a single type of plant, all recovered material must be immediately disposed of. In RELOG's full model, recovered materials may be sent to another plant for further processing.
|
* Because we only consider a single type of plant, all recovered material must be immediately disposed of. In RELOG's full model, recovered materials may be sent to another plant for further processing.
|
||||||
|
|
||||||
\begin{align}
|
```math
|
||||||
|
\begin{align*}
|
||||||
& q_{mpt} = z_{mpt}
|
& q_{mpt} = z_{mpt}
|
||||||
& \forall m \in M, p \in P, t \in T
|
& \forall m \in M, p \in P, t \in T
|
||||||
\end{align}
|
\end{align*}
|
||||||
|
```
|
||||||
|
|
||||||
* A plant is operational at time $t$ if it was operational at time $t-1$ or it was built at time $t$. This constraint also prevents a plant from being built multiple times.
|
* A plant is operational at time $t$ if it was operational at time $t-1$ or it was built at time $t$. This constraint also prevents a plant from being built multiple times.
|
||||||
|
|
||||||
\begin{align}
|
```math
|
||||||
|
\begin{align*}
|
||||||
& x_{pt} = x_{p,t-1} + u_{pt}
|
& x_{pt} = x_{p,t-1} + u_{pt}
|
||||||
& \forall p \in P, t \in T \setminus \{1\} \\
|
& \forall p \in P, t \in T \setminus \{1\} \\
|
||||||
& x_{p,1} = u_{p,1}
|
& x_{p,1} = u_{p,1}
|
||||||
& \forall p \in P
|
& \forall p \in P
|
||||||
\end{align}
|
\end{align*}
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
* Variable bounds:
|
* Variable bounds:
|
||||||
|
|
||||||
\begin{align}
|
```math
|
||||||
|
\begin{align*}
|
||||||
& q_{mpt} \geq 0
|
& q_{mpt} \geq 0
|
||||||
& \forall m \in M, p \in P, t \in T \\
|
& \forall m \in M, p \in P, t \in T \\
|
||||||
& u_{pt} \in \{0,1\}
|
& u_{pt} \in \{0,1\}
|
||||||
@@ -162,4 +192,5 @@ In the fourth line, we have the disposal costs.
|
|||||||
& p \in P, t \in T \\
|
& p \in P, t \in T \\
|
||||||
& z^{\text{disp}}_{mpt}, z^{\text{proc}}_{mpt} \geq 0
|
& z^{\text{disp}}_{mpt}, z^{\text{proc}}_{mpt} \geq 0
|
||||||
& \forall m \in M, p \in P, t \in T
|
& \forall m \in M, p \in P, t \in T
|
||||||
\end{align}
|
\end{align*}
|
||||||
|
```
|
||||||
@@ -9,7 +9,7 @@ In this page, we also illustrate what types of charts and visualizations can be
|
|||||||
Report showing plant costs, capacities, energy expenditure and utilization factors. Generated by `RELOG.write_plants_report(solution, filename)`.
|
Report showing plant costs, capacities, energy expenditure and utilization factors. Generated by `RELOG.write_plants_report(solution, filename)`.
|
||||||
|
|
||||||
| Column | Description
|
| Column | Description
|
||||||
|:--------------------------------------|---------------|
|
|:--------------------------------------|:---------------|
|
||||||
| `plant type` | Plant type.
|
| `plant type` | Plant type.
|
||||||
| `location name` | Location name.
|
| `location name` | Location name.
|
||||||
| `year` | What year this row corresponds to. This reports includes one row for each year.
|
| `year` | What year this row corresponds to. This reports includes one row for each year.
|
||||||
@@ -45,7 +45,9 @@ sns.barplot(x="year",
|
|||||||
.reset_index());
|
.reset_index());
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="../images/ex_plant_cost_per_year.png" width="500px"/>
|
```@raw html
|
||||||
|
<img src="../assets/ex_plant_cost_per_year.png" width="500px"/>
|
||||||
|
```
|
||||||
|
|
||||||
* Map showing plant locations (in Python):
|
* Map showing plant locations (in Python):
|
||||||
```python
|
```python
|
||||||
@@ -65,8 +67,9 @@ points = gp.points_from_xy(data["longitude (deg)"],
|
|||||||
gp.GeoDataFrame(data, geometry=points).plot(ax=ax);
|
gp.GeoDataFrame(data, geometry=points).plot(ax=ax);
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="../images/ex_plant_locations.png" width="1000px"/>
|
```@raw html
|
||||||
|
<img src="../assets/ex_plant_locations.png" width="1000px"/>
|
||||||
|
```
|
||||||
|
|
||||||
## Plant outputs report
|
## Plant outputs report
|
||||||
|
|
||||||
@@ -74,7 +77,7 @@ Report showing amount of products produced, sent and disposed of by each plant,
|
|||||||
|
|
||||||
|
|
||||||
| Column | Description
|
| Column | Description
|
||||||
|:--------------------------------------|---------------|
|
|:--------------------------------------|:---------------|
|
||||||
| `plant type` | Plant type.
|
| `plant type` | Plant type.
|
||||||
| `location name` | Location name.
|
| `location name` | Location name.
|
||||||
| `year` | What year this row corresponds to. This reports includes one row for each year.
|
| `year` | What year this row corresponds to. This reports includes one row for each year.
|
||||||
@@ -101,7 +104,9 @@ sns.barplot(x="amount produced (tonne)",
|
|||||||
.reset_index());
|
.reset_index());
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="../images/ex_amount_produced.png" width="500px"/>
|
```@raw html
|
||||||
|
<img src="../assets/ex_amount_produced.png" width="500px"/>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Plant emissions report
|
## Plant emissions report
|
||||||
@@ -109,7 +114,7 @@ sns.barplot(x="amount produced (tonne)",
|
|||||||
Report showing amount of emissions produced by each plant. Generated by `RELOG.write_plant_emissions_report(solution, filename)`.
|
Report showing amount of emissions produced by each plant. Generated by `RELOG.write_plant_emissions_report(solution, filename)`.
|
||||||
|
|
||||||
| Column | Description
|
| Column | Description
|
||||||
|:--------------------------------------|---------------|
|
|:--------------------------------------|:---------------|
|
||||||
| `plant type` | Plant type.
|
| `plant type` | Plant type.
|
||||||
| `location name` | Location name.
|
| `location name` | Location name.
|
||||||
| `year` | Year.
|
| `year` | Year.
|
||||||
@@ -133,20 +138,23 @@ sns.barplot(x="plant type",
|
|||||||
.reset_index());
|
.reset_index());
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="../images/ex_emissions.png" width="500px"/>
|
```@raw html
|
||||||
|
<img src="../assets/ex_emissions.png" width="500px"/>
|
||||||
|
```
|
||||||
|
|
||||||
## Products report
|
## Products report
|
||||||
|
|
||||||
Report showing primary product amounts, locations and marginal costs. Generated by `RELOG.write_products_report(solution, filename)`.
|
Report showing primary product amounts, locations and marginal costs. Generated by `RELOG.write_products_report(solution, filename)`.
|
||||||
|
|
||||||
| Column | Description
|
| Column | Description
|
||||||
|:--------------------------------------|---------------|
|
|:--------------------------------------|:---------------|
|
||||||
| `product name` | Product name.
|
| `product name` | Product name.
|
||||||
| `location name` | Name of the collection center.
|
| `location name` | Name of the collection center.
|
||||||
| `latitude (deg)` | Latitude of the collection center.
|
| `latitude (deg)` | Latitude of the collection center.
|
||||||
| `longitude (deg)` | Longitude of the collection center.
|
| `longitude (deg)` | Longitude of the collection center.
|
||||||
| `year` | What year this row corresponds to. This reports includes one row for each year.
|
| `year` | What year this row corresponds to. This reports includes one row for each year.
|
||||||
| `amount (tonne)` | Amount of product available at this collection center.
|
| `amount (tonne)` | Amount of product available at this collection center.
|
||||||
|
| `amount disposed (tonne)` | Amount of product disposed of at this collection center.
|
||||||
| `marginal cost ($/tonne)` | Cost to process one additional tonne of this product coming from this collection center.
|
| `marginal cost ($/tonne)` | Cost to process one additional tonne of this product coming from this collection center.
|
||||||
|
|
||||||
|
|
||||||
@@ -156,7 +164,7 @@ Report showing amount of product sent from initial locations to plants, and from
|
|||||||
|
|
||||||
|
|
||||||
| Column | Description
|
| Column | Description
|
||||||
|:--------------------------------------|---------------|
|
|:--------------------------------------|:---------------|
|
||||||
| `source type` | If product is being shipped from an initial location, equals `Origin`. If product is being shipped from a plant, equals plant type.
|
| `source type` | If product is being shipped from an initial location, equals `Origin`. If product is being shipped from a plant, equals plant type.
|
||||||
| `source location name` | Name of the location where the product is being shipped from.
|
| `source location name` | Name of the location where the product is being shipped from.
|
||||||
| `source latitude (deg)` | Latitude of the source location.
|
| `source latitude (deg)` | Latitude of the source location.
|
||||||
@@ -190,7 +198,9 @@ sns.barplot(x="product",
|
|||||||
.reset_index());
|
.reset_index());
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="../images/ex_transportation_amount_distance.png" width="500px"/>
|
```@raw html
|
||||||
|
<img src="../assets/ex_transportation_amount_distance.png" width="500px"/>
|
||||||
|
```
|
||||||
|
|
||||||
* Map of transportation lines (in Python):
|
* Map of transportation lines (in Python):
|
||||||
|
|
||||||
@@ -233,7 +243,9 @@ gp.GeoDataFrame(data, geometry=points).plot(ax=ax,
|
|||||||
markersize=50);
|
markersize=50);
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="../images/ex_transportation.png" width="1000px"/>
|
```@raw html
|
||||||
|
<img src="../assets/ex_transportation.png" width="1000px"/>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Transportation emissions report
|
## Transportation emissions report
|
||||||
@@ -241,7 +253,7 @@ gp.GeoDataFrame(data, geometry=points).plot(ax=ax,
|
|||||||
Report showing emissions for each trip between initial locations and plants, and between pairs of plants. Generated by `RELOG.write_transportation_emissions_report(solution, filename)`.
|
Report showing emissions for each trip between initial locations and plants, and between pairs of plants. Generated by `RELOG.write_transportation_emissions_report(solution, filename)`.
|
||||||
|
|
||||||
| Column | Description
|
| Column | Description
|
||||||
|:--------------------------------------|---------------|
|
|:--------------------------------------|:---------------|
|
||||||
| `source type` | If product is being shipped from an initial location, equals `Origin`. If product is being shipped from a plant, equals plant type.
|
| `source type` | If product is being shipped from an initial location, equals `Origin`. If product is being shipped from a plant, equals plant type.
|
||||||
| `source location name` | Name of the location where the product is being shipped from.
|
| `source location name` | Name of the location where the product is being shipped from.
|
||||||
| `source latitude (deg)` | Latitude of the source location.
|
| `source latitude (deg)` | Latitude of the source location.
|
||||||
@@ -275,4 +287,6 @@ sns.barplot(x="emission type",
|
|||||||
.reset_index());
|
.reset_index());
|
||||||
```
|
```
|
||||||
|
|
||||||
<img src="../images/ex_transportation_emissions.png" width="500px"/>
|
```@raw html
|
||||||
|
<img src="../assets/ex_transportation_emissions.png" width="500px"/>
|
||||||
|
```
|
||||||
@@ -3,22 +3,11 @@ Usage
|
|||||||
|
|
||||||
## 1. Installation
|
## 1. Installation
|
||||||
|
|
||||||
To use RELOG, the first step is to install the [Julia programming language](https://julialang.org/) on your machine. Note that RELOG was developed and tested with Julia 1.5 and may not be compatible with newer versions. After Julia is installed, launch the Julia console, type `]` to switch to package manger mode, then run:
|
To use RELOG, the first step is to install the [Julia programming language](https://julialang.org/) on your machine. Note that RELOG was developed and tested with Julia 1.8 and may not be compatible with newer versions. After Julia is installed, launch the Julia console, then run:
|
||||||
|
|
||||||
```text
|
```julia
|
||||||
(@v1.5) pkg> add https://github.com/ANL-CEEESA/RELOG.git
|
using Pkg
|
||||||
```
|
Pkg.add(name="RELOG", version="0.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
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 2. Modeling the problem
|
## 2. Modeling the problem
|
||||||
@@ -106,18 +95,22 @@ To use the `resolve` method, the new input file should be very similar to the or
|
|||||||
|
|
||||||
### 5.1 Changing the solver
|
### 5.1 Changing the solver
|
||||||
|
|
||||||
By default, RELOG internally uses [Cbc](https://github.com/coin-or/Cbc), an open-source and freely-available Mixed-Integer Linear Programming solver developed by the [COIN-OR Project](https://www.coin-or.org/). For larger-scale test cases, a commercial solver such as Gurobi, CPLEX or XPRESS is recommended. The following snippet shows how to switch from Cbc to Gurobi, for example:
|
By default, RELOG internally uses [HiGHS](https://github.com/ERGO-Code/HiGHS), an open-source and freely-available Mixed-Integer Linear Programming solver. For larger-scale test cases, a commercial solver such as Gurobi, CPLEX or XPRESS is recommended. The following snippet shows how to switch to Gurobi, for example:
|
||||||
|
|
||||||
```julia
|
```julia
|
||||||
using RELOG, Gurobi, JuMP
|
using RELOG, Gurobi, JuMP
|
||||||
|
|
||||||
gurobi = optimizer_with_attributes(Gurobi.Optimizer,
|
gurobi = optimizer_with_attributes(
|
||||||
"TimeLimit" => 3600,
|
Gurobi.Optimizer,
|
||||||
"MIPGap" => 0.001)
|
"TimeLimit" => 3600,
|
||||||
|
"MIPGap" => 0.001,
|
||||||
|
)
|
||||||
|
|
||||||
RELOG.solve("instance.json",
|
RELOG.solve(
|
||||||
output="solution.json",
|
"instance.json",
|
||||||
optimizer=gurobi)
|
output="solution.json",
|
||||||
|
optimizer=gurobi,
|
||||||
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
### 5.2 Multi-period heuristics
|
### 5.2 Multi-period heuristics
|
||||||
@@ -133,6 +126,8 @@ To solve an instance using this heuristic, use the option `heuristic=true`, as s
|
|||||||
```julia
|
```julia
|
||||||
using RELOG
|
using RELOG
|
||||||
|
|
||||||
solution = RELOG.solve("/home/user/instance.json",
|
solution = RELOG.solve(
|
||||||
heuristic=true)
|
"/home/user/instance.json",
|
||||||
|
heuristic=true,
|
||||||
|
)
|
||||||
```
|
```
|
||||||
@@ -1,202 +0,0 @@
|
|||||||
{
|
|
||||||
"parameters": {
|
|
||||||
"time horizon (years)": 2
|
|
||||||
},
|
|
||||||
"products": {
|
|
||||||
"P1": {
|
|
||||||
"transportation cost ($/km/tonne)": [0.015, 0.015],
|
|
||||||
"transportation energy (J/km/tonne)": [0.12, 0.11],
|
|
||||||
"transportation emissions (tonne/km/tonne)": {
|
|
||||||
"CO2": [0.052, 0.050],
|
|
||||||
"CH4": [0.003, 0.002]
|
|
||||||
},
|
|
||||||
"initial amounts": {
|
|
||||||
"C1": {
|
|
||||||
"latitude (deg)": 7.0,
|
|
||||||
"longitude (deg)": 7.0,
|
|
||||||
"amount (tonne)": [934.56, 934.56]
|
|
||||||
},
|
|
||||||
"C2": {
|
|
||||||
"latitude (deg)": 7.0,
|
|
||||||
"longitude (deg)": 19.0,
|
|
||||||
"amount (tonne)": [198.95, 198.95]
|
|
||||||
},
|
|
||||||
"C3": {
|
|
||||||
"latitude (deg)": 84.0,
|
|
||||||
"longitude (deg)": 76.0,
|
|
||||||
"amount (tonne)": [212.97, 212.97]
|
|
||||||
},
|
|
||||||
"C4": {
|
|
||||||
"latitude (deg)": 21.0,
|
|
||||||
"longitude (deg)": 16.0,
|
|
||||||
"amount (tonne)": [352.19, 352.19]
|
|
||||||
},
|
|
||||||
"C5": {
|
|
||||||
"latitude (deg)": 32.0,
|
|
||||||
"longitude (deg)": 92.0,
|
|
||||||
"amount (tonne)": [510.33, 510.33]
|
|
||||||
},
|
|
||||||
"C6": {
|
|
||||||
"latitude (deg)": 14.0,
|
|
||||||
"longitude (deg)": 62.0,
|
|
||||||
"amount (tonne)": [471.66, 471.66]
|
|
||||||
},
|
|
||||||
"C7": {
|
|
||||||
"latitude (deg)": 30.0,
|
|
||||||
"longitude (deg)": 83.0,
|
|
||||||
"amount (tonne)": [785.21, 785.21]
|
|
||||||
},
|
|
||||||
"C8": {
|
|
||||||
"latitude (deg)": 35.0,
|
|
||||||
"longitude (deg)": 40.0,
|
|
||||||
"amount (tonne)": [706.17, 706.17]
|
|
||||||
},
|
|
||||||
"C9": {
|
|
||||||
"latitude (deg)": 74.0,
|
|
||||||
"longitude (deg)": 52.0,
|
|
||||||
"amount (tonne)": [30.08, 30.08]
|
|
||||||
},
|
|
||||||
"C10": {
|
|
||||||
"latitude (deg)": 22.0,
|
|
||||||
"longitude (deg)": 54.0,
|
|
||||||
"amount (tonne)": [536.52, 536.52]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"P2": {
|
|
||||||
"transportation cost ($/km/tonne)": [0.02, 0.02]
|
|
||||||
},
|
|
||||||
"P3": {
|
|
||||||
"transportation cost ($/km/tonne)": [0.0125, 0.0125]
|
|
||||||
},
|
|
||||||
"P4": {
|
|
||||||
"transportation cost ($/km/tonne)": [0.0175, 0.0175]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"plants": {
|
|
||||||
"F1": {
|
|
||||||
"input": "P1",
|
|
||||||
"outputs (tonne/tonne)": {
|
|
||||||
"P2": 0.2,
|
|
||||||
"P3": 0.5
|
|
||||||
},
|
|
||||||
"energy (GJ/tonne)": [0.12, 0.11],
|
|
||||||
"emissions (tonne/tonne)": {
|
|
||||||
"CO2": [0.052, 0.050],
|
|
||||||
"CH4": [0.003, 0.002]
|
|
||||||
},
|
|
||||||
"locations": {
|
|
||||||
"L1": {
|
|
||||||
"latitude (deg)": 0.0,
|
|
||||||
"longitude (deg)": 0.0,
|
|
||||||
"disposal": {
|
|
||||||
"P2": {
|
|
||||||
"cost ($/tonne)": [-10.0, -10.0],
|
|
||||||
"limit (tonne)": [1.0, 1.0]
|
|
||||||
},
|
|
||||||
"P3": {
|
|
||||||
"cost ($/tonne)": [-10.0, -10.0],
|
|
||||||
"limit (tonne)": [1.0, 1.0]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"capacities (tonne)": {
|
|
||||||
"250.0": {
|
|
||||||
"opening cost ($)": [500.0, 500.0],
|
|
||||||
"fixed operating cost ($)": [30.0, 30.0],
|
|
||||||
"variable operating cost ($/tonne)": [30.0, 30.0]
|
|
||||||
},
|
|
||||||
"1000.0": {
|
|
||||||
"opening cost ($)": [1250.0, 1250.0],
|
|
||||||
"fixed operating cost ($)": [30.0, 30.0],
|
|
||||||
"variable operating cost ($/tonne)": [30.0, 30.0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"L2": {
|
|
||||||
"latitude (deg)": 0.5,
|
|
||||||
"longitude (deg)": 0.5,
|
|
||||||
"capacities (tonne)": {
|
|
||||||
"0.0": {
|
|
||||||
"opening cost ($)": [1000, 1000],
|
|
||||||
"fixed operating cost ($)": [50.0, 50.0],
|
|
||||||
"variable operating cost ($/tonne)": [50.0, 50.0]
|
|
||||||
},
|
|
||||||
"10000.0": {
|
|
||||||
"opening cost ($)": [10000, 10000],
|
|
||||||
"fixed operating cost ($)": [50.0, 50.0],
|
|
||||||
"variable operating cost ($/tonne)": [50.0, 50.0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"F2": {
|
|
||||||
"input": "P2",
|
|
||||||
"outputs (tonne/tonne)": {
|
|
||||||
"P3": 0.05,
|
|
||||||
"P4": 0.80
|
|
||||||
},
|
|
||||||
"locations": {
|
|
||||||
"L3": {
|
|
||||||
"latitude (deg)": 25.0,
|
|
||||||
"longitude (deg)": 65.0,
|
|
||||||
"disposal": {
|
|
||||||
"P3": {
|
|
||||||
"cost ($/tonne)": [100.0, 100.0]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"capacities (tonne)": {
|
|
||||||
"1000.0": {
|
|
||||||
"opening cost ($)": [3000, 3000],
|
|
||||||
"fixed operating cost ($)": [50.0, 50.0],
|
|
||||||
"variable operating cost ($/tonne)": [50.0, 50.0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"L4": {
|
|
||||||
"latitude (deg)": 0.75,
|
|
||||||
"longitude (deg)": 0.20,
|
|
||||||
"capacities (tonne)": {
|
|
||||||
"10000": {
|
|
||||||
"opening cost ($)": [3000, 3000],
|
|
||||||
"fixed operating cost ($)": [50.0, 50.0],
|
|
||||||
"variable operating cost ($/tonne)": [50.0, 50.0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"F3": {
|
|
||||||
"input": "P4",
|
|
||||||
"locations": {
|
|
||||||
"L5": {
|
|
||||||
"latitude (deg)": 100.0,
|
|
||||||
"longitude (deg)": 100.0,
|
|
||||||
"capacities (tonne)": {
|
|
||||||
"15000": {
|
|
||||||
"opening cost ($)": [0.0, 0.0],
|
|
||||||
"fixed operating cost ($)": [0.0, 0.0],
|
|
||||||
"variable operating cost ($/tonne)": [-15.0, -15.0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"F4": {
|
|
||||||
"input": "P3",
|
|
||||||
"locations": {
|
|
||||||
"L6": {
|
|
||||||
"latitude (deg)": 50.0,
|
|
||||||
"longitude (deg)": 50.0,
|
|
||||||
"capacities (tonne)": {
|
|
||||||
"10000": {
|
|
||||||
"opening cost ($)": [0.0, 0.0],
|
|
||||||
"fixed operating cost ($)": [0.0, 0.0],
|
|
||||||
"variable operating cost ($/tonne)": [-15.0, -15.0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
23
mkdocs.yml
@@ -1,23 +0,0 @@
|
|||||||
site_name: RELOG
|
|
||||||
theme: cinder
|
|
||||||
copyright: "Copyright © 2020, UChicago Argonne, LLC. All Rights Reserved."
|
|
||||||
repo_url: https://github.com/ANL-CEEESA/RELOG
|
|
||||||
edit_uri: edit/master/src/docs/
|
|
||||||
nav:
|
|
||||||
- Home: index.md
|
|
||||||
- Usage: usage.md
|
|
||||||
- Data Format: format.md
|
|
||||||
- Reports: reports.md
|
|
||||||
- Optimization Model: model.md
|
|
||||||
plugins:
|
|
||||||
- search
|
|
||||||
markdown_extensions:
|
|
||||||
- admonition
|
|
||||||
- mdx_math
|
|
||||||
extra_javascript:
|
|
||||||
- https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML
|
|
||||||
- js/mathjax.js
|
|
||||||
docs_dir: src/docs
|
|
||||||
site_dir: docs
|
|
||||||
extra_css:
|
|
||||||
- "css/custom.css"
|
|
||||||
23
relog-web/.gitignore
vendored
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
/.pnp
|
||||||
|
.pnp.js
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
.env.local
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
70
relog-web/README.md
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
# Getting Started with Create React App
|
||||||
|
|
||||||
|
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||||
|
|
||||||
|
## Available Scripts
|
||||||
|
|
||||||
|
In the project directory, you can run:
|
||||||
|
|
||||||
|
### `npm start`
|
||||||
|
|
||||||
|
Runs the app in the development mode.\
|
||||||
|
Open [http://localhost:3000](http://localhost:3000) to view it in your browser.
|
||||||
|
|
||||||
|
The page will reload when you make changes.\
|
||||||
|
You may also see any lint errors in the console.
|
||||||
|
|
||||||
|
### `npm test`
|
||||||
|
|
||||||
|
Launches the test runner in the interactive watch mode.\
|
||||||
|
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.
|
||||||
|
|
||||||
|
### `npm run build`
|
||||||
|
|
||||||
|
Builds the app for production to the `build` folder.\
|
||||||
|
It correctly bundles React in production mode and optimizes the build for the best performance.
|
||||||
|
|
||||||
|
The build is minified and the filenames include the hashes.\
|
||||||
|
Your app is ready to be deployed!
|
||||||
|
|
||||||
|
See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.
|
||||||
|
|
||||||
|
### `npm run eject`
|
||||||
|
|
||||||
|
**Note: this is a one-way operation. Once you `eject`, you can't go back!**
|
||||||
|
|
||||||
|
If you aren't satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.
|
||||||
|
|
||||||
|
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you're on your own.
|
||||||
|
|
||||||
|
You don't have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn't feel obligated to use this feature. However we understand that this tool wouldn't be useful if you couldn't customize it when you are ready for it.
|
||||||
|
|
||||||
|
## Learn More
|
||||||
|
|
||||||
|
You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).
|
||||||
|
|
||||||
|
To learn React, check out the [React documentation](https://reactjs.org/).
|
||||||
|
|
||||||
|
### Code Splitting
|
||||||
|
|
||||||
|
This section has moved here: [https://facebook.github.io/create-react-app/docs/code-splitting](https://facebook.github.io/create-react-app/docs/code-splitting)
|
||||||
|
|
||||||
|
### Analyzing the Bundle Size
|
||||||
|
|
||||||
|
This section has moved here: [https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size](https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size)
|
||||||
|
|
||||||
|
### Making a Progressive Web App
|
||||||
|
|
||||||
|
This section has moved here: [https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app](https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app)
|
||||||
|
|
||||||
|
### Advanced Configuration
|
||||||
|
|
||||||
|
This section has moved here: [https://facebook.github.io/create-react-app/docs/advanced-configuration](https://facebook.github.io/create-react-app/docs/advanced-configuration)
|
||||||
|
|
||||||
|
### Deployment
|
||||||
|
|
||||||
|
This section has moved here: [https://facebook.github.io/create-react-app/docs/deployment](https://facebook.github.io/create-react-app/docs/deployment)
|
||||||
|
|
||||||
|
### `npm run build` fails to minify
|
||||||
|
|
||||||
|
This section has moved here: [https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify](https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify)
|
||||||
29110
relog-web/package-lock.json
generated
Normal file
52
relog-web/package.json
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
{
|
||||||
|
"name": "relog-web",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"homepage": "/",
|
||||||
|
"jest": {
|
||||||
|
"moduleNameMapper": {
|
||||||
|
"d3": "<rootDir>/node_modules/d3/dist/d3.min.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@testing-library/jest-dom": "^5.16.2",
|
||||||
|
"@testing-library/react": "^12.1.4",
|
||||||
|
"@testing-library/user-event": "^13.5.0",
|
||||||
|
"ajv": "^8.11.0",
|
||||||
|
"d3": "^5.16.0",
|
||||||
|
"d3-array": "^2.12.1",
|
||||||
|
"dagre": "^0.8.5",
|
||||||
|
"idb": "^6.1.5",
|
||||||
|
"leaflet": "^1.8.0",
|
||||||
|
"react": "^17.0.2",
|
||||||
|
"react-dom": "^17.0.2",
|
||||||
|
"react-flow-renderer": "^9.7.4",
|
||||||
|
"react-router-dom": "^5.3.3",
|
||||||
|
"react-scripts": "5.0.0",
|
||||||
|
"web-vitals": "^2.1.4"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "react-scripts start",
|
||||||
|
"build": "react-scripts build",
|
||||||
|
"test": "react-scripts test",
|
||||||
|
"eject": "react-scripts eject"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"extends": [
|
||||||
|
"react-app",
|
||||||
|
"react-app/jest"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"browserslist": {
|
||||||
|
"production": [
|
||||||
|
">0.2%",
|
||||||
|
"not dead",
|
||||||
|
"not op_mini all"
|
||||||
|
],
|
||||||
|
"development": [
|
||||||
|
"last 1 chrome version",
|
||||||
|
"last 1 firefox version",
|
||||||
|
"last 1 safari version"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
13
relog-web/public/index.html
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<title>RELOG</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||||
|
<div id="root"></div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
417
relog-web/src/casebuilder/InputPage.js
Normal file
@@ -0,0 +1,417 @@
|
|||||||
|
import { openDB } from "idb";
|
||||||
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
|
import Button from "../common/Button";
|
||||||
|
import Footer from "../common/Footer";
|
||||||
|
import Header from "../common/Header";
|
||||||
|
import "../index.css";
|
||||||
|
import { generateFile } from "./csv";
|
||||||
|
import { defaultData, defaultPlant, defaultProduct } from "./defaults";
|
||||||
|
import { exportData, importData } from "./export";
|
||||||
|
import ParametersBlock from "./ParametersBlock";
|
||||||
|
import PipelineBlock, { randomPosition } from "./PipelineBlock";
|
||||||
|
import PlantBlock from "./PlantBlock";
|
||||||
|
import ProductBlock from "./ProductBlock";
|
||||||
|
import { validate } from "./validate";
|
||||||
|
import { useHistory } from "react-router-dom";
|
||||||
|
import { SERVER_URL } from "..";
|
||||||
|
|
||||||
|
const setDefaults = (actualDict, defaultDict) => {
|
||||||
|
for (const [key, defaultValue] of Object.entries(defaultDict)) {
|
||||||
|
if (!(key in actualDict)) {
|
||||||
|
if (typeof defaultValue === "object") {
|
||||||
|
actualDict[key] = { ...defaultValue };
|
||||||
|
} else {
|
||||||
|
actualDict[key] = defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const cleanDict = (dict, defaultDict) => {
|
||||||
|
for (const key of Object.keys(dict)) {
|
||||||
|
if (!(key in defaultDict)) {
|
||||||
|
delete dict[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const fixLists = (dict, blacklist, stringify) => {
|
||||||
|
for (const [key, val] of Object.entries(dict)) {
|
||||||
|
if (blacklist.includes(key)) continue;
|
||||||
|
if (Array.isArray(val)) {
|
||||||
|
// Replace constant lists by a single number
|
||||||
|
let isConstant = true;
|
||||||
|
for (let i = 1; i < val.length; i++) {
|
||||||
|
if (val[i - 1] !== val[i]) {
|
||||||
|
isConstant = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isConstant) dict[key] = val[0];
|
||||||
|
|
||||||
|
// Convert lists to JSON strings
|
||||||
|
if (stringify) dict[key] = JSON.stringify(dict[key]);
|
||||||
|
}
|
||||||
|
if (typeof val === "object") {
|
||||||
|
fixLists(val, blacklist, stringify);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const openRelogDB = async () => {
|
||||||
|
const dbPromise = await openDB("RELOG", 1, {
|
||||||
|
upgrade(db) {
|
||||||
|
db.createObjectStore("casebuilder");
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return dbPromise;
|
||||||
|
};
|
||||||
|
|
||||||
|
const InputPage = () => {
|
||||||
|
const fileElem = useRef();
|
||||||
|
let [data, setData] = useState(defaultData);
|
||||||
|
let [messages, setMessages] = useState([]);
|
||||||
|
let [processing, setProcessing] = useState(false);
|
||||||
|
|
||||||
|
const save = async (data) => {
|
||||||
|
const db = await openRelogDB();
|
||||||
|
await db.put("casebuilder", data, "data");
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(async () => {
|
||||||
|
const db = await openRelogDB();
|
||||||
|
const data = await db.get("casebuilder", "data");
|
||||||
|
if (data) setData(data);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const history = useHistory();
|
||||||
|
|
||||||
|
const promptName = (prevData) => {
|
||||||
|
const name = prompt("Name");
|
||||||
|
if (!name || name.length === 0) return;
|
||||||
|
if (name in prevData.products || name in prevData.plants) return;
|
||||||
|
return name;
|
||||||
|
};
|
||||||
|
|
||||||
|
const onAddPlant = () => {
|
||||||
|
setData((prevData) => {
|
||||||
|
const name = promptName(prevData);
|
||||||
|
if (name === undefined) return prevData;
|
||||||
|
const newData = { ...prevData };
|
||||||
|
const [x, y] = randomPosition();
|
||||||
|
newData.plants[name] = {
|
||||||
|
...defaultPlant,
|
||||||
|
x: x,
|
||||||
|
y: y,
|
||||||
|
};
|
||||||
|
save(newData);
|
||||||
|
return newData;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onAddProduct = () => {
|
||||||
|
setData((prevData) => {
|
||||||
|
const name = promptName(prevData);
|
||||||
|
if (name === undefined) return prevData;
|
||||||
|
const newData = { ...prevData };
|
||||||
|
const [x, y] = randomPosition();
|
||||||
|
console.log(x, y);
|
||||||
|
newData.products[name] = {
|
||||||
|
...defaultProduct,
|
||||||
|
x: x,
|
||||||
|
y: y,
|
||||||
|
};
|
||||||
|
save(newData);
|
||||||
|
return newData;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onRenamePlant = (prevName, newName) => {
|
||||||
|
setData((prevData) => {
|
||||||
|
const newData = { ...prevData };
|
||||||
|
newData.plants[newName] = newData.plants[prevName];
|
||||||
|
delete newData.plants[prevName];
|
||||||
|
save(newData);
|
||||||
|
return newData;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onRenameProduct = (prevName, newName) => {
|
||||||
|
setData((prevData) => {
|
||||||
|
const newData = { ...prevData };
|
||||||
|
newData.products[newName] = newData.products[prevName];
|
||||||
|
delete newData.products[prevName];
|
||||||
|
for (const [, plant] of Object.entries(newData.plants)) {
|
||||||
|
if (plant.input === prevName) {
|
||||||
|
plant.input = newName;
|
||||||
|
}
|
||||||
|
let outputFound = false;
|
||||||
|
for (const [outputName] of Object.entries(
|
||||||
|
plant["outputs (tonne/tonne)"]
|
||||||
|
)) {
|
||||||
|
if (outputName === prevName) outputFound = true;
|
||||||
|
}
|
||||||
|
if (outputFound) {
|
||||||
|
plant["outputs (tonne/tonne)"][newName] =
|
||||||
|
plant["outputs (tonne/tonne)"][prevName];
|
||||||
|
delete plant["outputs (tonne/tonne)"][prevName];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
save(newData);
|
||||||
|
return newData;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onMovePlant = (plantName, x, y) => {
|
||||||
|
setData((prevData) => {
|
||||||
|
const newData = { ...prevData };
|
||||||
|
newData.plants[plantName].x = x;
|
||||||
|
newData.plants[plantName].y = y;
|
||||||
|
save(newData);
|
||||||
|
return newData;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onMoveProduct = (productName, x, y) => {
|
||||||
|
setData((prevData) => {
|
||||||
|
const newData = { ...prevData };
|
||||||
|
newData.products[productName].x = x;
|
||||||
|
newData.products[productName].y = y;
|
||||||
|
save(newData);
|
||||||
|
return newData;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onRemovePlant = (plantName) => {
|
||||||
|
setData((prevData) => {
|
||||||
|
const newData = { ...prevData };
|
||||||
|
delete newData.plants[plantName];
|
||||||
|
save(newData);
|
||||||
|
return newData;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onRemoveProduct = (productName) => {
|
||||||
|
setData((prevData) => {
|
||||||
|
const newData = { ...prevData };
|
||||||
|
delete newData.products[productName];
|
||||||
|
for (const [, plant] of Object.entries(newData.plants)) {
|
||||||
|
if (plant.input === productName) {
|
||||||
|
delete plant.input;
|
||||||
|
}
|
||||||
|
let outputFound = false;
|
||||||
|
for (const [outputName] of Object.entries(
|
||||||
|
plant["outputs (tonne/tonne)"]
|
||||||
|
)) {
|
||||||
|
if (outputName === productName) outputFound = true;
|
||||||
|
}
|
||||||
|
if (outputFound) {
|
||||||
|
delete plant["outputs (tonne/tonne)"][productName];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
save(newData);
|
||||||
|
return newData;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSetPlantInput = (plantName, productName) => {
|
||||||
|
setData((prevData) => {
|
||||||
|
const newData = { ...prevData };
|
||||||
|
newData.plants[plantName].input = productName;
|
||||||
|
save(newData);
|
||||||
|
return newData;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onAddPlantOutput = (plantName, productName) => {
|
||||||
|
setData((prevData) => {
|
||||||
|
if (productName in prevData.plants[plantName]["outputs (tonne/tonne)"]) {
|
||||||
|
return prevData;
|
||||||
|
}
|
||||||
|
const newData = { ...prevData };
|
||||||
|
[
|
||||||
|
"outputs (tonne/tonne)",
|
||||||
|
"disposal cost ($/tonne)",
|
||||||
|
"disposal limit (tonne)",
|
||||||
|
].forEach((key) => {
|
||||||
|
newData.plants[plantName][key] = { ...newData.plants[plantName][key] };
|
||||||
|
newData.plants[plantName][key][productName] = 0;
|
||||||
|
});
|
||||||
|
save(newData);
|
||||||
|
return newData;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onSave = () => {
|
||||||
|
const exported = exportData(data);
|
||||||
|
const valid = validate(exported);
|
||||||
|
console.log(exported);
|
||||||
|
console.log(validate.errors);
|
||||||
|
if (valid) {
|
||||||
|
generateFile("case.json", JSON.stringify(exported, null, 2));
|
||||||
|
} else {
|
||||||
|
setMessages([
|
||||||
|
...messages,
|
||||||
|
"Data has validation errors and could not be saved.",
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onClear = () => {
|
||||||
|
const newData = JSON.parse(JSON.stringify(defaultData));
|
||||||
|
setData(newData);
|
||||||
|
save(newData);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onLoad = (contents) => {
|
||||||
|
const parsed = JSON.parse(contents);
|
||||||
|
const valid = validate(parsed);
|
||||||
|
if (valid) {
|
||||||
|
const newData = importData(parsed);
|
||||||
|
setData(newData);
|
||||||
|
save(newData);
|
||||||
|
} else {
|
||||||
|
console.log(validate.errors);
|
||||||
|
setMessages([...messages, "File is corrupted and could not be loaded."]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onDismissMessage = (idx) => {
|
||||||
|
setMessages([...messages.slice(0, idx), ...messages.slice(idx + 1)]);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onChange = (val, field1, field2) => {
|
||||||
|
setData((prevData) => {
|
||||||
|
const newData = { ...prevData };
|
||||||
|
if (field2 !== undefined) {
|
||||||
|
newData[field1][field2] = val;
|
||||||
|
} else {
|
||||||
|
newData[field1] = val;
|
||||||
|
}
|
||||||
|
save(newData);
|
||||||
|
return newData;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
let productComps = [];
|
||||||
|
for (const [prodName, prod] of Object.entries(data.products)) {
|
||||||
|
productComps.push(
|
||||||
|
<ProductBlock
|
||||||
|
key={prodName}
|
||||||
|
name={prodName}
|
||||||
|
value={prod}
|
||||||
|
onChange={(v) => onChange(v, "products", prodName, v)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const onSubmit = async () => {
|
||||||
|
const exported = exportData(data);
|
||||||
|
const valid = validate(exported);
|
||||||
|
if (valid) {
|
||||||
|
setProcessing(true);
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${SERVER_URL}/submit`, {
|
||||||
|
method: "POST",
|
||||||
|
body: JSON.stringify(exported),
|
||||||
|
});
|
||||||
|
if (response.ok) {
|
||||||
|
const data = await response.json();
|
||||||
|
history.push(`solver/${data.job_id}`);
|
||||||
|
} else {
|
||||||
|
throw "Error";
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
setMessages([
|
||||||
|
...messages,
|
||||||
|
"Failed to submit job. Please try again later.",
|
||||||
|
]);
|
||||||
|
} finally {
|
||||||
|
setProcessing(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let plantComps = [];
|
||||||
|
for (const [plantName, plant] of Object.entries(data.plants)) {
|
||||||
|
plantComps.push(
|
||||||
|
<PlantBlock
|
||||||
|
key={plantName}
|
||||||
|
name={plantName}
|
||||||
|
value={plant}
|
||||||
|
onChange={(v) => onChange(v, "plants", plantName)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let messageComps = [];
|
||||||
|
for (let i = 0; i < messages.length; i++) {
|
||||||
|
messageComps.push(
|
||||||
|
<div className="message error" key={i}>
|
||||||
|
<p>{messages[i]}</p>
|
||||||
|
<Button label="Dismiss" onClick={() => onDismissMessage(i)} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const onFileSelected = () => {
|
||||||
|
const file = fileElem.current.files[0];
|
||||||
|
if (file) {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.addEventListener("load", () => {
|
||||||
|
onLoad(reader.result);
|
||||||
|
});
|
||||||
|
reader.readAsText(file);
|
||||||
|
}
|
||||||
|
fileElem.current.value = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Header title="Case Builder">
|
||||||
|
<Button label="Clear" disabled={processing} onClick={onClear} />
|
||||||
|
<Button
|
||||||
|
label="Load"
|
||||||
|
disabled={processing}
|
||||||
|
onClick={(e) => fileElem.current.click()}
|
||||||
|
/>
|
||||||
|
<Button label="Save" disabled={processing} onClick={onSave} />
|
||||||
|
<Button label="Submit" disabled={processing} onClick={onSubmit} />
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
ref={fileElem}
|
||||||
|
accept=".json"
|
||||||
|
style={{ display: "none" }}
|
||||||
|
onChange={onFileSelected}
|
||||||
|
/>
|
||||||
|
</Header>
|
||||||
|
<div id="contentBackground">
|
||||||
|
<div id="content">
|
||||||
|
<PipelineBlock
|
||||||
|
onAddPlant={onAddPlant}
|
||||||
|
onAddPlantOutput={onAddPlantOutput}
|
||||||
|
onAddProduct={onAddProduct}
|
||||||
|
onMovePlant={onMovePlant}
|
||||||
|
onMoveProduct={onMoveProduct}
|
||||||
|
onRenamePlant={onRenamePlant}
|
||||||
|
onRenameProduct={onRenameProduct}
|
||||||
|
onSetPlantInput={onSetPlantInput}
|
||||||
|
onRemovePlant={onRemovePlant}
|
||||||
|
onRemoveProduct={onRemoveProduct}
|
||||||
|
plants={data.plants}
|
||||||
|
products={data.products}
|
||||||
|
/>
|
||||||
|
<ParametersBlock
|
||||||
|
value={data.parameters}
|
||||||
|
onChange={(v) => onChange(v, "parameters")}
|
||||||
|
/>
|
||||||
|
{productComps}
|
||||||
|
{plantComps}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="messageTray">{messageComps}</div>
|
||||||
|
<Footer />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default InputPage;
|
||||||
46
relog-web/src/casebuilder/ParametersBlock.js
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import Section from "../common/Section";
|
||||||
|
import Card from "../common/Card";
|
||||||
|
import Form from "../common/Form";
|
||||||
|
import TextInputRow from "../common/TextInputRow";
|
||||||
|
|
||||||
|
const ParametersBlock = (props) => {
|
||||||
|
const onChangeField = (field, val) => {
|
||||||
|
props.value[field] = val;
|
||||||
|
props.onChange(props.value);
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Section title="Parameters" />
|
||||||
|
<Card>
|
||||||
|
<Form>
|
||||||
|
<TextInputRow
|
||||||
|
label="Time horizon"
|
||||||
|
unit="years"
|
||||||
|
tooltip="Number of years in the simulation."
|
||||||
|
value={props.value["time horizon (years)"]}
|
||||||
|
onChange={(v) => onChangeField("time horizon (years)", v)}
|
||||||
|
validate="int"
|
||||||
|
/>
|
||||||
|
<TextInputRow
|
||||||
|
label="Building period"
|
||||||
|
unit="years"
|
||||||
|
tooltip="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."
|
||||||
|
value={props.value["building period (years)"]}
|
||||||
|
onChange={(v) => onChangeField("building period (years)", v)}
|
||||||
|
validate="intList"
|
||||||
|
/>
|
||||||
|
<TextInputRow
|
||||||
|
label="Inflation rate"
|
||||||
|
unit="%"
|
||||||
|
tooltip="Rate at which costs change from one time period to the next. This is applied uniformly to all costs."
|
||||||
|
value={props.value["inflation rate (%)"]}
|
||||||
|
onChange={(v) => onChangeField("inflation rate (%)", v)}
|
||||||
|
validate="float"
|
||||||
|
/>
|
||||||
|
</Form>
|
||||||
|
</Card>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ParametersBlock;
|
||||||
200
relog-web/src/casebuilder/PipelineBlock.js
Normal file
@@ -0,0 +1,200 @@
|
|||||||
|
import React, { useEffect } from "react";
|
||||||
|
import ReactFlow, { Background, isNode, Controls } from "react-flow-renderer";
|
||||||
|
import Section from "../common/Section";
|
||||||
|
import Card from "../common/Card";
|
||||||
|
import Button from "../common/Button";
|
||||||
|
import styles from "./PipelineBlock.module.css";
|
||||||
|
import dagre from "dagre";
|
||||||
|
|
||||||
|
window.nextX = 15;
|
||||||
|
window.nextY = 15;
|
||||||
|
|
||||||
|
export const randomPosition = () => {
|
||||||
|
window.nextY += 60;
|
||||||
|
if (window.nextY >= 500) {
|
||||||
|
window.nextY = 15;
|
||||||
|
window.nextX += 150;
|
||||||
|
}
|
||||||
|
return [window.nextX, window.nextY];
|
||||||
|
};
|
||||||
|
|
||||||
|
const getLayoutedElements = (elements) => {
|
||||||
|
const nodeWidth = 125;
|
||||||
|
const nodeHeight = 45;
|
||||||
|
const dagreGraph = new dagre.graphlib.Graph();
|
||||||
|
dagreGraph.setDefaultEdgeLabel(() => ({}));
|
||||||
|
dagreGraph.setGraph({ rankdir: "LR" });
|
||||||
|
elements.forEach((el) => {
|
||||||
|
if (isNode(el)) {
|
||||||
|
dagreGraph.setNode(el.id, { width: nodeWidth, height: nodeHeight });
|
||||||
|
} else {
|
||||||
|
dagreGraph.setEdge(el.source, el.target);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dagre.layout(dagreGraph);
|
||||||
|
return elements.map((el) => {
|
||||||
|
if (isNode(el)) {
|
||||||
|
const n = dagreGraph.node(el.id);
|
||||||
|
el.position = {
|
||||||
|
x: 15 + n.x - nodeWidth / 2,
|
||||||
|
y: 15 + n.y - nodeHeight / 2,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return el;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const PipelineBlock = (props) => {
|
||||||
|
let elements = [];
|
||||||
|
let mapNameToType = {};
|
||||||
|
let hasNullPositions = false;
|
||||||
|
|
||||||
|
for (const [productName, product] of Object.entries(props.products)) {
|
||||||
|
if (!product.x || !product.y) hasNullPositions = true;
|
||||||
|
mapNameToType[productName] = "product";
|
||||||
|
elements.push({
|
||||||
|
id: productName,
|
||||||
|
data: { label: productName, type: "product" },
|
||||||
|
position: { x: product.x, y: product.y },
|
||||||
|
sourcePosition: "right",
|
||||||
|
targetPosition: "left",
|
||||||
|
className: styles.ProductNode,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [plantName, plant] of Object.entries(props.plants)) {
|
||||||
|
if (!plant.x || !plant.y) hasNullPositions = true;
|
||||||
|
mapNameToType[plantName] = "plant";
|
||||||
|
elements.push({
|
||||||
|
id: plantName,
|
||||||
|
data: { label: plantName, type: "plant" },
|
||||||
|
position: { x: plant.x, y: plant.y },
|
||||||
|
sourcePosition: "right",
|
||||||
|
targetPosition: "left",
|
||||||
|
className: styles.PlantNode,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (plant.input !== undefined) {
|
||||||
|
elements.push({
|
||||||
|
id: `${plant.input}-${plantName}`,
|
||||||
|
source: plant.input,
|
||||||
|
target: plantName,
|
||||||
|
animated: true,
|
||||||
|
style: { stroke: "black" },
|
||||||
|
selectable: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [productName] of Object.entries(
|
||||||
|
plant["outputs (tonne/tonne)"]
|
||||||
|
)) {
|
||||||
|
elements.push({
|
||||||
|
id: `${plantName}-${productName}`,
|
||||||
|
source: plantName,
|
||||||
|
target: productName,
|
||||||
|
animated: true,
|
||||||
|
style: { stroke: "black" },
|
||||||
|
selectable: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const onNodeDoubleClick = (ev, node) => {
|
||||||
|
const oldName = node.data.label;
|
||||||
|
const newName = window.prompt("Enter new name", oldName);
|
||||||
|
if (newName === undefined || newName.length === 0) return;
|
||||||
|
if (newName in mapNameToType) return;
|
||||||
|
if (node.data.type === "plant") {
|
||||||
|
props.onRenamePlant(oldName, newName);
|
||||||
|
} else {
|
||||||
|
props.onRenameProduct(oldName, newName);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onElementsRemove = (elements) => {
|
||||||
|
elements.forEach((el) => {
|
||||||
|
if (!(el.id in mapNameToType)) return;
|
||||||
|
if (el.data.type === "plant") {
|
||||||
|
props.onRemovePlant(el.data.label);
|
||||||
|
} else {
|
||||||
|
props.onRemoveProduct(el.data.label);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onNodeDragStop = (ev, node) => {
|
||||||
|
if (node.data.type === "plant") {
|
||||||
|
props.onMovePlant(node.data.label, node.position.x, node.position.y);
|
||||||
|
} else {
|
||||||
|
props.onMoveProduct(node.data.label, node.position.x, node.position.y);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onConnect = (args) => {
|
||||||
|
const sourceType = mapNameToType[args.source];
|
||||||
|
const targetType = mapNameToType[args.target];
|
||||||
|
if (sourceType === "product" && targetType === "plant") {
|
||||||
|
props.onSetPlantInput(args.target, args.source);
|
||||||
|
} else if (sourceType === "plant" && targetType === "product") {
|
||||||
|
props.onAddPlantOutput(args.source, args.target);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const onLayout = () => {
|
||||||
|
const layoutedElements = getLayoutedElements(elements);
|
||||||
|
layoutedElements.forEach((el) => {
|
||||||
|
if (isNode(el)) {
|
||||||
|
if (el.data.type === "plant") {
|
||||||
|
props.onMovePlant(el.data.label, el.position.x, el.position.y);
|
||||||
|
} else {
|
||||||
|
props.onMoveProduct(el.data.label, el.position.x, el.position.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (hasNullPositions) onLayout();
|
||||||
|
}, [hasNullPositions]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Section title="Pipeline" />
|
||||||
|
<Card>
|
||||||
|
<div className={styles.PipelineBlock}>
|
||||||
|
<ReactFlow
|
||||||
|
elements={elements}
|
||||||
|
onNodeDoubleClick={onNodeDoubleClick}
|
||||||
|
onNodeDragStop={onNodeDragStop}
|
||||||
|
onConnect={onConnect}
|
||||||
|
onElementsRemove={onElementsRemove}
|
||||||
|
deleteKeyCode={46}
|
||||||
|
maxZoom={1.25}
|
||||||
|
minZoom={0.5}
|
||||||
|
snapToGrid={true}
|
||||||
|
preventScrolling={false}
|
||||||
|
>
|
||||||
|
<Background />
|
||||||
|
<Controls showInteractive={false} />
|
||||||
|
</ReactFlow>
|
||||||
|
</div>
|
||||||
|
<div style={{ textAlign: "center" }}>
|
||||||
|
<Button
|
||||||
|
label="Add product"
|
||||||
|
kind="inline"
|
||||||
|
onClick={props.onAddProduct}
|
||||||
|
/>
|
||||||
|
<Button label="Add plant" kind="inline" onClick={props.onAddPlant} />
|
||||||
|
<Button label="Auto Layout" kind="inline" onClick={onLayout} />
|
||||||
|
<Button
|
||||||
|
label="?"
|
||||||
|
kind="inline"
|
||||||
|
tooltip="Drag from one connector to another to create links between products and plants. Double click to rename an element. Click an element to select and move it. Press the [Delete] key to remove it."
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PipelineBlock;
|
||||||
25
relog-web/src/casebuilder/PipelineBlock.module.css
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
.PipelineBlock {
|
||||||
|
height: 800px !important;
|
||||||
|
border: 1px solid rgba(0, 0, 0, 0.1) !important;
|
||||||
|
border-radius: var(--border-radius) !important;
|
||||||
|
margin-bottom: 12px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.PlantNode,
|
||||||
|
.ProductNode {
|
||||||
|
border-color: rgba(0, 0, 0, 0.8) !important;
|
||||||
|
color: black !important;
|
||||||
|
font-size: 13px !important;
|
||||||
|
border-width: 1px !important;
|
||||||
|
border-radius: 6px !important;
|
||||||
|
box-shadow: 0px 2px 4px -3px black !important;
|
||||||
|
width: 100px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.PlantNode {
|
||||||
|
background-color: #8d8 !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ProductNode {
|
||||||
|
background-color: #e6e6e6 !important;
|
||||||
|
}
|
||||||
271
relog-web/src/casebuilder/PlantBlock.js
Normal file
@@ -0,0 +1,271 @@
|
|||||||
|
import Section from "../common/Section";
|
||||||
|
import Card from "../common/Card";
|
||||||
|
import Form from "../common/Form";
|
||||||
|
import TextInputRow from "../common/TextInputRow";
|
||||||
|
import FileInputRow from "../common/FileInputRow";
|
||||||
|
import DictInputRow from "../common/DictInputRow";
|
||||||
|
import { csvFormat, csvParse, generateFile } from "./csv";
|
||||||
|
|
||||||
|
const PlantBlock = (props) => {
|
||||||
|
const onChange = (val, field1, field2, field3) => {
|
||||||
|
const newPlant = { ...props.value };
|
||||||
|
if (field3 !== undefined) {
|
||||||
|
newPlant[field1][field2][field3] = val;
|
||||||
|
} else if (field2 !== undefined) {
|
||||||
|
newPlant[field1][field2] = val;
|
||||||
|
} else {
|
||||||
|
newPlant[field1] = val;
|
||||||
|
}
|
||||||
|
props.onChange(newPlant);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onCandidateLocationsTemplate = () => {
|
||||||
|
generateFile(
|
||||||
|
"Candidate locations - Template.csv",
|
||||||
|
csvFormat([
|
||||||
|
{
|
||||||
|
name: "Washakie County",
|
||||||
|
"latitude (deg)": "43.8356",
|
||||||
|
"longitude (deg)": "-107.6602",
|
||||||
|
"area cost factor": "0.88",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Platte County",
|
||||||
|
"latitude (deg)": "42.1314",
|
||||||
|
"longitude (deg)": "-104.9676",
|
||||||
|
"area cost factor": "1.29",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Park County",
|
||||||
|
"latitude (deg)": "44.4063",
|
||||||
|
"longitude (deg)": "-109.4153",
|
||||||
|
"area cost factor": "0.99",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Goshen County",
|
||||||
|
"latitude (deg)": "42.0853",
|
||||||
|
"longitude (deg)": "-104.3534",
|
||||||
|
"area cost factor": "1",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onCandidateLocationsFile = (contents) => {
|
||||||
|
const data = csvParse({
|
||||||
|
contents: contents,
|
||||||
|
requiredCols: [
|
||||||
|
"name",
|
||||||
|
"latitude (deg)",
|
||||||
|
"longitude (deg)",
|
||||||
|
"area cost factor",
|
||||||
|
],
|
||||||
|
});
|
||||||
|
const result = {};
|
||||||
|
data.forEach((el) => {
|
||||||
|
result[el["name"]] = {
|
||||||
|
"latitude (deg)": el["latitude (deg)"],
|
||||||
|
"longitude (deg)": el["longitude (deg)"],
|
||||||
|
"area cost factor": el["area cost factor"],
|
||||||
|
};
|
||||||
|
});
|
||||||
|
onChange(result, "locations");
|
||||||
|
};
|
||||||
|
|
||||||
|
const onCandidateLocationsDownload = () => {
|
||||||
|
const result = [];
|
||||||
|
for (const [locationName, locationDict] of Object.entries(
|
||||||
|
props.value["locations"]
|
||||||
|
)) {
|
||||||
|
result.push({
|
||||||
|
name: locationName,
|
||||||
|
"latitude (deg)": locationDict["latitude (deg)"],
|
||||||
|
"longitude (deg)": locationDict["longitude (deg)"],
|
||||||
|
"area cost factor": locationDict["area cost factor"],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
generateFile(`Candidate locations - ${props.name}.csv`, csvFormat(result));
|
||||||
|
};
|
||||||
|
|
||||||
|
const onCandidateLocationsClear = () => {
|
||||||
|
onChange({}, "locations");
|
||||||
|
};
|
||||||
|
|
||||||
|
let description = "No locations set";
|
||||||
|
const nCenters = Object.keys(props.value["locations"]).length;
|
||||||
|
if (nCenters > 0) description = `${nCenters} locations`;
|
||||||
|
|
||||||
|
const shouldDisableMaxCap =
|
||||||
|
props.value["minimum capacity (tonne)"] ===
|
||||||
|
props.value["maximum capacity (tonne)"];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Section title={props.name} />
|
||||||
|
<Card>
|
||||||
|
<Form>
|
||||||
|
<h1>General information</h1>
|
||||||
|
<FileInputRow
|
||||||
|
label="Candidate locations"
|
||||||
|
tooltip="A table describing potential locations where plants can be built and their characteristics."
|
||||||
|
onTemplate={onCandidateLocationsTemplate}
|
||||||
|
onFile={onCandidateLocationsFile}
|
||||||
|
onDownload={onCandidateLocationsDownload}
|
||||||
|
onClear={onCandidateLocationsClear}
|
||||||
|
value={description}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<h1>Inputs & Outputs</h1>
|
||||||
|
<TextInputRow
|
||||||
|
label="Input"
|
||||||
|
tooltip="The name of the product that this plant takes as input."
|
||||||
|
disabled="disabled"
|
||||||
|
value={props.value["input"]}
|
||||||
|
/>
|
||||||
|
<DictInputRow
|
||||||
|
label="Outputs"
|
||||||
|
unit="tonne/tonne"
|
||||||
|
tooltip="A dictionary specifying how many tonnes of each product is produced for each tonne of input."
|
||||||
|
value={props.value["outputs (tonne/tonne)"]}
|
||||||
|
onChange={(v) => onChange(v, "outputs (tonne/tonne)")}
|
||||||
|
disableKeys={true}
|
||||||
|
validate="float"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<h1>Capacity & Costs</h1>
|
||||||
|
<TextInputRow
|
||||||
|
label="Minimum capacity"
|
||||||
|
unit="tonne"
|
||||||
|
tooltip="The minimum size of the plant."
|
||||||
|
value={props.value["minimum capacity (tonne)"]}
|
||||||
|
onChange={(v) => onChange(v, "minimum capacity (tonne)")}
|
||||||
|
validate="float"
|
||||||
|
/>
|
||||||
|
<TextInputRow
|
||||||
|
label="Opening cost (min capacity)"
|
||||||
|
unit="$"
|
||||||
|
tooltip="The cost to open the plant at minimum capacity."
|
||||||
|
value={props.value["opening cost (min capacity) ($)"]}
|
||||||
|
onChange={(v) => onChange(v, "opening cost (min capacity) ($)")}
|
||||||
|
validate="float"
|
||||||
|
/>
|
||||||
|
<TextInputRow
|
||||||
|
label="Fixed operating cost (min capacity)"
|
||||||
|
unit="$"
|
||||||
|
tooltip="The cost to keep the plant open, even if the plant doesn't process anything."
|
||||||
|
value={props.value["fixed operating cost (min capacity) ($)"]}
|
||||||
|
onChange={(v) =>
|
||||||
|
onChange(v, "fixed operating cost (min capacity) ($)")
|
||||||
|
}
|
||||||
|
validate="float"
|
||||||
|
/>
|
||||||
|
<TextInputRow
|
||||||
|
label="Maximum capacity"
|
||||||
|
unit="tonne"
|
||||||
|
tooltip="The maximum size of the plant."
|
||||||
|
value={props.value["maximum capacity (tonne)"]}
|
||||||
|
onChange={(v) => onChange(v, "maximum capacity (tonne)")}
|
||||||
|
validate="float"
|
||||||
|
/>
|
||||||
|
<TextInputRow
|
||||||
|
label="Opening cost (max capacity)"
|
||||||
|
unit="$"
|
||||||
|
tooltip="The cost to open a plant of this size."
|
||||||
|
value={
|
||||||
|
shouldDisableMaxCap
|
||||||
|
? ""
|
||||||
|
: props.value["opening cost (max capacity) ($)"]
|
||||||
|
}
|
||||||
|
onChange={(v) => onChange(v, "opening cost (max capacity) ($)")}
|
||||||
|
validate="float"
|
||||||
|
disabled={shouldDisableMaxCap}
|
||||||
|
/>
|
||||||
|
<TextInputRow
|
||||||
|
label="Fixed operating cost (max capacity)"
|
||||||
|
unit="$"
|
||||||
|
tooltip="The cost to keep the plant open, even if the plant doesn't process anything."
|
||||||
|
value={
|
||||||
|
shouldDisableMaxCap
|
||||||
|
? ""
|
||||||
|
: props.value["fixed operating cost (max capacity) ($)"]
|
||||||
|
}
|
||||||
|
onChange={(v) =>
|
||||||
|
onChange(v, "fixed operating cost (max capacity) ($)")
|
||||||
|
}
|
||||||
|
validate="float"
|
||||||
|
disabled={shouldDisableMaxCap}
|
||||||
|
/>
|
||||||
|
<TextInputRow
|
||||||
|
label="Variable operating cost"
|
||||||
|
unit="$/tonne"
|
||||||
|
tooltip="The cost that the plant incurs to process each tonne of input."
|
||||||
|
value={props.value["variable operating cost ($/tonne)"]}
|
||||||
|
onChange={(v) => onChange(v, "variable operating cost ($/tonne)")}
|
||||||
|
validate="float"
|
||||||
|
/>
|
||||||
|
<TextInputRow
|
||||||
|
label="Energy expenditure"
|
||||||
|
unit="GJ/tonne"
|
||||||
|
tooltip="The energy required to process one tonne of the input."
|
||||||
|
value={props.value["energy (GJ/tonne)"]}
|
||||||
|
onChange={(v) => onChange(v, "energy (GJ/tonne)")}
|
||||||
|
validate="float"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<h1>Storage</h1>
|
||||||
|
<TextInputRow
|
||||||
|
label="Storage cost"
|
||||||
|
unit="$/tonne"
|
||||||
|
tooltip="The cost to store a tonne of input product for one time period."
|
||||||
|
value={props.value["storage"]["cost ($/tonne)"]}
|
||||||
|
onChange={(v) => onChange(v, "storage", "cost ($/tonne)")}
|
||||||
|
validate="float"
|
||||||
|
/>
|
||||||
|
<TextInputRow
|
||||||
|
label="Storage limit"
|
||||||
|
unit="tonne"
|
||||||
|
tooltip="The maximum amount of input product this plant can have in storage at any given time."
|
||||||
|
value={props.value["storage"]["limit (tonne)"]}
|
||||||
|
onChange={(v) => onChange(v, "storage", "limit (tonne)")}
|
||||||
|
validate="float"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<h1>Disposal</h1>
|
||||||
|
<DictInputRow
|
||||||
|
label="Disposal cost"
|
||||||
|
unit="$/tonne"
|
||||||
|
tooltip="The cost to dispose of the product."
|
||||||
|
value={props.value["disposal cost ($/tonne)"]}
|
||||||
|
onChange={(v) => onChange(v, "disposal cost ($/tonne)")}
|
||||||
|
disableKeys={true}
|
||||||
|
validate="float"
|
||||||
|
/>
|
||||||
|
<DictInputRow
|
||||||
|
label="Disposal limit"
|
||||||
|
unit="tonne"
|
||||||
|
tooltip="The maximum amount that can be disposed of. If an unlimited amount can be disposed, leave blank."
|
||||||
|
value={props.value["disposal limit (tonne)"]}
|
||||||
|
onChange={(v) => onChange(v, "disposal limit (tonne)")}
|
||||||
|
disableKeys={true}
|
||||||
|
valuePlaceholder="Unlimited"
|
||||||
|
validate="float"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<h1>Emissions</h1>
|
||||||
|
<DictInputRow
|
||||||
|
label="Emissions"
|
||||||
|
unit="tonne/tonne"
|
||||||
|
tooltip="A dictionary mapping the name of each greenhouse gas, produced to process each tonne of input, to the amount of gas produced (in tonne)."
|
||||||
|
value={props.value["emissions (tonne/tonne)"]}
|
||||||
|
onChange={(v) => onChange(v, "emissions (tonne/tonne)")}
|
||||||
|
keyPlaceholder="Emission name"
|
||||||
|
valuePlaceholder="0"
|
||||||
|
validate="float"
|
||||||
|
/>
|
||||||
|
</Form>
|
||||||
|
</Card>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default PlantBlock;
|
||||||
187
relog-web/src/casebuilder/ProductBlock.js
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
import Section from "../common/Section";
|
||||||
|
import Card from "../common/Card";
|
||||||
|
import Form from "../common/Form";
|
||||||
|
import TextInputRow from "../common/TextInputRow";
|
||||||
|
import FileInputRow from "../common/FileInputRow";
|
||||||
|
import DictInputRow from "../common/DictInputRow";
|
||||||
|
import { csvParse, extractNumericColumns, generateFile } from "./csv";
|
||||||
|
import { csvFormat } from "d3";
|
||||||
|
|
||||||
|
const ProductBlock = (props) => {
|
||||||
|
const onChange = (field, val) => {
|
||||||
|
const newProduct = { ...props.value };
|
||||||
|
newProduct[field] = val;
|
||||||
|
props.onChange(newProduct);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onInitialAmountsFile = (contents) => {
|
||||||
|
const data = csvParse({
|
||||||
|
contents: contents,
|
||||||
|
requiredCols: ["latitude (deg)", "longitude (deg)", "name"],
|
||||||
|
});
|
||||||
|
const result = {};
|
||||||
|
data.forEach((el) => {
|
||||||
|
result[el["name"]] = {
|
||||||
|
"latitude (deg)": el["latitude (deg)"],
|
||||||
|
"longitude (deg)": el["longitude (deg)"],
|
||||||
|
"amount (tonne)": extractNumericColumns(el, "amount"),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
onChange("initial amounts", result);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onInitialAmountsClear = () => {
|
||||||
|
onChange("initial amounts", {});
|
||||||
|
};
|
||||||
|
|
||||||
|
const onInitialAmountsTemplate = () => {
|
||||||
|
generateFile(
|
||||||
|
"Initial amounts - Template.csv",
|
||||||
|
csvFormat([
|
||||||
|
{
|
||||||
|
name: "Washakie County",
|
||||||
|
"latitude (deg)": "43.8356",
|
||||||
|
"longitude (deg)": "-107.6602",
|
||||||
|
"amount 1": "21902",
|
||||||
|
"amount 2": "6160",
|
||||||
|
"amount 3": "2721",
|
||||||
|
"amount 4": "12917",
|
||||||
|
"amount 5": "18048",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Platte County",
|
||||||
|
"latitude (deg)": "42.1314",
|
||||||
|
"longitude (deg)": "-104.9676",
|
||||||
|
"amount 1": "16723",
|
||||||
|
"amount 2": "8709",
|
||||||
|
"amount 3": "22584",
|
||||||
|
"amount 4": "12278",
|
||||||
|
"amount 5": "7196",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Park County",
|
||||||
|
"latitude (deg)": "44.4063",
|
||||||
|
"longitude (deg)": "-109.4153",
|
||||||
|
"amount 1": "14731",
|
||||||
|
"amount 2": "11729",
|
||||||
|
"amount 3": "15562",
|
||||||
|
"amount 4": "7703",
|
||||||
|
"amount 5": "23349",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onInitialAmountsDownload = () => {
|
||||||
|
const results = [];
|
||||||
|
for (const [locationName, locationDict] of Object.entries(
|
||||||
|
props.value["initial amounts"]
|
||||||
|
)) {
|
||||||
|
const row = {
|
||||||
|
name: locationName,
|
||||||
|
"latitude (deg)": locationDict["latitude (deg)"],
|
||||||
|
"longitude (deg)": locationDict["longitude (deg)"],
|
||||||
|
};
|
||||||
|
locationDict["amount (tonne)"].forEach((el, idx) => {
|
||||||
|
row[`amount ${idx + 1}`] = el;
|
||||||
|
});
|
||||||
|
results.push(row);
|
||||||
|
}
|
||||||
|
generateFile(`Initial amounts - ${props.name}.csv`, csvFormat(results));
|
||||||
|
};
|
||||||
|
|
||||||
|
let description = "Not initially available";
|
||||||
|
let notInitiallyAvailable = true;
|
||||||
|
const nCenters = Object.keys(props.value["initial amounts"]).length;
|
||||||
|
if (nCenters > 0) {
|
||||||
|
description = `${nCenters} collection centers`;
|
||||||
|
notInitiallyAvailable = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Section title={props.name} />
|
||||||
|
<Card>
|
||||||
|
<Form>
|
||||||
|
<h1>General Information</h1>
|
||||||
|
<FileInputRow
|
||||||
|
value={description}
|
||||||
|
label="Initial amounts"
|
||||||
|
tooltip="A table indicating the amount of this product initially available at each collection center."
|
||||||
|
accept=".csv"
|
||||||
|
onFile={onInitialAmountsFile}
|
||||||
|
onDownload={onInitialAmountsDownload}
|
||||||
|
onClear={onInitialAmountsClear}
|
||||||
|
onTemplate={onInitialAmountsTemplate}
|
||||||
|
disableDownload={notInitiallyAvailable}
|
||||||
|
disableClear={notInitiallyAvailable}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<h1 style={{ display: nCenters == 0 ? "none" : "block" }}>
|
||||||
|
Disposal
|
||||||
|
</h1>
|
||||||
|
<div style={{ display: nCenters == 0 ? "none" : "block" }}>
|
||||||
|
<TextInputRow
|
||||||
|
label="Disposal cost"
|
||||||
|
unit="$/tonne"
|
||||||
|
tooltip="The cost to dispose of one tonne of this product at a collection center, without further processing."
|
||||||
|
value={props.value["disposal cost ($/tonne)"]}
|
||||||
|
onChange={(v) => onChange("disposal cost ($/tonne)", v)}
|
||||||
|
validate="floatList"
|
||||||
|
/>
|
||||||
|
<TextInputRow
|
||||||
|
label="Disposal limit"
|
||||||
|
unit="tonne"
|
||||||
|
tooltip="The maximum amount (in tonnes) of this product that can be disposed of across all collection centers, without further processing."
|
||||||
|
value={props.value["disposal limit (tonne)"]}
|
||||||
|
onChange={(v) => onChange("disposal limit (tonne)", v)}
|
||||||
|
validate="floatList"
|
||||||
|
disabled={String(props.value["disposal limit (%)"]).length > 0}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TextInputRow
|
||||||
|
label="Disposal limit"
|
||||||
|
unit="%"
|
||||||
|
tooltip="The maximum amount of this product that can be disposed of across all collection centers, without further processing, as a percentage of the total amount available."
|
||||||
|
value={props.value["disposal limit (%)"]}
|
||||||
|
onChange={(v) => onChange("disposal limit (%)", v)}
|
||||||
|
validate="floatList"
|
||||||
|
disabled={props.value["disposal limit (tonne)"].length > 0}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h1>Transportation</h1>
|
||||||
|
<TextInputRow
|
||||||
|
label="Transportation cost"
|
||||||
|
unit="$/km/tonne"
|
||||||
|
tooltip="The cost to transport this product."
|
||||||
|
value={props.value["transportation cost ($/km/tonne)"]}
|
||||||
|
onChange={(v) => onChange("transportation cost ($/km/tonne)", v)}
|
||||||
|
validate="floatList"
|
||||||
|
/>
|
||||||
|
<TextInputRow
|
||||||
|
label="Transportation energy"
|
||||||
|
unit="J/km/tonne"
|
||||||
|
tooltip="The energy required to transport this product."
|
||||||
|
value={props.value["transportation energy (J/km/tonne)"]}
|
||||||
|
onChange={(v) => onChange("transportation energy (J/km/tonne)", v)}
|
||||||
|
validate="floatList"
|
||||||
|
/>
|
||||||
|
<DictInputRow
|
||||||
|
label="Transportation emissions"
|
||||||
|
unit="tonne/km/tonne"
|
||||||
|
tooltip="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."
|
||||||
|
keyPlaceholder="Emission name"
|
||||||
|
value={props.value["transportation emissions (tonne/km/tonne)"]}
|
||||||
|
onChange={(v) =>
|
||||||
|
onChange("transportation emissions (tonne/km/tonne)", v)
|
||||||
|
}
|
||||||
|
validate="floatList"
|
||||||
|
/>
|
||||||
|
</Form>
|
||||||
|
</Card>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ProductBlock;
|
||||||
50
relog-web/src/casebuilder/csv.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import * as d3 from "d3";
|
||||||
|
|
||||||
|
export const csvParse = ({ contents, requiredCols }) => {
|
||||||
|
const data = d3.csvParse(contents, d3.autoType);
|
||||||
|
requiredCols.forEach((col) => {
|
||||||
|
if (!(col in data[0])) {
|
||||||
|
throw Error(`Column "${col}" not found in CSV file.`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const parseCsv = (contents, requiredCols = []) => {
|
||||||
|
const data = d3.csvParse(contents);
|
||||||
|
const T = data.columns.length - requiredCols.length;
|
||||||
|
let isValid = true;
|
||||||
|
for (let t = 0; t < T; t++) {
|
||||||
|
requiredCols.push(t + 1);
|
||||||
|
}
|
||||||
|
requiredCols.forEach((col) => {
|
||||||
|
if (!(col in data[0])) {
|
||||||
|
console.log(`Column "${col}" not found in CSV file.`);
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (!isValid) return [undefined, undefined];
|
||||||
|
return [data, T];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const extractNumericColumns = (obj, prefix) => {
|
||||||
|
const result = [];
|
||||||
|
for (let i = 1; `${prefix} ${i}` in obj; i++) {
|
||||||
|
result.push(obj[`${prefix} ${i}`]);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const csvFormat = (data) => {
|
||||||
|
return d3.csvFormat(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const generateFile = (filename, contents) => {
|
||||||
|
var link = document.createElement("a");
|
||||||
|
link.setAttribute("href", URL.createObjectURL(new Blob([contents])));
|
||||||
|
link.setAttribute("download", filename);
|
||||||
|
link.style.visibility = "hidden";
|
||||||
|
document.body.appendChild(link);
|
||||||
|
link.click();
|
||||||
|
document.body.removeChild(link);
|
||||||
|
};
|
||||||
53
relog-web/src/casebuilder/csv.test.js
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import { csvParse, extractNumericColumns, csvFormat } from "./csv";
|
||||||
|
import { exportValue } from "./export";
|
||||||
|
|
||||||
|
test("parse CSV", () => {
|
||||||
|
const contents = "name,location,1,2,3\ntest,illinois,100,200,300";
|
||||||
|
const actual = csvParse({
|
||||||
|
contents: contents,
|
||||||
|
requiredCols: ["name", "location"],
|
||||||
|
});
|
||||||
|
expect(actual.length).toEqual(1);
|
||||||
|
expect(actual[0]).toEqual({
|
||||||
|
name: "test",
|
||||||
|
location: "illinois",
|
||||||
|
1: 100,
|
||||||
|
2: 200,
|
||||||
|
3: 300,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("parse CSV with missing columns", () => {
|
||||||
|
const contents = "name,location,1,2,3\ntest,illinois,100,200,300";
|
||||||
|
expect(() =>
|
||||||
|
csvParse({
|
||||||
|
contents: contents,
|
||||||
|
requiredCols: ["name", "location", "latitude"],
|
||||||
|
})
|
||||||
|
).toThrow('Column "latitude" not found in CSV file.');
|
||||||
|
});
|
||||||
|
|
||||||
|
test("extract numeric columns from object", () => {
|
||||||
|
const obj1 = {
|
||||||
|
"amount 1": "hello",
|
||||||
|
"amount 2": "world",
|
||||||
|
"amount 4": "ignored",
|
||||||
|
};
|
||||||
|
const obj2 = { hello: "world" };
|
||||||
|
expect(extractNumericColumns(obj1, "amount")).toEqual(["hello", "world"]);
|
||||||
|
expect(extractNumericColumns(obj2, "amount")).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("generate CSV", () => {
|
||||||
|
const data = [
|
||||||
|
{ name: "alice", age: 20 },
|
||||||
|
{ name: "bob", age: null },
|
||||||
|
];
|
||||||
|
expect(csvFormat(data)).toEqual("name,age\nalice,20\nbob,");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("export value", () => {
|
||||||
|
expect(exportValue("1")).toEqual(1);
|
||||||
|
expect(exportValue("[1,2,3]")).toEqual([1, 2, 3]);
|
||||||
|
expect(exportValue("qwe")).toEqual("qwe");
|
||||||
|
});
|
||||||
49
relog-web/src/casebuilder/defaults.js
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
export const defaultProduct = {
|
||||||
|
"initial amounts": {},
|
||||||
|
"disposal cost ($/tonne)": "0",
|
||||||
|
"disposal limit (tonne)": "0",
|
||||||
|
"disposal limit (%)": "",
|
||||||
|
"transportation cost ($/km/tonne)": "0",
|
||||||
|
"transportation energy (J/km/tonne)": "0",
|
||||||
|
"transportation emissions (tonne/km/tonne)": {},
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const defaultPlantLocation = {
|
||||||
|
"area cost factor": 1.0,
|
||||||
|
"latitude (deg)": 0,
|
||||||
|
"longitude (deg)": 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const defaultPlant = {
|
||||||
|
locations: {},
|
||||||
|
"outputs (tonne/tonne)": {},
|
||||||
|
"disposal cost ($/tonne)": {},
|
||||||
|
"disposal limit (tonne)": {},
|
||||||
|
"emissions (tonne/tonne)": {},
|
||||||
|
storage: {
|
||||||
|
"cost ($/tonne)": 0,
|
||||||
|
"limit (tonne)": 0,
|
||||||
|
},
|
||||||
|
"maximum capacity (tonne)": 0,
|
||||||
|
"minimum capacity (tonne)": 0,
|
||||||
|
"opening cost (max capacity) ($)": 0,
|
||||||
|
"opening cost (min capacity) ($)": 0,
|
||||||
|
"fixed operating cost (max capacity) ($)": 0,
|
||||||
|
"fixed operating cost (min capacity) ($)": 0,
|
||||||
|
"variable operating cost ($/tonne)": 0,
|
||||||
|
"energy (GJ/tonne)": 0,
|
||||||
|
x: 0,
|
||||||
|
y: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const defaultData = {
|
||||||
|
parameters: {
|
||||||
|
"time horizon (years)": "1",
|
||||||
|
"building period (years)": "[1]",
|
||||||
|
"inflation rate (%)": "0",
|
||||||
|
},
|
||||||
|
products: {},
|
||||||
|
plants: {},
|
||||||
|
};
|
||||||
555
relog-web/src/casebuilder/export.js
Normal file
@@ -0,0 +1,555 @@
|
|||||||
|
const isNumeric = (val) => {
|
||||||
|
return String(val).length > 0 && !isNaN(val);
|
||||||
|
};
|
||||||
|
|
||||||
|
const keysToList = (obj) => {
|
||||||
|
const result = [];
|
||||||
|
for (const key of Object.keys(obj)) {
|
||||||
|
result.push(key);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const exportValue = (original, T, R = 1) => {
|
||||||
|
if (isNumeric(original)) {
|
||||||
|
if (T) {
|
||||||
|
let v = parseFloat(original);
|
||||||
|
const result = [];
|
||||||
|
for (let i = 0; i < T; i++) {
|
||||||
|
result.push(v);
|
||||||
|
v *= R;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
return parseFloat(original);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(original);
|
||||||
|
return parsed;
|
||||||
|
} catch {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
return original;
|
||||||
|
};
|
||||||
|
|
||||||
|
const exportValueDict = (original, T) => {
|
||||||
|
const result = {};
|
||||||
|
for (const [key, val] of Object.entries(original)) {
|
||||||
|
if (key.length === 0) continue;
|
||||||
|
result[key] = exportValue(val, T);
|
||||||
|
}
|
||||||
|
if (Object.keys(result).length > 0) {
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const computeTotalInitialAmount = (prod) => {
|
||||||
|
let total = null;
|
||||||
|
for (const locDict of Object.values(prod["initial amounts"])) {
|
||||||
|
const locAmount = locDict["amount (tonne)"];
|
||||||
|
if (!total) total = [...locAmount];
|
||||||
|
else {
|
||||||
|
for (let i = 0; i < locAmount.length; i++) {
|
||||||
|
total[i] += locAmount[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const importList = (args, R = 1) => {
|
||||||
|
if (args === undefined) return "";
|
||||||
|
if (Array.isArray(args) && args.length > 0) {
|
||||||
|
let isConstant = true;
|
||||||
|
for (let i = 1; i < args.length; i++) {
|
||||||
|
if (Math.abs(args[i - 1] - args[i] / R) > 1e-3) {
|
||||||
|
isConstant = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isConstant) {
|
||||||
|
return String(args[0]);
|
||||||
|
} else {
|
||||||
|
return JSON.stringify(args);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const importDict = (args) => {
|
||||||
|
if (!args) return {};
|
||||||
|
const result = {};
|
||||||
|
for (const [key, val] of Object.entries(args)) {
|
||||||
|
result[key] = importList(val);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const computeAbsDisposal = (prod) => {
|
||||||
|
const disposalPerc = prod["disposal limit (%)"];
|
||||||
|
const total = computeTotalInitialAmount(prod);
|
||||||
|
const disposalAbs = [];
|
||||||
|
for (let i = 0; i < total.length; i++) {
|
||||||
|
disposalAbs[i] = (total[i] * disposalPerc) / 100;
|
||||||
|
}
|
||||||
|
return disposalAbs;
|
||||||
|
};
|
||||||
|
|
||||||
|
const computeInflationAndTimeHorizon = (obj, keys) => {
|
||||||
|
for (let i = 0; i < keys.length; i++) {
|
||||||
|
const list = obj[keys[i]];
|
||||||
|
if (
|
||||||
|
Array.isArray(list) &&
|
||||||
|
list.length > 1 &&
|
||||||
|
isNumeric(list[0]) &&
|
||||||
|
isNumeric(list[1]) &&
|
||||||
|
Math.abs(list[0]) > 0
|
||||||
|
) {
|
||||||
|
return [list[1] / list[0], list.length];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return [1, 1];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const exportProduct = (original, parameters) => {
|
||||||
|
const result = {};
|
||||||
|
|
||||||
|
// Read time horizon
|
||||||
|
let T = parameters["time horizon (years)"];
|
||||||
|
if (isNumeric(T)) T = parseInt(T);
|
||||||
|
else T = 1;
|
||||||
|
|
||||||
|
// Read inflation
|
||||||
|
let R = parameters["inflation rate (%)"];
|
||||||
|
if (isNumeric(R)) R = parseFloat(R) / 100 + 1;
|
||||||
|
else R = 1;
|
||||||
|
|
||||||
|
// Copy constant time series
|
||||||
|
result["initial amounts"] = original["initial amounts"];
|
||||||
|
["disposal limit (tonne)", "transportation energy (J/km/tonne)"].forEach(
|
||||||
|
(key) => {
|
||||||
|
const v = exportValue(original[key], T);
|
||||||
|
if (v.length > 0) result[key] = v;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Copy cost time series (with inflation)
|
||||||
|
["disposal cost ($/tonne)", "transportation cost ($/km/tonne)"].forEach(
|
||||||
|
(key) => {
|
||||||
|
const v = exportValue(original[key], T, R);
|
||||||
|
if (v.length > 0) result[key] = v;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Copy dictionaries
|
||||||
|
["transportation emissions (tonne/km/tonne)"].forEach((key) => {
|
||||||
|
const v = exportValueDict(original[key], T);
|
||||||
|
if (v) result[key] = v;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Transform percentage disposal limits into absolute
|
||||||
|
if (isNumeric(original["disposal limit (%)"])) {
|
||||||
|
result["disposal limit (tonne)"] = computeAbsDisposal(original);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const exportPlant = (original, parameters) => {
|
||||||
|
const result = {};
|
||||||
|
|
||||||
|
// Read time horizon
|
||||||
|
let T = parameters["time horizon (years)"];
|
||||||
|
if (isNumeric(T)) T = parseInt(T);
|
||||||
|
else T = 1;
|
||||||
|
|
||||||
|
// Read inflation
|
||||||
|
let R = parameters["inflation rate (%)"];
|
||||||
|
if (isNumeric(R)) R = parseFloat(R) / 100 + 1;
|
||||||
|
else R = 1;
|
||||||
|
|
||||||
|
// Copy scalar values
|
||||||
|
["input"].forEach((key) => {
|
||||||
|
result[key] = original[key];
|
||||||
|
});
|
||||||
|
|
||||||
|
// Copy time series values
|
||||||
|
["energy (GJ/tonne)"].forEach((key) => {
|
||||||
|
result[key] = exportValue(original[key], T);
|
||||||
|
if (result[key] === undefined) {
|
||||||
|
delete result[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Copy scalar dicts
|
||||||
|
["outputs (tonne/tonne)"].forEach((key) => {
|
||||||
|
const v = exportValueDict(original[key]);
|
||||||
|
if (v) result[key] = v;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Copy time series dicts
|
||||||
|
["emissions (tonne/tonne)"].forEach((key) => {
|
||||||
|
const v = exportValueDict(original[key], T);
|
||||||
|
if (v) result[key] = v;
|
||||||
|
});
|
||||||
|
|
||||||
|
const minCap = original["minimum capacity (tonne)"];
|
||||||
|
const maxCap = original["maximum capacity (tonne)"];
|
||||||
|
|
||||||
|
result.locations = {};
|
||||||
|
for (const [locName, origDict] of Object.entries(original["locations"])) {
|
||||||
|
const resDict = (result.locations[locName] = {});
|
||||||
|
const capDict = (resDict["capacities (tonne)"] = {});
|
||||||
|
|
||||||
|
const acf = origDict["area cost factor"];
|
||||||
|
|
||||||
|
const exportValueAcf = (obj) => {
|
||||||
|
const v = exportValue(obj, T, R);
|
||||||
|
if (Array.isArray(v)) {
|
||||||
|
return v.map((v) => v * acf);
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
};
|
||||||
|
|
||||||
|
// Copy scalar values
|
||||||
|
["latitude (deg)", "longitude (deg)"].forEach((key) => {
|
||||||
|
resDict[key] = origDict[key];
|
||||||
|
});
|
||||||
|
|
||||||
|
// Copy minimum capacity dict
|
||||||
|
capDict[minCap] = {};
|
||||||
|
for (const [resKeyName, origKeyName] of Object.entries({
|
||||||
|
"opening cost ($)": "opening cost (min capacity) ($)",
|
||||||
|
"fixed operating cost ($)": "fixed operating cost (min capacity) ($)",
|
||||||
|
"variable operating cost ($/tonne)": "variable operating cost ($/tonne)",
|
||||||
|
})) {
|
||||||
|
capDict[minCap][resKeyName] = exportValueAcf(original[origKeyName]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxCap !== minCap) {
|
||||||
|
// Copy maximum capacity dict
|
||||||
|
capDict[maxCap] = {};
|
||||||
|
for (const [resKeyName, origKeyName] of Object.entries({
|
||||||
|
"opening cost ($)": "opening cost (max capacity) ($)",
|
||||||
|
"fixed operating cost ($)": "fixed operating cost (max capacity) ($)",
|
||||||
|
"variable operating cost ($/tonne)":
|
||||||
|
"variable operating cost ($/tonne)",
|
||||||
|
})) {
|
||||||
|
capDict[maxCap][resKeyName] = exportValueAcf(original[origKeyName]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy disposal
|
||||||
|
resDict.disposal = {};
|
||||||
|
for (const [dispName, dispCost] of Object.entries(
|
||||||
|
original["disposal cost ($/tonne)"]
|
||||||
|
)) {
|
||||||
|
if (dispName.length === 0) continue;
|
||||||
|
const v = exportValueAcf(dispCost, T);
|
||||||
|
if (v) {
|
||||||
|
resDict.disposal[dispName] = { "cost ($/tonne)": v };
|
||||||
|
const limit = original["disposal limit (tonne)"][dispName];
|
||||||
|
if (isNumeric(limit)) {
|
||||||
|
resDict.disposal[dispName]["limit (tonne)"] = exportValue(limit, T);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Copy storage
|
||||||
|
resDict.storage = {
|
||||||
|
"cost ($/tonne)": exportValueAcf(original["storage"]["cost ($/tonne)"]),
|
||||||
|
};
|
||||||
|
const storLimit = original["storage"]["limit (tonne)"];
|
||||||
|
if (isNumeric(storLimit)) {
|
||||||
|
resDict.storage["limit (tonne)"] = exportValue(storLimit);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const exportData = (original) => {
|
||||||
|
const result = {
|
||||||
|
parameters: {},
|
||||||
|
products: {},
|
||||||
|
plants: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Export parameters
|
||||||
|
["time horizon (years)", "building period (years)"].forEach((key) => {
|
||||||
|
result.parameters[key] = exportValue(original.parameters[key]);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Read time horizon
|
||||||
|
let T = result.parameters["time horizon (years)"];
|
||||||
|
if (!isNumeric(T)) T = 1;
|
||||||
|
|
||||||
|
// Export products
|
||||||
|
for (const [prodName, prodDict] of Object.entries(original.products)) {
|
||||||
|
result.products[prodName] = exportProduct(prodDict, original.parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export plants
|
||||||
|
for (const [plantName, plantDict] of Object.entries(original.plants)) {
|
||||||
|
result.plants[plantName] = exportPlant(plantDict, original.parameters);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const compressDisposalLimits = (original, result) => {
|
||||||
|
if (!("disposal limit (tonne)" in original)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const total = computeTotalInitialAmount(original);
|
||||||
|
if (!total) return;
|
||||||
|
const limit = original["disposal limit (tonne)"];
|
||||||
|
let perc = Math.round((limit[0] / total[0]) * 1e6) / 1e6;
|
||||||
|
for (let i = 1; i < limit.length; i++) {
|
||||||
|
if (Math.abs(limit[i] / total[i] - perc) > 1e-5) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result["disposal limit (tonne)"] = "";
|
||||||
|
result["disposal limit (%)"] = String(perc * 100);
|
||||||
|
};
|
||||||
|
|
||||||
|
export const importProduct = (original) => {
|
||||||
|
const prod = {};
|
||||||
|
const parameters = {};
|
||||||
|
|
||||||
|
prod["initial amounts"] = { ...original["initial amounts"] };
|
||||||
|
|
||||||
|
// Initialize null values
|
||||||
|
["x", "y"].forEach((key) => {
|
||||||
|
prod[key] = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initialize empty values
|
||||||
|
["disposal limit (%)"].forEach((key) => {
|
||||||
|
prod[key] = "";
|
||||||
|
});
|
||||||
|
|
||||||
|
// Import constant lists
|
||||||
|
["transportation energy (J/km/tonne)", "disposal limit (tonne)"].forEach(
|
||||||
|
(key) => {
|
||||||
|
prod[key] = importList(original[key]);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Compute inflation and time horizon
|
||||||
|
const [R, T] = computeInflationAndTimeHorizon(original, [
|
||||||
|
"transportation cost ($/km/tonne)",
|
||||||
|
"disposal cost ($/tonne)",
|
||||||
|
]);
|
||||||
|
parameters["inflation rate (%)"] = String((R - 1) * 100);
|
||||||
|
parameters["time horizon (years)"] = String(T);
|
||||||
|
|
||||||
|
// Import cost lists
|
||||||
|
["transportation cost ($/km/tonne)", "disposal cost ($/tonne)"].forEach(
|
||||||
|
(key) => {
|
||||||
|
prod[key] = importList(original[key], R);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// Import dicts
|
||||||
|
["transportation emissions (tonne/km/tonne)"].forEach((key) => {
|
||||||
|
prod[key] = importDict(original[key]);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Attempt to convert absolute disposal limits to relative
|
||||||
|
compressDisposalLimits(original, prod);
|
||||||
|
|
||||||
|
return [prod, parameters];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const importPlant = (original) => {
|
||||||
|
const plant = {};
|
||||||
|
const parameters = {};
|
||||||
|
|
||||||
|
plant["storage"] = {};
|
||||||
|
plant["storage"]["cost ($/tonne)"] = 0;
|
||||||
|
plant["storage"]["limit (tonne)"] = 0;
|
||||||
|
plant["disposal cost ($/tonne)"] = 0;
|
||||||
|
plant["disposal limit (tonne)"] = 0;
|
||||||
|
|
||||||
|
// Initialize null values
|
||||||
|
["x", "y"].forEach((key) => {
|
||||||
|
plant[key] = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Import scalar values
|
||||||
|
["input"].forEach((key) => {
|
||||||
|
plant[key] = original[key];
|
||||||
|
});
|
||||||
|
|
||||||
|
// Import timeseries values
|
||||||
|
["energy (GJ/tonne)"].forEach((key) => {
|
||||||
|
plant[key] = importList(original[key]);
|
||||||
|
if (plant[key] === "") {
|
||||||
|
delete plant[key];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Import dicts
|
||||||
|
["outputs (tonne/tonne)", "emissions (tonne/tonne)"].forEach((key) => {
|
||||||
|
plant[key] = importDict(original[key]);
|
||||||
|
});
|
||||||
|
|
||||||
|
let costsInitialized = false;
|
||||||
|
let R = null;
|
||||||
|
|
||||||
|
// Read locations
|
||||||
|
const resLocDict = (plant.locations = {});
|
||||||
|
for (const [locName, origLocDict] of Object.entries(original["locations"])) {
|
||||||
|
resLocDict[locName] = {};
|
||||||
|
|
||||||
|
// Import latitude and longitude
|
||||||
|
["latitude (deg)", "longitude (deg)"].forEach((key) => {
|
||||||
|
resLocDict[locName][key] = origLocDict[key];
|
||||||
|
});
|
||||||
|
|
||||||
|
const capacities = keysToList(origLocDict["capacities (tonne)"]);
|
||||||
|
const last = capacities.length - 1;
|
||||||
|
const minCap = capacities[0];
|
||||||
|
const maxCap = capacities[last];
|
||||||
|
const minCapDict = origLocDict["capacities (tonne)"][minCap];
|
||||||
|
const maxCapDict = origLocDict["capacities (tonne)"][maxCap];
|
||||||
|
|
||||||
|
// Import min/max capacity
|
||||||
|
if ("minimum capacity (tonne)" in plant) {
|
||||||
|
if (
|
||||||
|
plant["minimum capacity (tonne)"] !== minCap ||
|
||||||
|
plant["maximum capacity (tonne)"] !== maxCap
|
||||||
|
) {
|
||||||
|
throw "Data loss";
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
plant["minimum capacity (tonne)"] = minCap;
|
||||||
|
plant["maximum capacity (tonne)"] = maxCap;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compute area cost factor
|
||||||
|
let acf = 1;
|
||||||
|
if (costsInitialized) {
|
||||||
|
acf = plant["opening cost (max capacity) ($)"];
|
||||||
|
if (Array.isArray(acf)) acf = acf[0];
|
||||||
|
acf = maxCapDict["opening cost ($)"][0] / acf;
|
||||||
|
}
|
||||||
|
resLocDict[locName]["area cost factor"] = acf;
|
||||||
|
|
||||||
|
const [R, T] = computeInflationAndTimeHorizon(maxCapDict, [
|
||||||
|
"opening cost ($)",
|
||||||
|
"fixed operating cost ($)",
|
||||||
|
"variable operating cost ($/tonne)",
|
||||||
|
]);
|
||||||
|
parameters["inflation rate (%)"] = String((R - 1) * 100);
|
||||||
|
parameters["time horizon (years)"] = String(T);
|
||||||
|
|
||||||
|
// Read adjusted costs
|
||||||
|
const importListAcf = (obj) =>
|
||||||
|
importList(
|
||||||
|
obj.map((v) => v / acf),
|
||||||
|
R
|
||||||
|
);
|
||||||
|
const openCostMax = importListAcf(maxCapDict["opening cost ($)"]);
|
||||||
|
const openCostMin = importListAcf(minCapDict["opening cost ($)"]);
|
||||||
|
const fixCostMax = importListAcf(maxCapDict["fixed operating cost ($)"]);
|
||||||
|
const fixCostMin = importListAcf(minCapDict["fixed operating cost ($)"]);
|
||||||
|
const storCost = importListAcf(origLocDict.storage["cost ($/tonne)"]);
|
||||||
|
const storLimit = String(origLocDict.storage["limit (tonne)"]);
|
||||||
|
const varCost = importListAcf(
|
||||||
|
minCapDict["variable operating cost ($/tonne)"]
|
||||||
|
);
|
||||||
|
|
||||||
|
const dispCost = {};
|
||||||
|
const dispLimit = {};
|
||||||
|
for (const prodName of Object.keys(original["outputs (tonne/tonne)"])) {
|
||||||
|
dispCost[prodName] = "";
|
||||||
|
dispLimit[prodName] = "";
|
||||||
|
|
||||||
|
if (prodName in origLocDict["disposal"]) {
|
||||||
|
const prodDict = origLocDict["disposal"][prodName];
|
||||||
|
dispCost[prodName] = importListAcf(prodDict["cost ($/tonne)"]);
|
||||||
|
if ("limit (tonne)" in prodDict)
|
||||||
|
dispLimit[prodName] = importList(prodDict["limit (tonne)"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const check = (left, right) => {
|
||||||
|
let valid = true;
|
||||||
|
if (isNumeric(left) && isNumeric(right)) {
|
||||||
|
valid = Math.abs(left - right) < 1.0;
|
||||||
|
} else {
|
||||||
|
valid = left === right;
|
||||||
|
}
|
||||||
|
if (!valid)
|
||||||
|
console.warn(`Data loss detected: ${locName}, ${left} != ${right}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
if (costsInitialized) {
|
||||||
|
// Verify that location costs match the previously initialized ones
|
||||||
|
check(plant["opening cost (max capacity) ($)"], openCostMax);
|
||||||
|
check(plant["opening cost (min capacity) ($)"], openCostMin);
|
||||||
|
check(plant["fixed operating cost (max capacity) ($)"], fixCostMax);
|
||||||
|
check(plant["fixed operating cost (min capacity) ($)"], fixCostMin);
|
||||||
|
check(plant["variable operating cost ($/tonne)"], varCost);
|
||||||
|
check(plant["storage"]["cost ($/tonne)"], storCost);
|
||||||
|
check(plant["storage"]["limit (tonne)"], storLimit);
|
||||||
|
check(String(plant["disposal cost ($/tonne)"]), String(dispCost));
|
||||||
|
check(String(plant["disposal limit (tonne)"]), String(dispLimit));
|
||||||
|
} else {
|
||||||
|
// Initialize plant costs
|
||||||
|
costsInitialized = true;
|
||||||
|
plant["opening cost (max capacity) ($)"] = openCostMax;
|
||||||
|
plant["opening cost (min capacity) ($)"] = openCostMin;
|
||||||
|
plant["fixed operating cost (max capacity) ($)"] = fixCostMax;
|
||||||
|
plant["fixed operating cost (min capacity) ($)"] = fixCostMin;
|
||||||
|
plant["variable operating cost ($/tonne)"] = varCost;
|
||||||
|
plant["storage"] = {};
|
||||||
|
plant["storage"]["cost ($/tonne)"] = storCost;
|
||||||
|
plant["storage"]["limit (tonne)"] = storLimit;
|
||||||
|
plant["disposal cost ($/tonne)"] = dispCost;
|
||||||
|
plant["disposal limit (tonne)"] = dispLimit;
|
||||||
|
parameters["inflation rate (%)"] = String((R - 1) * 100);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return [plant, parameters];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const importData = (original) => {
|
||||||
|
["parameters", "plants", "products"].forEach((key) => {
|
||||||
|
if (!(key in original)) {
|
||||||
|
throw "File not recognized.";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = {};
|
||||||
|
result.parameters = importDict(original.parameters);
|
||||||
|
["building period (years)"].forEach((k) => {
|
||||||
|
result.parameters[k] = JSON.stringify(original.parameters[k]);
|
||||||
|
});
|
||||||
|
result.parameters["inflation rate (%)"] = "0";
|
||||||
|
|
||||||
|
// Import products
|
||||||
|
result.products = {};
|
||||||
|
for (const [prodName, origProdDict] of Object.entries(original.products)) {
|
||||||
|
const [recoveredProd, recoveredParams] = importProduct(origProdDict);
|
||||||
|
result.products[prodName] = recoveredProd;
|
||||||
|
result.parameters = { ...result.parameters, ...recoveredParams };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Import plants
|
||||||
|
result.plants = {};
|
||||||
|
for (const [plantName, origPlantDict] of Object.entries(original.plants)) {
|
||||||
|
const [recoveredPlant, recoveredParams] = importPlant(origPlantDict);
|
||||||
|
result.plants[plantName] = recoveredPlant;
|
||||||
|
result.parameters = { ...result.parameters, ...recoveredParams };
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
};
|
||||||
583
relog-web/src/casebuilder/export.test.js
Normal file
@@ -0,0 +1,583 @@
|
|||||||
|
import {
|
||||||
|
exportProduct,
|
||||||
|
exportPlant,
|
||||||
|
importProduct,
|
||||||
|
importList,
|
||||||
|
importDict,
|
||||||
|
importPlant,
|
||||||
|
} from "./export";
|
||||||
|
|
||||||
|
const sampleProductsOriginal = [
|
||||||
|
// basic product
|
||||||
|
{
|
||||||
|
"initial amounts": {
|
||||||
|
"Washakie County": {
|
||||||
|
"latitude (deg)": 43.8356,
|
||||||
|
"longitude (deg)": -107.6602,
|
||||||
|
"amount (tonne)": [100, 200, 300],
|
||||||
|
},
|
||||||
|
"Platte County": {
|
||||||
|
"latitude (deg)": 42.1314,
|
||||||
|
"longitude (deg)": -104.9676,
|
||||||
|
"amount (tonne)": [100, 200, 300],
|
||||||
|
},
|
||||||
|
"Park County": {
|
||||||
|
"latitude (deg)": 44.4063,
|
||||||
|
"longitude (deg)": -109.4153,
|
||||||
|
"amount (tonne)": [100, 200, 300],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"disposal cost ($/tonne)": "50",
|
||||||
|
"disposal limit (tonne)": "30",
|
||||||
|
"disposal limit (%)": "",
|
||||||
|
"transportation cost ($/km/tonne)": "0",
|
||||||
|
"transportation energy (J/km/tonne)": "10",
|
||||||
|
"transportation emissions (tonne/km/tonne)": {
|
||||||
|
CO2: "0.5",
|
||||||
|
},
|
||||||
|
x: null,
|
||||||
|
y: null,
|
||||||
|
},
|
||||||
|
// product with percentage disposal limit
|
||||||
|
{
|
||||||
|
"initial amounts": {
|
||||||
|
"Washakie County": {
|
||||||
|
"latitude (deg)": 43.8356,
|
||||||
|
"longitude (deg)": -107.6602,
|
||||||
|
"amount (tonne)": [100, 200, 300],
|
||||||
|
},
|
||||||
|
"Platte County": {
|
||||||
|
"latitude (deg)": 42.1314,
|
||||||
|
"longitude (deg)": -104.9676,
|
||||||
|
"amount (tonne)": [100, 200, 300],
|
||||||
|
},
|
||||||
|
"Park County": {
|
||||||
|
"latitude (deg)": 44.4063,
|
||||||
|
"longitude (deg)": -109.4153,
|
||||||
|
"amount (tonne)": [100, 200, 300],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"disposal cost ($/tonne)": "50",
|
||||||
|
"disposal limit (tonne)": "",
|
||||||
|
"disposal limit (%)": "10",
|
||||||
|
"transportation cost ($/km/tonne)": "5",
|
||||||
|
"transportation energy (J/km/tonne)": "10",
|
||||||
|
"transportation emissions (tonne/km/tonne)": {
|
||||||
|
CO2: "0.5",
|
||||||
|
},
|
||||||
|
x: null,
|
||||||
|
y: null,
|
||||||
|
},
|
||||||
|
// product using defaults
|
||||||
|
{
|
||||||
|
"initial amounts": {
|
||||||
|
"Washakie County": {
|
||||||
|
"latitude (deg)": 43.8356,
|
||||||
|
"longitude (deg)": -107.6602,
|
||||||
|
"amount (tonne)": [100, 200, 300],
|
||||||
|
},
|
||||||
|
"Platte County": {
|
||||||
|
"latitude (deg)": 42.1314,
|
||||||
|
"longitude (deg)": -104.9676,
|
||||||
|
"amount (tonne)": [100, 200, 300],
|
||||||
|
},
|
||||||
|
"Park County": {
|
||||||
|
"latitude (deg)": 44.4063,
|
||||||
|
"longitude (deg)": -109.4153,
|
||||||
|
"amount (tonne)": [100, 200, 300],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"disposal cost ($/tonne)": "50",
|
||||||
|
"disposal limit (tonne)": "",
|
||||||
|
"disposal limit (%)": "",
|
||||||
|
"transportation cost ($/km/tonne)": "5",
|
||||||
|
"transportation energy (J/km/tonne)": "",
|
||||||
|
"transportation emissions (tonne/km/tonne)": {},
|
||||||
|
x: null,
|
||||||
|
y: null,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const sampleProductsExported = [
|
||||||
|
// basic product
|
||||||
|
{
|
||||||
|
"initial amounts": {
|
||||||
|
"Washakie County": {
|
||||||
|
"latitude (deg)": 43.8356,
|
||||||
|
"longitude (deg)": -107.6602,
|
||||||
|
"amount (tonne)": [100, 200, 300],
|
||||||
|
},
|
||||||
|
"Platte County": {
|
||||||
|
"latitude (deg)": 42.1314,
|
||||||
|
"longitude (deg)": -104.9676,
|
||||||
|
"amount (tonne)": [100, 200, 300],
|
||||||
|
},
|
||||||
|
"Park County": {
|
||||||
|
"latitude (deg)": 44.4063,
|
||||||
|
"longitude (deg)": -109.4153,
|
||||||
|
"amount (tonne)": [100, 200, 300],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"disposal cost ($/tonne)": [50, 100, 200],
|
||||||
|
"disposal limit (tonne)": [30, 30, 30],
|
||||||
|
"transportation cost ($/km/tonne)": [0, 0, 0],
|
||||||
|
"transportation energy (J/km/tonne)": [10, 10, 10],
|
||||||
|
"transportation emissions (tonne/km/tonne)": {
|
||||||
|
CO2: [0.5, 0.5, 0.5],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// product with percentage disposal limit
|
||||||
|
{
|
||||||
|
"initial amounts": {
|
||||||
|
"Washakie County": {
|
||||||
|
"latitude (deg)": 43.8356,
|
||||||
|
"longitude (deg)": -107.6602,
|
||||||
|
"amount (tonne)": [100, 200, 300],
|
||||||
|
},
|
||||||
|
"Platte County": {
|
||||||
|
"latitude (deg)": 42.1314,
|
||||||
|
"longitude (deg)": -104.9676,
|
||||||
|
"amount (tonne)": [100, 200, 300],
|
||||||
|
},
|
||||||
|
"Park County": {
|
||||||
|
"latitude (deg)": 44.4063,
|
||||||
|
"longitude (deg)": -109.4153,
|
||||||
|
"amount (tonne)": [100, 200, 300],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"disposal cost ($/tonne)": [50, 50, 50],
|
||||||
|
"disposal limit (tonne)": [30, 60, 90],
|
||||||
|
"transportation cost ($/km/tonne)": [5, 5, 5],
|
||||||
|
"transportation energy (J/km/tonne)": [10, 10, 10],
|
||||||
|
"transportation emissions (tonne/km/tonne)": {
|
||||||
|
CO2: [0.5, 0.5, 0.5],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// product using defaults
|
||||||
|
{
|
||||||
|
"initial amounts": {
|
||||||
|
"Washakie County": {
|
||||||
|
"latitude (deg)": 43.8356,
|
||||||
|
"longitude (deg)": -107.6602,
|
||||||
|
"amount (tonne)": [100, 200, 300],
|
||||||
|
},
|
||||||
|
"Platte County": {
|
||||||
|
"latitude (deg)": 42.1314,
|
||||||
|
"longitude (deg)": -104.9676,
|
||||||
|
"amount (tonne)": [100, 200, 300],
|
||||||
|
},
|
||||||
|
"Park County": {
|
||||||
|
"latitude (deg)": 44.4063,
|
||||||
|
"longitude (deg)": -109.4153,
|
||||||
|
"amount (tonne)": [100, 200, 300],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"disposal cost ($/tonne)": [50, 50, 50],
|
||||||
|
"transportation cost ($/km/tonne)": [5, 5, 5],
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const samplePlantsOriginal = [
|
||||||
|
// basic plant
|
||||||
|
{
|
||||||
|
input: "Baled agricultural biomass",
|
||||||
|
"outputs (tonne/tonne)": {
|
||||||
|
"Hydrogen gas": 0.095,
|
||||||
|
"Carbon dioxide": 1.164,
|
||||||
|
Tar: 0,
|
||||||
|
},
|
||||||
|
locations: {
|
||||||
|
"Washakie County": {
|
||||||
|
"latitude (deg)": 43.8356,
|
||||||
|
"longitude (deg)": -107.6602,
|
||||||
|
"area cost factor": 1.0,
|
||||||
|
},
|
||||||
|
"Platte County": {
|
||||||
|
"latitude (deg)": 42.1314,
|
||||||
|
"longitude (deg)": -104.9676,
|
||||||
|
"area cost factor": 0.5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"disposal cost ($/tonne)": {
|
||||||
|
"Hydrogen gas": "0",
|
||||||
|
"Carbon dioxide": "0",
|
||||||
|
Tar: "200",
|
||||||
|
},
|
||||||
|
"disposal limit (tonne)": {
|
||||||
|
"Hydrogen gas": "10",
|
||||||
|
"Carbon dioxide": "",
|
||||||
|
Tar: "",
|
||||||
|
},
|
||||||
|
"emissions (tonne/tonne)": {
|
||||||
|
CO2: "100",
|
||||||
|
},
|
||||||
|
storage: {
|
||||||
|
"cost ($/tonne)": "5",
|
||||||
|
"limit (tonne)": "10000",
|
||||||
|
},
|
||||||
|
"maximum capacity (tonne)": "730000",
|
||||||
|
"minimum capacity (tonne)": "182500",
|
||||||
|
"opening cost (max capacity) ($)": "300000",
|
||||||
|
"opening cost (min capacity) ($)": "200000",
|
||||||
|
"fixed operating cost (max capacity) ($)": "7000",
|
||||||
|
"fixed operating cost (min capacity) ($)": "5000",
|
||||||
|
"variable operating cost ($/tonne)": "10",
|
||||||
|
x: null,
|
||||||
|
y: null,
|
||||||
|
},
|
||||||
|
// plant with fixed capacity
|
||||||
|
{
|
||||||
|
input: "Baled agricultural biomass",
|
||||||
|
"outputs (tonne/tonne)": {
|
||||||
|
"Hydrogen gas": 0.095,
|
||||||
|
"Carbon dioxide": 1.164,
|
||||||
|
Tar: 0.06,
|
||||||
|
},
|
||||||
|
"energy (GJ/tonne)": "50",
|
||||||
|
locations: {
|
||||||
|
"Washakie County": {
|
||||||
|
"latitude (deg)": 43.8356,
|
||||||
|
"longitude (deg)": -107.6602,
|
||||||
|
"area cost factor": 1.0,
|
||||||
|
},
|
||||||
|
"Platte County": {
|
||||||
|
"latitude (deg)": 42.1314,
|
||||||
|
"longitude (deg)": -104.9676,
|
||||||
|
"area cost factor": 0.5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"disposal cost ($/tonne)": {
|
||||||
|
"Hydrogen gas": "0",
|
||||||
|
"Carbon dioxide": "0",
|
||||||
|
Tar: "200",
|
||||||
|
},
|
||||||
|
"disposal limit (tonne)": {
|
||||||
|
"Hydrogen gas": "10",
|
||||||
|
"Carbon dioxide": "",
|
||||||
|
Tar: "",
|
||||||
|
},
|
||||||
|
"emissions (tonne/tonne)": {
|
||||||
|
CO2: "100",
|
||||||
|
},
|
||||||
|
storage: {
|
||||||
|
"cost ($/tonne)": "5",
|
||||||
|
"limit (tonne)": "10000",
|
||||||
|
},
|
||||||
|
"maximum capacity (tonne)": "182500",
|
||||||
|
"minimum capacity (tonne)": "182500",
|
||||||
|
"opening cost (max capacity) ($)": "200000",
|
||||||
|
"opening cost (min capacity) ($)": "200000",
|
||||||
|
"fixed operating cost (max capacity) ($)": "5000",
|
||||||
|
"fixed operating cost (min capacity) ($)": "5000",
|
||||||
|
"variable operating cost ($/tonne)": "10",
|
||||||
|
x: null,
|
||||||
|
y: null,
|
||||||
|
},
|
||||||
|
// plant with defaults
|
||||||
|
{
|
||||||
|
input: "Baled agricultural biomass",
|
||||||
|
"outputs (tonne/tonne)": {
|
||||||
|
"Hydrogen gas": 0.095,
|
||||||
|
"Carbon dioxide": 1.164,
|
||||||
|
Tar: 0.06,
|
||||||
|
},
|
||||||
|
"energy (GJ/tonne)": "50",
|
||||||
|
locations: {
|
||||||
|
"Washakie County": {
|
||||||
|
"latitude (deg)": 43.8356,
|
||||||
|
"longitude (deg)": -107.6602,
|
||||||
|
"area cost factor": 1.0,
|
||||||
|
},
|
||||||
|
"Platte County": {
|
||||||
|
"latitude (deg)": 42.1314,
|
||||||
|
"longitude (deg)": -104.9676,
|
||||||
|
"area cost factor": 0.5,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"disposal cost ($/tonne)": {
|
||||||
|
"Hydrogen gas": "",
|
||||||
|
"Carbon dioxide": "",
|
||||||
|
Tar: "",
|
||||||
|
},
|
||||||
|
"disposal limit (tonne)": {
|
||||||
|
"Hydrogen gas": "",
|
||||||
|
"Carbon dioxide": "",
|
||||||
|
Tar: "",
|
||||||
|
},
|
||||||
|
"emissions (tonne/tonne)": {
|
||||||
|
CO2: "100",
|
||||||
|
},
|
||||||
|
storage: {
|
||||||
|
"cost ($/tonne)": "5",
|
||||||
|
"limit (tonne)": "10000",
|
||||||
|
},
|
||||||
|
"maximum capacity (tonne)": "730000",
|
||||||
|
"minimum capacity (tonne)": "182500",
|
||||||
|
"opening cost (max capacity) ($)": "300000",
|
||||||
|
"opening cost (min capacity) ($)": "200000",
|
||||||
|
"fixed operating cost (max capacity) ($)": "7000",
|
||||||
|
"fixed operating cost (min capacity) ($)": "5000",
|
||||||
|
"variable operating cost ($/tonne)": "10",
|
||||||
|
x: null,
|
||||||
|
y: null,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const samplePlantsExported = [
|
||||||
|
//basic plant
|
||||||
|
{
|
||||||
|
input: "Baled agricultural biomass",
|
||||||
|
"outputs (tonne/tonne)": {
|
||||||
|
"Hydrogen gas": 0.095,
|
||||||
|
"Carbon dioxide": 1.164,
|
||||||
|
Tar: 0,
|
||||||
|
},
|
||||||
|
locations: {
|
||||||
|
"Washakie County": {
|
||||||
|
"latitude (deg)": 43.8356,
|
||||||
|
"longitude (deg)": -107.6602,
|
||||||
|
disposal: {
|
||||||
|
"Hydrogen gas": {
|
||||||
|
"cost ($/tonne)": [0, 0, 0],
|
||||||
|
"limit (tonne)": [10, 10, 10],
|
||||||
|
},
|
||||||
|
"Carbon dioxide": {
|
||||||
|
"cost ($/tonne)": [0, 0, 0],
|
||||||
|
},
|
||||||
|
Tar: {
|
||||||
|
"cost ($/tonne)": [200, 400, 800],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
storage: {
|
||||||
|
"cost ($/tonne)": [5, 10, 20],
|
||||||
|
"limit (tonne)": 10000,
|
||||||
|
},
|
||||||
|
"capacities (tonne)": {
|
||||||
|
182500: {
|
||||||
|
"opening cost ($)": [200000, 400000, 800000],
|
||||||
|
"fixed operating cost ($)": [5000, 10000, 20000],
|
||||||
|
"variable operating cost ($/tonne)": [10, 20, 40],
|
||||||
|
},
|
||||||
|
730000: {
|
||||||
|
"opening cost ($)": [300000, 600000, 1200000],
|
||||||
|
"fixed operating cost ($)": [7000, 14000, 28000],
|
||||||
|
"variable operating cost ($/tonne)": [10, 20, 40],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Platte County": {
|
||||||
|
"latitude (deg)": 42.1314,
|
||||||
|
"longitude (deg)": -104.9676,
|
||||||
|
disposal: {
|
||||||
|
"Hydrogen gas": {
|
||||||
|
"cost ($/tonne)": [0, 0, 0],
|
||||||
|
"limit (tonne)": [10, 10, 10],
|
||||||
|
},
|
||||||
|
"Carbon dioxide": {
|
||||||
|
"cost ($/tonne)": [0, 0, 0],
|
||||||
|
},
|
||||||
|
Tar: {
|
||||||
|
"cost ($/tonne)": [100, 200.0, 400],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
storage: {
|
||||||
|
"cost ($/tonne)": [2.5, 5, 10],
|
||||||
|
"limit (tonne)": 10000,
|
||||||
|
},
|
||||||
|
"capacities (tonne)": {
|
||||||
|
182500: {
|
||||||
|
"opening cost ($)": [100000, 200000, 400000],
|
||||||
|
"fixed operating cost ($)": [2500, 5000, 10000],
|
||||||
|
"variable operating cost ($/tonne)": [5, 10, 20],
|
||||||
|
},
|
||||||
|
730000: {
|
||||||
|
"opening cost ($)": [150000, 300000, 600000],
|
||||||
|
"fixed operating cost ($)": [3500, 7000, 14000],
|
||||||
|
"variable operating cost ($/tonne)": [5, 10, 20],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"emissions (tonne/tonne)": {
|
||||||
|
CO2: [100, 100, 100],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// plant with fixed capacity
|
||||||
|
{
|
||||||
|
input: "Baled agricultural biomass",
|
||||||
|
"outputs (tonne/tonne)": {
|
||||||
|
"Hydrogen gas": 0.095,
|
||||||
|
"Carbon dioxide": 1.164,
|
||||||
|
Tar: 0.06,
|
||||||
|
},
|
||||||
|
"energy (GJ/tonne)": [50, 50, 50],
|
||||||
|
locations: {
|
||||||
|
"Washakie County": {
|
||||||
|
"latitude (deg)": 43.8356,
|
||||||
|
"longitude (deg)": -107.6602,
|
||||||
|
disposal: {
|
||||||
|
"Hydrogen gas": {
|
||||||
|
"cost ($/tonne)": [0, 0, 0],
|
||||||
|
"limit (tonne)": [10, 10, 10],
|
||||||
|
},
|
||||||
|
"Carbon dioxide": {
|
||||||
|
"cost ($/tonne)": [0, 0, 0],
|
||||||
|
},
|
||||||
|
Tar: {
|
||||||
|
"cost ($/tonne)": [200.0, 200.0, 200.0],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
storage: {
|
||||||
|
"cost ($/tonne)": [5, 5, 5],
|
||||||
|
"limit (tonne)": 10000,
|
||||||
|
},
|
||||||
|
"capacities (tonne)": {
|
||||||
|
182500: {
|
||||||
|
"opening cost ($)": [200000, 200000, 200000],
|
||||||
|
"fixed operating cost ($)": [5000, 5000, 5000],
|
||||||
|
"variable operating cost ($/tonne)": [10, 10, 10],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Platte County": {
|
||||||
|
"latitude (deg)": 42.1314,
|
||||||
|
"longitude (deg)": -104.9676,
|
||||||
|
disposal: {
|
||||||
|
"Hydrogen gas": {
|
||||||
|
"cost ($/tonne)": [0, 0, 0],
|
||||||
|
"limit (tonne)": [10, 10, 10],
|
||||||
|
},
|
||||||
|
"Carbon dioxide": {
|
||||||
|
"cost ($/tonne)": [0, 0, 0],
|
||||||
|
},
|
||||||
|
Tar: {
|
||||||
|
"cost ($/tonne)": [100.0, 100.0, 100.0],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
storage: {
|
||||||
|
"cost ($/tonne)": [2.5, 2.5, 2.5],
|
||||||
|
"limit (tonne)": 10000,
|
||||||
|
},
|
||||||
|
"capacities (tonne)": {
|
||||||
|
182500: {
|
||||||
|
"opening cost ($)": [100000, 100000, 100000],
|
||||||
|
"fixed operating cost ($)": [2500, 2500, 2500],
|
||||||
|
"variable operating cost ($/tonne)": [5, 5, 5],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"emissions (tonne/tonne)": {
|
||||||
|
CO2: [100, 100, 100],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// plant with defaults
|
||||||
|
{
|
||||||
|
input: "Baled agricultural biomass",
|
||||||
|
"outputs (tonne/tonne)": {
|
||||||
|
"Hydrogen gas": 0.095,
|
||||||
|
"Carbon dioxide": 1.164,
|
||||||
|
Tar: 0.06,
|
||||||
|
},
|
||||||
|
"energy (GJ/tonne)": [50, 50, 50],
|
||||||
|
locations: {
|
||||||
|
"Washakie County": {
|
||||||
|
"latitude (deg)": 43.8356,
|
||||||
|
"longitude (deg)": -107.6602,
|
||||||
|
disposal: {},
|
||||||
|
storage: {
|
||||||
|
"cost ($/tonne)": [5, 5, 5],
|
||||||
|
"limit (tonne)": 10000,
|
||||||
|
},
|
||||||
|
"capacities (tonne)": {
|
||||||
|
182500: {
|
||||||
|
"opening cost ($)": [200000, 200000, 200000],
|
||||||
|
"fixed operating cost ($)": [5000, 5000, 5000],
|
||||||
|
"variable operating cost ($/tonne)": [10, 10, 10],
|
||||||
|
},
|
||||||
|
730000: {
|
||||||
|
"opening cost ($)": [300000, 300000, 300000],
|
||||||
|
"fixed operating cost ($)": [7000, 7000, 7000],
|
||||||
|
"variable operating cost ($/tonne)": [10, 10, 10],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Platte County": {
|
||||||
|
"latitude (deg)": 42.1314,
|
||||||
|
"longitude (deg)": -104.9676,
|
||||||
|
disposal: {},
|
||||||
|
storage: {
|
||||||
|
"cost ($/tonne)": [2.5, 2.5, 2.5],
|
||||||
|
"limit (tonne)": 10000,
|
||||||
|
},
|
||||||
|
"capacities (tonne)": {
|
||||||
|
182500: {
|
||||||
|
"opening cost ($)": [100000, 100000, 100000],
|
||||||
|
"fixed operating cost ($)": [2500, 2500, 2500],
|
||||||
|
"variable operating cost ($/tonne)": [5, 5, 5],
|
||||||
|
},
|
||||||
|
730000: {
|
||||||
|
"opening cost ($)": [150000, 150000, 150000],
|
||||||
|
"fixed operating cost ($)": [3500, 3500, 3500],
|
||||||
|
"variable operating cost ($/tonne)": [5, 5, 5],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"emissions (tonne/tonne)": {
|
||||||
|
CO2: [100, 100, 100],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const sampleParameters = [
|
||||||
|
{
|
||||||
|
"time horizon (years)": "3",
|
||||||
|
"inflation rate (%)": "100",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"time horizon (years)": "3",
|
||||||
|
"inflation rate (%)": "0",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"time horizon (years)": "3",
|
||||||
|
"inflation rate (%)": "0",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
test("export products", () => {
|
||||||
|
for (let i = 0; i < sampleProductsOriginal.length; i++) {
|
||||||
|
const original = sampleProductsOriginal[i];
|
||||||
|
const exported = sampleProductsExported[i];
|
||||||
|
expect(exportProduct(original, sampleParameters[i])).toEqual(exported);
|
||||||
|
|
||||||
|
const [recoveredProd, recoveredParams] = importProduct(exported);
|
||||||
|
expect(recoveredProd).toEqual(original);
|
||||||
|
expect(recoveredParams).toEqual(sampleParameters[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("export plants", () => {
|
||||||
|
for (let i = 0; i < samplePlantsOriginal.length; i++) {
|
||||||
|
const original = samplePlantsOriginal[i];
|
||||||
|
const exported = samplePlantsExported[i];
|
||||||
|
expect(exportPlant(original, sampleParameters[i])).toEqual(exported);
|
||||||
|
|
||||||
|
const [recoveredPlant, recoveredParams] = importPlant(exported);
|
||||||
|
expect(recoveredPlant).toEqual(original);
|
||||||
|
expect(recoveredParams).toEqual(sampleParameters[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test("importList", () => {
|
||||||
|
expect(importList("invalid")).toEqual("invalid");
|
||||||
|
expect(importList([1, 1, 1])).toEqual("1");
|
||||||
|
expect(importList([1, 2, 3])).toEqual("[1,2,3]");
|
||||||
|
expect(importList(["A", "A", "A"])).toEqual("A");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("importDict", () => {
|
||||||
|
expect(importDict({ a: [5, 5, 5] })).toEqual({ a: "5" });
|
||||||
|
expect(importDict({ a: [1, 2, 3] })).toEqual({ a: "[1,2,3]" });
|
||||||
|
expect(importDict({ a: "invalid" })).toEqual({ a: "invalid" });
|
||||||
|
});
|
||||||
182
relog-web/src/casebuilder/validate.js
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
const Ajv = require("ajv");
|
||||||
|
const ajv = new Ajv();
|
||||||
|
|
||||||
|
const schema = {
|
||||||
|
$schema: "http://json-schema.org/draft-07/schema#",
|
||||||
|
$id: "https://anl-ceeesa.github.io/RELOG/input",
|
||||||
|
title: "Schema for RELOG Input File",
|
||||||
|
definitions: {
|
||||||
|
TimeSeries: {
|
||||||
|
type: "array",
|
||||||
|
items: {
|
||||||
|
type: "number",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Parameters: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
"time horizon (years)": {
|
||||||
|
type: "number",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ["time horizon (years)"],
|
||||||
|
},
|
||||||
|
Plant: {
|
||||||
|
type: "object",
|
||||||
|
additionalProperties: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
input: {
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
"outputs (tonne/tonne)": {
|
||||||
|
type: "object",
|
||||||
|
additionalProperties: {
|
||||||
|
type: "number",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"energy (GJ/tonne)": {
|
||||||
|
$ref: "#/definitions/TimeSeries",
|
||||||
|
},
|
||||||
|
"emissions (tonne/tonne)": {
|
||||||
|
type: "object",
|
||||||
|
additionalProperties: {
|
||||||
|
$ref: "#/definitions/TimeSeries",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
locations: {
|
||||||
|
$ref: "#/definitions/PlantLocation",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ["input", "locations"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
PlantLocation: {
|
||||||
|
type: "object",
|
||||||
|
additionalProperties: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
location: {
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
"latitude (deg)": {
|
||||||
|
type: "number",
|
||||||
|
},
|
||||||
|
"longitude (deg)": {
|
||||||
|
type: "number",
|
||||||
|
},
|
||||||
|
disposal: {
|
||||||
|
type: "object",
|
||||||
|
additionalProperties: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
"cost ($/tonne)": {
|
||||||
|
$ref: "#/definitions/TimeSeries",
|
||||||
|
},
|
||||||
|
"limit (tonne)": {
|
||||||
|
$ref: "#/definitions/TimeSeries",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ["cost ($/tonne)"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
storage: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
"cost ($/tonne)": {
|
||||||
|
$ref: "#/definitions/TimeSeries",
|
||||||
|
},
|
||||||
|
"limit (tonne)": {
|
||||||
|
type: "number",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ["cost ($/tonne)", "limit (tonne)"],
|
||||||
|
},
|
||||||
|
"capacities (tonne)": {
|
||||||
|
type: "object",
|
||||||
|
additionalProperties: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
"variable operating cost ($/tonne)": {
|
||||||
|
$ref: "#/definitions/TimeSeries",
|
||||||
|
},
|
||||||
|
"fixed operating cost ($)": {
|
||||||
|
$ref: "#/definitions/TimeSeries",
|
||||||
|
},
|
||||||
|
"opening cost ($)": {
|
||||||
|
$ref: "#/definitions/TimeSeries",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: [
|
||||||
|
"variable operating cost ($/tonne)",
|
||||||
|
"fixed operating cost ($)",
|
||||||
|
"opening cost ($)",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ["capacities (tonne)"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
InitialAmount: {
|
||||||
|
type: "object",
|
||||||
|
additionalProperties: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
location: {
|
||||||
|
type: "string",
|
||||||
|
},
|
||||||
|
"latitude (deg)": {
|
||||||
|
type: "number",
|
||||||
|
},
|
||||||
|
"longitude (deg)": {
|
||||||
|
type: "number",
|
||||||
|
},
|
||||||
|
"amount (tonne)": {
|
||||||
|
$ref: "#/definitions/TimeSeries",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ["amount (tonne)"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Product: {
|
||||||
|
type: "object",
|
||||||
|
additionalProperties: {
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
"transportation cost ($/km/tonne)": {
|
||||||
|
$ref: "#/definitions/TimeSeries",
|
||||||
|
},
|
||||||
|
"transportation energy (J/km/tonne)": {
|
||||||
|
$ref: "#/definitions/TimeSeries",
|
||||||
|
},
|
||||||
|
"transportation emissions (tonne/km/tonne)": {
|
||||||
|
type: "object",
|
||||||
|
additionalProperties: {
|
||||||
|
$ref: "#/definitions/TimeSeries",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"initial amounts": {
|
||||||
|
$ref: "#/definitions/InitialAmount",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ["transportation cost ($/km/tonne)"],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
type: "object",
|
||||||
|
properties: {
|
||||||
|
parameters: {
|
||||||
|
$ref: "#/definitions/Parameters",
|
||||||
|
},
|
||||||
|
plants: {
|
||||||
|
$ref: "#/definitions/Plant",
|
||||||
|
},
|
||||||
|
products: {
|
||||||
|
$ref: "#/definitions/Product",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ["parameters", "plants", "products"],
|
||||||
|
};
|
||||||
|
|
||||||
|
export const validate = ajv.compile(schema);
|
||||||
26
relog-web/src/common/Button.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import styles from "./Button.module.css";
|
||||||
|
|
||||||
|
const Button = (props) => {
|
||||||
|
let className = styles.Button;
|
||||||
|
if (props.kind === "inline") {
|
||||||
|
className += " " + styles.inline;
|
||||||
|
}
|
||||||
|
|
||||||
|
let tooltip = "";
|
||||||
|
if (props.tooltip !== undefined) {
|
||||||
|
tooltip = <span className={styles.tooltip}>{props.tooltip}</span>;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button
|
||||||
|
className={className}
|
||||||
|
onClick={props.onClick}
|
||||||
|
disabled={props.disabled}
|
||||||
|
>
|
||||||
|
{tooltip}
|
||||||
|
{props.label}
|
||||||
|
</button>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Button;
|
||||||
67
relog-web/src/common/Button.module.css
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
.Button {
|
||||||
|
padding: 6px 36px;
|
||||||
|
margin: 12px 6px;
|
||||||
|
line-height: 24px;
|
||||||
|
border: var(--box-border);
|
||||||
|
/* background-color: white; */
|
||||||
|
box-shadow: var(--box-shadow);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
cursor: pointer;
|
||||||
|
color: rgba(0, 0, 0, 0.8);
|
||||||
|
text-transform: uppercase;
|
||||||
|
font-weight: bold;
|
||||||
|
font-size: 12px;
|
||||||
|
background: linear-gradient(rgb(255, 255, 255) 25%, rgb(245, 245, 245) 100%);
|
||||||
|
}
|
||||||
|
|
||||||
|
.Button:hover {
|
||||||
|
background: rgb(245, 245, 245);
|
||||||
|
}
|
||||||
|
|
||||||
|
.Button:active {
|
||||||
|
background: rgba(220, 220, 220);
|
||||||
|
}
|
||||||
|
|
||||||
|
.inline {
|
||||||
|
padding: 0 12px;
|
||||||
|
margin: 2px 4px 2px 0;
|
||||||
|
height: 32px;
|
||||||
|
font-size: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* .inline:last-child {
|
||||||
|
margin: 2px 1px;
|
||||||
|
} */
|
||||||
|
|
||||||
|
.tooltip {
|
||||||
|
visibility: hidden;
|
||||||
|
background-color: #333;
|
||||||
|
color: white;
|
||||||
|
opacity: 0%;
|
||||||
|
width: 180px;
|
||||||
|
margin-top: 36px;
|
||||||
|
margin-left: -180px;
|
||||||
|
position: absolute;
|
||||||
|
z-index: 100;
|
||||||
|
text-transform: none;
|
||||||
|
font-size: 13px;
|
||||||
|
border-radius: 4px;
|
||||||
|
box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.25);
|
||||||
|
line-height: 18px;
|
||||||
|
padding: 6px;
|
||||||
|
transition: opacity 0.5s;
|
||||||
|
font-weight: normal;
|
||||||
|
text-align: left;
|
||||||
|
padding: 6px 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.Button:hover .tooltip {
|
||||||
|
visibility: visible;
|
||||||
|
opacity: 100%;
|
||||||
|
transition: opacity 0.5s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.Button:disabled {
|
||||||
|
color: rgba(0, 0, 0, 0.25);
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
7
relog-web/src/common/Card.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import styles from "./Card.module.css";
|
||||||
|
|
||||||
|
const Card = (props) => {
|
||||||
|
return <div className={styles.Card}>{props.children}</div>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Card;
|
||||||
22
relog-web/src/common/Card.module.css
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
.Card {
|
||||||
|
border: var(--box-border);
|
||||||
|
box-shadow: var(--box-shadow);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
background-color: white;
|
||||||
|
padding: 12px;
|
||||||
|
min-height: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.Card h1 {
|
||||||
|
margin: 12px -12px 0px -12px;
|
||||||
|
padding: 6px 12px 0px 12px;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 35px;
|
||||||
|
border-top: 1px solid #ddd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.Card h1:first-child {
|
||||||
|
margin: -12px -12px 0px -12px;
|
||||||
|
border-top: none;
|
||||||
|
background: none;
|
||||||
|
}
|
||||||
91
relog-web/src/common/DictInputRow.js
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
import form_styles from "./Form.module.css";
|
||||||
|
import Button from "./Button";
|
||||||
|
import { validate } from "./Form";
|
||||||
|
|
||||||
|
const DictInputRow = (props) => {
|
||||||
|
const dict = { ...props.value };
|
||||||
|
if (!props.disableKeys) {
|
||||||
|
dict[""] = "0";
|
||||||
|
}
|
||||||
|
|
||||||
|
let unit = "";
|
||||||
|
if (props.unit) {
|
||||||
|
unit = <span className={form_styles.FormRow_unit}>({props.unit})</span>;
|
||||||
|
}
|
||||||
|
|
||||||
|
let tooltip = "";
|
||||||
|
if (props.tooltip !== undefined) {
|
||||||
|
tooltip = <Button label="?" kind="inline" tooltip={props.tooltip} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const onChangeValue = (key, v) => {
|
||||||
|
const newDict = { ...dict };
|
||||||
|
newDict[key] = v;
|
||||||
|
props.onChange(newDict);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onChangeKey = (prevKey, newKey) => {
|
||||||
|
const newDict = renameKey(dict, prevKey, newKey);
|
||||||
|
if (!("" in newDict)) newDict[""] = "";
|
||||||
|
props.onChange(newDict);
|
||||||
|
};
|
||||||
|
|
||||||
|
const form = [];
|
||||||
|
Object.keys(dict).forEach((key, index) => {
|
||||||
|
let label = (
|
||||||
|
<span>
|
||||||
|
{props.label} {unit}
|
||||||
|
</span>
|
||||||
|
);
|
||||||
|
if (index > 0) {
|
||||||
|
label = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
let isValid = true;
|
||||||
|
if (props.validate !== undefined) {
|
||||||
|
isValid = validate(props.validate, dict[key]);
|
||||||
|
}
|
||||||
|
|
||||||
|
let className = "";
|
||||||
|
if (!isValid) className = form_styles.invalid;
|
||||||
|
|
||||||
|
form.push(
|
||||||
|
<div className={form_styles.FormRow} key={index}>
|
||||||
|
<label>{label}</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
data-index={index}
|
||||||
|
value={key}
|
||||||
|
placeholder={props.keyPlaceholder}
|
||||||
|
disabled={props.disableKeys}
|
||||||
|
onChange={(e) => onChangeKey(key, e.target.value)}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
data-index={index}
|
||||||
|
value={dict[key]}
|
||||||
|
placeholder={props.valuePlaceholder}
|
||||||
|
className={className}
|
||||||
|
onChange={(e) => onChangeValue(key, e.target.value)}
|
||||||
|
/>
|
||||||
|
{tooltip}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return <>{form}</>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export function renameKey(obj, prevKey, newKey) {
|
||||||
|
const keys = Object.keys(obj);
|
||||||
|
return keys.reduce((acc, val) => {
|
||||||
|
if (val === prevKey) {
|
||||||
|
acc[newKey] = obj[prevKey];
|
||||||
|
} else {
|
||||||
|
acc[val] = obj[val];
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
export default DictInputRow;
|
||||||
59
relog-web/src/common/FileInputRow.js
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import form_styles from "./Form.module.css";
|
||||||
|
import Button from "./Button";
|
||||||
|
import { useRef } from "react";
|
||||||
|
|
||||||
|
const FileInputRow = (props) => {
|
||||||
|
let tooltip = "";
|
||||||
|
if (props.tooltip !== undefined) {
|
||||||
|
tooltip = <Button label="?" kind="inline" tooltip={props.tooltip} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileElem = useRef();
|
||||||
|
|
||||||
|
const onClickUpload = () => {
|
||||||
|
fileElem.current.click();
|
||||||
|
};
|
||||||
|
|
||||||
|
const onFileSelected = () => {
|
||||||
|
const file = fileElem.current.files[0];
|
||||||
|
if (file) {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.addEventListener("load", () => {
|
||||||
|
props.onFile(reader.result);
|
||||||
|
});
|
||||||
|
reader.readAsText(file);
|
||||||
|
}
|
||||||
|
fileElem.current.value = "";
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={form_styles.FormRow}>
|
||||||
|
<label>{props.label}</label>
|
||||||
|
<input type="text" value={props.value} disabled="disabled" />
|
||||||
|
<Button label="Upload" kind="inline" onClick={onClickUpload} />
|
||||||
|
<Button
|
||||||
|
label="Download"
|
||||||
|
kind="inline"
|
||||||
|
onClick={props.onDownload}
|
||||||
|
disabled={props.disableDownload}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
label="Clear"
|
||||||
|
kind="inline"
|
||||||
|
onClick={props.onClear}
|
||||||
|
disabled={props.disableClear}
|
||||||
|
/>
|
||||||
|
<Button label="Template" kind="inline" onClick={props.onTemplate} />
|
||||||
|
{tooltip}
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
ref={fileElem}
|
||||||
|
accept={props.accept}
|
||||||
|
style={{ display: "none" }}
|
||||||
|
onChange={onFileSelected}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FileInputRow;
|
||||||
15
relog-web/src/common/Footer.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import styles from "./Footer.module.css";
|
||||||
|
|
||||||
|
const Footer = () => {
|
||||||
|
return (
|
||||||
|
<div className={styles.Footer}>
|
||||||
|
<p>RELOG: Reverse Logistics Optimization</p>
|
||||||
|
<p>
|
||||||
|
Copyright © 2020—2022, UChicago Argonne, LLC. All Rights
|
||||||
|
Reserved.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Footer;
|
||||||
8
relog-web/src/common/Footer.module.css
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
.Footer {
|
||||||
|
padding: 12px;
|
||||||
|
color: rgba(255, 255, 255, 0.5);
|
||||||
|
text-align: center;
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 8px;
|
||||||
|
min-width: 900px;
|
||||||
|
}
|
||||||
19
relog-web/src/common/Form.js
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
const VALIDATION_REGEX = {
|
||||||
|
int: new RegExp("^[0-9]+$"),
|
||||||
|
intList: new RegExp("[[0-9]*]$"),
|
||||||
|
float: new RegExp("^[0-9]*\\.?[0-9]*$"),
|
||||||
|
floatList: new RegExp("^[?[0-9,.]*]?$"),
|
||||||
|
};
|
||||||
|
|
||||||
|
export const validate = (kind, value) => {
|
||||||
|
if (!VALIDATION_REGEX[kind].test(value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const Form = (props) => {
|
||||||
|
return <>{props.children}</>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Form;
|
||||||
28
relog-web/src/common/Form.module.css
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
.FormRow {
|
||||||
|
display: flex;
|
||||||
|
line-height: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.FormRow label {
|
||||||
|
width: 350px;
|
||||||
|
padding: 6px 12px;
|
||||||
|
text-align: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.FormRow input {
|
||||||
|
flex: 1;
|
||||||
|
font-family: monospace;
|
||||||
|
border: var(--box-border);
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
padding: 4px;
|
||||||
|
margin: 2px 3px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.FormRow_unit {
|
||||||
|
color: rgba(0, 0, 0, 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.invalid {
|
||||||
|
border: 2px solid #faa !important;
|
||||||
|
background-color: rgba(255, 0, 0, 0.05);
|
||||||
|
}
|
||||||
17
relog-web/src/common/Header.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import styles from "./Header.module.css";
|
||||||
|
|
||||||
|
const Header = (props) => {
|
||||||
|
return (
|
||||||
|
<div className={styles.HeaderBox}>
|
||||||
|
<div className={styles.HeaderContent}>
|
||||||
|
<h1>RELOG</h1>
|
||||||
|
<h2>{props.title}</h2>
|
||||||
|
<div style={{ float: "right", paddingTop: "5px" }}>
|
||||||
|
{props.children}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Header;
|
||||||
28
relog-web/src/common/Header.module.css
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
.HeaderBox {
|
||||||
|
background-color: white;
|
||||||
|
border-bottom: var(--box-border);
|
||||||
|
box-shadow: var(--box-shadow);
|
||||||
|
padding: 0;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.HeaderContent {
|
||||||
|
margin: 0 auto;
|
||||||
|
max-width: var(--site-width);
|
||||||
|
}
|
||||||
|
|
||||||
|
.HeaderContent h1,
|
||||||
|
.HeaderContent h2 {
|
||||||
|
line-height: 48px;
|
||||||
|
font-size: 28px;
|
||||||
|
padding: 12px;
|
||||||
|
margin: 0;
|
||||||
|
display: inline-block;
|
||||||
|
vertical-align: middle;
|
||||||
|
}
|
||||||
|
|
||||||
|
.HeaderContent h2 {
|
||||||
|
font-size: 22px;
|
||||||
|
font-weight: normal;
|
||||||
|
color: rgba(0, 0, 0, 0.6);
|
||||||
|
}
|
||||||
7
relog-web/src/common/Section.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
import styles from "./Section.module.css";
|
||||||
|
|
||||||
|
const Section = (props) => {
|
||||||
|
return <h2 className={styles.Section}>{props.title}</h2>;
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Section;
|
||||||
6
relog-web/src/common/Section.module.css
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
.Section {
|
||||||
|
line-height: 36px;
|
||||||
|
margin: 12px;
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
44
relog-web/src/common/TextInputRow.js
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
import form_styles from "./Form.module.css";
|
||||||
|
import Button from "./Button";
|
||||||
|
import { validate } from "./Form";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
|
const TextInputRow = React.forwardRef((props, ref) => {
|
||||||
|
let unit = "";
|
||||||
|
if (props.unit) {
|
||||||
|
unit = <span className={form_styles.FormRow_unit}>({props.unit})</span>;
|
||||||
|
}
|
||||||
|
|
||||||
|
let tooltip = "";
|
||||||
|
if (props.tooltip !== undefined) {
|
||||||
|
tooltip = <Button label="?" kind="inline" tooltip={props.tooltip} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
let isValid = true;
|
||||||
|
if (!props.disabled && props.validate !== undefined) {
|
||||||
|
isValid = validate(props.validate, props.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
let className = "";
|
||||||
|
if (!isValid) className = form_styles.invalid;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={form_styles.FormRow}>
|
||||||
|
<label>
|
||||||
|
{props.label} {unit}
|
||||||
|
</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder={props.default}
|
||||||
|
disabled={props.disabled}
|
||||||
|
value={props.value}
|
||||||
|
className={className}
|
||||||
|
onChange={(e) => props.onChange(e.target.value)}
|
||||||
|
ref={ref}
|
||||||
|
/>
|
||||||
|
{tooltip}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
export default TextInputRow;
|
||||||
109
relog-web/src/index.css
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
:root {
|
||||||
|
--site-width: 1200px;
|
||||||
|
--box-border: 1px solid rgba(0, 0, 0, 0.2);
|
||||||
|
--box-shadow: 0px 2px 4px -3px rgba(0, 0, 0, 0.2);
|
||||||
|
--border-radius: 4px;
|
||||||
|
--primary: #0d6efd;
|
||||||
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
border: 0;
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background-color: #333;
|
||||||
|
color: rgba(0, 0, 0, 0.95);
|
||||||
|
}
|
||||||
|
|
||||||
|
#contentBackground {
|
||||||
|
background-color: #f6f6f6;
|
||||||
|
}
|
||||||
|
|
||||||
|
#content {
|
||||||
|
max-width: var(--site-width);
|
||||||
|
min-width: 900px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 1px 6px 32px 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.react-flow__node.selected {
|
||||||
|
box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2) !important;
|
||||||
|
border-width: 2px !important;
|
||||||
|
margin-top: -1px !important;
|
||||||
|
margin-left: -1px !important;
|
||||||
|
border-radius: 8px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.react-flow__handle {
|
||||||
|
width: 6px !important;
|
||||||
|
height: 6px !important;
|
||||||
|
background-color: white !important;
|
||||||
|
border: 1px solid black !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.react-flow__handle:hover {
|
||||||
|
background-color: black !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.react-flow__handle-right {
|
||||||
|
right: -4px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.react-flow__handle-left {
|
||||||
|
left: -4px !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#messageTray {
|
||||||
|
max-width: var(--site-width);
|
||||||
|
margin: 0 auto;
|
||||||
|
position: fixed;
|
||||||
|
bottom: 12px;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
z-index: 100;
|
||||||
|
}
|
||||||
|
|
||||||
|
#messageTray .message {
|
||||||
|
background-color: rgb(221, 69, 69);
|
||||||
|
color: #eee;
|
||||||
|
padding: 12px;
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
box-shadow: 4px 4px 8px rgba(0, 0, 0, 0.4);
|
||||||
|
display: flex;
|
||||||
|
margin-top: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#messageTray .message p {
|
||||||
|
flex: 1;
|
||||||
|
margin: 0;
|
||||||
|
padding: 12px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#messageTray .message button {
|
||||||
|
margin: 0;
|
||||||
|
background: transparent;
|
||||||
|
border: 1px solid #eee;
|
||||||
|
color: #eee;
|
||||||
|
float: right;
|
||||||
|
padding: 0 24px;
|
||||||
|
line-height: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#messageTray .message button:hover {
|
||||||
|
background: rgba(255, 255, 255, 0.05);
|
||||||
|
}
|
||||||
|
|
||||||
|
#messageTray .message button:active {
|
||||||
|
background: rgba(255, 255, 255, 0.1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nodata {
|
||||||
|
text-align: center;
|
||||||
|
padding: 24px 0;
|
||||||
|
color: #888;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
27
relog-web/src/index.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import React from "react";
|
||||||
|
import ReactDOM from "react-dom";
|
||||||
|
import "./index.css";
|
||||||
|
import InputPage from "./casebuilder/InputPage";
|
||||||
|
import SolverPage from "./solver/SolverPage";
|
||||||
|
import { Route, BrowserRouter, Switch, Redirect } from "react-router-dom";
|
||||||
|
|
||||||
|
export const SERVER_URL = "";
|
||||||
|
|
||||||
|
ReactDOM.render(
|
||||||
|
<BrowserRouter>
|
||||||
|
<React.StrictMode>
|
||||||
|
<Switch>
|
||||||
|
<Route path="/casebuilder">
|
||||||
|
<InputPage />
|
||||||
|
</Route>
|
||||||
|
<Route path="/solver/:job_id">
|
||||||
|
<SolverPage />
|
||||||
|
</Route>
|
||||||
|
<Route path="/">
|
||||||
|
<Redirect to="/casebuilder" />
|
||||||
|
</Route>
|
||||||
|
</Switch>
|
||||||
|
</React.StrictMode>
|
||||||
|
</BrowserRouter>,
|
||||||
|
document.getElementById("root")
|
||||||
|
);
|
||||||
46
relog-web/src/solver/FilesBlock.js
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import Section from "../common/Section";
|
||||||
|
import Card from "../common/Card";
|
||||||
|
import styles from "./FilesBlock.module.css";
|
||||||
|
import { SERVER_URL } from "..";
|
||||||
|
|
||||||
|
const FilesBlock = (props) => {
|
||||||
|
const [filesFound, setFilesFound] = useState(false);
|
||||||
|
|
||||||
|
const fetchFiles = async () => {
|
||||||
|
const response = await fetch(`${SERVER_URL}/jobs/${props.job}/output.json`);
|
||||||
|
if (response.ok) {
|
||||||
|
setFilesFound(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fetch files periodically from the server
|
||||||
|
useEffect(() => {
|
||||||
|
fetchFiles();
|
||||||
|
if (!filesFound) {
|
||||||
|
const interval = setInterval(() => {
|
||||||
|
fetchFiles();
|
||||||
|
}, 1000);
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}
|
||||||
|
}, [filesFound]);
|
||||||
|
|
||||||
|
let content = <div className="nodata">No files available</div>;
|
||||||
|
if (filesFound) {
|
||||||
|
content = (
|
||||||
|
<div className={styles.files}>
|
||||||
|
<a href={`${SERVER_URL}/jobs/${props.job}/output.zip`}>output.zip</a>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Section title="Output Files" />
|
||||||
|
<Card>{content}</Card>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default FilesBlock;
|
||||||
19
relog-web/src/solver/FilesBlock.module.css
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
.files a {
|
||||||
|
display: block;
|
||||||
|
padding: 16px;
|
||||||
|
text-decoration: none;
|
||||||
|
color: var(--primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.files a:hover {
|
||||||
|
background-color: var(--primary);
|
||||||
|
color: white;
|
||||||
|
border-radius: var(--border-radius);
|
||||||
|
}
|
||||||
|
|
||||||
|
.nodata {
|
||||||
|
text-align: center;
|
||||||
|
padding: 24px 0;
|
||||||
|
color: #888;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
47
relog-web/src/solver/LogBlock.js
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
import Section from "../common/Section";
|
||||||
|
import Card from "../common/Card";
|
||||||
|
import styles from "./LogBlock.module.css";
|
||||||
|
import { useRef } from "react";
|
||||||
|
import { SERVER_URL } from "..";
|
||||||
|
|
||||||
|
const LogBlock = (props) => {
|
||||||
|
const [log, setLog] = useState();
|
||||||
|
const preRef = useRef(null);
|
||||||
|
|
||||||
|
const fetchLog = async () => {
|
||||||
|
const response = await fetch(`${SERVER_URL}/jobs/${props.job}/solve.log`);
|
||||||
|
const data = await response.text();
|
||||||
|
if (log !== data) {
|
||||||
|
setLog(data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fetch log periodically from the server
|
||||||
|
useEffect(() => {
|
||||||
|
fetchLog();
|
||||||
|
const interval = setInterval(() => {
|
||||||
|
fetchLog();
|
||||||
|
}, 1000);
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Scroll to bottom whenever the log is updated
|
||||||
|
useEffect(() => {
|
||||||
|
preRef.current.scrollTop = preRef.current.scrollHeight;
|
||||||
|
}, [log]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Section title="Optimization Log" />
|
||||||
|
<Card>
|
||||||
|
<pre ref={preRef} className={styles.log}>
|
||||||
|
{log}
|
||||||
|
</pre>
|
||||||
|
</Card>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default LogBlock;
|
||||||
8
relog-web/src/solver/LogBlock.module.css
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
.log {
|
||||||
|
max-height: 500px;
|
||||||
|
min-height: 500px;
|
||||||
|
border: 0;
|
||||||
|
margin: 0;
|
||||||
|
overflow: auto;
|
||||||
|
line-height: 1.4em;
|
||||||
|
}
|
||||||
238
relog-web/src/solver/MapBlock.js
Normal file
@@ -0,0 +1,238 @@
|
|||||||
|
import * as d3 from "d3";
|
||||||
|
import { group } from "d3-array";
|
||||||
|
import * as L from "leaflet";
|
||||||
|
import "leaflet/dist/leaflet.css";
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
|
import { SERVER_URL } from "..";
|
||||||
|
import Card from "../common/Card";
|
||||||
|
import Section from "../common/Section";
|
||||||
|
|
||||||
|
function drawMap(csv_plants, csv_tr) {
|
||||||
|
const mapLink = '<a href="http://openstreetmap.org">OpenStreetMap</a>';
|
||||||
|
|
||||||
|
const base = L.tileLayer(
|
||||||
|
"https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png",
|
||||||
|
{
|
||||||
|
attribution:
|
||||||
|
'© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors © <a href="https://carto.com/attributions">CARTO</a>',
|
||||||
|
subdomains: "abcd",
|
||||||
|
maxZoom: 10,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const plant_types = [...new Set(csv_plants.map((d) => d["plant type"]))];
|
||||||
|
plant_types.push("Multiple");
|
||||||
|
const plant_color = d3
|
||||||
|
.scaleOrdinal()
|
||||||
|
.domain(plant_types)
|
||||||
|
.range([
|
||||||
|
"#558B2F",
|
||||||
|
"#FF8F00",
|
||||||
|
"#0277BD",
|
||||||
|
"#AD1457",
|
||||||
|
"#00838F",
|
||||||
|
"#4527A0",
|
||||||
|
"#C62828",
|
||||||
|
"#424242",
|
||||||
|
]);
|
||||||
|
|
||||||
|
const plant_locations = d3
|
||||||
|
.nest()
|
||||||
|
.key((d) => d["location name"])
|
||||||
|
.rollup(function (v) {
|
||||||
|
return {
|
||||||
|
amount_processed: d3.sum(v, function (d) {
|
||||||
|
return d["amount processed (tonne)"];
|
||||||
|
}),
|
||||||
|
latitude: d3.mean(v, function (d) {
|
||||||
|
return d["latitude (deg)"];
|
||||||
|
}),
|
||||||
|
longitude: d3.mean(v, function (d) {
|
||||||
|
return d["longitude (deg)"];
|
||||||
|
}),
|
||||||
|
plant_types: [...new Set(v.map((d) => d["plant type"]))],
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.entries(csv_plants);
|
||||||
|
|
||||||
|
const plant_scale = d3
|
||||||
|
.scaleSqrt()
|
||||||
|
.range([2, 10])
|
||||||
|
.domain([0, d3.max(plant_locations, (d) => d.value.amount_processed)]);
|
||||||
|
|
||||||
|
const plants_array = [];
|
||||||
|
plant_locations.forEach((d) => {
|
||||||
|
if (d.value.plant_types.length > 1) {
|
||||||
|
d.value.plant_type = "Multiple";
|
||||||
|
} else {
|
||||||
|
d.value.plant_type = d.value.plant_types[0];
|
||||||
|
}
|
||||||
|
const marker = L.circleMarker([d.value.latitude, d.value.longitude], {
|
||||||
|
id: "circleMarker",
|
||||||
|
className: "marker",
|
||||||
|
color: "#222",
|
||||||
|
weight: 1,
|
||||||
|
fillColor: plant_color(d.value.plant_type),
|
||||||
|
fillOpacity: 0.9,
|
||||||
|
radius: plant_scale(d.value.amount_processed),
|
||||||
|
});
|
||||||
|
const num = d.value.amount_processed.toFixed(2);
|
||||||
|
const num_parts = num.toString().split(".");
|
||||||
|
num_parts[0] = num_parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||||
|
marker.bindTooltip(
|
||||||
|
`<b>${d.key}</b>
|
||||||
|
<br>
|
||||||
|
Amount processed:
|
||||||
|
${num_parts.join(".")}
|
||||||
|
<br>
|
||||||
|
Plant types:
|
||||||
|
${d.value.plant_types}`
|
||||||
|
);
|
||||||
|
plants_array.push(marker);
|
||||||
|
});
|
||||||
|
|
||||||
|
const collection_centers = d3
|
||||||
|
.nest()
|
||||||
|
.key((d) => d["source location name"])
|
||||||
|
.rollup(function (v) {
|
||||||
|
return {
|
||||||
|
source_lat: d3.mean(v, (d) => d["source latitude (deg)"]),
|
||||||
|
source_long: d3.mean(v, (d) => d["source longitude (deg)"]),
|
||||||
|
amount: d3.sum(v, (d) => d["amount (tonne)"]),
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.entries(csv_tr);
|
||||||
|
|
||||||
|
//Color scale for the collection centers
|
||||||
|
const colors = d3
|
||||||
|
.scaleLog()
|
||||||
|
.domain([
|
||||||
|
d3.min(collection_centers, (d) => d.value.amount),
|
||||||
|
d3.max(collection_centers, (d) => d.value.amount),
|
||||||
|
])
|
||||||
|
.range(["#777", "#777"]);
|
||||||
|
|
||||||
|
//Plot the collection centers
|
||||||
|
const collection_array = [];
|
||||||
|
collection_centers.forEach(function (d) {
|
||||||
|
const marker = L.circleMarker([d.value.source_lat, d.value.source_long], {
|
||||||
|
color: "#000",
|
||||||
|
fillColor: colors(d.value.amount),
|
||||||
|
fillOpacity: 1,
|
||||||
|
radius: 1.25,
|
||||||
|
weight: 0,
|
||||||
|
className: "marker",
|
||||||
|
});
|
||||||
|
collection_array.push(marker);
|
||||||
|
});
|
||||||
|
|
||||||
|
const transportation_lines = group(
|
||||||
|
csv_tr,
|
||||||
|
(d) => d["source location name"],
|
||||||
|
(d) => d["destination location name"]
|
||||||
|
);
|
||||||
|
|
||||||
|
//Plot the transportation lines
|
||||||
|
const transport_array = [];
|
||||||
|
transportation_lines.forEach(function (d1) {
|
||||||
|
d1.forEach(function (d2) {
|
||||||
|
const object = d2[0];
|
||||||
|
const line = L.polyline(
|
||||||
|
[
|
||||||
|
[object["source latitude (deg)"], object["source longitude (deg)"]],
|
||||||
|
[
|
||||||
|
object["destination latitude (deg)"],
|
||||||
|
object["destination longitude (deg)"],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
{
|
||||||
|
color: "#666",
|
||||||
|
stroke: true,
|
||||||
|
weight: 0.5,
|
||||||
|
opacity: Math.max(0.1, 0.5 / d1.size),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
transport_array.push(line);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const plants = L.layerGroup(plants_array);
|
||||||
|
const cities = L.layerGroup(collection_array);
|
||||||
|
const transport = L.layerGroup(transport_array);
|
||||||
|
|
||||||
|
const baseMaps = {
|
||||||
|
"Open Street Map": base,
|
||||||
|
};
|
||||||
|
const overlayMaps = {
|
||||||
|
Plants: plants,
|
||||||
|
"Collection Centers": cities,
|
||||||
|
"Transportation Lines": transport,
|
||||||
|
};
|
||||||
|
|
||||||
|
cities.on({
|
||||||
|
add: function () {
|
||||||
|
cities.eachLayer((layer) => layer.bringToBack());
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
transport.on({
|
||||||
|
add: function () {
|
||||||
|
plants.eachLayer((layer) => layer.bringToFront());
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
function setHeight() {
|
||||||
|
let mapDiv = document.getElementById("map");
|
||||||
|
mapDiv.style.height = `${+mapDiv.offsetWidth * 0.55}px`;
|
||||||
|
}
|
||||||
|
|
||||||
|
//$(window).resize(setHeight);
|
||||||
|
|
||||||
|
setHeight();
|
||||||
|
const map = L.map("map", {
|
||||||
|
layers: [base, plants],
|
||||||
|
}).setView([37.8, -96.9], 4);
|
||||||
|
|
||||||
|
const svg6 = d3.select(map.getPanes().overlayPane).append("svg");
|
||||||
|
svg6.append("g").attr("class", "leaflet-zoom-hide");
|
||||||
|
|
||||||
|
L.control.layers(baseMaps, overlayMaps).addTo(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
const MapBlock = (props) => {
|
||||||
|
const [filesFound, setFilesFound] = useState(false);
|
||||||
|
|
||||||
|
const fetchFiles = () => {
|
||||||
|
const file_prefix = `${SERVER_URL}/jobs/${props.job}/case`;
|
||||||
|
d3.csv(`${file_prefix}_plants.csv`).then((csv_plants) => {
|
||||||
|
d3.csv(`${file_prefix}_tr.csv`).then((csv_tr) => {
|
||||||
|
setFilesFound(true);
|
||||||
|
drawMap(csv_plants, csv_tr, file_prefix);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fetch files periodically from the server
|
||||||
|
useEffect(() => {
|
||||||
|
fetchFiles();
|
||||||
|
if (!filesFound) {
|
||||||
|
const interval = setInterval(() => {
|
||||||
|
fetchFiles();
|
||||||
|
}, 1000);
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}
|
||||||
|
}, [filesFound]);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Section title="Map" />
|
||||||
|
<Card>
|
||||||
|
<div id="map">
|
||||||
|
<div className="nodata">No data available</div>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default MapBlock;
|
||||||
28
relog-web/src/solver/SolverPage.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
|
import Footer from "../common/Footer";
|
||||||
|
import Header from "../common/Header";
|
||||||
|
import LogBlock from "./LogBlock";
|
||||||
|
import FilesBlock from "./FilesBlock";
|
||||||
|
import MapBlock from "./MapBlock";
|
||||||
|
|
||||||
|
const SolverPage = () => {
|
||||||
|
const params = useParams();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Header title="Solver"></Header>
|
||||||
|
<div id="contentBackground">
|
||||||
|
{" "}
|
||||||
|
<div id="content">
|
||||||
|
<LogBlock job={params.job_id} />
|
||||||
|
<FilesBlock job={params.job_id} />
|
||||||
|
<MapBlock job={params.job_id} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Footer />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default SolverPage;
|
||||||
11
src/RELOG.jl
@@ -4,20 +4,24 @@
|
|||||||
|
|
||||||
module RELOG
|
module RELOG
|
||||||
|
|
||||||
include("instance/structs.jl")
|
using Pkg
|
||||||
|
|
||||||
|
version() = Pkg.dependencies()[Base.UUID("a2afcdf7-cf04-4913-85f9-c0d81ddf2008")].version
|
||||||
|
|
||||||
|
include("instance/structs.jl")
|
||||||
include("graph/structs.jl")
|
include("graph/structs.jl")
|
||||||
|
|
||||||
|
include("instance/geodb.jl")
|
||||||
|
include("graph/dist.jl")
|
||||||
include("graph/build.jl")
|
include("graph/build.jl")
|
||||||
include("graph/csv.jl")
|
include("graph/csv.jl")
|
||||||
include("instance/compress.jl")
|
include("instance/compress.jl")
|
||||||
include("instance/geodb.jl")
|
|
||||||
include("instance/parse.jl")
|
include("instance/parse.jl")
|
||||||
include("instance/validate.jl")
|
include("instance/validate.jl")
|
||||||
include("model/build.jl")
|
include("model/build.jl")
|
||||||
include("model/getsol.jl")
|
include("model/getsol.jl")
|
||||||
include("model/solve.jl")
|
|
||||||
include("model/resolve.jl")
|
include("model/resolve.jl")
|
||||||
|
include("model/solve.jl")
|
||||||
include("reports/plant_emissions.jl")
|
include("reports/plant_emissions.jl")
|
||||||
include("reports/plant_outputs.jl")
|
include("reports/plant_outputs.jl")
|
||||||
include("reports/plants.jl")
|
include("reports/plants.jl")
|
||||||
@@ -25,4 +29,5 @@ include("reports/products.jl")
|
|||||||
include("reports/tr_emissions.jl")
|
include("reports/tr_emissions.jl")
|
||||||
include("reports/tr.jl")
|
include("reports/tr.jl")
|
||||||
include("reports/write.jl")
|
include("reports/write.jl")
|
||||||
|
include("web/web.jl")
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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.
|
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||||
# Released under the modified BSD license. See COPYING.md for more details.
|
# Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
|
||||||
using 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
|
function build_graph(instance::Instance)::Graph
|
||||||
arcs = []
|
arcs = []
|
||||||
next_index = 0
|
next_index = 0
|
||||||
@@ -18,6 +10,7 @@ function build_graph(instance::Instance)::Graph
|
|||||||
collection_shipping_nodes = ShippingNode[]
|
collection_shipping_nodes = ShippingNode[]
|
||||||
|
|
||||||
name_to_process_node_map = Dict{Tuple{AbstractString,AbstractString},ProcessNode}()
|
name_to_process_node_map = Dict{Tuple{AbstractString,AbstractString},ProcessNode}()
|
||||||
|
collection_center_to_node = Dict()
|
||||||
|
|
||||||
process_nodes_by_input_product =
|
process_nodes_by_input_product =
|
||||||
Dict(product => ProcessNode[] for product in instance.products)
|
Dict(product => ProcessNode[] for product in instance.products)
|
||||||
@@ -27,6 +20,7 @@ function build_graph(instance::Instance)::Graph
|
|||||||
for center in instance.collection_centers
|
for center in instance.collection_centers
|
||||||
node = ShippingNode(next_index, center, center.product, [], [])
|
node = ShippingNode(next_index, center, center.product, [], [])
|
||||||
next_index += 1
|
next_index += 1
|
||||||
|
collection_center_to_node[center] = node
|
||||||
push!(collection_shipping_nodes, node)
|
push!(collection_shipping_nodes, node)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -50,11 +44,12 @@ function build_graph(instance::Instance)::Graph
|
|||||||
# Build arcs from collection centers to plants, and from one plant to another
|
# Build arcs from collection centers to plants, and from one plant to another
|
||||||
for source in [collection_shipping_nodes; plant_shipping_nodes]
|
for source in [collection_shipping_nodes; plant_shipping_nodes]
|
||||||
for dest in process_nodes_by_input_product[source.product]
|
for dest in process_nodes_by_input_product[source.product]
|
||||||
distance = calculate_distance(
|
distance = _calculate_distance(
|
||||||
source.location.latitude,
|
source.location.latitude,
|
||||||
source.location.longitude,
|
source.location.longitude,
|
||||||
dest.location.latitude,
|
dest.location.latitude,
|
||||||
dest.location.longitude,
|
dest.location.longitude,
|
||||||
|
instance.distance_metric,
|
||||||
)
|
)
|
||||||
values = Dict("distance" => distance)
|
values = Dict("distance" => distance)
|
||||||
arc = Arc(source, dest, values)
|
arc = Arc(source, dest, values)
|
||||||
@@ -83,6 +78,7 @@ function build_graph(instance::Instance)::Graph
|
|||||||
collection_shipping_nodes,
|
collection_shipping_nodes,
|
||||||
arcs,
|
arcs,
|
||||||
name_to_process_node_map,
|
name_to_process_node_map,
|
||||||
|
collection_center_to_node,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
60
src/graph/dist.jl
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
# 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, missingstring = "NaN"))
|
||||||
|
dropmissing!(df)
|
||||||
|
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])
|
||||||
|
dist_pred = round(dist_euclidean * ratio_pred, digits = 3)
|
||||||
|
isfinite(dist_pred) || error("non-finite distance detected: $dist_pred")
|
||||||
|
return dist_pred
|
||||||
|
end
|
||||||
@@ -33,6 +33,7 @@ mutable struct Graph
|
|||||||
collection_shipping_nodes::Vector{ShippingNode}
|
collection_shipping_nodes::Vector{ShippingNode}
|
||||||
arcs::Vector{Arc}
|
arcs::Vector{Arc}
|
||||||
name_to_process_node_map::Dict{Tuple{AbstractString,AbstractString},ProcessNode}
|
name_to_process_node_map::Dict{Tuple{AbstractString,AbstractString},ProcessNode}
|
||||||
|
collection_center_to_node::Dict{CollectionCenter,ShippingNode}
|
||||||
end
|
end
|
||||||
|
|
||||||
function Base.show(io::IO, instance::Graph)
|
function Base.show(io::IO, instance::Graph)
|
||||||
|
|||||||
@@ -23,8 +23,20 @@ function parse(json)::Instance
|
|||||||
validate(json, Schema(json_schema))
|
validate(json, Schema(json_schema))
|
||||||
|
|
||||||
building_period = [1]
|
building_period = [1]
|
||||||
if "building period (years)" in keys(json)
|
if "building period (years)" in keys(json["parameters"])
|
||||||
building_period = json["building period (years)"]
|
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
|
end
|
||||||
|
|
||||||
plants = Plant[]
|
plants = Plant[]
|
||||||
@@ -37,6 +49,8 @@ function parse(json)::Instance
|
|||||||
cost = product_dict["transportation cost (\$/km/tonne)"]
|
cost = product_dict["transportation cost (\$/km/tonne)"]
|
||||||
energy = zeros(T)
|
energy = zeros(T)
|
||||||
emissions = Dict()
|
emissions = Dict()
|
||||||
|
disposal_limit = zeros(T)
|
||||||
|
disposal_cost = zeros(T)
|
||||||
|
|
||||||
if "transportation energy (J/km/tonne)" in keys(product_dict)
|
if "transportation energy (J/km/tonne)" in keys(product_dict)
|
||||||
energy = product_dict["transportation energy (J/km/tonne)"]
|
energy = product_dict["transportation energy (J/km/tonne)"]
|
||||||
@@ -46,7 +60,25 @@ function parse(json)::Instance
|
|||||||
emissions = product_dict["transportation emissions (tonne/km/tonne)"]
|
emissions = product_dict["transportation emissions (tonne/km/tonne)"]
|
||||||
end
|
end
|
||||||
|
|
||||||
product = Product(product_name, cost, energy, emissions)
|
if "disposal limit (tonne)" in keys(product_dict)
|
||||||
|
disposal_limit = product_dict["disposal limit (tonne)"]
|
||||||
|
end
|
||||||
|
|
||||||
|
if "disposal cost (\$/tonne)" in keys(product_dict)
|
||||||
|
disposal_cost = product_dict["disposal cost (\$/tonne)"]
|
||||||
|
end
|
||||||
|
|
||||||
|
prod_centers = []
|
||||||
|
|
||||||
|
product = Product(
|
||||||
|
product_name,
|
||||||
|
cost,
|
||||||
|
energy,
|
||||||
|
emissions,
|
||||||
|
disposal_limit,
|
||||||
|
disposal_cost,
|
||||||
|
prod_centers,
|
||||||
|
)
|
||||||
push!(products, product)
|
push!(products, product)
|
||||||
prod_name_to_product[product_name] = product
|
prod_name_to_product[product_name] = product
|
||||||
|
|
||||||
@@ -66,6 +98,7 @@ function parse(json)::Instance
|
|||||||
product,
|
product,
|
||||||
center_dict["amount (tonne)"],
|
center_dict["amount (tonne)"],
|
||||||
)
|
)
|
||||||
|
push!(prod_centers, center)
|
||||||
push!(collection_centers, center)
|
push!(collection_centers, center)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -176,5 +209,12 @@ function parse(json)::Instance
|
|||||||
@info @sprintf("%12d collection centers", length(collection_centers))
|
@info @sprintf("%12d collection centers", length(collection_centers))
|
||||||
@info @sprintf("%12d candidate plant locations", length(plants))
|
@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
|
end
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ mutable struct Product
|
|||||||
transportation_cost::Vector{Float64}
|
transportation_cost::Vector{Float64}
|
||||||
transportation_energy::Vector{Float64}
|
transportation_energy::Vector{Float64}
|
||||||
transportation_emissions::Dict{String,Vector{Float64}}
|
transportation_emissions::Dict{String,Vector{Float64}}
|
||||||
|
disposal_limit::Vector{Float64}
|
||||||
|
disposal_cost::Vector{Float64}
|
||||||
|
collection_centers::Vector
|
||||||
end
|
end
|
||||||
|
|
||||||
mutable struct CollectionCenter
|
mutable struct CollectionCenter
|
||||||
@@ -48,10 +51,21 @@ mutable struct Plant
|
|||||||
storage_cost::Vector{Float64}
|
storage_cost::Vector{Float64}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
abstract type DistanceMetric end
|
||||||
|
|
||||||
|
Base.@kwdef mutable struct KnnDrivingDistance <: DistanceMetric
|
||||||
|
tree = nothing
|
||||||
|
ratios = nothing
|
||||||
|
end
|
||||||
|
|
||||||
|
mutable struct EuclideanDistance <: DistanceMetric end
|
||||||
|
|
||||||
mutable struct Instance
|
mutable struct Instance
|
||||||
time::Int64
|
time::Int64
|
||||||
products::Vector{Product}
|
products::Vector{Product}
|
||||||
collection_centers::Vector{CollectionCenter}
|
collection_centers::Vector{CollectionCenter}
|
||||||
plants::Vector{Plant}
|
plants::Vector{Plant}
|
||||||
building_period::Vector{Int64}
|
building_period::Vector{Int64}
|
||||||
|
distance_metric::DistanceMetric
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,14 +12,10 @@ function validate(json, schema)
|
|||||||
result = JSONSchema.validate(json, schema)
|
result = JSONSchema.validate(json, schema)
|
||||||
if result !== nothing
|
if result !== nothing
|
||||||
if result isa JSONSchema.SingleIssue
|
if result isa JSONSchema.SingleIssue
|
||||||
path = join(result.path, " → ")
|
msg = "$(result.reason) in $(result.path)"
|
||||||
if length(path) == 0
|
|
||||||
path = "root"
|
|
||||||
end
|
|
||||||
msg = "$(result.msg) in $(path)"
|
|
||||||
else
|
else
|
||||||
msg = convert(String, result)
|
msg = convert(String, result)
|
||||||
end
|
end
|
||||||
throw(msg)
|
throw("Error parsing input file: $(msg)")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||||
# Released under the modified BSD license. See COPYING.md for more details.
|
# Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
|
||||||
using JuMP, LinearAlgebra, Geodesy, Cbc, Clp, ProgressBars, Printf, DataStructures
|
using JuMP, LinearAlgebra, Geodesy, ProgressBars, Printf, DataStructures
|
||||||
|
|
||||||
function build_model(instance::Instance, graph::Graph, optimizer)::JuMP.Model
|
function build_model(instance::Instance, graph::Graph, optimizer)::JuMP.Model
|
||||||
model = Model(optimizer)
|
model = Model(optimizer)
|
||||||
@@ -20,13 +20,17 @@ function create_vars!(model::JuMP.Model)
|
|||||||
graph, T = model[:graph], model[:instance].time
|
graph, T = model[:graph], model[:instance].time
|
||||||
model[:flow] =
|
model[:flow] =
|
||||||
Dict((a, t) => @variable(model, lower_bound = 0) for a in graph.arcs, t = 1:T)
|
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(
|
(n, t) => @variable(
|
||||||
model,
|
model,
|
||||||
lower_bound = 0,
|
lower_bound = 0,
|
||||||
upper_bound = n.location.disposal_limit[n.product][t]
|
upper_bound = n.location.disposal_limit[n.product][t]
|
||||||
) for n in values(graph.plant_shipping_nodes), t = 1: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(
|
model[:store] = Dict(
|
||||||
(n, t) =>
|
(n, t) =>
|
||||||
@variable(model, lower_bound = 0, upper_bound = n.location.storage_limit)
|
@variable(model, lower_bound = 0, upper_bound = n.location.storage_limit)
|
||||||
@@ -131,14 +135,25 @@ function create_objective_function!(model::JuMP.Model)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Shipping node costs
|
# Plant shipping node costs
|
||||||
for n in values(graph.plant_shipping_nodes), t = 1:T
|
for n in values(graph.plant_shipping_nodes), t = 1:T
|
||||||
|
|
||||||
# Disposal costs
|
# Disposal costs
|
||||||
add_to_expression!(
|
add_to_expression!(
|
||||||
obj,
|
obj,
|
||||||
n.location.disposal_cost[n.product][t],
|
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
|
end
|
||||||
|
|
||||||
@@ -154,16 +169,29 @@ function create_shipping_node_constraints!(model::JuMP.Model)
|
|||||||
for n in graph.collection_shipping_nodes
|
for n in graph.collection_shipping_nodes
|
||||||
model[:eq_balance][n, t] = @constraint(
|
model[:eq_balance][n, t] = @constraint(
|
||||||
model,
|
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
|
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
|
# Plants
|
||||||
for n in graph.plant_shipping_nodes
|
for n in graph.plant_shipping_nodes
|
||||||
@constraint(
|
@constraint(
|
||||||
model,
|
model,
|
||||||
sum(model[:flow][a, t] for a in n.incoming_arcs) ==
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||||
# Released under the modified BSD license. See COPYING.md for more details.
|
# Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
|
||||||
using JuMP, LinearAlgebra, Geodesy, Cbc, Clp, ProgressBars, Printf, DataStructures
|
using JuMP, LinearAlgebra, Geodesy, ProgressBars, Printf, DataStructures
|
||||||
|
|
||||||
function get_solution(model::JuMP.Model; marginal_costs = true)
|
function get_solution(model::JuMP.Model; marginal_costs = true)
|
||||||
graph, instance = model[:graph], model[:instance]
|
graph, instance = model[:graph], model[:instance]
|
||||||
@@ -39,21 +39,24 @@ function get_solution(model::JuMP.Model; marginal_costs = true)
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Products
|
# Products
|
||||||
if marginal_costs
|
for n in graph.collection_shipping_nodes
|
||||||
for n in graph.collection_shipping_nodes
|
location_dict = OrderedDict{Any,Any}(
|
||||||
location_dict = OrderedDict{Any,Any}(
|
"Latitude (deg)" => n.location.latitude,
|
||||||
"Marginal cost (\$/tonne)" => [
|
"Longitude (deg)" => n.location.longitude,
|
||||||
round(abs(JuMP.shadow_price(model[:eq_balance][n, t])), digits = 2) for t = 1:T
|
"Amount (tonne)" => n.location.amount,
|
||||||
],
|
"Dispose (tonne)" =>
|
||||||
"Latitude (deg)" => n.location.latitude,
|
[JuMP.value(model[:collection_dispose][n, t]) for t = 1:T],
|
||||||
"Longitude (deg)" => n.location.longitude,
|
)
|
||||||
"Amount (tonne)" => n.location.amount,
|
if marginal_costs
|
||||||
)
|
location_dict["Marginal cost (\$/tonne)"] = [
|
||||||
if n.product.name ∉ keys(output["Products"])
|
round(abs(JuMP.shadow_price(model[:eq_balance][n, t])), digits = 2) for
|
||||||
output["Products"][n.product.name] = OrderedDict()
|
t = 1:T
|
||||||
end
|
]
|
||||||
output["Products"][n.product.name][n.location.name] = location_dict
|
|
||||||
end
|
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
|
# Plants
|
||||||
@@ -178,13 +181,14 @@ function get_solution(model::JuMP.Model; marginal_costs = true)
|
|||||||
plant_dict["Total output"][product_name] = zeros(T)
|
plant_dict["Total output"][product_name] = zeros(T)
|
||||||
plant_dict["Output"]["Send"][product_name] = product_dict = OrderedDict()
|
plant_dict["Output"]["Send"][product_name] = product_dict = OrderedDict()
|
||||||
|
|
||||||
disposal_amount = [JuMP.value(model[:dispose][shipping_node, t]) for t = 1:T]
|
disposal_amount =
|
||||||
|
[JuMP.value(model[:plant_dispose][shipping_node, t]) for t = 1:T]
|
||||||
if sum(disposal_amount) > 1e-5
|
if sum(disposal_amount) > 1e-5
|
||||||
skip_plant = false
|
skip_plant = false
|
||||||
plant_dict["Output"]["Dispose"][product_name] =
|
plant_dict["Output"]["Dispose"][product_name] =
|
||||||
disposal_dict = OrderedDict()
|
disposal_dict = OrderedDict()
|
||||||
disposal_dict["Amount (tonne)"] =
|
disposal_dict["Amount (tonne)"] =
|
||||||
[JuMP.value(model[:dispose][shipping_node, t]) for t = 1:T]
|
[JuMP.value(model[:plant_dispose][shipping_node, t]) for t = 1:T]
|
||||||
disposal_dict["Cost (\$)"] = [
|
disposal_dict["Cost (\$)"] = [
|
||||||
disposal_dict["Amount (tonne)"][t] *
|
disposal_dict["Amount (tonne)"][t] *
|
||||||
plant.disposal_cost[shipping_node.product][t] for t = 1:T
|
plant.disposal_cost[shipping_node.product][t] for t = 1:T
|
||||||
|
|||||||
@@ -2,49 +2,60 @@
|
|||||||
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
# Copyright (C) 2020, UChicago Argonne, LLC. All rights reserved.
|
||||||
# Released under the modified BSD license. See COPYING.md for more details.
|
# Released under the modified BSD license. See COPYING.md for more details.
|
||||||
|
|
||||||
using JuMP, LinearAlgebra, Geodesy, Cbc, Clp, ProgressBars, Printf, DataStructures
|
using JuMP, LinearAlgebra, Geodesy, ProgressBars, Printf, DataStructures, HiGHS
|
||||||
|
|
||||||
function _get_default_milp_optimizer()
|
function _get_default_milp_optimizer()
|
||||||
return optimizer_with_attributes(Cbc.Optimizer, "logLevel" => 0)
|
return optimizer_with_attributes(HiGHS.Optimizer)
|
||||||
end
|
end
|
||||||
|
|
||||||
function _get_default_lp_optimizer()
|
function _get_default_lp_optimizer()
|
||||||
return optimizer_with_attributes(Clp.Optimizer, "LogLevel" => 0)
|
return optimizer_with_attributes(HiGHS.Optimizer)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function _print_graph_stats(instance::Instance, graph::Graph)::Nothing
|
function _print_graph_stats(instance::Instance, graph::Graph)::Nothing
|
||||||
@info @sprintf(" %12d time periods", instance.time)
|
@info @sprintf("%12d time periods", instance.time)
|
||||||
@info @sprintf(" %12d process nodes", length(graph.process_nodes))
|
@info @sprintf("%12d process nodes", length(graph.process_nodes))
|
||||||
@info @sprintf(" %12d shipping nodes (plant)", length(graph.plant_shipping_nodes))
|
@info @sprintf("%12d shipping nodes (plant)", length(graph.plant_shipping_nodes))
|
||||||
@info @sprintf(
|
@info @sprintf(
|
||||||
" %12d shipping nodes (collection)",
|
"%12d shipping nodes (collection)",
|
||||||
length(graph.collection_shipping_nodes)
|
length(graph.collection_shipping_nodes)
|
||||||
)
|
)
|
||||||
@info @sprintf(" %12d arcs", length(graph.arcs))
|
@info @sprintf("%12d arcs", length(graph.arcs))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
function solve(
|
function solve(
|
||||||
instance::Instance;
|
instance::Instance;
|
||||||
optimizer = nothing,
|
optimizer = nothing,
|
||||||
|
lp_optimizer = nothing,
|
||||||
output = nothing,
|
output = nothing,
|
||||||
marginal_costs = true,
|
marginal_costs = true,
|
||||||
return_model = false,
|
return_model = false,
|
||||||
)
|
)
|
||||||
|
|
||||||
milp_optimizer = lp_optimizer = optimizer
|
if lp_optimizer == nothing
|
||||||
if optimizer == nothing
|
if optimizer == nothing
|
||||||
milp_optimizer = _get_default_milp_optimizer()
|
# If neither is provided, use default LP optimizer.
|
||||||
lp_optimizer = _get_default_lp_optimizer()
|
lp_optimizer = _get_default_lp_optimizer()
|
||||||
|
else
|
||||||
|
# If only MIP optimizer is provided, use it as
|
||||||
|
# LP solver too.
|
||||||
|
lp_optimizer = optimizer
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if optimizer == nothing
|
||||||
|
optimizer = _get_default_milp_optimizer()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
@info "Building graph..."
|
@info "Building graph..."
|
||||||
graph = RELOG.build_graph(instance)
|
graph = RELOG.build_graph(instance)
|
||||||
_print_graph_stats(instance, graph)
|
_print_graph_stats(instance, graph)
|
||||||
|
|
||||||
@info "Building optimization model..."
|
@info "Building optimization model..."
|
||||||
model = RELOG.build_model(instance, graph, milp_optimizer)
|
model = RELOG.build_model(instance, graph, optimizer)
|
||||||
|
|
||||||
@info "Optimizing MILP..."
|
@info "Optimizing MILP..."
|
||||||
JuMP.optimize!(model)
|
JuMP.optimize!(model)
|
||||||
@@ -87,7 +98,13 @@ function solve(filename::AbstractString; heuristic = false, kwargs...)
|
|||||||
if heuristic && instance.time > 1
|
if heuristic && instance.time > 1
|
||||||
@info "Solving single-period version..."
|
@info "Solving single-period version..."
|
||||||
compressed = _compress(instance)
|
compressed = _compress(instance)
|
||||||
csol = solve(compressed; output = nothing, marginal_costs = false, kwargs...)
|
csol, _ = solve(
|
||||||
|
compressed;
|
||||||
|
return_model = true,
|
||||||
|
output = nothing,
|
||||||
|
marginal_costs = false,
|
||||||
|
kwargs...,
|
||||||
|
)
|
||||||
@info "Filtering candidate locations..."
|
@info "Filtering candidate locations..."
|
||||||
selected_pairs = []
|
selected_pairs = []
|
||||||
for (plant_name, plant_dict) in csol["Plants"]
|
for (plant_name, plant_dict) in csol["Plants"]
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ function products_report(solution; marginal_costs = true)::DataFrame
|
|||||||
df."longitude (deg)" = Float64[]
|
df."longitude (deg)" = Float64[]
|
||||||
df."year" = Int[]
|
df."year" = Int[]
|
||||||
df."amount (tonne)" = Float64[]
|
df."amount (tonne)" = Float64[]
|
||||||
|
df."amount disposed (tonne)" = Float64[]
|
||||||
df."marginal cost (\$/tonne)" = Float64[]
|
df."marginal cost (\$/tonne)" = Float64[]
|
||||||
T = length(solution["Energy"]["Plants (GJ)"])
|
T = length(solution["Energy"]["Plants (GJ)"])
|
||||||
for (prod_name, prod_dict) in solution["Products"]
|
for (prod_name, prod_dict) in solution["Products"]
|
||||||
@@ -22,6 +23,7 @@ function products_report(solution; marginal_costs = true)::DataFrame
|
|||||||
latitude = round(location_dict["Latitude (deg)"], digits = 6)
|
latitude = round(location_dict["Latitude (deg)"], digits = 6)
|
||||||
longitude = round(location_dict["Longitude (deg)"], digits = 6)
|
longitude = round(location_dict["Longitude (deg)"], digits = 6)
|
||||||
amount = location_dict["Amount (tonne)"][year]
|
amount = location_dict["Amount (tonne)"][year]
|
||||||
|
amount_disposed = location_dict["Dispose (tonne)"][year]
|
||||||
push!(
|
push!(
|
||||||
df,
|
df,
|
||||||
[
|
[
|
||||||
@@ -32,6 +34,7 @@ function products_report(solution; marginal_costs = true)::DataFrame
|
|||||||
year,
|
year,
|
||||||
amount,
|
amount,
|
||||||
marginal_cost,
|
marginal_cost,
|
||||||
|
amount_disposed,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,6 +14,9 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"time horizon (years)": {
|
"time horizon (years)": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
|
},
|
||||||
|
"distance metric": {
|
||||||
|
"type": "string"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
@@ -169,6 +172,12 @@
|
|||||||
},
|
},
|
||||||
"initial amounts": {
|
"initial amounts": {
|
||||||
"$ref": "#/definitions/InitialAmount"
|
"$ref": "#/definitions/InitialAmount"
|
||||||
|
},
|
||||||
|
"disposal limit (tonne)": {
|
||||||
|
"$ref": "#/definitions/TimeSeries"
|
||||||
|
},
|
||||||
|
"disposal cost ($/tonne)": {
|
||||||
|
"$ref": "#/definitions/TimeSeries"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
using PackageCompiler
|
|
||||||
|
|
||||||
using Cbc
|
|
||||||
using Clp
|
|
||||||
using Geodesy
|
|
||||||
using JSON
|
|
||||||
using JSONSchema
|
|
||||||
using JuMP
|
|
||||||
using MathOptInterface
|
|
||||||
using ProgressBars
|
|
||||||
|
|
||||||
pkg = [:Cbc, :Clp, :Geodesy, :JSON, :JSONSchema, :JuMP, :MathOptInterface, :ProgressBars]
|
|
||||||
|
|
||||||
@info "Building system image..."
|
|
||||||
create_sysimage(pkg, sysimage_path = "build/sysimage.so")
|
|
||||||
116
src/web/run.jl
Normal file
@@ -0,0 +1,116 @@
|
|||||||
|
println("Initializing...")
|
||||||
|
|
||||||
|
using Logging
|
||||||
|
using JSON
|
||||||
|
using JuMP
|
||||||
|
using HiGHS
|
||||||
|
using RELOG
|
||||||
|
|
||||||
|
function solve(root, filename)
|
||||||
|
ref_file = "$root/$filename"
|
||||||
|
optimizer = optimizer_with_attributes(
|
||||||
|
HiGHS.Optimizer,
|
||||||
|
"time_limit" => parse(Float64, ENV["RELOG_TIME_LIMIT_SEC"]),
|
||||||
|
)
|
||||||
|
ref_solution, ref_model = RELOG.solve(
|
||||||
|
ref_file,
|
||||||
|
heuristic = true,
|
||||||
|
optimizer = optimizer,
|
||||||
|
lp_optimizer = HiGHS.Optimizer,
|
||||||
|
return_model = true,
|
||||||
|
marginal_costs = true,
|
||||||
|
)
|
||||||
|
Libc.flush_cstdio()
|
||||||
|
flush(stdout)
|
||||||
|
sleep(1)
|
||||||
|
|
||||||
|
if length(ref_solution) == 0
|
||||||
|
return
|
||||||
|
end
|
||||||
|
RELOG.write_products_report(ref_solution, replace(ref_file, ".json" => "_products.csv"))
|
||||||
|
RELOG.write_plants_report(ref_solution, replace(ref_file, ".json" => "_plants.csv"))
|
||||||
|
RELOG.write_plant_outputs_report(
|
||||||
|
ref_solution,
|
||||||
|
replace(ref_file, ".json" => "_plant_outputs.csv"),
|
||||||
|
)
|
||||||
|
RELOG.write_plant_emissions_report(
|
||||||
|
ref_solution,
|
||||||
|
replace(ref_file, ".json" => "_plant_emissions.csv"),
|
||||||
|
)
|
||||||
|
RELOG.write_transportation_report(ref_solution, replace(ref_file, ".json" => "_tr.csv"))
|
||||||
|
RELOG.write_transportation_emissions_report(
|
||||||
|
ref_solution,
|
||||||
|
replace(ref_file, ".json" => "_tr_emissions.csv"),
|
||||||
|
)
|
||||||
|
|
||||||
|
isdir("$root/scenarios") || return
|
||||||
|
for filename in readdir("$root/scenarios")
|
||||||
|
scenario = "$root/scenarios/$filename"
|
||||||
|
endswith(filename, ".json") || continue
|
||||||
|
|
||||||
|
sc_solution = RELOG.resolve(
|
||||||
|
ref_model,
|
||||||
|
scenario,
|
||||||
|
optimizer = optimizer,
|
||||||
|
lp_optimizer = HiGHS.Optimizer,
|
||||||
|
)
|
||||||
|
if length(sc_solution) == 0
|
||||||
|
return
|
||||||
|
end
|
||||||
|
RELOG.write_plants_report(sc_solution, replace(scenario, ".json" => "_plants.csv"))
|
||||||
|
RELOG.write_products_report(
|
||||||
|
sc_solution,
|
||||||
|
replace(scenario, ".json" => "_products.csv"),
|
||||||
|
)
|
||||||
|
RELOG.write_plant_outputs_report(
|
||||||
|
sc_solution,
|
||||||
|
replace(scenario, ".json" => "_plant_outputs.csv"),
|
||||||
|
)
|
||||||
|
RELOG.write_plant_emissions_report(
|
||||||
|
sc_solution,
|
||||||
|
replace(scenario, ".json" => "_plant_emissions.csv"),
|
||||||
|
)
|
||||||
|
RELOG.write_transportation_report(
|
||||||
|
sc_solution,
|
||||||
|
replace(scenario, ".json" => "_tr.csv"),
|
||||||
|
)
|
||||||
|
RELOG.write_transportation_emissions_report(
|
||||||
|
sc_solution,
|
||||||
|
replace(scenario, ".json" => "_tr_emissions.csv"),
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function solve_recursive(path)
|
||||||
|
cd(path)
|
||||||
|
|
||||||
|
# Solve instances
|
||||||
|
for (root, dirs, files) in walkdir(".")
|
||||||
|
if occursin(r"scenarios"i, root)
|
||||||
|
continue
|
||||||
|
end
|
||||||
|
for filename in files
|
||||||
|
endswith(filename, ".json") || continue
|
||||||
|
solve(root, filename)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Collect results
|
||||||
|
results = []
|
||||||
|
for (root, dirs, files) in walkdir(".")
|
||||||
|
for filename in files
|
||||||
|
endswith(filename, "_plants.csv") || continue
|
||||||
|
push!(
|
||||||
|
results,
|
||||||
|
joinpath(replace(root, path => ""), replace(filename, "_plants.csv" => "")),
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
open("output.json", "w") do file
|
||||||
|
JSON.print(file, results)
|
||||||
|
end
|
||||||
|
|
||||||
|
run(`zip -r output.zip .`)
|
||||||
|
end
|
||||||
|
|
||||||
|
solve_recursive(ARGS[1])
|
||||||
65
src/web/web.jl
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
import HTTP
|
||||||
|
import JSON
|
||||||
|
using Random
|
||||||
|
|
||||||
|
const ROUTER = HTTP.Router()
|
||||||
|
const PROJECT_DIR = joinpath(dirname(@__FILE__), "..", "..")
|
||||||
|
const STATIC_DIR = joinpath(PROJECT_DIR, "relog-web", "build", "static")
|
||||||
|
const JOBS_DIR = joinpath(PROJECT_DIR, "jobs")
|
||||||
|
|
||||||
|
function serve_file(req::HTTP.Request, filename)
|
||||||
|
if isfile(filename)
|
||||||
|
open(filename) do file
|
||||||
|
return HTTP.Response(200, read(file))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return HTTP.Response(404)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function submit(req::HTTP.Request)
|
||||||
|
# Generate random job id
|
||||||
|
job_id = lowercase(randstring(12))
|
||||||
|
|
||||||
|
# Create job folder
|
||||||
|
job_path = joinpath(JOBS_DIR, job_id)
|
||||||
|
mkpath(job_path)
|
||||||
|
|
||||||
|
# Write JSON file
|
||||||
|
case = JSON.parse(String(req.body))
|
||||||
|
open(joinpath(job_path, "case.json"), "w") do file
|
||||||
|
JSON.print(file, case)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Run job
|
||||||
|
run(
|
||||||
|
`bash -c "(julia --project=$PROJECT_DIR $PROJECT_DIR/src/web/run.jl $job_path 2>&1 | tee $job_path/solve.log) >/dev/null 2>&1 &"`,
|
||||||
|
)
|
||||||
|
|
||||||
|
response = Dict("job_id" => job_id)
|
||||||
|
return HTTP.Response(200, body = JSON.json(response))
|
||||||
|
end
|
||||||
|
|
||||||
|
function get_index(req::HTTP.Request)
|
||||||
|
return serve_file(req, joinpath(STATIC_DIR, "..", "index.html"))
|
||||||
|
end
|
||||||
|
|
||||||
|
function get_static(req::HTTP.Request)
|
||||||
|
return serve_file(req, joinpath(STATIC_DIR, req.target[9:end]))
|
||||||
|
end
|
||||||
|
|
||||||
|
function get_jobs(req::HTTP.Request)
|
||||||
|
return serve_file(req, joinpath(JOBS_DIR, req.target[7:end]))
|
||||||
|
end
|
||||||
|
|
||||||
|
HTTP.@register(ROUTER, "GET", "/static", get_static)
|
||||||
|
HTTP.@register(ROUTER, "GET", "/jobs", get_jobs)
|
||||||
|
HTTP.@register(ROUTER, "POST", "/submit", submit)
|
||||||
|
HTTP.@register(ROUTER, "GET", "/", get_index)
|
||||||
|
|
||||||
|
function web(host = "127.0.0.1", port = 8080)
|
||||||
|
@info "Launching web interface: http://$(host):$(port)/"
|
||||||
|
Base.exit_on_sigint(false)
|
||||||
|
HTTP.serve(ROUTER, host, port)
|
||||||
|
Base.exit_on_sigint(true)
|
||||||
|
end
|
||||||
19
test/Project.toml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
name = "RELOGT"
|
||||||
|
uuid = "a6dae211-05d8-42ed-9081-b88c982fc90a"
|
||||||
|
authors = ["Alinson S. Xavier <git@axavier.org>"]
|
||||||
|
version = "0.1.0"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
Cbc = "9961bab8-2fa3-5c5a-9d89-47fab24efd76"
|
||||||
|
GZip = "92fee26a-97fe-5a0c-ad85-20a5f3185b63"
|
||||||
|
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
|
||||||
|
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
|
||||||
|
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
|
||||||
|
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
|
||||||
|
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
|
||||||
|
RELOG = "a2afcdf7-cf04-4913-85f9-c0d81ddf2008"
|
||||||
|
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
|
||||||
|
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
||||||
|
|
||||||
|
[compat]
|
||||||
|
JuliaFormatter = "1"
|
||||||
358
test/fixtures/s1.json
vendored
Normal file
@@ -0,0 +1,358 @@
|
|||||||
|
{
|
||||||
|
"parameters": {
|
||||||
|
"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 emissions (tonne/km/tonne)": {
|
||||||
|
"CO2": [
|
||||||
|
0.052,
|
||||||
|
0.050
|
||||||
|
],
|
||||||
|
"CH4": [
|
||||||
|
0.003,
|
||||||
|
0.002
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"initial amounts": {
|
||||||
|
"C1": {
|
||||||
|
"latitude (deg)": 7.0,
|
||||||
|
"longitude (deg)": 7.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
934.56,
|
||||||
|
934.56
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"C2": {
|
||||||
|
"latitude (deg)": 7.0,
|
||||||
|
"longitude (deg)": 19.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
198.95,
|
||||||
|
198.95
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"C3": {
|
||||||
|
"latitude (deg)": 84.0,
|
||||||
|
"longitude (deg)": 76.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
212.97,
|
||||||
|
212.97
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"C4": {
|
||||||
|
"latitude (deg)": 21.0,
|
||||||
|
"longitude (deg)": 16.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
352.19,
|
||||||
|
352.19
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"C5": {
|
||||||
|
"latitude (deg)": 32.0,
|
||||||
|
"longitude (deg)": 92.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
510.33,
|
||||||
|
510.33
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"C6": {
|
||||||
|
"latitude (deg)": 14.0,
|
||||||
|
"longitude (deg)": 62.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
471.66,
|
||||||
|
471.66
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"C7": {
|
||||||
|
"latitude (deg)": 30.0,
|
||||||
|
"longitude (deg)": 83.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
785.21,
|
||||||
|
785.21
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"C8": {
|
||||||
|
"latitude (deg)": 35.0,
|
||||||
|
"longitude (deg)": 40.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
706.17,
|
||||||
|
706.17
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"C9": {
|
||||||
|
"latitude (deg)": 74.0,
|
||||||
|
"longitude (deg)": 52.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
30.08,
|
||||||
|
30.08
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"C10": {
|
||||||
|
"latitude (deg)": 22.0,
|
||||||
|
"longitude (deg)": 54.0,
|
||||||
|
"amount (tonne)": [
|
||||||
|
536.52,
|
||||||
|
536.52
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"disposal limit (tonne)": [
|
||||||
|
1.0,
|
||||||
|
1.0
|
||||||
|
],
|
||||||
|
"disposal cost ($/tonne)": [
|
||||||
|
-1000,
|
||||||
|
-1000
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"P2": {
|
||||||
|
"transportation cost ($/km/tonne)": [
|
||||||
|
0.02,
|
||||||
|
0.02
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"P3": {
|
||||||
|
"transportation cost ($/km/tonne)": [
|
||||||
|
0.0125,
|
||||||
|
0.0125
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"P4": {
|
||||||
|
"transportation cost ($/km/tonne)": [
|
||||||
|
0.0175,
|
||||||
|
0.0175
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"plants": {
|
||||||
|
"F1": {
|
||||||
|
"input": "P1",
|
||||||
|
"outputs (tonne/tonne)": {
|
||||||
|
"P2": 0.2,
|
||||||
|
"P3": 0.5
|
||||||
|
},
|
||||||
|
"energy (GJ/tonne)": [
|
||||||
|
0.12,
|
||||||
|
0.11
|
||||||
|
],
|
||||||
|
"emissions (tonne/tonne)": {
|
||||||
|
"CO2": [
|
||||||
|
0.052,
|
||||||
|
0.050
|
||||||
|
],
|
||||||
|
"CH4": [
|
||||||
|
0.003,
|
||||||
|
0.002
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"locations": {
|
||||||
|
"L1": {
|
||||||
|
"latitude (deg)": 0.0,
|
||||||
|
"longitude (deg)": 0.0,
|
||||||
|
"disposal": {
|
||||||
|
"P2": {
|
||||||
|
"cost ($/tonne)": [
|
||||||
|
-10.0,
|
||||||
|
-10.0
|
||||||
|
],
|
||||||
|
"limit (tonne)": [
|
||||||
|
1.0,
|
||||||
|
1.0
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"P3": {
|
||||||
|
"cost ($/tonne)": [
|
||||||
|
-10.0,
|
||||||
|
-10.0
|
||||||
|
],
|
||||||
|
"limit (tonne)": [
|
||||||
|
1.0,
|
||||||
|
1.0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"capacities (tonne)": {
|
||||||
|
"250.0": {
|
||||||
|
"opening cost ($)": [
|
||||||
|
500.0,
|
||||||
|
500.0
|
||||||
|
],
|
||||||
|
"fixed operating cost ($)": [
|
||||||
|
30.0,
|
||||||
|
30.0
|
||||||
|
],
|
||||||
|
"variable operating cost ($/tonne)": [
|
||||||
|
30.0,
|
||||||
|
30.0
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"1000.0": {
|
||||||
|
"opening cost ($)": [
|
||||||
|
1250.0,
|
||||||
|
1250.0
|
||||||
|
],
|
||||||
|
"fixed operating cost ($)": [
|
||||||
|
30.0,
|
||||||
|
30.0
|
||||||
|
],
|
||||||
|
"variable operating cost ($/tonne)": [
|
||||||
|
30.0,
|
||||||
|
30.0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"L2": {
|
||||||
|
"latitude (deg)": 0.5,
|
||||||
|
"longitude (deg)": 0.5,
|
||||||
|
"capacities (tonne)": {
|
||||||
|
"0.0": {
|
||||||
|
"opening cost ($)": [
|
||||||
|
1000,
|
||||||
|
1000
|
||||||
|
],
|
||||||
|
"fixed operating cost ($)": [
|
||||||
|
50.0,
|
||||||
|
50.0
|
||||||
|
],
|
||||||
|
"variable operating cost ($/tonne)": [
|
||||||
|
50.0,
|
||||||
|
50.0
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"10000.0": {
|
||||||
|
"opening cost ($)": [
|
||||||
|
10000,
|
||||||
|
10000
|
||||||
|
],
|
||||||
|
"fixed operating cost ($)": [
|
||||||
|
50.0,
|
||||||
|
50.0
|
||||||
|
],
|
||||||
|
"variable operating cost ($/tonne)": [
|
||||||
|
50.0,
|
||||||
|
50.0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"F2": {
|
||||||
|
"input": "P2",
|
||||||
|
"outputs (tonne/tonne)": {
|
||||||
|
"P3": 0.05,
|
||||||
|
"P4": 0.80
|
||||||
|
},
|
||||||
|
"locations": {
|
||||||
|
"L3": {
|
||||||
|
"latitude (deg)": 25.0,
|
||||||
|
"longitude (deg)": 65.0,
|
||||||
|
"disposal": {
|
||||||
|
"P3": {
|
||||||
|
"cost ($/tonne)": [
|
||||||
|
100.0,
|
||||||
|
100.0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"capacities (tonne)": {
|
||||||
|
"1000.0": {
|
||||||
|
"opening cost ($)": [
|
||||||
|
3000,
|
||||||
|
3000
|
||||||
|
],
|
||||||
|
"fixed operating cost ($)": [
|
||||||
|
50.0,
|
||||||
|
50.0
|
||||||
|
],
|
||||||
|
"variable operating cost ($/tonne)": [
|
||||||
|
50.0,
|
||||||
|
50.0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"L4": {
|
||||||
|
"latitude (deg)": 0.75,
|
||||||
|
"longitude (deg)": 0.20,
|
||||||
|
"capacities (tonne)": {
|
||||||
|
"10000": {
|
||||||
|
"opening cost ($)": [
|
||||||
|
3000,
|
||||||
|
3000
|
||||||
|
],
|
||||||
|
"fixed operating cost ($)": [
|
||||||
|
50.0,
|
||||||
|
50.0
|
||||||
|
],
|
||||||
|
"variable operating cost ($/tonne)": [
|
||||||
|
50.0,
|
||||||
|
50.0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"F3": {
|
||||||
|
"input": "P4",
|
||||||
|
"locations": {
|
||||||
|
"L5": {
|
||||||
|
"latitude (deg)": 100.0,
|
||||||
|
"longitude (deg)": 100.0,
|
||||||
|
"capacities (tonne)": {
|
||||||
|
"15000": {
|
||||||
|
"opening cost ($)": [
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"fixed operating cost ($)": [
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"variable operating cost ($/tonne)": [
|
||||||
|
-15.0,
|
||||||
|
-15.0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"F4": {
|
||||||
|
"input": "P3",
|
||||||
|
"locations": {
|
||||||
|
"L6": {
|
||||||
|
"latitude (deg)": 50.0,
|
||||||
|
"longitude (deg)": 50.0,
|
||||||
|
"capacities (tonne)": {
|
||||||
|
"10000": {
|
||||||
|
"opening cost ($)": [
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"fixed operating cost ($)": [
|
||||||
|
0.0,
|
||||||
|
0.0
|
||||||
|
],
|
||||||
|
"variable operating cost ($/tonne)": [
|
||||||
|
-15.0,
|
||||||
|
-15.0
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
test/fixtures/s1.zip
vendored
Normal file
@@ -1,39 +0,0 @@
|
|||||||
# Copyright (C) 2020 Argonne National Laboratory
|
|
||||||
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
|
||||||
|
|
||||||
using RELOG
|
|
||||||
|
|
||||||
@testset "build_graph" begin
|
|
||||||
basedir = dirname(@__FILE__)
|
|
||||||
instance = RELOG.parsefile("$basedir/../../instances/s1.json")
|
|
||||||
graph = RELOG.build_graph(instance)
|
|
||||||
process_node_by_location_name =
|
|
||||||
Dict(n.location.location_name => n for n in graph.process_nodes)
|
|
||||||
|
|
||||||
@test length(graph.plant_shipping_nodes) == 8
|
|
||||||
@test length(graph.collection_shipping_nodes) == 10
|
|
||||||
@test length(graph.process_nodes) == 6
|
|
||||||
|
|
||||||
node = graph.collection_shipping_nodes[1]
|
|
||||||
@test node.location.name == "C1"
|
|
||||||
@test length(node.incoming_arcs) == 0
|
|
||||||
@test length(node.outgoing_arcs) == 2
|
|
||||||
@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
|
|
||||||
|
|
||||||
node = process_node_by_location_name["L1"]
|
|
||||||
@test node.location.plant_name == "F1"
|
|
||||||
@test node.location.location_name == "L1"
|
|
||||||
@test length(node.incoming_arcs) == 10
|
|
||||||
@test length(node.outgoing_arcs) == 2
|
|
||||||
|
|
||||||
node = process_node_by_location_name["L3"]
|
|
||||||
@test node.location.plant_name == "F2"
|
|
||||||
@test node.location.location_name == "L3"
|
|
||||||
@test length(node.incoming_arcs) == 2
|
|
||||||
@test length(node.outgoing_arcs) == 2
|
|
||||||
|
|
||||||
@test length(graph.arcs) == 38
|
|
||||||
end
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
# Copyright (C) 2020 Argonne National Laboratory
|
|
||||||
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
|
||||||
|
|
||||||
using RELOG
|
|
||||||
|
|
||||||
@testset "compress" begin
|
|
||||||
basedir = dirname(@__FILE__)
|
|
||||||
instance = RELOG.parsefile("$basedir/../../instances/s1.json")
|
|
||||||
compressed = RELOG._compress(instance)
|
|
||||||
|
|
||||||
product_name_to_product = Dict(p.name => p for p in compressed.products)
|
|
||||||
location_name_to_facility = Dict()
|
|
||||||
for p in compressed.plants
|
|
||||||
location_name_to_facility[p.location_name] = p
|
|
||||||
end
|
|
||||||
for c in compressed.collection_centers
|
|
||||||
location_name_to_facility[c.name] = c
|
|
||||||
end
|
|
||||||
|
|
||||||
p1 = product_name_to_product["P1"]
|
|
||||||
p2 = product_name_to_product["P2"]
|
|
||||||
p3 = product_name_to_product["P3"]
|
|
||||||
c1 = location_name_to_facility["C1"]
|
|
||||||
l1 = location_name_to_facility["L1"]
|
|
||||||
|
|
||||||
@test compressed.time == 1
|
|
||||||
@test compressed.building_period == [1]
|
|
||||||
|
|
||||||
@test p1.name == "P1"
|
|
||||||
@test p1.transportation_cost ≈ [0.015]
|
|
||||||
@test p1.transportation_energy ≈ [0.115]
|
|
||||||
@test p1.transportation_emissions["CO2"] ≈ [0.051]
|
|
||||||
@test p1.transportation_emissions["CH4"] ≈ [0.0025]
|
|
||||||
|
|
||||||
@test c1.name == "C1"
|
|
||||||
@test c1.amount ≈ [1869.12]
|
|
||||||
|
|
||||||
@test l1.plant_name == "F1"
|
|
||||||
@test l1.location_name == "L1"
|
|
||||||
@test l1.energy ≈ [0.115]
|
|
||||||
@test l1.emissions["CO2"] ≈ [0.051]
|
|
||||||
@test l1.emissions["CH4"] ≈ [0.0025]
|
|
||||||
@test l1.sizes[1].opening_cost ≈ [500]
|
|
||||||
@test l1.sizes[2].opening_cost ≈ [1250]
|
|
||||||
@test l1.sizes[1].fixed_operating_cost ≈ [60]
|
|
||||||
@test l1.sizes[2].fixed_operating_cost ≈ [60]
|
|
||||||
@test l1.sizes[1].variable_operating_cost ≈ [30]
|
|
||||||
@test l1.sizes[2].variable_operating_cost ≈ [30]
|
|
||||||
@test l1.disposal_limit[p2] ≈ [2.0]
|
|
||||||
@test l1.disposal_limit[p3] ≈ [2.0]
|
|
||||||
@test l1.disposal_cost[p2] ≈ [-10.0]
|
|
||||||
@test l1.disposal_cost[p3] ≈ [-10.0]
|
|
||||||
end
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
# 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 "geodb_query (2018-us-county)" begin
|
|
||||||
region = RELOG.geodb_query("2018-us-county:17043")
|
|
||||||
@test region.centroid.lat == 41.83956
|
|
||||||
@test region.centroid.lon == -88.08857
|
|
||||||
@test region.population == 922_921
|
|
||||||
end
|
|
||||||
|
|
||||||
# @testset "geodb_query (2018-us-zcta)" begin
|
|
||||||
# region = RELOG.geodb_query("2018-us-zcta:60439")
|
|
||||||
# @test region.centroid.lat == 41.68241
|
|
||||||
# @test region.centroid.lon == -87.98954
|
|
||||||
# end
|
|
||||||
|
|
||||||
@testset "geodb_query (us-state)" begin
|
|
||||||
region = RELOG.geodb_query("us-state:IL")
|
|
||||||
@test region.centroid.lat == 39.73939
|
|
||||||
@test region.centroid.lon == -89.50414
|
|
||||||
@test region.population == 12_671_821
|
|
||||||
end
|
|
||||||
@@ -1,86 +0,0 @@
|
|||||||
# Copyright (C) 2020 Argonne National Laboratory
|
|
||||||
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
|
||||||
|
|
||||||
using RELOG
|
|
||||||
|
|
||||||
@testset "parse" begin
|
|
||||||
basedir = dirname(@__FILE__)
|
|
||||||
instance = RELOG.parsefile("$basedir/../../instances/s1.json")
|
|
||||||
|
|
||||||
centers = instance.collection_centers
|
|
||||||
plants = instance.plants
|
|
||||||
products = instance.products
|
|
||||||
location_name_to_plant = Dict(p.location_name => p for p in plants)
|
|
||||||
product_name_to_product = Dict(p.name => p for p in products)
|
|
||||||
|
|
||||||
@test length(centers) == 10
|
|
||||||
@test centers[1].name == "C1"
|
|
||||||
@test centers[1].latitude == 7
|
|
||||||
@test centers[1].latitude == 7
|
|
||||||
@test centers[1].longitude == 7
|
|
||||||
@test centers[1].amount == [934.56, 934.56]
|
|
||||||
@test centers[1].product.name == "P1"
|
|
||||||
|
|
||||||
@test length(plants) == 6
|
|
||||||
|
|
||||||
plant = location_name_to_plant["L1"]
|
|
||||||
@test plant.plant_name == "F1"
|
|
||||||
@test plant.location_name == "L1"
|
|
||||||
@test plant.input.name == "P1"
|
|
||||||
@test plant.latitude == 0
|
|
||||||
@test plant.longitude == 0
|
|
||||||
|
|
||||||
@test length(plant.sizes) == 2
|
|
||||||
@test plant.sizes[1].capacity == 250
|
|
||||||
@test plant.sizes[1].opening_cost == [500, 500]
|
|
||||||
@test plant.sizes[1].fixed_operating_cost == [30, 30]
|
|
||||||
@test plant.sizes[1].variable_operating_cost == [30, 30]
|
|
||||||
@test plant.sizes[2].capacity == 1000
|
|
||||||
@test plant.sizes[2].opening_cost == [1250, 1250]
|
|
||||||
@test plant.sizes[2].fixed_operating_cost == [30, 30]
|
|
||||||
@test plant.sizes[2].variable_operating_cost == [30, 30]
|
|
||||||
|
|
||||||
p2 = product_name_to_product["P2"]
|
|
||||||
p3 = product_name_to_product["P3"]
|
|
||||||
@test length(plant.output) == 2
|
|
||||||
@test plant.output[p2] == 0.2
|
|
||||||
@test plant.output[p3] == 0.5
|
|
||||||
@test plant.disposal_limit[p2] == [1, 1]
|
|
||||||
@test plant.disposal_limit[p3] == [1, 1]
|
|
||||||
@test plant.disposal_cost[p2] == [-10, -10]
|
|
||||||
@test plant.disposal_cost[p3] == [-10, -10]
|
|
||||||
|
|
||||||
plant = location_name_to_plant["L3"]
|
|
||||||
@test plant.location_name == "L3"
|
|
||||||
@test plant.input.name == "P2"
|
|
||||||
@test plant.latitude == 25
|
|
||||||
@test plant.longitude == 65
|
|
||||||
|
|
||||||
@test length(plant.sizes) == 2
|
|
||||||
@test plant.sizes[1].capacity == 1000.0
|
|
||||||
@test plant.sizes[1].opening_cost == [3000, 3000]
|
|
||||||
@test plant.sizes[1].fixed_operating_cost == [50, 50]
|
|
||||||
@test plant.sizes[1].variable_operating_cost == [50, 50]
|
|
||||||
@test plant.sizes[1] == plant.sizes[2]
|
|
||||||
|
|
||||||
p4 = product_name_to_product["P4"]
|
|
||||||
@test plant.output[p3] == 0.05
|
|
||||||
@test plant.output[p4] == 0.8
|
|
||||||
@test plant.disposal_limit[p3] == [1e8, 1e8]
|
|
||||||
@test plant.disposal_limit[p4] == [0, 0]
|
|
||||||
end
|
|
||||||
|
|
||||||
@testset "parse (geodb)" begin
|
|
||||||
basedir = dirname(@__FILE__)
|
|
||||||
instance = RELOG.parsefile("$basedir/../../instances/s2.json")
|
|
||||||
|
|
||||||
centers = instance.collection_centers
|
|
||||||
@test centers[1].name == "C1"
|
|
||||||
@test centers[1].latitude == 41.83956
|
|
||||||
@test centers[1].longitude == -88.08857
|
|
||||||
end
|
|
||||||
|
|
||||||
# @testset "parse (invalid)" begin
|
|
||||||
# basedir = dirname(@__FILE__)
|
|
||||||
# @test_throws ErrorException RELOG.parsefile("$basedir/../fixtures/s1-wrong-length.json")
|
|
||||||
# end
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
# Copyright (C) 2020 Argonne National Laboratory
|
|
||||||
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
|
||||||
|
|
||||||
using RELOG, Cbc, JuMP, Printf, JSON, MathOptInterface.FileFormats
|
|
||||||
|
|
||||||
@testset "build" begin
|
|
||||||
basedir = dirname(@__FILE__)
|
|
||||||
instance = RELOG.parsefile("$basedir/../../instances/s1.json")
|
|
||||||
graph = RELOG.build_graph(instance)
|
|
||||||
model = RELOG.build_model(instance, graph, Cbc.Optimizer)
|
|
||||||
set_optimizer_attribute(model, "logLevel", 0)
|
|
||||||
|
|
||||||
process_node_by_location_name =
|
|
||||||
Dict(n.location.location_name => n for n in graph.process_nodes)
|
|
||||||
|
|
||||||
shipping_node_by_loc_and_prod_names = Dict(
|
|
||||||
(n.location.location_name, n.product.name) => n for n in graph.plant_shipping_nodes
|
|
||||||
)
|
|
||||||
|
|
||||||
@test length(model[:flow]) == 76
|
|
||||||
@test length(model[:dispose]) == 16
|
|
||||||
@test length(model[:open_plant]) == 12
|
|
||||||
@test length(model[:capacity]) == 12
|
|
||||||
@test length(model[:expansion]) == 12
|
|
||||||
|
|
||||||
l1 = process_node_by_location_name["L1"]
|
|
||||||
v = model[:capacity][l1, 1]
|
|
||||||
@test lower_bound(v) == 0.0
|
|
||||||
@test upper_bound(v) == 1000.0
|
|
||||||
|
|
||||||
v = model[:expansion][l1, 1]
|
|
||||||
@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]
|
|
||||||
@test lower_bound(v) == 0.0
|
|
||||||
@test upper_bound(v) == 1.0
|
|
||||||
end
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
# Copyright (C) 2020 Argonne National Laboratory
|
|
||||||
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
|
||||||
|
|
||||||
using RELOG
|
|
||||||
|
|
||||||
@testset "Resolve" begin
|
|
||||||
# Shoud not crash
|
|
||||||
filename = "$(pwd())/../instances/s1.json"
|
|
||||||
solution_old, model_old = RELOG.solve(filename, return_model = true)
|
|
||||||
solution_new = RELOG.resolve(model_old, filename)
|
|
||||||
end
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
# Copyright (C) 2020 Argonne National Laboratory
|
|
||||||
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
|
||||||
|
|
||||||
using RELOG, Cbc, JuMP, Printf, JSON, MathOptInterface.FileFormats
|
|
||||||
|
|
||||||
basedir = dirname(@__FILE__)
|
|
||||||
|
|
||||||
@testset "solve (exact)" begin
|
|
||||||
solution_filename_a = tempname()
|
|
||||||
solution_filename_b = tempname()
|
|
||||||
solution = RELOG.solve("$basedir/../../instances/s1.json", output = solution_filename_a)
|
|
||||||
|
|
||||||
@test isfile(solution_filename_a)
|
|
||||||
|
|
||||||
RELOG.write(solution, solution_filename_b)
|
|
||||||
@test isfile(solution_filename_b)
|
|
||||||
|
|
||||||
@test "Costs" in keys(solution)
|
|
||||||
@test "Fixed operating (\$)" in keys(solution["Costs"])
|
|
||||||
@test "Transportation (\$)" in keys(solution["Costs"])
|
|
||||||
@test "Variable operating (\$)" in keys(solution["Costs"])
|
|
||||||
@test "Total (\$)" in keys(solution["Costs"])
|
|
||||||
|
|
||||||
@test "Plants" in keys(solution)
|
|
||||||
@test "F1" in keys(solution["Plants"])
|
|
||||||
@test "F2" in keys(solution["Plants"])
|
|
||||||
@test "F3" in keys(solution["Plants"])
|
|
||||||
@test "F4" in keys(solution["Plants"])
|
|
||||||
end
|
|
||||||
|
|
||||||
@testset "solve (heuristic)" begin
|
|
||||||
# Should not crash
|
|
||||||
solution = RELOG.solve("$basedir/../../instances/s1.json", heuristic = true)
|
|
||||||
end
|
|
||||||
|
|
||||||
@testset "solve (infeasible)" begin
|
|
||||||
json = JSON.parsefile("$basedir/../../instances/s1.json")
|
|
||||||
for (location_name, location_dict) in json["products"]["P1"]["initial amounts"]
|
|
||||||
location_dict["amount (tonne)"] *= 1000
|
|
||||||
end
|
|
||||||
@test_throws ErrorException("No solution available") RELOG.solve(RELOG.parse(json))
|
|
||||||
end
|
|
||||||
|
|
||||||
@testset "solve (with storage)" begin
|
|
||||||
basedir = dirname(@__FILE__)
|
|
||||||
filename = "$basedir/../fixtures/storage.json"
|
|
||||||
instance = RELOG.parsefile(filename)
|
|
||||||
@test instance.plants[1].storage_limit == 50.0
|
|
||||||
@test instance.plants[1].storage_cost == [2.0, 1.5, 1.0]
|
|
||||||
|
|
||||||
solution = RELOG.solve(filename)
|
|
||||||
plant_dict = solution["Plants"]["mega plant"]["Chicago"]
|
|
||||||
@test plant_dict["Variable operating cost (\$)"] == [500.0, 0.0, 100.0]
|
|
||||||
@test plant_dict["Process (tonne)"] == [50.0, 0.0, 50.0]
|
|
||||||
@test plant_dict["Storage (tonne)"] == [50.0, 50.0, 0.0]
|
|
||||||
@test plant_dict["Storage cost (\$)"] == [100.0, 75.0, 0.0]
|
|
||||||
|
|
||||||
@test solution["Costs"]["Variable operating (\$)"] == [500.0, 0.0, 100.0]
|
|
||||||
@test solution["Costs"]["Storage (\$)"] == [100.0, 75.0, 0.0]
|
|
||||||
@test solution["Costs"]["Total (\$)"] == [600.0, 75.0, 100.0]
|
|
||||||
end
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
# 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, JSON, GZip
|
|
||||||
|
|
||||||
@testset "Reports" begin
|
|
||||||
@testset "from solve" begin
|
|
||||||
solution = RELOG.solve("$(pwd())/../instances/s1.json")
|
|
||||||
tmp_filename = tempname()
|
|
||||||
# The following should not crash
|
|
||||||
RELOG.write_plant_emissions_report(solution, tmp_filename)
|
|
||||||
RELOG.write_plant_outputs_report(solution, tmp_filename)
|
|
||||||
RELOG.write_plants_report(solution, tmp_filename)
|
|
||||||
RELOG.write_products_report(solution, tmp_filename)
|
|
||||||
RELOG.write_transportation_emissions_report(solution, tmp_filename)
|
|
||||||
RELOG.write_transportation_report(solution, tmp_filename)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
# Copyright (C) 2020 Argonne National Laboratory
|
|
||||||
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
|
||||||
|
|
||||||
using Test
|
|
||||||
|
|
||||||
@testset "RELOG" begin
|
|
||||||
@testset "Instance" begin
|
|
||||||
include("instance/compress_test.jl")
|
|
||||||
include("instance/geodb_test.jl")
|
|
||||||
include("instance/parse_test.jl")
|
|
||||||
end
|
|
||||||
@testset "Graph" begin
|
|
||||||
include("graph/build_test.jl")
|
|
||||||
end
|
|
||||||
@testset "Model" begin
|
|
||||||
include("model/build_test.jl")
|
|
||||||
include("model/solve_test.jl")
|
|
||||||
include("model/resolve_test.jl")
|
|
||||||
end
|
|
||||||
include("reports_test.jl")
|
|
||||||
end
|
|
||||||
51
test/src/RELOGT.jl
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
module RELOGT
|
||||||
|
|
||||||
|
using Test
|
||||||
|
using JuliaFormatter
|
||||||
|
|
||||||
|
include("instance/compress_test.jl")
|
||||||
|
include("instance/geodb_test.jl")
|
||||||
|
include("instance/parse_test.jl")
|
||||||
|
include("graph/build_test.jl")
|
||||||
|
include("graph/dist_test.jl")
|
||||||
|
include("model/build_test.jl")
|
||||||
|
include("model/solve_test.jl")
|
||||||
|
include("model/resolve_test.jl")
|
||||||
|
include("reports_test.jl")
|
||||||
|
|
||||||
|
basedir = dirname(@__FILE__)
|
||||||
|
|
||||||
|
function fixture(path::String)::String
|
||||||
|
return "$basedir/../fixtures/$path"
|
||||||
|
end
|
||||||
|
|
||||||
|
function runtests()
|
||||||
|
@testset "RELOG" begin
|
||||||
|
@testset "instance" begin
|
||||||
|
instance_compress_test()
|
||||||
|
instance_geodb_test()
|
||||||
|
instance_parse_test()
|
||||||
|
end
|
||||||
|
@testset "graph" begin
|
||||||
|
graph_build_test()
|
||||||
|
graph_dist_test()
|
||||||
|
end
|
||||||
|
@testset "model" begin
|
||||||
|
model_build_test()
|
||||||
|
model_solve_test()
|
||||||
|
model_resolve_test()
|
||||||
|
end
|
||||||
|
reports_test()
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
function format()
|
||||||
|
JuliaFormatter.format(basedir, verbose = true)
|
||||||
|
JuliaFormatter.format("$basedir/../../src", verbose = true)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
export runtests, format
|
||||||
|
|
||||||
|
end # module RELOGT
|
||||||
40
test/src/graph/build_test.jl
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# Copyright (C) 2020 Argonne National Laboratory
|
||||||
|
# Written by Alinson Santos Xavier <axavier@anl.gov>
|
||||||
|
|
||||||
|
using RELOG
|
||||||
|
|
||||||
|
function graph_build_test()
|
||||||
|
@testset "build_graph" begin
|
||||||
|
instance = RELOG.parsefile(fixture("s1.json"))
|
||||||
|
graph = RELOG.build_graph(instance)
|
||||||
|
process_node_by_location_name =
|
||||||
|
Dict(n.location.location_name => n for n in graph.process_nodes)
|
||||||
|
|
||||||
|
@test length(graph.plant_shipping_nodes) == 8
|
||||||
|
@test length(graph.collection_shipping_nodes) == 10
|
||||||
|
@test length(graph.process_nodes) == 6
|
||||||
|
|
||||||
|
node = graph.collection_shipping_nodes[1]
|
||||||
|
@test node.location.name == "C1"
|
||||||
|
@test length(node.incoming_arcs) == 0
|
||||||
|
@test length(node.outgoing_arcs) == 2
|
||||||
|
@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"] == 1695.364
|
||||||
|
|
||||||
|
node = process_node_by_location_name["L1"]
|
||||||
|
@test node.location.plant_name == "F1"
|
||||||
|
@test node.location.location_name == "L1"
|
||||||
|
@test length(node.incoming_arcs) == 10
|
||||||
|
@test length(node.outgoing_arcs) == 2
|
||||||
|
|
||||||
|
node = process_node_by_location_name["L3"]
|
||||||
|
@test node.location.plant_name == "F2"
|
||||||
|
@test node.location.location_name == "L3"
|
||||||
|
@test length(node.incoming_arcs) == 2
|
||||||
|
@test length(node.outgoing_arcs) == 2
|
||||||
|
|
||||||
|
@test length(graph.arcs) == 38
|
||||||
|
end
|
||||||
|
end
|
||||||