// Copyright 2004 Laurent GUEGUEN // This file is part of Sarment. // Sarment is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // Sarment is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with Sarment; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #include template RM_Noeud::RM_Noeud() : R(), _no(1), _su(0), _pd(0) { } template RM_Noeud::RM_Noeud(Cdesc_comp* const pd) : R(), _no(1), _su(0), _pd(pd) { } template RM_Noeud::RM_Noeud(const R& r, const Cdesc_comp* const pd) : R(r), _pd(pd), _no(1), _su(0) { } template RM_Noeud::RM_Noeud(const RM_Noeud& C) : R(C), _no(1), _pd(C._pd), _val(C._val) { _su=C._su; if (_su) _su->_no++; } template RM_Noeud::~RM_Noeud() { net_succ(); } template double RM_Noeud::val() const { return _val; } template void RM_Noeud::g_val(double x) { _val=x; } template void RM_Noeud::nettoie_sur(int l) { RM_Noeud** tab; tab=new RM_Noeud*[l]; RM_Noeud* ps; int i=0; ps=_su; while ((iNoeud_normal()){ tab[i++]=ps; ps=ps->_su; } while (--i>=1){ if (tab[i]->_no<=2){ tab[i-1]->_su=tab[i]->_su; delete tab[i]; } } delete[] tab; } template void RM_Noeud::net_succ() { if (_su && (--(_su->_no)==1) && _su->Noeud_normal() ){ delete _su; _su=0; } } ///////////////////////////////////// // initialisations /////////////////////////////////////// template void RM_Noeud::init(const Cdescripteur* const i , const Cdescripteur* const d, const Cdescripteur* const f, RM_Noeud& r) { if (_pd) g_val(_pd->multiplie(i,d,f)); dev_su(r); } template void RM_Noeud::init(const mat_iter& m_i, RM_Noeud& r) { if (_pd) g_val(_pd->multiplie(m_i)); dev_su(r); } template void RM_Noeud::init(double val, RM_Noeud& r) { g_val(val); dev_su(r); } /////////////////////////////////////// // modifications /////////////////////////////////////// template void RM_Noeud::avance() { R::avance(); } template void RM_Noeud::recule() { R::recule(); } template void RM_Noeud::ajoute_su(const Cdescripteur* const i , const Cdescripteur* const d, const Cdescripteur* const f) { if (_pd) _val+=(_pd->multiplie(i,d,f)+_pd->auto_trans()); } template void RM_Noeud::ajoute_su(const mat_iter& m_i) { if (_pd) _val+=(_pd->multiplie(m_i)+_pd->auto_trans()); } template void RM_Noeud::ajoute_su(const Cdescripteur* const i , const Cdescripteur* const d, const Cdescripteur* const f, const Tliste* >& L) { static Tliste_iter* > it; static RM_Noeud **ppr, *prm; static double m,x; it.colle(L); if (!(ppr=it())) return; prm=*ppr; m=prm->val()+_pd->trans_de(prm->_pd->num()); while (ppr=it()){ if ((x=(*ppr)->val()+_pd->trans_de((*ppr)->_pd->num()))>m){ m=x; prm=*ppr; } } if (prm->_pd->num()==_pd->num()) recup_su_de(*prm); else dev_su(*prm); g_val(_pd->multiplie(i,d,f)+m); } template void RM_Noeud::ajoute_su(const mat_iter& m_i, const Tliste* >& L) { static Tliste_iter* > it; static RM_Noeud **ppr, *prm; static double m,x; it.colle(L); if (!(ppr=it())) return; prm=*ppr; m=prm->val()+_pd->trans_de(prm->_pd->num()); while (ppr=it()){ if ((x=(*ppr)->val()+_pd->trans_de((*ppr)->_pd->num()))>m){ m=x; prm=*ppr; } } if (prm->_pd->num()==_pd->num()) recup_su_de(*prm); else dev_su(*prm); g_val(_pd->multiplie(m_i)+m); } template void RM_Noeud::ajoute_pred(const Cdescripteur* const i , const Cdescripteur* const d, const Cdescripteur* const f) { if (_pd) _val+=(_pd->multiplie(i,d,f)); } template void RM_Noeud::ajoute_pred(const mat_iter& m_i) { if (_pd) _val+=(_pd->multiplie(m_i)); } template void RM_Noeud::backward(const Tliste* >& L) { static Tliste ld; static Tliste_iter itld(ld); ld.nettoie(); static double x,m; static double *pd; static Tliste_iter* > it; static RM_Noeud **ppr; static int pdn; it.colle(L); pdn=_pd->num(); if (ppr=it()){ m=(*ppr)->val()+(*ppr)->_pd->trans_de(pdn); ld.aj_fin(m); } while (ppr=it()){ x=(*ppr)->val()+(*ppr)->_pd->trans_de(pdn); ld.aj_fin(x); if (m void RM_Noeud::forward(const Tliste* >& L) { static Tliste ld; static Tliste_iter itld(ld); ld.nettoie(); static double x,m; static double *pd; static Tliste_iter* > it; static RM_Noeud **ppr; it.colle(L); if (ppr=it()){ m=(*ppr)->val()+_pd->trans_de((*ppr)->_pd->num()); ld.aj_fin(m); } while (ppr=it()){ x=(*ppr)->val()+_pd->trans_de((*ppr)->_pd->num()); ld.aj_fin(x); if (m short RM_Noeud::no() const { return _no; } template RM_Noeud* RM_Noeud::su() const { return _su; } template int RM_Noeud::lg() const { RM_Noeud* ps=_su; int l=1; while (ps && ps->Noeud_normal()){ ps=ps->_su; l++; } return l; } /////////////////// // modifications /////////////////// template void RM_Noeud::dev_su(RM_Noeud& C) { net_succ(); _su=&C; C._no++; } template void RM_Noeud::recup_su_de(RM_Noeud& C) { net_succ(); _su=C._su; if (_su) _su->_no++; } template void RM_Noeud::operator=(RM_Noeud& C) { R::operator=(C); recup_su_de(C); } template const Cdesc_comp* RM_Noeud::pd() const { return _pd; }