Skip to content

Commit e6abf78

Browse files
committed
Rename "capacity constraints" to "activity constraints" everywhere
1 parent 061426c commit e6abf78

4 files changed

Lines changed: 35 additions & 36 deletions

File tree

src/output.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ const ASSETS_FILE_NAME: &str = "assets.csv";
3232
/// The output file name for commodity balance duals
3333
const COMMODITY_BALANCE_DUALS_FILE_NAME: &str = "debug_commodity_balance_duals.csv";
3434

35-
/// The output file name for capacity duals
36-
const CAPACITY_DUALS_FILE_NAME: &str = "debug_capacity_duals.csv";
35+
/// The output file name for activity duals
36+
const ACTIVITY_DUALS_FILE_NAME: &str = "debug_activity_duals.csv";
3737

3838
/// Get the model name from the specified directory path
3939
pub fn get_output_dir(model_dir: &Path) -> Result<PathBuf> {
@@ -111,9 +111,9 @@ struct CommodityPriceRow {
111111
price: f64,
112112
}
113113

114-
/// Represents the capacity duals data in a row of the capacity duals CSV file
114+
/// Represents the activity duals data in a row of the activity duals CSV file
115115
#[derive(Serialize, Deserialize, Debug, PartialEq)]
116-
struct CapacityDualsRow {
116+
struct ActivityDualsRow {
117117
milestone_year: u32,
118118
asset_id: AssetID,
119119
time_slice: TimeSliceID,
@@ -144,7 +144,7 @@ struct FixedAssetDualsRow {
144144
/// For writing extra debug information about the model
145145
struct DebugDataWriter {
146146
commodity_balance_duals_writer: csv::Writer<File>,
147-
capacity_duals_writer: csv::Writer<File>,
147+
activity_duals_writer: csv::Writer<File>,
148148
}
149149

150150
impl DebugDataWriter {
@@ -161,33 +161,33 @@ impl DebugDataWriter {
161161

162162
Ok(Self {
163163
commodity_balance_duals_writer: new_writer(COMMODITY_BALANCE_DUALS_FILE_NAME)?,
164-
capacity_duals_writer: new_writer(CAPACITY_DUALS_FILE_NAME)?,
164+
activity_duals_writer: new_writer(ACTIVITY_DUALS_FILE_NAME)?,
165165
})
166166
}
167167

168168
/// Write all debug info to output files
169169
fn write_debug_info(&mut self, milestone_year: u32, solution: &Solution) -> Result<()> {
170-
self.write_capacity_duals(milestone_year, solution.iter_capacity_duals())?;
170+
self.write_activity_duals(milestone_year, solution.iter_activity_duals())?;
171171
self.write_commodity_balance_duals(
172172
milestone_year,
173173
solution.iter_commodity_balance_duals(),
174174
)?;
175175
Ok(())
176176
}
177177

178-
/// Write capacity duals to file
179-
fn write_capacity_duals<'a, I>(&mut self, milestone_year: u32, iter: I) -> Result<()>
178+
/// Write activity duals to file
179+
fn write_activity_duals<'a, I>(&mut self, milestone_year: u32, iter: I) -> Result<()>
180180
where
181181
I: Iterator<Item = (&'a AssetRef, &'a TimeSliceID, f64)>,
182182
{
183183
for (asset, time_slice, value) in iter {
184-
let row = CapacityDualsRow {
184+
let row = ActivityDualsRow {
185185
milestone_year,
186186
asset_id: asset.id.unwrap(),
187187
time_slice: time_slice.clone(),
188188
value,
189189
};
190-
self.capacity_duals_writer.serialize(row)?;
190+
self.activity_duals_writer.serialize(row)?;
191191
}
192192

193193
Ok(())
@@ -215,7 +215,7 @@ impl DebugDataWriter {
215215
/// Flush the underlying streams
216216
fn flush(&mut self) -> Result<()> {
217217
self.commodity_balance_duals_writer.flush()?;
218-
self.capacity_duals_writer.flush()?;
218+
self.activity_duals_writer.flush()?;
219219

220220
Ok(())
221221
}
@@ -468,30 +468,30 @@ mod tests {
468468
}
469469

470470
#[rstest]
471-
fn test_write_capacity_duals(assets: AssetPool, time_slice: TimeSliceID) {
471+
fn test_write_activity_duals(assets: AssetPool, time_slice: TimeSliceID) {
472472
let milestone_year = 2020;
473473
let value = 0.5;
474474
let dir = tempdir().unwrap();
475475
let asset = assets.iter().next().unwrap();
476476

477-
// Write capacity dual
477+
// Write activity dual
478478
{
479479
let mut writer = DebugDataWriter::create(dir.path()).unwrap();
480480
writer
481-
.write_capacity_duals(milestone_year, iter::once((asset, &time_slice, value)))
481+
.write_activity_duals(milestone_year, iter::once((asset, &time_slice, value)))
482482
.unwrap();
483483
writer.flush().unwrap();
484484
}
485485

486486
// Read back and compare
487-
let expected = CapacityDualsRow {
487+
let expected = ActivityDualsRow {
488488
milestone_year,
489489
asset_id: asset.id.unwrap(),
490490
time_slice,
491491
value,
492492
};
493-
let records: Vec<CapacityDualsRow> =
494-
csv::Reader::from_path(dir.path().join(CAPACITY_DUALS_FILE_NAME))
493+
let records: Vec<ActivityDualsRow> =
494+
csv::Reader::from_path(dir.path().join(ACTIVITY_DUALS_FILE_NAME))
495495
.unwrap()
496496
.into_deserialize()
497497
.try_collect()

src/simulation/optimisation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ impl Solution<'_> {
9494
})
9595
}
9696

97-
/// Keys and dual values for capacity constraints.
98-
pub fn iter_capacity_duals(&self) -> impl Iterator<Item = (&AssetRef, &TimeSliceID, f64)> {
97+
/// Keys and dual values for activity constraints.
98+
pub fn iter_activity_duals(&self) -> impl Iterator<Item = (&AssetRef, &TimeSliceID, f64)> {
9999
self.constraint_keys
100-
.capacity_keys
100+
.activity_keys
101101
.zip_duals(self.solution.dual_rows())
102102
.map(|((asset, time_slice), dual)| (asset, time_slice, dual))
103103
}

src/simulation/optimisation/constraints.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,33 @@ impl<T> KeysWithOffset<T> {
2828
/// Indicates the commodity ID and time slice selection covered by each commodity balance constraint
2929
pub type CommodityBalanceKeys = KeysWithOffset<(CommodityID, RegionID, TimeSliceSelection)>;
3030

31-
/// Indicates the asset ID and time slice covered by each capacity constraint
32-
pub type CapacityKeys = KeysWithOffset<(AssetRef, TimeSliceID)>;
31+
/// Indicates the asset ID and time slice covered by each activity constraint
32+
pub type ActivityKeys = KeysWithOffset<(AssetRef, TimeSliceID)>;
3333

3434
/// The keys for different constraints
3535
pub struct ConstraintKeys {
3636
/// Keys for commodity balance constraints
3737
pub commodity_balance_keys: CommodityBalanceKeys,
38-
/// Keys for capacity constraints
39-
pub capacity_keys: CapacityKeys,
38+
/// Keys for activity constraints
39+
pub activity_keys: ActivityKeys,
4040
}
4141

4242
/// Add asset-level constraints
4343
///
4444
/// Note: the ordering of constraints is important, as the dual values of the constraints must later
4545
/// be retrieved to calculate commodity prices.
4646
///
47-
/// # Arguments:
47+
/// # Arguments
4848
///
4949
/// * `problem` - The optimisation problem
5050
/// * `variables` - The variables in the problem
5151
/// * `model` - The model
5252
/// * `assets` - The asset pool
5353
/// * `year` - Current milestone year
5454
///
55-
/// # Returns:
55+
/// # Returns
5656
///
57-
/// * A vector of keys for commodity balance constraints
58-
/// * A vector of keys for capacity constraints
57+
/// Keys for the different constraints.
5958
pub fn add_asset_constraints(
6059
problem: &mut Problem,
6160
variables: &VariableMap,
@@ -67,12 +66,12 @@ pub fn add_asset_constraints(
6766
add_commodity_balance_constraints(problem, variables, model, assets, year);
6867

6968
let capacity_keys =
70-
add_asset_capacity_constraints(problem, variables, &model.time_slice_info, assets);
69+
add_activity_constraints(problem, variables, &model.time_slice_info, assets);
7170

7271
// Return constraint keys
7372
ConstraintKeys {
7473
commodity_balance_keys,
75-
capacity_keys,
74+
activity_keys: capacity_keys,
7675
}
7776
}
7877

@@ -101,16 +100,16 @@ fn add_commodity_balance_constraints(
101100
CommodityBalanceKeys { offset, keys }
102101
}
103102

104-
/// Add asset-level capacity and availability constraints.
103+
/// Add constraints on the activity of different assets.
105104
///
106105
/// This ensures that assets do not exceed their specified capacity and availability for each time
107106
/// slice.
108-
fn add_asset_capacity_constraints(
107+
fn add_activity_constraints(
109108
problem: &mut Problem,
110109
variables: &VariableMap,
111110
time_slice_info: &TimeSliceInfo,
112111
assets: &AssetPool,
113-
) -> CapacityKeys {
112+
) -> ActivityKeys {
114113
// Row offset in problem. This line **must** come before we add more constraints.
115114
let offset = problem.num_rows();
116115

@@ -125,5 +124,5 @@ fn add_asset_capacity_constraints(
125124
}
126125
}
127126

128-
CapacityKeys { offset, keys }
127+
ActivityKeys { offset, keys }
129128
}

src/simulation/prices.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl CommodityPrices {
3939
/// Add commodity prices for which there are values in the solution
4040
///
4141
/// Commodity prices are calculated as the sum of the commodity balance duals and the highest
42-
/// capacity dual for each commodity/timeslice.
42+
/// activity dual for each commodity/timeslice.
4343
///
4444
/// # Arguments
4545
///

0 commit comments

Comments
 (0)