steiner tree (?)
This commit is contained in:
parent
4e89eeda91
commit
c28120f09c
1 changed files with 19 additions and 11 deletions
|
@ -1,14 +1,9 @@
|
|||
use {
|
||||
std::collections::HashMap,
|
||||
crate::{
|
||||
TypeID,
|
||||
TypeTerm,
|
||||
morphism::{
|
||||
MorphismType,
|
||||
Morphism,
|
||||
MorphismBase
|
||||
}
|
||||
}
|
||||
Morphism, MorphismBase, MorphismType
|
||||
}, MorphismInstance, TypeID, TypeTerm
|
||||
}, std::collections::HashMap
|
||||
};
|
||||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>\\
|
||||
|
@ -91,10 +86,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) = morphisms.find_morphism_path(
|
||||
MorphismType {
|
||||
|
@ -102,6 +98,15 @@ impl PathApproxSteinerTreeSolver {
|
|||
dst_type: goal.clone()
|
||||
}
|
||||
) {
|
||||
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();
|
||||
|
@ -109,12 +114,14 @@ impl PathApproxSteinerTreeSolver {
|
|||
// check all existing nodes..
|
||||
|
||||
if new_path_iter.peek().unwrap().get_type().src_type == src_type {
|
||||
eprintln!("skip initial node..");
|
||||
new_path_iter.next();
|
||||
}
|
||||
|
||||
for mt in tree.iter() {
|
||||
//assert!( mt.src_type == &src_type );
|
||||
if let Some(t) = new_path_iter.peek() {
|
||||
eprintln!("");
|
||||
if &mt.dst_type == &t.get_type().src_type {
|
||||
// eliminate this node from new path
|
||||
src_type = new_path_iter.next().unwrap().get_type().src_type;
|
||||
|
@ -127,6 +134,7 @@ impl PathApproxSteinerTreeSolver {
|
|||
for m in new_path_iter {
|
||||
tree.push(m.get_type());
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
eprintln!("could not find path\nfrom {:?}\nto {:?}", &self.root, &goal);
|
||||
return None;
|
||||
|
@ -136,7 +144,7 @@ impl PathApproxSteinerTreeSolver {
|
|||
Some(SteinerTree {
|
||||
weight: 0,
|
||||
goals: vec![],
|
||||
edges: tree
|
||||
edges
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue