@@ -260,7 +260,16 @@ impl Solution<'_> {
260260 . capacity_vars
261261 . keys ( )
262262 . zip ( self . solution . columns ( ) [ self . variables . capacity_var_idx . clone ( ) ] . iter ( ) )
263- . map ( |( asset, capacity) | ( asset, Capacity ( * capacity) ) )
263+ . map ( |( asset, capacity) | {
264+ // If the asset is divisible, the capacity variable represents number of units,
265+ // so convert to total capacity
266+ let capacity_value = if let Some ( unit_size) = asset. unit_size ( ) {
267+ capacity * unit_size. value ( )
268+ } else {
269+ * capacity
270+ } ;
271+ ( asset, Capacity ( capacity_value) )
272+ } )
264273 }
265274
266275 /// Keys and dual values for commodity balance constraints.
@@ -647,10 +656,22 @@ fn add_capacity_variables(
647656 ) ;
648657
649658 let current_capacity = asset. capacity ( ) . value ( ) ;
650- let lower = ( ( 1.0 - capacity_margin) * current_capacity) . max ( 0.0 ) ;
651- let upper = ( 1.0 + capacity_margin) * current_capacity;
652659 let coeff = calculate_capacity_coefficient ( asset) ;
653- let var = problem. add_column ( coeff. value ( ) , lower..=upper) ;
660+
661+ let var = if let Some ( unit_size) = asset. unit_size ( ) {
662+ // Divisible asset: capacity variable represents number of units
663+ let unit_size_value = unit_size. value ( ) ;
664+ let current_units = current_capacity / unit_size_value;
665+ let lower = ( ( 1.0 - capacity_margin) * current_units) . max ( 0.0 ) ;
666+ let upper = ( 1.0 + capacity_margin) * current_units;
667+ problem. add_integer_column ( coeff. value ( ) * unit_size_value, lower..=upper)
668+ } else {
669+ // Indivisible asset: capacity variable represents total capacity
670+ let lower = ( ( 1.0 - capacity_margin) * current_capacity) . max ( 0.0 ) ;
671+ let upper = ( 1.0 + capacity_margin) * current_capacity;
672+ problem. add_column ( coeff. value ( ) , lower..=upper)
673+ } ;
674+
654675 let existing = variables. insert ( asset. clone ( ) , var) . is_some ( ) ;
655676 assert ! ( !existing, "Duplicate entry for var" ) ;
656677 }
0 commit comments