steiner tree (?)

This commit is contained in:
Michael Sippel 2025-02-25 22:54:57 +01:00
parent 505063ac8b
commit 6ef48468ec
Signed by: senvas
GPG key ID: F96CF119C34B64A6

View file

@ -2,7 +2,8 @@ use {
crate::{
morphism::{
Morphism, MorphismType
}, morphism_base::MorphismBase, morphism_path::ShortestPathProblem, TypeID, TypeTerm
}, morphism_base::MorphismBase, morphism_path::ShortestPathProblem, TypeID, TypeTerm,
MorphismInstance,
}, std::collections::HashMap
};
@ -86,10 +87,11 @@ impl PathApproxSteinerTreeSolver {
}
}
pub fn solve<M: Morphism + Clone>(self, morphisms: &MorphismBase<M>) -> Option< SteinerTree > {
let mut tree = Vec::<MorphismType>::new();
pub fn solve<M: Morphism + Clone + PartialEq>(self, morphisms: &MorphismBase<M>) -> Option< SteinerTree > {
let mut edges = Vec::<MorphismType>::new();
for goal in self.leaves {
eprintln!("solve steiner tree: find path to goal {:?}", goal);
// try to find shortest path from root to current leaf
if let Some(new_path) = ShortestPathProblem::new(
morphisms,
@ -98,6 +100,16 @@ impl PathApproxSteinerTreeSolver {
dst_type: goal.clone()
}
).solve() {
eprintln!("path to {:?} has len {}", goal.clone(), new_path.len());
for morph_inst in new_path {
let t = morph_inst.get_type();
if ! edges.contains(&t) {
eprintln!("add edge {:?}", t);
edges.push(t);
}
}
/*
// reduce new path so that it does not collide with any existing path
let mut src_type = self.root.clone();
let mut new_path_iter = new_path.into_iter().peekable();
@ -110,6 +122,7 @@ impl PathApproxSteinerTreeSolver {
for mt in tree.iter() {
//assert!( mt.src_type == &src_type );
if let Some(inst) = new_path_iter.peek() {
let t = inst.get_type().dst_type;
if &mt.dst_type == &t {
@ -128,6 +141,7 @@ impl PathApproxSteinerTreeSolver {
});
src_type = inst.get_type().dst_type;
}
*/
} else {
eprintln!("could not find path\nfrom {:?}\nto {:?}", &self.root, &goal);
return None;
@ -137,7 +151,7 @@ impl PathApproxSteinerTreeSolver {
Some(SteinerTree {
weight: 0,
goals: vec![],
edges: tree
edges
})
}
}