Skip to content

Commit 3d71c5d

Browse files
authored
Merge pull request #908 from EnergySystemsModellingLab/empty-input-files
Allow `assets.csv` and `commodity_levies.csv` to be empty
2 parents 340f7f5 + 2f7ca62 commit 3d71c5d

4 files changed

Lines changed: 12 additions & 7 deletions

File tree

src/input/asset.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Code for reading [Asset]s from a CSV file.
2-
use super::{input_err_msg, read_csv};
2+
use super::{input_err_msg, read_csv_optional};
33
use crate::agent::AgentID;
44
use crate::asset::Asset;
55
use crate::id::IDCollection;
@@ -35,15 +35,15 @@ struct AssetRaw {
3535
///
3636
/// # Returns
3737
///
38-
/// A `HashMap` containing assets grouped by agent ID.
38+
/// A `Vec` of [`Asset`]s or an error.
3939
pub fn read_assets(
4040
model_dir: &Path,
4141
agent_ids: &IndexSet<AgentID>,
4242
processes: &ProcessMap,
4343
region_ids: &IndexSet<RegionID>,
4444
) -> Result<Vec<Asset>> {
4545
let file_path = model_dir.join(ASSETS_FILE_NAME);
46-
let assets_csv = read_csv(&file_path)?;
46+
let assets_csv = read_csv_optional(&file_path)?;
4747
read_assets_from_iter(assets_csv, agent_ids, processes, region_ids)
4848
.with_context(|| input_err_msg(&file_path))
4949
}

src/input/commodity/levy.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//! Code for reading in the commodity levies CSV file.
2-
use super::super::{input_err_msg, read_csv, try_insert};
2+
use super::super::{input_err_msg, read_csv_optional, try_insert};
33
use crate::commodity::{BalanceType, CommodityID, CommodityLevy, CommodityLevyMap};
44
use crate::id::IDCollection;
55
use crate::region::{RegionID, parse_region_str};
@@ -44,7 +44,7 @@ struct CommodityLevyRaw {
4444
///
4545
/// # Returns
4646
///
47-
/// A map containing levies, grouped by commodity ID.
47+
/// A map containing levies, grouped by commodity ID or an error.
4848
pub fn read_commodity_levies(
4949
model_dir: &Path,
5050
commodity_ids: &IndexSet<CommodityID>,
@@ -53,7 +53,7 @@ pub fn read_commodity_levies(
5353
milestone_years: &[u32],
5454
) -> Result<HashMap<CommodityID, CommodityLevyMap>> {
5555
let file_path = model_dir.join(COMMODITY_LEVIES_FILE_NAME);
56-
let commodity_levies_csv = read_csv::<CommodityLevyRaw>(&file_path)?;
56+
let commodity_levies_csv = read_csv_optional(&file_path)?;
5757
read_commodity_levies_iter(
5858
commodity_levies_csv,
5959
commodity_ids,

src/simulation/investment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub fn perform_agent_investment(
123123
}
124124

125125
// Add the selected assets to the list of all selected assets
126-
all_selected_assets.extend(selected_assets.clone());
126+
all_selected_assets.extend(selected_assets.iter().cloned());
127127

128128
// Perform dispatch optimisation with assets that have been selected so far
129129
// **TODO**: presumably we only need to do this for selected_assets, as assets added in

src/simulation/optimisation.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ pub fn solve_optimal(model: highs::Model) -> Result<highs::SolvedModel> {
161161
.map_err(|err| anyhow!("Incoherent model: {err:?}"))?;
162162

163163
let status = solved.status();
164+
ensure!(
165+
status != HighsModelStatus::Infeasible,
166+
"The solver has indicated that the problem is infeasible. It may be because the assets in \
167+
this year cannot meet the required demand."
168+
);
164169
ensure!(
165170
status == HighsModelStatus::Optimal,
166171
"Could not find optimal result for model: {status:?}"

0 commit comments

Comments
 (0)