Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/decider/gatewaydecider/flow_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,11 @@ pub async fn runSuperRouterFlow(
saving_percentage: 0.0,
}]
};

logger::debug!("Networks to process for SUPER_ROUTER before normalization: {:?}", networks_to_process);

// normalize the cost savings within range [0, 1]
let networks_to_process = network_decider::helpers::normalize_cost_savings(networks_to_process);

logger::debug!("Networks to process for SUPER_ROUTER: {:?}", networks_to_process);

Expand Down
28 changes: 28 additions & 0 deletions src/decider/network_decider/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,3 +252,31 @@ impl gateway_decider_types::NETWORK {
}
}
}

// Using max normalization strategy
// min cost saving will always be 0. So, max normalization is equivalent to min-max normalization
pub fn normalize_cost_savings(
network_cost_savings: Vec<types::NetworkSavingInfo>
) -> Vec<types::NetworkSavingInfo> {
let mut max_saving = f64::NEG_INFINITY;

for network_cost in &network_cost_savings {
max_saving = max_saving.max(network_cost.saving_percentage);
}

// If all the cost savings are 0, return the original array.
// This avoids division by zero in next code segment while normalizing cost savings.
if (max_saving - 0.0).abs() < f64::EPSILON {
return network_cost_savings;
}

network_cost_savings.iter()
.map(|network_cost| {
let normalized_cost_saving = network_cost.saving_percentage / max_saving;
types::NetworkSavingInfo {
network: network_cost.network.clone(),
saving_percentage: normalized_cost_saving,
}
})
.collect()
}
Loading