Skip to content

Commit

Permalink
add contiguous option to metis
Browse files Browse the repository at this point in the history
  • Loading branch information
paulheinr committed Mar 22, 2024
1 parent 4f6c9e3 commit 1fa189e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
17 changes: 16 additions & 1 deletion src/simulation/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ pub struct MetisOptions {
pub imbalance_factor: f32,
#[serde(default = "u32_value_100")]
pub iteration_number: u32,
#[serde(default = "bool_value_true")]
pub contiguous: bool,
}

#[derive(PartialEq, Debug, ValueEnum, Clone, Copy, Serialize, Deserialize)]
Expand All @@ -291,6 +293,7 @@ impl Default for MetisOptions {
edge_weight: EdgeWeight::Constant,
imbalance_factor: 0.03,
iteration_number: 10,
contiguous: true,
}
}
}
Expand Down Expand Up @@ -323,6 +326,11 @@ impl MetisOptions {
};
val
}

pub fn set_contiguous(mut self, contiguous: bool) -> Self {
self.contiguous = contiguous;
self
}
}

fn f32_value_0_03() -> f32 {
Expand All @@ -337,6 +345,10 @@ fn u32_value_100() -> u32 {
100
}

fn bool_value_true() -> bool {
true
}

fn default_vertex_weight() -> Vec<VertexWeight> {
vec![InLinkCapacity]
}
Expand All @@ -363,6 +375,7 @@ mod tests {
edge_weight: EdgeWeight::Constant,
imbalance_factor: 1.02,
iteration_number: 100,
contiguous: true,
}),
};
config
Expand All @@ -385,6 +398,7 @@ mod tests {
edge_weight: EdgeWeight::Constant,
imbalance_factor: 1.02,
iteration_number: 100,
contiguous: true,
})
);
}
Expand Down Expand Up @@ -424,7 +438,8 @@ mod tests {
vertex_weight: vec![VertexWeight::InLinkCount],
edge_weight: EdgeWeight::Capacity,
imbalance_factor: 1.1,
iteration_number: 100
iteration_number: 100,
contiguous: true,
})
);
}
Expand Down
19 changes: 12 additions & 7 deletions src/simulation/network/metis_partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn partition(network: &Network, num_parts: u32, options: MetisOptions) -> Ve
let mut graph = Graph::new(ncon, num_parts as Idx, &mut xadj, &mut adjncy)
.set_option(metis::option::UFactor(options.ufactor() as Idx))
.set_option(metis::option::Seed(4711))
.set_option(metis::option::Contig(true))
.set_option(metis::option::Contig(options.contiguous))
.set_adjwgt(&mut adjwgt);

if !vwgt.is_empty() {
Expand Down Expand Up @@ -125,7 +125,7 @@ mod tests {
let network = Network::from_file(
"./assets/andorra-network.xml.gz",
5,
PartitionMethod::Metis(MetisOptions::default()),
PartitionMethod::Metis(MetisOptions::default().set_contiguous(false)),
);
println!("=== Default ===");
let _node_count = node_count(&network);
Expand All @@ -140,7 +140,8 @@ mod tests {
PartitionMethod::Metis(
MetisOptions::default()
.add_vertex_weight(VertexWeight::InLinkCapacity)
.set_imbalance_factor(0.),
.set_imbalance_factor(0.)
.set_contiguous(false),
),
);
println!("=== Capacity ===");
Expand All @@ -156,7 +157,8 @@ mod tests {
PartitionMethod::Metis(
MetisOptions::default()
.add_vertex_weight(VertexWeight::InLinkCount)
.set_imbalance_factor(0.),
.set_imbalance_factor(0.)
.set_contiguous(false),
),
);
println!("=== InLinkCount ===");
Expand All @@ -173,7 +175,8 @@ mod tests {
MetisOptions::default()
.add_vertex_weight(VertexWeight::InLinkCapacity)
.add_vertex_weight(VertexWeight::InLinkCount)
.set_imbalance_factor(0.),
.set_imbalance_factor(0.)
.set_contiguous(false),
),
);
println!("=== Capacity & InLinkCount ===");
Expand All @@ -189,7 +192,8 @@ mod tests {
PartitionMethod::Metis(
MetisOptions::default()
.add_vertex_weight(VertexWeight::Constant)
.set_imbalance_factor(0.),
.set_imbalance_factor(0.)
.set_contiguous(false),
),
);
println!("=== Constant Vertex ===");
Expand All @@ -207,7 +211,8 @@ mod tests {
.add_vertex_weight(VertexWeight::Constant)
.add_vertex_weight(VertexWeight::InLinkCount)
.set_imbalance_factor(0.)
.set_iteration_number(100),
.set_iteration_number(100)
.set_contiguous(false),
),
);
println!("=== Constant Vertex & InLinkCount ===");
Expand Down

0 comments on commit 1fa189e

Please sign in to comment.