6 Commits

40 changed files with 429 additions and 535 deletions

View File

@@ -10,7 +10,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
version: ['1.3', '1.4', '1.5', '1.6']
version: ['1.6', '1.7', '1.8']
os:
- ubuntu-latest
arch:

View File

@@ -11,39 +11,43 @@ All notable changes to this project will be documented in this file.
[semver]: https://semver.org/spec/v2.0.0.html
[pkjjl]: https://pkgdocs.julialang.org/v1/compatibility/#compat-pre-1.0
## [0.5.2] -- 2022-08-26
### Changed
- Update to JuMP 1.x
## [0.5.1] -- 2021-07-23
## Added
### Added
- Allow user to specify locations as unique identifiers, instead of latitude and longitude (e.g. `us-state:IL` or `2018-us-county:17043`)
- Add what-if scenarios.
- Add products report.
## [0.5.0] -- 2021-01-06
## Added
### Added
- Allow plants to store input material for processing in later years
## [0.4.0] -- 2020-09-18
## Added
### Added
- Generate simplified solution reports (CSV)
## [0.3.3] -- 2020-10-13
## Added
### Added
- Add option to write solution to JSON file in RELOG.solve
- Improve error message when instance is infeasible
- Make output file more readable
## [0.3.2] -- 2020-10-07
## Added
### Added
- Add "building period" parameter
## [0.3.1] -- 2020-07-17
## Fixed
### Fixed
- Fix expansion cost breakdown
## [0.3.0] -- 2020-06-25
## Added
### Added
- Track emissions and energy (transportation and plants)
## Changed
### Changed
- Minor changes to input file format:
- Make all dictionary keys lowercase
- Rename "outputs (tonne)" to "outputs (tonne/tonne)"

View File

@@ -1,25 +1,19 @@
JULIA := julia --project=.
SRC_FILES := $(wildcard src/*.jl test/*.jl)
VERSION := 0.5
all: docs test
build/sysimage.so: src/sysimage.jl Project.toml Manifest.toml
@$(JULIA) src/sysimage.jl
clean:
rm -rf build/*
rm -rfv build Manifest.toml test/Manifest.toml deps/formatter/build deps/formatter/Manifest.toml
docs:
mkdocs build -d ../docs/$(VERSION)/
cd docs; julia --project=. make.jl; cd ..
rsync -avP --delete-after docs/build/ ../docs/$(VERSION)/
format:
julia -e 'using JuliaFormatter; format(["src", "test"], verbose=true);'
cd deps/formatter; ../../juliaw format.jl
test:
@$(JULIA) --sysimage build/sysimage.so test/runtests.jl
test: test/Manifest.toml
./juliaw test/runtests.jl
test-watch:
bash -c "while true; do make test --quiet; sleep 1; done"
test/Manifest.toml: test/Project.toml
julia --project=test -e "using Pkg; Pkg.instantiate()"
.PHONY: docs test
.PHONY: docs test format

View File

@@ -1,7 +1,7 @@
name = "RELOG"
uuid = "a2afcdf7-cf04-4913-85f9-c0d81ddf2008"
authors = ["Alinson S Xavier <axavier@anl.gov>"]
version = "0.5.1"
version = "0.5.2"
[deps]
CRC = "44b605c4-b955-5f2b-9b6d-d2bd01d3d205"
@@ -19,7 +19,6 @@ JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
PackageCompiler = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
ProgressBars = "49802e3a-d2f1-5c88-81d8-b72133a6f568"
Shapefile = "8e980c4a-a4fe-5da2-b3a7-4b4b0353a2f4"
@@ -29,20 +28,19 @@ ZipFile = "a5390f91-8eb1-5f08-bee0-b1d1ffed6cea"
[compat]
CRC = "4"
CSV = "0.7"
Cbc = "0.6"
Clp = "0.8"
DataFrames = "0.21"
DataStructures = "0.17"
CSV = "0.10"
Cbc = "1"
Clp = "1"
DataFrames = "1"
DataStructures = "0.18"
GZip = "0.5"
Geodesy = "0.5"
Geodesy = "1"
JSON = "0.21"
JSONSchema = "0.3"
JuMP = "0.21"
MathOptInterface = "0.9"
OrderedCollections = "1.4"
PackageCompiler = "1"
ProgressBars = "0.6"
Shapefile = "0.7"
ZipFile = "0.9"
JSONSchema = "1"
JuMP = "1"
MathOptInterface = "1"
OrderedCollections = "1"
ProgressBars = "1"
Shapefile = "0.8"
ZipFile = "0.10"
julia = "1"

View File

@@ -15,7 +15,7 @@
<img src="https://anl-ceeesa.github.io/RELOG/0.5/images/ex_transportation.png" width="1000px"/>
<img src="https://anl-ceeesa.github.io/RELOG/0.5/assets/ex_transportation.png" width="1000px"/>
### Documentation
@@ -26,8 +26,10 @@
### Authors
* **Alinson S. Xavier,** Argonne National Laboratory <<axavier@anl.gov>>
* **Nwike Iloeje,** Argonne National Laboratory <<ciloeje@anl.gov>>
* **Alinson S. Xavier** <<axavier@anl.gov>>
* **Nwike Iloeje** <<ciloeje@anl.gov>>
* **John Atkins**
* **Kyle Sun**
### License

5
deps/formatter/Project.toml vendored Normal file
View File

@@ -0,0 +1,5 @@
[deps]
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
[compat]
JuliaFormatter = "0.14.4"

8
deps/formatter/format.jl vendored Normal file
View File

@@ -0,0 +1,8 @@
using JuliaFormatter
format(
[
"../../src",
"../../test",
],
verbose=true,
)

4
docs/Project.toml Normal file
View 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
View 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()

View 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);
}

View File

Before

Width:  |  Height:  |  Size: 52 KiB

After

Width:  |  Height:  |  Size: 52 KiB

View File

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 37 KiB

View File

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

Before

Width:  |  Height:  |  Size: 91 KiB

After

Width:  |  Height:  |  Size: 91 KiB

View File

Before

Width:  |  Height:  |  Size: 586 KiB

After

Width:  |  Height:  |  Size: 586 KiB

View File

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 29 KiB

View File

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View File

@@ -11,7 +11,7 @@ RELOG accepts as input a JSON file with three sections: `parameters`, `products`
The **parameters** section describes details about the simulation itself.
| Key | Description
|:--------------------------|---------------|
|:--------------------------|:---------------|
|`time horizon (years)` | Number of years in the simulation.
|`building period (years)` | List of years in which we are allowed to open new plants. For example, if this parameter is set to `[1,2,3]`, we can only open plants during the first three years. By default, this equals `[1]`; that is, plants can only be opened during the first year. |
@@ -31,18 +31,16 @@ The **parameters** section describes details about the simulation itself.
The **products** section describes all products and subproducts in the simulation. The field `instance["Products"]` is a dictionary mapping the name of the product to a dictionary which describes its characteristics. Each product description contains the following keys:
| Key | Description
|:--------------------------------------|---------------|
|:--------------------------------------|:---------------|
|`transportation cost ($/km/tonne)` | The cost to transport this product. Must be a time series.
|`transportation energy (J/km/tonne)` | The energy required to transport this product. Must be a time series. Optional.
|`transportation emissions (tonne/km/tonne)` | A dictionary mapping the name of each greenhouse gas, produced to transport one tonne of this product along one kilometer, to the amount of gas produced (in tonnes). Must be a time series. Optional.
|`initial amounts` | A dictionary mapping the name of each location to its description (see below). If this product is not initially available, this key may be omitted. Must be a time series.
| `disposal limit (tonne)` | Total amount of product that can be disposed of across all collection centers. If omitted, all product must be processed. This parameter has no effect on product disposal at plants.
| `disposal cost ($/tonne)` | Cost of disposing one tonne of this product at a collection center. If omitted, defaults to zero. This parameter has no effect on product disposal costs at plants.
Each product may have some amount available at the beginning of each time period. In this case, the key `initial amounts` maps to a dictionary with the following keys:
| Key | Description
|:------------------------|---------------|
|:------------------------|:---------------|
| `latitude (deg)` | The latitude of the location.
| `longitude (deg)` | The longitude of the location.
| `amount (tonne)` | The amount of the product initially available at the location. Must be a time series.
@@ -75,9 +73,7 @@ Each product may have some amount available at the beginning of each time period
"transportation emissions (tonne/km/tonne)": {
"CO2": [0.052, 0.050],
"CH4": [0.003, 0.002]
},
"disposal cost ($/tonne)": [-10.0, -12.0],
"disposal limit (tonne)": [1.0, 1.0],
}
},
"P2": {
"transportation cost ($/km/tonne)": [0.022, 0.020]
@@ -97,7 +93,7 @@ Each product may have some amount available at the beginning of each time period
The **plants** section describes the available types of reverse manufacturing plants, their potential locations and associated costs, as well as their inputs and outputs. The field `instance["Plants"]` is a dictionary mapping the name of the plant to a dictionary with the following keys:
| Key | Description
|:------------------------|---------------|
|:------------------------|:---------------|
| `input` | The name of the product that this plant takes as input. Only one input is accepted per plant.
| `outputs (tonne/tonne)` | A dictionary specifying how many tonnes of each product is produced for each tonnes of input. For example, if the plant outputs 0.5 tonnes of P2 and 0.25 tonnes of P3 for each tonnes of P1 provided, then this entry should be `{"P2": 0.5, "P3": 0.25}`. If the plant does not output anything, this key may be omitted.
|`energy (GJ/tonne)` | The energy required to process 1 tonne of the input. Must be a time series. Optional.
@@ -117,14 +113,14 @@ Each type of plant is associated with a set of potential locations where it can
The `storage` dictionary should contain the following keys:
| Key | Description
|:------------------------|---------------|
|:------------------------|:---------------|
| `cost ($/tonne)` | The cost to store a tonne of input product for one time period. Must be a time series.
| `limit (tonne)` | The maximum amount of input product this plant can have in storage at any given time.
The keys in the `disposal` dictionary should be the names of the products. The values are dictionaries with the following keys:
| Key | Description
|:------------------------|---------------|
|:------------------------|:---------------|
| `cost ($/tonne)` | The cost to dispose of the product. Must be a time series.
| `limit (tonne)` | The maximum amount that can be disposed of. If an unlimited amount can be disposed, this key may be omitted. Must be a time series.
@@ -132,7 +128,7 @@ The keys in the `disposal` dictionary should be the names of the products. The v
The keys in the `capacities (tonne)` dictionary should be the amounts (in tonnes). The values are dictionaries with the following keys:
| Key | Description
|:--------------------------------------|---------------|
|:--------------------------------------|:---------------|
| `opening cost ($)` | The cost to open a plant of this size.
| `fixed operating cost ($)` | The cost to keep the plant open, even if the plant doesn't process anything. Must be a time series.
| `variable operating cost ($/tonne)` | The cost that the plant incurs to process each tonne of input. Must be a time series.
@@ -214,7 +210,7 @@ is is possible to write:
Location names follow the format `db:id`, where `db` is the name of the database and `id` is the identifier for a specific location. RELOG currently includes the following databases:
Database | Description | Examples
---------|-------------|----------
:--------|:------------|:---------
`us-state`| List of states of the United States. | `us-state:IL` (State of Illinois)
`2018-us-county` | List of United States counties, as of 2018. IDs are 5-digit FIPS codes. | `2018-us-county:17043` (DuPage county in Illinois)

View File

@@ -1,25 +1,29 @@
# RELOG: Reverse Logistics Optimization
**RELOG** is an open-source supply chain optimization package focusing on reverse logistics and reverse manufacturing. The package uses Mixed-Integer Linear Programming to determine where to build recycling plants, what size should these plants have and which customers should be served by which plants. The package supports custom reverse logistics pipelines, with multiple types of plants, multiple types of product and multiple time periods.
<img src="images/ex_transportation.png" width="1000px"/>
```@raw html
<center>
<img src="assets/ex_transportation.png" width="1000px"/>
</center>
```
### Table of Contents
* [Usage](usage.md)
* [Input and Output Data Formats](format.md)
* [Simplified Solution Reports](reports.md)
* [Optimization Model](model.md)
```@contents
Pages = ["usage.md", "format.md", "reports.md", "model.md"]
Depth = 3
```
### Source Code
* [https://github.com/ANL-CEEESA/RELOG](https://github.com/ANL-CEEESA/RELOG)
### Authors
* **Alinson S. Xavier,** Argonne National Laboratory <<axavier@anl.gov>>
* **Nwike Iloeje,** Argonne National Laboratory <<ciloeje@anl.gov>>
* **Alinson S. Xavier,** Argonne National Laboratory <axavier@anl.gov>
* **Nwike Iloeje,** Argonne National Laboratory <ciloeje@anl.gov>
### License

View File

@@ -6,53 +6,65 @@ In this page, we describe the precise mathematical optimization model used by RE
### Sets
* $L$ - Set of locations holding the original material to be recycled
* $M$ - Set of materials recovered during the reverse manufacturing process
* $P$ - Set of potential plants to open
* $T = \{ 1, \ldots, t^{max} \} $ - Set of time periods
Symbol | Description
:-------|:------------
$L$ | Set of locations holding the original material to be recycled
$M$ | Set of materials recovered during the reverse manufacturing process
$P$ | Set of potential plants to open
$T = \{ 1, \ldots, t^{max} \}$ | Set of time periods
### Constants
**Plants:**
#### Plants
* $c^\text{disp}_{pmt}$ - Cost of disposing one tonne of material $m$ at plant $p$ during time $t$ (`$/tonne/km`)
* $c^\text{exp}_{pt}$ - Cost of adding one tonne of capacity to plant $p$ at time $t$ (`$/tonne`)
* $c^\text{open}_{pt}$ - Cost of opening plant $p$ at time $t$, at minimum capacity (`$`)
* $c^\text{f-base}_{pt}$ - Fixed cost of keeping plant $p$ open during time period $t$ (`$`)
* $c^\text{f-exp}_{pt}$ - Increase in fixed cost for each additional tonne of capacity (`$/tonne`)
* $c^\text{var}_{pt}$ - Variable cost of processing one tonne of input at plant $p$ at time $t$ (`$/tonne`)
* $c^\text{store}_{pt}$ - Cost of storing one tonne of original material at plant $p$ at time $t$ (`$/tonne`)
* $m^\text{min}_p$ - Minimum capacity of plant $p$ (`tonne`)
* $m^\text{max}_p$ - Maximum capacity of plant $p$ (`tonne`)
* $m^\text{disp}_{pmt}$ - Maximum amount of material $m$ that plant $p$ can dispose of during time $t$ (`tonne`)
* $m^\text{store}_p$ - Maximum amount of original material that plant $p$ can store for later processing.
Symbol | Description | Unit
:-------|:------------|:---
$c^\text{disp}_{pmt}$ | Cost of disposing one tonne of material $m$ at plant $p$ during time $t$ | \$/tonne/km
$c^\text{exp}_{pt}$ | Cost of adding one tonne of capacity to plant $p$ at time $t$ | \$/tonne
$c^\text{open}_{pt}$ | Cost of opening plant $p$ at time $t$, at minimum capacity | $
$c^\text{f-base}_{pt}$ | Fixed cost of keeping plant $p$ open during time period $t$ | $
$c^\text{f-exp}_{pt}$ | Increase in fixed cost for each additional tonne of capacity | \$/tonne
$c^\text{var}_{pt}$ | Variable cost of processing one tonne of input at plant $p$ at time $t$ | \$/tonne
$c^\text{store}_{pt}$ | Cost of storing one tonne of original material at plant $p$ at time $t$ | \$/tonne
$m^\text{min}_p$ | Minimum capacity of plant $p$ | tonne
$m^\text{max}_p$ | Maximum capacity of plant $p$ | tonne
$m^\text{disp}_{pmt}$ | Maximum amount of material $m$ that plant $p$ can dispose of during time $t$ | tonne
$m^\text{store}_p$ | Maximum amount of original material that plant $p$ can store for later processing. | tonne
**Products:**
#### Products
* $\alpha_{pm}$ - Amount of material $m$ recovered by plant $t$ for each tonne of original material (`tonne/tonne`)
* $m^\text{initial}_{lt}$ - Amount of original material to be recycled at location $l$ during time $t$ (`tonne`)
Symbol | Description | Unit
:-------|:------------|:---
$\alpha_{pm}$ | Amount of material $m$ recovered by plant $t$ for each tonne of original material | tonne/tonne
$m^\text{initial}_{lt}$ | Amount of original material to be recycled at location $l$ during time $t$ | tonne
**Transportation:**
#### Transportation
* $c^\text{tr}_{t}$ - Transportation cost during time $t$ (`$/tonne/km`)
* $d_{lp}$ - Distance between plant $p$ and location $l$ (`km`)
Symbol | Description | Unit
:-------|:------------|:---
$c^\text{tr}_{t}$ | Transportation cost during time $t$ | \$/tonne/km
$d_{lp}$ | Distance between plant $p$ and location $l$ | km
### Decision variables
* $q_{mpt}$ - Amount of material $m$ recovered by plant $p$ during time $t$ (`tonne`)
* $u_{pt}$ - Binary variable that equals 1 if plant $p$ starts operating at time $t$ (`bool`)
* $w_{pt}$ - Extra capacity (amount above the minimum) added to plant $p$ during time $t$ (`tonne`)
* $x_{pt}$ - Binary variable that equals 1 if plant $p$ is operational at time $t$ (`bool`)
* $y_{lpt}$ - Amount of product sent from location $l$ to plant $p$ during time $t$ (`tonne`)
* $z^{\text{disp}}_{mpt}$ - Amount of material $m$ disposed of by plant $p$ during time $t$ (`tonne`)
* $z^{\text{store}}_{pt}$ - Amount of original material in storage at plant $p$ by the end of time period $t$ (`tonne`)
* $z^{\text{proc}}_{mpt}$ - Amount of original material processed by plant $p$ during time period $t$ (`tonne`)
Symbol | Description | Unit
:-------|:------------|:---
$q_{mpt}$ | Amount of material $m$ recovered by plant $p$ during time $t$ | tonne
$u_{pt}$ | Binary variable that equals 1 if plant $p$ starts operating at time $t$ | Boolean
$w_{pt}$ | Extra capacity (amount above the minimum) added to plant $p$ during time $t$ | tonne
$x_{pt}$ | Binary variable that equals 1 if plant $p$ is operational at time $t$ | Boolean
$y_{lpt}$ | Amount of product sent from location $l$ to plant $p$ during time $t$ | tonne
$z^{\text{disp}}_{mpt}$ | Amount of material $m$ disposed of by plant $p$ during time $t$ | tonne
$z^{\text{store}}_{pt}$ | Amount of original material in storage at plant $p$ by the end of time period $t$ | tonne
$z^{\text{proc}}_{mpt}$ | Amount of original material processed by plant $p$ during time period $t$ | tonne
### Objective function
RELOG minimizes the overall capital, production and transportation costs:
```math
\begin{align*}
\text{minimize} \;\; &
\sum_{t \in T} \sum_{p \in P} \left[
@@ -73,6 +85,7 @@ RELOG minimizes the overall capital, production and transportation costs:
&
\sum_{t \in T} \sum_{p \in P} \sum_{m \in M} c^{\text{disp}}_{pmt} z_{pmt}
\end{align*}
```
In the first line, we have (i) opening costs, if plant starts operating at time $t$, (ii) fixed operating costs, if plant is operational, (iii) additional fixed operating costs coming from expansion performed in all previous time periods up to the current one, and finally (iv) the expansion costs during the current time period.
In the second line, we have storage and variable processing costs.
@@ -83,14 +96,17 @@ In the fourth line, we have the disposal costs.
* All original materials must be sent to a plant:
\begin{align}
```math
\begin{align*}
& \sum_{p \in P} y_{lpt} = m^\text{initial}_{lt}
& \forall l \in L, t \in T
\end{align}
\end{align*}
```
* Amount received equals amount processed plus stored. Furthermore, all original material should be processed by the end of the simulation.
\begin{align}
```math
\begin{align*}
& \sum_{l \in L} y_{lpt} + z^{\text{store}}_{p,t-1}
= z^{\text{proc}}_{pt} + z^{\text{store}}_{p,t}
& \forall p \in P, t \in T \\
@@ -98,56 +114,70 @@ In the fourth line, we have the disposal costs.
& \forall p \in P \\
& z^{\text{store}}_{p,t^{\max}} = 0
& \forall p \in P
\end{align}
\end{align*}
```
* Plants have a limited processing capacity. Furthermore, if a plant is closed, it has zero processing capacity:
\begin{align}
```math
\begin{align*}
& z^{\text{proc}}_{pt} \leq m^\text{min}_p x_p + \sum_{i=1}^t w_p
& \forall p \in P, t \in T
\end{align}
\end{align*}
```
* Plants have limited storage capacity. Furthermore, if a plant is closed, is has zero storage capacity:
\begin{align}
```math
\begin{align*}
& z^{\text{store}}_{pt} \leq m^\text{store}_p x_p
& \forall p \in P, t \in T
\end{align}
\end{align*}
```
* Plants can only be expanded up to their maximum capacity. Furthermore, if a plant is closed, it cannot be expanded:
\begin{align}
```math
\begin{align*}
& \sum_{i=1}^t w_p \leq m^\text{max}_p x_p
& \forall p \in P, t \in T
\end{align}
\end{align*}
```
* Amount of recovered material is proportional to amount processed:
\begin{align}
```math
\begin{align*}
& q_{mpt} = \alpha_{pm} z^{\text{proc}}_{pt}
& \forall m \in M, p \in P, t \in T
\end{align}
\end{align*}
```
* Because we only consider a single type of plant, all recovered material must be immediately disposed of. In RELOG's full model, recovered materials may be sent to another plant for further processing.
\begin{align}
```math
\begin{align*}
& q_{mpt} = z_{mpt}
& \forall m \in M, p \in P, t \in T
\end{align}
\end{align*}
```
* A plant is operational at time $t$ if it was operational at time $t-1$ or it was built at time $t$. This constraint also prevents a plant from being built multiple times.
\begin{align}
```math
\begin{align*}
& x_{pt} = x_{p,t-1} + u_{pt}
& \forall p \in P, t \in T \setminus \{1\} \\
& x_{p,1} = u_{p,1}
& \forall p \in P
\end{align}
\end{align*}
```
* Variable bounds:
\begin{align}
```math
\begin{align*}
& q_{mpt} \geq 0
& \forall m \in M, p \in P, t \in T \\
& u_{pt} \in \{0,1\}
@@ -162,4 +192,5 @@ In the fourth line, we have the disposal costs.
& p \in P, t \in T \\
& z^{\text{disp}}_{mpt}, z^{\text{proc}}_{mpt} \geq 0
& \forall m \in M, p \in P, t \in T
\end{align}
\end{align*}
```

View File

@@ -9,7 +9,7 @@ In this page, we also illustrate what types of charts and visualizations can be
Report showing plant costs, capacities, energy expenditure and utilization factors. Generated by `RELOG.write_plants_report(solution, filename)`.
| Column | Description
|:--------------------------------------|---------------|
|:--------------------------------------|:---------------|
| `plant type` | Plant type.
| `location name` | Location name.
| `year` | What year this row corresponds to. This reports includes one row for each year.
@@ -45,7 +45,9 @@ sns.barplot(x="year",
.reset_index());
```
<img src="../images/ex_plant_cost_per_year.png" width="500px"/>
```@raw html
<img src="../assets/ex_plant_cost_per_year.png" width="500px"/>
```
* Map showing plant locations (in Python):
```python
@@ -65,8 +67,9 @@ points = gp.points_from_xy(data["longitude (deg)"],
gp.GeoDataFrame(data, geometry=points).plot(ax=ax);
```
<img src="../images/ex_plant_locations.png" width="1000px"/>
```@raw html
<img src="../assets/ex_plant_locations.png" width="1000px"/>
```
## Plant outputs report
@@ -74,7 +77,7 @@ Report showing amount of products produced, sent and disposed of by each plant,
| Column | Description
|:--------------------------------------|---------------|
|:--------------------------------------|:---------------|
| `plant type` | Plant type.
| `location name` | Location name.
| `year` | What year this row corresponds to. This reports includes one row for each year.
@@ -101,7 +104,9 @@ sns.barplot(x="amount produced (tonne)",
.reset_index());
```
<img src="../images/ex_amount_produced.png" width="500px"/>
```@raw html
<img src="../assets/ex_amount_produced.png" width="500px"/>
```
## Plant emissions report
@@ -109,7 +114,7 @@ sns.barplot(x="amount produced (tonne)",
Report showing amount of emissions produced by each plant. Generated by `RELOG.write_plant_emissions_report(solution, filename)`.
| Column | Description
|:--------------------------------------|---------------|
|:--------------------------------------|:---------------|
| `plant type` | Plant type.
| `location name` | Location name.
| `year` | Year.
@@ -133,21 +138,22 @@ sns.barplot(x="plant type",
.reset_index());
```
<img src="../images/ex_emissions.png" width="500px"/>
```@raw html
<img src="../assets/ex_emissions.png" width="500px"/>
```
## Products report
Report showing primary product amounts, locations and marginal costs. Generated by `RELOG.write_products_report(solution, filename)`.
| Column | Description
|:--------------------------------------|---------------|
|:--------------------------------------|:---------------|
| `product name` | Product name.
| `location name` | Name of the collection center.
| `latitude (deg)` | Latitude of the collection center.
| `longitude (deg)` | Longitude of the collection center.
| `year` | What year this row corresponds to. This reports includes one row for each year.
| `amount (tonne)` | Amount of product available at this collection center.
| `amount disposed (tonne)` | Amount of product disposed of at this collection center.
| `marginal cost ($/tonne)` | Cost to process one additional tonne of this product coming from this collection center.
@@ -157,7 +163,7 @@ Report showing amount of product sent from initial locations to plants, and from
| Column | Description
|:--------------------------------------|---------------|
|:--------------------------------------|:---------------|
| `source type` | If product is being shipped from an initial location, equals `Origin`. If product is being shipped from a plant, equals plant type.
| `source location name` | Name of the location where the product is being shipped from.
| `source latitude (deg)` | Latitude of the source location.
@@ -191,7 +197,9 @@ sns.barplot(x="product",
.reset_index());
```
<img src="../images/ex_transportation_amount_distance.png" width="500px"/>
```@raw html
<img src="../assets/ex_transportation_amount_distance.png" width="500px"/>
```
* Map of transportation lines (in Python):
@@ -234,7 +242,9 @@ gp.GeoDataFrame(data, geometry=points).plot(ax=ax,
markersize=50);
```
<img src="../images/ex_transportation.png" width="1000px"/>
```@raw html
<img src="../assets/ex_transportation.png" width="1000px"/>
```
## Transportation emissions report
@@ -242,7 +252,7 @@ gp.GeoDataFrame(data, geometry=points).plot(ax=ax,
Report showing emissions for each trip between initial locations and plants, and between pairs of plants. Generated by `RELOG.write_transportation_emissions_report(solution, filename)`.
| Column | Description
|:--------------------------------------|---------------|
|:--------------------------------------|:---------------|
| `source type` | If product is being shipped from an initial location, equals `Origin`. If product is being shipped from a plant, equals plant type.
| `source location name` | Name of the location where the product is being shipped from.
| `source latitude (deg)` | Latitude of the source location.
@@ -276,4 +286,6 @@ sns.barplot(x="emission type",
.reset_index());
```
<img src="../images/ex_transportation_emissions.png" width="500px"/>
```@raw html
<img src="../assets/ex_transportation_emissions.png" width="500px"/>
```

View File

@@ -3,22 +3,17 @@ Usage
## 1. Installation
To use RELOG, the first step is to install the [Julia programming language](https://julialang.org/) on your machine. Note that RELOG was developed and tested with Julia 1.5 and may not be compatible with newer versions. After Julia is installed, launch the Julia console, type `]` to switch to package manger mode, then run:
To use RELOG, the first step is to install the [Julia programming language](https://julialang.org/) on your machine. Note that RELOG was developed and tested with Julia 1.8 and may not be compatible with newer versions. After Julia is installed, launch the Julia console, then run:
```text
(@v1.5) pkg> add https://github.com/ANL-CEEESA/RELOG.git
```julia
using Pkg
Pkg.add(name="RELOG", version="0.5")
```
After the package and all its dependencies have been installed, please run the RELOG test suite, as shown below, to make sure that the package has been correctly installed:
```text
(@v1.5) pkg> test RELOG
```
To update the package to a newer version, type `]` to enter the package manager mode, then run:
```text
(@v1.5) pkg> update RELOG
```julia
Pkg.test("RELOG")
```
## 2. Modeling the problem
@@ -111,13 +106,17 @@ By default, RELOG internally uses [Cbc](https://github.com/coin-or/Cbc), an open
```julia
using RELOG, Gurobi, JuMP
gurobi = optimizer_with_attributes(Gurobi.Optimizer,
"TimeLimit" => 3600,
"MIPGap" => 0.001)
gurobi = optimizer_with_attributes(
Gurobi.Optimizer,
"TimeLimit" => 3600,
"MIPGap" => 0.001,
)
RELOG.solve("instance.json",
output="solution.json",
optimizer=gurobi)
RELOG.solve(
"instance.json",
output="solution.json",
optimizer=gurobi,
)
```
### 5.2 Multi-period heuristics
@@ -133,6 +132,8 @@ To solve an instance using this heuristic, use the option `heuristic=true`, as s
```julia
using RELOG
solution = RELOG.solve("/home/user/instance.json",
heuristic=true)
solution = RELOG.solve(
"/home/user/instance.json",
heuristic=true,
)
```

View File

@@ -4,132 +4,73 @@
},
"products": {
"P1": {
"transportation cost ($/km/tonne)": [
0.015,
0.015
],
"transportation energy (J/km/tonne)": [
0.12,
0.11
],
"transportation cost ($/km/tonne)": [0.015, 0.015],
"transportation energy (J/km/tonne)": [0.12, 0.11],
"transportation emissions (tonne/km/tonne)": {
"CO2": [
0.052,
0.050
],
"CH4": [
0.003,
0.002
]
},
"CO2": [0.052, 0.050],
"CH4": [0.003, 0.002]
},
"initial amounts": {
"C1": {
"latitude (deg)": 7.0,
"longitude (deg)": 7.0,
"amount (tonne)": [
934.56,
934.56
]
"amount (tonne)": [934.56, 934.56]
},
"C2": {
"latitude (deg)": 7.0,
"longitude (deg)": 19.0,
"amount (tonne)": [
198.95,
198.95
]
"amount (tonne)": [198.95, 198.95]
},
"C3": {
"latitude (deg)": 84.0,
"longitude (deg)": 76.0,
"amount (tonne)": [
212.97,
212.97
]
"amount (tonne)": [212.97, 212.97]
},
"C4": {
"latitude (deg)": 21.0,
"longitude (deg)": 16.0,
"amount (tonne)": [
352.19,
352.19
]
"amount (tonne)": [352.19, 352.19]
},
"C5": {
"latitude (deg)": 32.0,
"longitude (deg)": 92.0,
"amount (tonne)": [
510.33,
510.33
]
"amount (tonne)": [510.33, 510.33]
},
"C6": {
"latitude (deg)": 14.0,
"longitude (deg)": 62.0,
"amount (tonne)": [
471.66,
471.66
]
"amount (tonne)": [471.66, 471.66]
},
"C7": {
"latitude (deg)": 30.0,
"longitude (deg)": 83.0,
"amount (tonne)": [
785.21,
785.21
]
"amount (tonne)": [785.21, 785.21]
},
"C8": {
"latitude (deg)": 35.0,
"longitude (deg)": 40.0,
"amount (tonne)": [
706.17,
706.17
]
"amount (tonne)": [706.17, 706.17]
},
"C9": {
"latitude (deg)": 74.0,
"longitude (deg)": 52.0,
"amount (tonne)": [
30.08,
30.08
]
"amount (tonne)": [30.08, 30.08]
},
"C10": {
"latitude (deg)": 22.0,
"longitude (deg)": 54.0,
"amount (tonne)": [
536.52,
536.52
]
"amount (tonne)": [536.52, 536.52]
}
},
"disposal limit (tonne)": [
1.0,
1.0
],
"disposal cost ($/tonne)": [
-1000,
-1000
]
}
},
"P2": {
"transportation cost ($/km/tonne)": [
0.02,
0.02
]
"transportation cost ($/km/tonne)": [0.02, 0.02]
},
"P3": {
"transportation cost ($/km/tonne)": [
0.0125,
0.0125
]
"transportation cost ($/km/tonne)": [0.0125, 0.0125]
},
"P4": {
"transportation cost ($/km/tonne)": [
0.0175,
0.0175
]
"transportation cost ($/km/tonne)": [0.0175, 0.0175]
}
},
"plants": {
@@ -139,74 +80,35 @@
"P2": 0.2,
"P3": 0.5
},
"energy (GJ/tonne)": [
0.12,
0.11
],
"energy (GJ/tonne)": [0.12, 0.11],
"emissions (tonne/tonne)": {
"CO2": [
0.052,
0.050
],
"CH4": [
0.003,
0.002
]
},
"CO2": [0.052, 0.050],
"CH4": [0.003, 0.002]
},
"locations": {
"L1": {
"latitude (deg)": 0.0,
"longitude (deg)": 0.0,
"disposal": {
"P2": {
"cost ($/tonne)": [
-10.0,
-10.0
],
"limit (tonne)": [
1.0,
1.0
]
"cost ($/tonne)": [-10.0, -10.0],
"limit (tonne)": [1.0, 1.0]
},
"P3": {
"cost ($/tonne)": [
-10.0,
-10.0
],
"limit (tonne)": [
1.0,
1.0
]
"cost ($/tonne)": [-10.0, -10.0],
"limit (tonne)": [1.0, 1.0]
}
},
"capacities (tonne)": {
"250.0": {
"opening cost ($)": [
500.0,
500.0
],
"fixed operating cost ($)": [
30.0,
30.0
],
"variable operating cost ($/tonne)": [
30.0,
30.0
]
"opening cost ($)": [500.0, 500.0],
"fixed operating cost ($)": [30.0, 30.0],
"variable operating cost ($/tonne)": [30.0, 30.0]
},
"1000.0": {
"opening cost ($)": [
1250.0,
1250.0
],
"fixed operating cost ($)": [
30.0,
30.0
],
"variable operating cost ($/tonne)": [
30.0,
30.0
]
"opening cost ($)": [1250.0, 1250.0],
"fixed operating cost ($)": [30.0, 30.0],
"variable operating cost ($/tonne)": [30.0, 30.0]
}
}
},
@@ -215,35 +117,17 @@
"longitude (deg)": 0.5,
"capacities (tonne)": {
"0.0": {
"opening cost ($)": [
1000,
1000
],
"fixed operating cost ($)": [
50.0,
50.0
],
"variable operating cost ($/tonne)": [
50.0,
50.0
]
"opening cost ($)": [1000, 1000],
"fixed operating cost ($)": [50.0, 50.0],
"variable operating cost ($/tonne)": [50.0, 50.0]
},
"10000.0": {
"opening cost ($)": [
10000,
10000
],
"fixed operating cost ($)": [
50.0,
50.0
],
"variable operating cost ($/tonne)": [
50.0,
50.0
]
"opening cost ($)": [10000, 10000],
"fixed operating cost ($)": [50.0, 50.0],
"variable operating cost ($/tonne)": [50.0, 50.0]
}
}
}
}
}
},
"F2": {
@@ -258,26 +142,14 @@
"longitude (deg)": 65.0,
"disposal": {
"P3": {
"cost ($/tonne)": [
100.0,
100.0
]
"cost ($/tonne)": [100.0, 100.0]
}
},
"capacities (tonne)": {
"1000.0": {
"opening cost ($)": [
3000,
3000
],
"fixed operating cost ($)": [
50.0,
50.0
],
"variable operating cost ($/tonne)": [
50.0,
50.0
]
"opening cost ($)": [3000, 3000],
"fixed operating cost ($)": [50.0, 50.0],
"variable operating cost ($/tonne)": [50.0, 50.0]
}
}
},
@@ -286,18 +158,9 @@
"longitude (deg)": 0.20,
"capacities (tonne)": {
"10000": {
"opening cost ($)": [
3000,
3000
],
"fixed operating cost ($)": [
50.0,
50.0
],
"variable operating cost ($/tonne)": [
50.0,
50.0
]
"opening cost ($)": [3000, 3000],
"fixed operating cost ($)": [50.0, 50.0],
"variable operating cost ($/tonne)": [50.0, 50.0]
}
}
}
@@ -311,21 +174,12 @@
"longitude (deg)": 100.0,
"capacities (tonne)": {
"15000": {
"opening cost ($)": [
0.0,
0.0
],
"fixed operating cost ($)": [
0.0,
0.0
],
"variable operating cost ($/tonne)": [
-15.0,
-15.0
]
"opening cost ($)": [0.0, 0.0],
"fixed operating cost ($)": [0.0, 0.0],
"variable operating cost ($/tonne)": [-15.0, -15.0]
}
}
}
}
}
},
"F4": {
@@ -336,21 +190,12 @@
"longitude (deg)": 50.0,
"capacities (tonne)": {
"10000": {
"opening cost ($)": [
0.0,
0.0
],
"fixed operating cost ($)": [
0.0,
0.0
],
"variable operating cost ($/tonne)": [
-15.0,
-15.0
]
"opening cost ($)": [0.0, 0.0],
"fixed operating cost ($)": [0.0, 0.0],
"variable operating cost ($/tonne)": [-15.0, -15.0]
}
}
}
}
}
}
}

75
juliaw Executable file
View File

@@ -0,0 +1,75 @@
#!/bin/bash
# UnitCommitment.jl: Optimization Package for Security-Constrained Unit Commitment
# Copyright (C) 2020-2021, UChicago Argonne, LLC. All rights reserved.
# Released under the modified BSD license. See COPYING.md for more details.
if [ ! -e Project.toml ]; then
echo "juliaw: Project.toml not found"
exit 1
fi
if [ ! -e Manifest.toml ]; then
julia --project=. -e 'using Pkg; Pkg.instantiate()' || exit 1
fi
if [ ! -e build/sysimage.so -o Project.toml -nt build/sysimage.so ]; then
echo "juliaw: rebuilding system image..."
# Generate temporary project folder
rm -rf $HOME/.juliaw
mkdir -p $HOME/.juliaw/src
cp Project.toml Manifest.toml $HOME/.juliaw
NAME=$(julia -e 'using TOML; toml = TOML.parsefile("Project.toml"); "name" in keys(toml) && print(toml["name"])')
if [ ! -z $NAME ]; then
cat > $HOME/.juliaw/src/$NAME.jl << EOF
module $NAME
end
EOF
fi
# Add PackageCompiler dependencies to temporary project
julia --project=$HOME/.juliaw -e 'using Pkg; Pkg.add(["PackageCompiler", "TOML", "Logging"])'
# Generate system image scripts
cat > $HOME/.juliaw/sysimage.jl << EOF
using PackageCompiler
using TOML
using Logging
Logging.disable_logging(Logging.Info)
mkpath("$PWD/build")
println("juliaw: generating precompilation statements...")
run(\`julia --project="$PWD" --trace-compile="$PWD"/build/precompile.jl \$(ARGS)\`)
println("juliaw: finding dependencies...")
project = TOML.parsefile("Project.toml")
manifest = TOML.parsefile("Manifest.toml")
deps = Symbol[]
for dep in keys(project["deps"])
if dep in keys(manifest)
# Up to Julia 1.6
dep_entry = manifest[dep][1]
else
# Julia 1.7+
dep_entry = manifest["deps"][dep][1]
end
if "path" in keys(dep_entry)
println(" - \$(dep) [skip]")
else
println(" - \$(dep)")
push!(deps, Symbol(dep))
end
end
println("juliaw: building system image...")
create_sysimage(
deps,
precompile_statements_file = "$PWD/build/precompile.jl",
sysimage_path = "$PWD/build/sysimage.so",
)
EOF
julia --project=$HOME/.juliaw $HOME/.juliaw/sysimage.jl $*
else
julia --project=. --sysimage build/sysimage.so $*
fi

View File

@@ -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;
}

View File

@@ -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"]
});

View File

@@ -7,7 +7,7 @@ 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)
return round(euclidean_distance(x, y) / 1000.0, digits = 2)
end
function build_graph(instance::Instance)::Graph
@@ -18,7 +18,6 @@ function build_graph(instance::Instance)::Graph
collection_shipping_nodes = ShippingNode[]
name_to_process_node_map = Dict{Tuple{AbstractString,AbstractString},ProcessNode}()
collection_center_to_node = Dict()
process_nodes_by_input_product =
Dict(product => ProcessNode[] for product in instance.products)
@@ -28,7 +27,6 @@ function build_graph(instance::Instance)::Graph
for center in instance.collection_centers
node = ShippingNode(next_index, center, center.product, [], [])
next_index += 1
collection_center_to_node[center] = node
push!(collection_shipping_nodes, node)
end
@@ -85,7 +83,6 @@ function build_graph(instance::Instance)::Graph
collection_shipping_nodes,
arcs,
name_to_process_node_map,
collection_center_to_node,
)
end

View File

@@ -33,7 +33,6 @@ mutable struct Graph
collection_shipping_nodes::Vector{ShippingNode}
arcs::Vector{Arc}
name_to_process_node_map::Dict{Tuple{AbstractString,AbstractString},ProcessNode}
collection_center_to_node::Dict{CollectionCenter,ShippingNode}
end
function Base.show(io::IO, instance::Graph)

View File

@@ -37,8 +37,6 @@ function parse(json)::Instance
cost = product_dict["transportation cost (\$/km/tonne)"]
energy = zeros(T)
emissions = Dict()
disposal_limit = zeros(T)
disposal_cost = zeros(T)
if "transportation energy (J/km/tonne)" in keys(product_dict)
energy = product_dict["transportation energy (J/km/tonne)"]
@@ -48,25 +46,7 @@ function parse(json)::Instance
emissions = product_dict["transportation emissions (tonne/km/tonne)"]
end
if "disposal limit (tonne)" in keys(product_dict)
disposal_limit = product_dict["disposal limit (tonne)"]
end
if "disposal cost (\$/tonne)" in keys(product_dict)
disposal_cost = product_dict["disposal cost (\$/tonne)"]
end
prod_centers = []
product = Product(
product_name,
cost,
energy,
emissions,
disposal_limit,
disposal_cost,
prod_centers,
)
product = Product(product_name, cost, energy, emissions)
push!(products, product)
prod_name_to_product[product_name] = product
@@ -86,7 +66,6 @@ function parse(json)::Instance
product,
center_dict["amount (tonne)"],
)
push!(prod_centers, center)
push!(collection_centers, center)
end
end

View File

@@ -13,9 +13,6 @@ mutable struct Product
transportation_cost::Vector{Float64}
transportation_energy::Vector{Float64}
transportation_emissions::Dict{String,Vector{Float64}}
disposal_limit::Vector{Float64}
disposal_cost::Vector{Float64}
collection_centers::Vector
end
mutable struct CollectionCenter

View File

@@ -20,17 +20,13 @@ function create_vars!(model::JuMP.Model)
graph, T = model[:graph], model[:instance].time
model[:flow] =
Dict((a, t) => @variable(model, lower_bound = 0) for a in graph.arcs, t = 1:T)
model[:plant_dispose] = Dict(
model[:dispose] = Dict(
(n, t) => @variable(
model,
lower_bound = 0,
upper_bound = n.location.disposal_limit[n.product][t]
) for n in values(graph.plant_shipping_nodes), t = 1:T
)
model[:collection_dispose] = Dict(
(n, t) => @variable(model, lower_bound = 0,) for
n in values(graph.collection_shipping_nodes), t = 1:T
)
model[:store] = Dict(
(n, t) =>
@variable(model, lower_bound = 0, upper_bound = n.location.storage_limit)
@@ -135,25 +131,14 @@ function create_objective_function!(model::JuMP.Model)
end
end
# Plant shipping node costs
# Shipping node costs
for n in values(graph.plant_shipping_nodes), t = 1:T
# Disposal costs
add_to_expression!(
obj,
n.location.disposal_cost[n.product][t],
model[:plant_dispose][n, t],
)
end
# Collection shipping node costs
for n in values(graph.collection_shipping_nodes), t = 1:T
# Disposal costs
add_to_expression!(
obj,
n.location.product.disposal_cost[t],
model[:collection_dispose][n, t],
model[:dispose][n, t],
)
end
@@ -169,29 +154,16 @@ function create_shipping_node_constraints!(model::JuMP.Model)
for n in graph.collection_shipping_nodes
model[:eq_balance][n, t] = @constraint(
model,
sum(model[:flow][a, t] for a in n.outgoing_arcs) ==
n.location.amount[t] + model[:collection_dispose][n, t]
sum(model[:flow][a, t] for a in n.outgoing_arcs) == n.location.amount[t]
)
end
for prod in model[:instance].products
if isempty(prod.collection_centers)
continue
end
expr = AffExpr()
for center in prod.collection_centers
n = graph.collection_center_to_node[center]
add_to_expression!(expr, model[:collection_dispose][n, t])
end
@constraint(model, expr <= prod.disposal_limit[t])
end
# Plants
for n in graph.plant_shipping_nodes
@constraint(
model,
sum(model[:flow][a, t] for a in n.incoming_arcs) ==
sum(model[:flow][a, t] for a in n.outgoing_arcs) +
model[:plant_dispose][n, t]
sum(model[:flow][a, t] for a in n.outgoing_arcs) + model[:dispose][n, t]
)
end
end

View File

@@ -39,24 +39,21 @@ function get_solution(model::JuMP.Model; marginal_costs = true)
end
# Products
for n in graph.collection_shipping_nodes
location_dict = OrderedDict{Any,Any}(
"Latitude (deg)" => n.location.latitude,
"Longitude (deg)" => n.location.longitude,
"Amount (tonne)" => n.location.amount,
"Dispose (tonne)" =>
[JuMP.value(model[:collection_dispose][n, t]) for t = 1:T],
)
if marginal_costs
location_dict["Marginal cost (\$/tonne)"] = [
round(abs(JuMP.shadow_price(model[:eq_balance][n, t])), digits = 2) for
t = 1:T
]
if marginal_costs
for n in graph.collection_shipping_nodes
location_dict = OrderedDict{Any,Any}(
"Marginal cost (\$/tonne)" => [
round(abs(JuMP.shadow_price(model[:eq_balance][n, t])), digits = 2) for t = 1:T
],
"Latitude (deg)" => n.location.latitude,
"Longitude (deg)" => n.location.longitude,
"Amount (tonne)" => n.location.amount,
)
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
if n.product.name keys(output["Products"])
output["Products"][n.product.name] = OrderedDict()
end
output["Products"][n.product.name][n.location.name] = location_dict
end
# Plants
@@ -181,14 +178,13 @@ function get_solution(model::JuMP.Model; marginal_costs = true)
plant_dict["Total output"][product_name] = zeros(T)
plant_dict["Output"]["Send"][product_name] = product_dict = OrderedDict()
disposal_amount =
[JuMP.value(model[:plant_dispose][shipping_node, t]) for t = 1:T]
disposal_amount = [JuMP.value(model[:dispose][shipping_node, t]) for t = 1:T]
if sum(disposal_amount) > 1e-5
skip_plant = false
plant_dict["Output"]["Dispose"][product_name] =
disposal_dict = OrderedDict()
disposal_dict["Amount (tonne)"] =
[JuMP.value(model[:plant_dispose][shipping_node, t]) for t = 1:T]
[JuMP.value(model[:dispose][shipping_node, t]) for t = 1:T]
disposal_dict["Cost (\$)"] = [
disposal_dict["Amount (tonne)"][t] *
plant.disposal_cost[shipping_node.product][t] for t = 1:T

View File

@@ -13,7 +13,6 @@ function products_report(solution; marginal_costs = true)::DataFrame
df."longitude (deg)" = Float64[]
df."year" = Int[]
df."amount (tonne)" = Float64[]
df."amount disposed (tonne)" = Float64[]
df."marginal cost (\$/tonne)" = Float64[]
T = length(solution["Energy"]["Plants (GJ)"])
for (prod_name, prod_dict) in solution["Products"]
@@ -23,7 +22,6 @@ function products_report(solution; marginal_costs = true)::DataFrame
latitude = round(location_dict["Latitude (deg)"], digits = 6)
longitude = round(location_dict["Longitude (deg)"], digits = 6)
amount = location_dict["Amount (tonne)"][year]
amount_disposed = location_dict["Dispose (tonne)"][year]
push!(
df,
[
@@ -34,7 +32,6 @@ function products_report(solution; marginal_costs = true)::DataFrame
year,
amount,
marginal_cost,
amount_disposed,
],
)
end

View File

@@ -169,12 +169,6 @@
},
"initial amounts": {
"$ref": "#/definitions/InitialAmount"
},
"disposal limit (tonne)": {
"$ref": "#/definitions/TimeSeries"
},
"disposal cost ($/tonne)": {
"$ref": "#/definitions/TimeSeries"
}
},
"required": [

View File

@@ -1,30 +1,15 @@
using PackageCompiler
using TOML
using Logging
Logging.disable_logging(Logging.Info)
using Cbc
using Clp
using Geodesy
using JSON
using JSONSchema
using JuMP
using MathOptInterface
using ProgressBars
mkpath("build")
pkg = [:Cbc, :Clp, :Geodesy, :JSON, :JSONSchema, :JuMP, :MathOptInterface, :ProgressBars]
printstyled("Generating precompilation statements...\n", color = :light_green)
run(`julia --project=. --trace-compile=build/precompile.jl $ARGS`)
printstyled("Finding dependencies...\n", color = :light_green)
project = TOML.parsefile("Project.toml")
manifest = TOML.parsefile("Manifest.toml")
deps = Symbol[]
for dep in keys(project["deps"])
if "path" in keys(manifest[dep][1])
printstyled(" skip $(dep)\n", color = :light_black)
else
println(" add $(dep)")
push!(deps, Symbol(dep))
end
end
printstyled("Building system image...\n", color = :light_green)
create_sysimage(
deps,
precompile_statements_file = "build/precompile.jl",
sysimage_path = "build/sysimage.so",
)
@info "Building system image..."
create_sysimage(pkg, sysimage_path = "build/sysimage.so")

View File

@@ -40,14 +40,7 @@ using RELOG
@test plant.sizes[2].fixed_operating_cost == [30, 30]
@test plant.sizes[2].variable_operating_cost == [30, 30]
p1 = product_name_to_product["P1"]
@test p1.disposal_limit == [1.0, 1.0]
@test p1.disposal_cost == [-1000.0, -1000.0]
p2 = product_name_to_product["P2"]
@test p2.disposal_limit == [0.0, 0.0]
@test p2.disposal_cost == [0.0, 0.0]
p3 = product_name_to_product["P3"]
@test length(plant.output) == 2
@test plant.output[p2] == 0.2

View File

@@ -18,7 +18,7 @@ using RELOG, Cbc, JuMP, Printf, JSON, MathOptInterface.FileFormats
)
@test length(model[:flow]) == 76
@test length(model[:plant_dispose]) == 16
@test length(model[:dispose]) == 16
@test length(model[:open_plant]) == 12
@test length(model[:capacity]) == 12
@test length(model[:expansion]) == 12
@@ -32,7 +32,7 @@ using RELOG, Cbc, JuMP, Printf, JSON, MathOptInterface.FileFormats
@test lower_bound(v) == 0.0
@test upper_bound(v) == 750.0
v = model[:plant_dispose][shipping_node_by_loc_and_prod_names["L1", "P2"], 1]
v = model[:dispose][shipping_node_by_loc_and_prod_names["L1", "P2"], 1]
@test lower_bound(v) == 0.0
@test upper_bound(v) == 1.0
end

View File

@@ -3,11 +3,9 @@
using RELOG
basedir = @__DIR__
@testset "Resolve" begin
# Shoud not crash
filename = "$basedir/../../instances/s1.json"
filename = "$(pwd())/../instances/s1.json"
solution_old, model_old = RELOG.solve(filename, return_model = true)
solution_new = RELOG.resolve(model_old, filename)
end

View File

@@ -26,15 +26,6 @@ basedir = dirname(@__FILE__)
@test "F2" in keys(solution["Plants"])
@test "F3" in keys(solution["Plants"])
@test "F4" in keys(solution["Plants"])
@test "Products" in keys(solution)
@test "P1" in keys(solution["Products"])
@test "C1" in keys(solution["Products"]["P1"])
@test "Dispose (tonne)" in keys(solution["Products"]["P1"]["C1"])
total_disposal =
sum([loc["Dispose (tonne)"] for loc in values(solution["Products"]["P1"])])
@test total_disposal == [1.0, 1.0]
end
@testset "solve (heuristic)" begin

View File

@@ -4,11 +4,9 @@
using RELOG, JSON, GZip
basedir = @__DIR__
@testset "Reports" begin
@testset "from solve" begin
solution = RELOG.solve("$basedir/../instances/s1.json")
solution = RELOG.solve("$(pwd())/../instances/s1.json")
tmp_filename = tempname()
# The following should not crash
RELOG.write_plant_emissions_report(solution, tmp_filename)