Skip to content

Commit 94db7ef

Browse files
authored
Merge branch 'main' into input_docs
2 parents 02a5cda + 7827181 commit 94db7ef

9 files changed

Lines changed: 160 additions & 3 deletions

File tree

.github/workflows/cargo-test.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ on:
44
push:
55
branches: [main]
66
pull_request:
7-
8-
env:
9-
CARGO_TERM_COLOR: always
7+
workflow_dispatch:
108

119
jobs:
1210
build_and_test:

.github/workflows/check-docs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ on:
33
push:
44
branches: [main]
55
pull_request:
6+
workflow_dispatch:
67
schedule:
78
- cron: "0 0 * * 1" # midnight every Monday
89

.github/workflows/pre-commit.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches: [main]
66
pull_request:
7+
workflow_dispatch:
78

89
jobs:
910
pre-commit:

.github/workflows/release.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: Release
2+
on:
3+
push:
4+
branches: [main]
5+
release:
6+
workflow_dispatch:
7+
8+
jobs:
9+
build_and_upload:
10+
name: Build release
11+
timeout-minutes: 15
12+
runs-on: ${{ matrix.os }}
13+
container:
14+
image: ${{ matrix.image }}
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
os: [ubuntu-latest, macos-latest]
19+
archive_ext: [tar.gz]
20+
archive_cmd: ["tar cf"]
21+
include:
22+
- os: ubuntu-latest
23+
osname: linux
24+
# We build on an old Linux distro so that we get an older version of libstdc++.
25+
# libstdc++ has good backwards compatibility (but not forwards) so by linking against an
26+
# old version, we can target more Linuxes.
27+
image: debian:oldstable
28+
- os: windows-latest
29+
osname: windows
30+
archive_ext: zip
31+
archive_cmd: 7z a
32+
exe_suffix: .exe
33+
- os: macos-latest
34+
osname: macos_arm
35+
steps:
36+
- uses: actions/checkout@v4
37+
- name: Install extra dependencies on Linux
38+
if: ${{ matrix.osname == 'linux' }}
39+
run: |
40+
apt update
41+
apt install -y curl build-essential cmake libclang-16-dev
42+
- uses: actions-rust-lang/setup-rust-toolchain@v1
43+
with:
44+
toolchain: stable
45+
- run: cargo build --release
46+
- name: Gather release files
47+
run: |
48+
mkdir muse2
49+
cp target/release/muse2${{ matrix.exe_suffix }} muse2
50+
cp LICENSE muse2/LICENCE.txt
51+
cp assets/readme/readme_${{ matrix.osname }}.txt muse2/README.txt
52+
- uses: actions/upload-artifact@v4
53+
if: ${{ github.event_name != 'release' }}
54+
with:
55+
name: muse2_${{ matrix.osname }}
56+
path: muse2
57+
- name: Archive release
58+
if: ${{ github.event_name == 'release' }}
59+
run: |
60+
cd muse2
61+
${{ matrix.archive_cmd }} ../muse2_${{ matrix.osname }}.${{ matrix.archive_ext }} *
62+
- name: Upload release artifacts
63+
if: ${{ github.event_name == 'release' }}
64+
uses: softprops/action-gh-release@v2
65+
with:
66+
files: muse2_${{ matrix.osname }}.${{ matrix.archive_ext }}

assets/readme/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Readme files for MUSE 2.0
2+
3+
This folder contains readme files to be included with MUSE 2.0 releases.

assets/readme/readme_linux.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
This folder contains the MUSE 2.0 executable for Linux, called `muse2`.
2+
3+
The only pre-requisite is libstdc++.so, which is likely installed on your system already. If not,
4+
you can install with your package manager, e.g. for Ubuntu:
5+
6+
sudo apt install libstdc++6
7+
8+
For more information on how to use MUSE 2.0, you can consult the program help:
9+
10+
./muse2 help
11+
12+
Documentation is also available on the web:
13+
https://energysystemsmodellinglab.github.io/MUSE_2.0/
14+
15+
Please report bugs on our GitHub issue tracker:
16+
https://github.com/EnergySystemsModellingLab/MUSE_2.0/issues

assets/readme/readme_macos_arm.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
This folder contains the MUSE 2.0 executable for macOS (Apple Silicon), called `muse2`.
2+
3+
When trying to run the `muse2` program, you may see an error message saying "muse2 can't be opened
4+
because Apple cannot check it for malicious software." To fix this, you should open `muse2` by
5+
right-clicking on it in your file explorer and clicking "Open". You will be prompted to give
6+
permission for the program to run. Once you have completed this step, you should be able to run the
7+
program as normal.
8+
9+
For more information on how to use MUSE 2.0, you can consult the program help:
10+
11+
./muse2 help
12+
13+
Documentation is also available on the web:
14+
https://energysystemsmodellinglab.github.io/MUSE_2.0/
15+
16+
Please report bugs on our GitHub issue tracker:
17+
https://github.com/EnergySystemsModellingLab/MUSE_2.0/issues

assets/readme/readme_windows.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
This folder contains the MUSE 2.0 executable for Windows, called `muse2`.
2+
3+
For more information on how to use MUSE 2.0, you can consult the program help:
4+
5+
./muse2 help
6+
7+
Documentation is also available on the web:
8+
https://energysystemsmodellinglab.github.io/MUSE_2.0/
9+
10+
Please report bugs on our GitHub issue tracker:
11+
https://github.com/EnergySystemsModellingLab/MUSE_2.0/issues

src/asset.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,18 @@ impl Hash for AssetRef {
187187
}
188188
}
189189

190+
impl PartialOrd for AssetRef {
191+
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
192+
Some(self.cmp(other))
193+
}
194+
}
195+
196+
impl Ord for AssetRef {
197+
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
198+
self.id.unwrap().cmp(&other.id.unwrap())
199+
}
200+
}
201+
190202
/// A pool of [`Asset`]s
191203
pub struct AssetPool {
192204
/// The pool of active assets
@@ -295,6 +307,9 @@ impl AssetPool {
295307

296308
self.active.clear();
297309
self.active.extend(new_pool);
310+
311+
// New pool may not have been sorted, but active needs to be sorted by ID
312+
self.active.sort();
298313
}
299314
}
300315

@@ -526,4 +541,33 @@ mod tests {
526541
assert_eq!(asset_pool.active[0].id, Some(AssetID(2)));
527542
assert_eq!(asset_pool.active[0].agent_id, "some_other_agent".into());
528543
}
544+
545+
#[rstest]
546+
fn test_asset_pool_replace_active_pool_out_of_order(
547+
mut asset_pool: AssetPool,
548+
process: Process,
549+
) {
550+
let new_asset = Asset::new(
551+
"some_other_agent".into(),
552+
process.into(),
553+
"GBR".into(),
554+
2.0,
555+
2010,
556+
)
557+
.unwrap();
558+
559+
asset_pool.commission_new(2020);
560+
assert_eq!(asset_pool.active.len(), 2);
561+
let mut new_pool: Vec<Rc<Asset>> = asset_pool
562+
.iter()
563+
.map(|asset| asset.clone().into())
564+
.collect();
565+
new_pool.push(new_asset.into());
566+
new_pool.reverse();
567+
568+
asset_pool.replace_active_pool(new_pool);
569+
assert_equal(asset_pool.iter().map(|asset| asset.id.unwrap().0), 0..3);
570+
assert_eq!(asset_pool.active[2].id, Some(AssetID(2)));
571+
assert_eq!(asset_pool.active[2].agent_id, "some_other_agent".into());
572+
}
529573
}

0 commit comments

Comments
 (0)