Skip to content

Commit

Permalink
Merge pull request #128 from Janekdererste/metis-contiguous
Browse files Browse the repository at this point in the history
add contiguous option to metis
  • Loading branch information
paulheinr authored Mar 22, 2024
2 parents d82ce88 + 1fa189e commit 5c85c39
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 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
18 changes: 12 additions & 6 deletions src/simulation/network/metis_partitioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +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(options.contiguous))
.set_adjwgt(&mut adjwgt);

if !vwgt.is_empty() {
Expand Down Expand Up @@ -124,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 @@ -139,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 @@ -155,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 @@ -172,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 @@ -188,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 @@ -206,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 5c85c39

Please sign in to comment.