From 72fa7feeea6e5aed4d071e7ee6d54b05816826b2 Mon Sep 17 00:00:00 2001 From: Ryo Nakabayashi Date: Wed, 2 Aug 2023 12:39:30 +0900 Subject: [PATCH] rename UpdateInfo -> UpdateCycle --- src/min_flow.rs | 8 +++--- src/min_flow/residue.rs | 60 ++++++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/min_flow.rs b/src/min_flow.rs index bc34510..86012f5 100644 --- a/src/min_flow.rs +++ b/src/min_flow.rs @@ -58,7 +58,7 @@ use petgraph::graph::{DiGraph, EdgeIndex}; use residue::{ enumerate_neighboring_flows_in_residue, find_neighboring_flow_by_edge_change_in_residue, flow_to_residue_convex, improve_flow, improve_flow_convex, CycleDetectMethod, ResidueDirection, - UpdateInfo, + UpdateCycle, }; use zero_demand::{find_initial_flow, is_zero_demand_flow_graph}; // use convex::is_convex_cost_flow_graph; @@ -221,14 +221,14 @@ where /// /// enumerate neighboring flows of current flow on MinFlowNetwork. /// -/// `Flow` and `UpdateInfo = Vec<(EdgeIndex, ResidueDirection)>` +/// `Flow` and `UpdateCycle = Vec<(EdgeIndex, ResidueDirection)>` /// pub fn enumerate_neighboring_flows( graph: &DiGraph, flow: &Flow, max_depth: Option, max_flip: Option, -) -> Vec<(Flow, UpdateInfo)> +) -> Vec<(Flow, UpdateCycle)> where F: FlowRateLike, E: FlowEdge + ConvexCost, @@ -252,7 +252,7 @@ pub fn find_neighboring_flow_by_edge_change( edge: EdgeIndex, direction: ResidueDirection, weight: W, -) -> Option<(Flow, UpdateInfo)> +) -> Option<(Flow, UpdateCycle)> where F: FlowRateLike, E: FlowEdge + ConvexCost, diff --git a/src/min_flow/residue.rs b/src/min_flow/residue.rs index f1c612e..59b3938 100644 --- a/src/min_flow/residue.rs +++ b/src/min_flow/residue.rs @@ -323,10 +323,10 @@ pub fn residue_graph_cycle_to_flow( flow: &Flow, residue_graph: &ResidueGraph, cycle_in_residue_graph: &[EdgeIndex], -) -> (Flow, UpdateInfo) { +) -> (Flow, UpdateCycle) { ( apply_residual_edges_to_flow(flow, residue_graph, cycle_in_residue_graph), - cycle_in_residue_graph_into_update_info(residue_graph, cycle_in_residue_graph), + cycle_in_residue_graph_into_update_cycle(residue_graph, cycle_in_residue_graph), ) } @@ -427,7 +427,7 @@ pub fn enumerate_neighboring_flows_in_residue( flow: &Flow, max_cycle_size: Option, max_flip: Option, -) -> Vec<(Flow, UpdateInfo)> { +) -> Vec<(Flow, UpdateCycle)> { // println!("{:?}", petgraph::dot::Dot::with_config(&rg, &[])); let simple_cycles = match max_cycle_size { Some(k) => simple_k_cycles_with_cond(rg, k, |edges, edge| { @@ -450,7 +450,7 @@ pub fn enumerate_neighboring_flows_in_residue( let flows: Vec<_> = simple_cycles .into_iter() .map(|cycle| residue_graph_cycle_to_flow(flow, rg, cycle.edges())) - .filter(|(new_flow, _update_info)| new_flow != flow) + .filter(|(new_flow, _)| new_flow != flow) .collect(); // eprintln!("# n_flows={}", flows.len()); flows @@ -496,7 +496,7 @@ pub fn find_neighboring_flow_by_edge_change_in_residue( edge: EdgeIndex, direction: ResidueDirection, weight: W, -) -> Option<(Flow, UpdateInfo)> +) -> Option<(Flow, UpdateCycle)> where F: FlowRateLike, W: Fn(EdgeIndex) -> usize, @@ -537,7 +537,7 @@ where assert!(is_cycle(&rg, &edges)); assert!(is_edge_simple(&rg, &edges)); - // convert the cycle into flow and updateinfo + // convert the cycle into flow and UpdateCycle Some(residue_graph_cycle_to_flow(flow, rg, &edges)) } None => None, @@ -704,10 +704,10 @@ fn update_flow_in_residue_graph( } } -fn cycle_in_residue_graph_into_update_info( +fn cycle_in_residue_graph_into_update_cycle( rg: &ResidueGraph, cycle: &[EdgeIndex], -) -> UpdateInfo { +) -> UpdateCycle { cycle .iter() .map(|&e| { @@ -737,25 +737,25 @@ pub fn improve_flow + ConstCost>( } /// -/// `UpdateInfo` = `Vec<(EdgeIndex, ResidueDirection)>` +/// `UpdateCycle` = `Vec<(EdgeIndex, ResidueDirection)>` /// /// information of updating a edge of either direction? /// -pub type UpdateInfo = Vec<(EdgeIndex, ResidueDirection)>; +pub type UpdateCycle = Vec<(EdgeIndex, ResidueDirection)>; -/// Stringify `UpdateInfo = Vec<(EdgeIndex, ResidueDirection)>` +/// Stringify `UpdateCycle = Vec<(EdgeIndex, ResidueDirection)>` /// into `e40+e10-e20+e11+` format string. /// -pub fn update_info_to_string(info: &UpdateInfo) -> String { +pub fn update_cycle_to_string(info: &UpdateCycle) -> String { info.iter() .map(|(edge, dir)| format!("e{}{}", edge.index(), dir)) .join("") } -/// Stringify `UpdateInfo = Vec<(EdgeIndex, ResidueDirection)>` +/// Stringify `UpdateCycle = Vec<(EdgeIndex, ResidueDirection)>` /// into `e40+e10-e20+e11+` format string. /// -pub fn update_info_from_str(s: &str) -> Option { +pub fn update_cycle_from_str(s: &str) -> Option { s.split_inclusive(&['+', '-']) .map(|t| { let t = t.strip_prefix('e')?; @@ -773,7 +773,7 @@ pub fn update_info_from_str(s: &str) -> Option { } // /// -// /// summary of UpdateInfo +// /// summary of UpdateCycle // /// // pub type UpdateSummary = Vec<(Vec, ResidueDirection)>; // @@ -792,11 +792,11 @@ pub fn update_info_from_str(s: &str) -> Option { /// create a new improved flow from current flow /// by upgrading along the negative weight cycle in the residual graph -pub fn improve_flow_convex_with_update_info( +pub fn improve_flow_convex_with_update_cycle( graph: &DiGraph, flow: &Flow, method: CycleDetectMethod, -) -> Option<(Flow, UpdateInfo)> +) -> Option<(Flow, UpdateCycle)> where F: FlowRateLike, E: FlowEdge + ConvexCost, @@ -806,7 +806,7 @@ where match update_flow_in_residue_graph(flow, &rg, method) { Some((new_flow, cycle)) => Some(( new_flow, - cycle_in_residue_graph_into_update_info(&rg, &cycle), + cycle_in_residue_graph_into_update_cycle(&rg, &cycle), )), None => None, } @@ -968,21 +968,21 @@ mod tests { } #[test] - fn conversion_update_info_string() { - let info_a: UpdateInfo = vec![ + fn conversion_update_cycle_string() { + let info_a: UpdateCycle = vec![ (ei(5), ResidueDirection::Up), (ei(2), ResidueDirection::Up), (ei(3), ResidueDirection::Down), ]; - let info_b: UpdateInfo = vec![]; - let info_c: UpdateInfo = vec![(ei(0), ResidueDirection::Up)]; - assert_eq!(update_info_to_string(&info_a), "e5+e2+e3-"); - assert_eq!(update_info_to_string(&info_b), ""); - assert_eq!(update_info_to_string(&info_c), "e0+"); - - assert_eq!(update_info_from_str("e5+e2+e3-"), Some(info_a)); - assert_eq!(update_info_from_str("ee5++e2+e3-"), None); - assert_eq!(update_info_from_str(""), Some(info_b)); - assert_eq!(update_info_from_str("e0+"), Some(info_c)); + let info_b: UpdateCycle = vec![]; + let info_c: UpdateCycle = vec![(ei(0), ResidueDirection::Up)]; + assert_eq!(update_cycle_to_string(&info_a), "e5+e2+e3-"); + assert_eq!(update_cycle_to_string(&info_b), ""); + assert_eq!(update_cycle_to_string(&info_c), "e0+"); + + assert_eq!(update_cycle_from_str("e5+e2+e3-"), Some(info_a)); + assert_eq!(update_cycle_from_str("ee5++e2+e3-"), None); + assert_eq!(update_cycle_from_str(""), Some(info_b)); + assert_eq!(update_cycle_from_str("e0+"), Some(info_c)); } }