From f33ad0a7e2faf23ee5db6cb6bc4466696ef7ab88 Mon Sep 17 00:00:00 2001
From: Michael Sippel <micha@fragmental.art>
Date: Tue, 24 Dec 2024 12:54:43 +0100
Subject: [PATCH] steiner tree: eliminate identity loops

---
 src/morphism.rs     |  4 ++--
 src/steiner_tree.rs | 12 ++++++++----
 src/term.rs         |  5 +----
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/morphism.rs b/src/morphism.rs
index 9ba1ecb..a433bdc 100644
--- a/src/morphism.rs
+++ b/src/morphism.rs
@@ -65,7 +65,7 @@ impl<M: Morphism + Clone> MorphismBase<M> {
                 &m.get_type().src_type,
                 &src_type.clone().normalize()
             ) {
-                let dst_type = 
+                let dst_type =
                     m.get_type().dst_type.clone()
                     .apply_substitution( &|x| σ.get(x).cloned() )
                     .clone();
@@ -185,6 +185,7 @@ impl<M: Morphism + Clone> MorphismBase<M> {
         None
     }
 
+    /// finde a morphism that matches the given morphism type
     pub fn find_morphism(&self, ty: &MorphismType)
     -> Option< ( M, HashMap<TypeID, TypeTerm> ) > {
 
@@ -255,4 +256,3 @@ impl<M: Morphism + Clone> MorphismBase<M> {
 }
 
 //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>\\
-
diff --git a/src/steiner_tree.rs b/src/steiner_tree.rs
index d168812..c8984dd 100644
--- a/src/steiner_tree.rs
+++ b/src/steiner_tree.rs
@@ -34,7 +34,7 @@ impl SteinerTree {
         let mut new_goals = Vec::new();
         let mut added = false;
 
-        for g in self.goals.clone() { 
+        for g in self.goals.clone() {
             if let Ok(σ) = crate::unify(&ty.dst_type, &g) {
                 if !added {
                     self.edges.push(ty.clone());
@@ -107,8 +107,13 @@ impl PathApproxSteinerTreeSolver {
                 let mut new_path_iter = new_path.into_iter().peekable();
 
                 // check all existing nodes..
+
+                if new_path_iter.peek().unwrap() == &src_type {
+                    new_path_iter.next();
+                }
+
                 for mt in tree.iter() {
-//                    assert!( mt.src_type == &src_type );
+                    //assert!( mt.src_type == &src_type );
                     if let Some(t) = new_path_iter.peek() {
                         if &mt.dst_type == t {
                             // eliminate this node from new path
@@ -196,7 +201,7 @@ impl SteinerTreeProblem {
     pub fn solve_approx_path<M: Morphism + Clone>(&mut self, morphisms: &MorphismBase<M>) -> Option< SteinerTree > {
         if let Some(master) = self.src_types.first() {
 
-            
+
         }
     }
 */
@@ -238,4 +243,3 @@ impl SteinerTreeProblem {
         None
     }
 }
-
diff --git a/src/term.rs b/src/term.rs
index 29c7d27..2879ced 100644
--- a/src/term.rs
+++ b/src/term.rs
@@ -14,8 +14,6 @@ pub enum TypeTerm {
     Num(i64),
     Char(char),
 
-    
-
     /* Complex Terms */
 
     // Type Parameters
@@ -47,10 +45,9 @@ impl TypeTerm {
                 *self = TypeTerm::App(vec![
                     self.clone(),
                     t.into()
-                ])                
+                ])
             }
         }
-
         self
     }