gravatar
deba@inf.elte.hu
deba@inf.elte.hu
Wrong member variable settings bug fix. (Ticket #95)
0 2 0
default
2 files changed with 4 insertions and 4 deletions:
↑ Collapse diff ↑
Ignore white space 192 line context
... ...
@@ -923,214 +923,214 @@
923 923
    typedef typename Digraph::OutArcIt OutArcIt;
924 924
    
925 925
    ///\brief The type of the map that stores
926 926
    ///the reached nodes
927 927
    typedef typename TR::ReachedMap ReachedMap;
928 928
    ///\brief The type of the map that stores
929 929
    ///the processed nodes
930 930
    typedef typename TR::ProcessedMap ProcessedMap;
931 931
    ///\brief The type of the map that stores the last
932 932
    ///arcs of the shortest paths.
933 933
    typedef typename TR::PredMap PredMap;
934 934
    ///The type of the map that stores the dists of the nodes.
935 935
    typedef typename TR::DistMap DistMap;
936 936

	
937 937
  public:
938 938
    /// Constructor.
939 939
    BfsWizard() : TR() {}
940 940

	
941 941
    /// Constructor that requires parameters.
942 942

	
943 943
    /// Constructor that requires parameters.
944 944
    /// These parameters will be the default values for the traits class.
945 945
    BfsWizard(const Digraph &g, Node s=INVALID) :
946 946
      TR(g,s) {}
947 947

	
948 948
    ///Copy constructor
949 949
    BfsWizard(const TR &b) : TR(b) {}
950 950

	
951 951
    ~BfsWizard() {}
952 952

	
953 953
    ///Runs Bfs algorithm from a given node.
954 954
    
955 955
    ///Runs Bfs algorithm from a given node.
956 956
    ///The node can be given by the \ref source function.
957 957
    void run()
958 958
    {
959 959
      if(Base::_source==INVALID) throw UninitializedParameter();
960 960
      Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
961 961
      if(Base::_reached)
962 962
	alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached));
963 963
      if(Base::_processed) 
964 964
        alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
965 965
      if(Base::_pred) 
966 966
        alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
967 967
      if(Base::_dist) 
968 968
        alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
969 969
      alg.run(Base::_source);
970 970
    }
971 971

	
972 972
    ///Runs Bfs algorithm from the given node.
973 973

	
974 974
    ///Runs Bfs algorithm from the given node.
975 975
    ///\param s is the given source.
976 976
    void run(Node s)
977 977
    {
978 978
      Base::_source=s;
979 979
      run();
980 980
    }
981 981

	
982 982
    template<class T>
983 983
    struct DefPredMapBase : public Base {
984 984
      typedef T PredMap;
985 985
      static PredMap *createPredMap(const Digraph &) { return 0; };
986 986
      DefPredMapBase(const TR &b) : TR(b) {}
987 987
    };
988 988
    
989 989
    ///\brief \ref named-templ-param "Named parameter"
990 990
    ///function for setting PredMap
991 991
    ///
992 992
    /// \ref named-templ-param "Named parameter"
993 993
    ///function for setting PredMap
994 994
    ///
995 995
    template<class T>
996 996
    BfsWizard<DefPredMapBase<T> > predMap(const T &t) 
997 997
    {
998 998
      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
999 999
      return BfsWizard<DefPredMapBase<T> >(*this);
1000 1000
    }
1001 1001
    
1002 1002
 
1003 1003
    template<class T>
1004 1004
    struct DefReachedMapBase : public Base {
1005 1005
      typedef T ReachedMap;
1006 1006
      static ReachedMap *createReachedMap(const Digraph &) { return 0; };
1007 1007
      DefReachedMapBase(const TR &b) : TR(b) {}
1008 1008
    };
1009 1009
    
1010 1010
    ///\brief \ref named-templ-param "Named parameter"
1011 1011
    ///function for setting ReachedMap
1012 1012
    ///
1013 1013
    /// \ref named-templ-param "Named parameter"
1014 1014
    ///function for setting ReachedMap
1015 1015
    ///
1016 1016
    template<class T>
1017 1017
    BfsWizard<DefReachedMapBase<T> > reachedMap(const T &t) 
1018 1018
    {
1019
      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
1019
      Base::_reached=reinterpret_cast<void*>(const_cast<T*>(&t));
1020 1020
      return BfsWizard<DefReachedMapBase<T> >(*this);
1021 1021
    }
1022 1022
    
1023 1023

	
1024 1024
    template<class T>
1025 1025
    struct DefProcessedMapBase : public Base {
1026 1026
      typedef T ProcessedMap;
1027 1027
      static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
1028 1028
      DefProcessedMapBase(const TR &b) : TR(b) {}
1029 1029
    };
1030 1030
    
1031 1031
    ///\brief \ref named-templ-param "Named parameter"
1032 1032
    ///function for setting ProcessedMap
1033 1033
    ///
1034 1034
    /// \ref named-templ-param "Named parameter"
1035 1035
    ///function for setting ProcessedMap
1036 1036
    ///
1037 1037
    template<class T>
1038 1038
    BfsWizard<DefProcessedMapBase<T> > processedMap(const T &t) 
1039 1039
    {
1040
      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
1040
      Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t));
1041 1041
      return BfsWizard<DefProcessedMapBase<T> >(*this);
1042 1042
    }
1043 1043
    
1044 1044
   
1045 1045
    template<class T>
1046 1046
    struct DefDistMapBase : public Base {
1047 1047
      typedef T DistMap;
1048 1048
      static DistMap *createDistMap(const Digraph &) { return 0; };
1049 1049
      DefDistMapBase(const TR &b) : TR(b) {}
1050 1050
    };
1051 1051
    
1052 1052
    ///\brief \ref named-templ-param "Named parameter"
1053 1053
    ///function for setting DistMap type
1054 1054
    ///
1055 1055
    /// \ref named-templ-param "Named parameter"
1056 1056
    ///function for setting DistMap type
1057 1057
    ///
1058 1058
    template<class T>
1059 1059
    BfsWizard<DefDistMapBase<T> > distMap(const T &t) 
1060 1060
    {
1061 1061
      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
1062 1062
      return BfsWizard<DefDistMapBase<T> >(*this);
1063 1063
    }
1064 1064
    
1065 1065
    /// Sets the source node, from which the Bfs algorithm runs.
1066 1066

	
1067 1067
    /// Sets the source node, from which the Bfs algorithm runs.
1068 1068
    /// \param s is the source node.
1069 1069
    BfsWizard<TR> &source(Node s) 
1070 1070
    {
1071 1071
      Base::_source=s;
1072 1072
      return *this;
1073 1073
    }
1074 1074
    
1075 1075
  };
1076 1076
  
1077 1077
  ///Function type interface for Bfs algorithm.
1078 1078

	
1079 1079
  /// \ingroup search
1080 1080
  ///Function type interface for Bfs algorithm.
1081 1081
  ///
1082 1082
  ///This function also has several
1083 1083
  ///\ref named-templ-func-param "named parameters",
1084 1084
  ///they are declared as the members of class \ref BfsWizard.
1085 1085
  ///The following
1086 1086
  ///example shows how to use these parameters.
1087 1087
  ///\code
1088 1088
  ///  bfs(g,source).predMap(preds).run();
1089 1089
  ///\endcode
1090 1090
  ///\warning Don't forget to put the \ref BfsWizard::run() "run()"
1091 1091
  ///to the end of the parameter list.
1092 1092
  ///\sa BfsWizard
1093 1093
  ///\sa Bfs
1094 1094
  template<class GR>
1095 1095
  BfsWizard<BfsWizardBase<GR> >
1096 1096
  bfs(const GR &g,typename GR::Node s=INVALID)
1097 1097
  {
1098 1098
    return BfsWizard<BfsWizardBase<GR> >(g,s);
1099 1099
  }
1100 1100

	
1101 1101
#ifdef DOXYGEN
1102 1102
  /// \brief Visitor class for bfs.
1103 1103
  ///  
1104 1104
  /// This class defines the interface of the BfsVisit events, and
1105 1105
  /// it could be the base of a real Visitor class.
1106 1106
  template <typename _Digraph>
1107 1107
  struct BfsVisitor {
1108 1108
    typedef _Digraph Digraph;
1109 1109
    typedef typename Digraph::Arc Arc;
1110 1110
    typedef typename Digraph::Node Node;
1111 1111
    /// \brief Called when the arc reach a node.
1112 1112
    /// 
1113 1113
    /// It is called when the bfs find an arc which target is not
1114 1114
    /// reached yet.
1115 1115
    void discover(const Arc& arc) {}
1116 1116
    /// \brief Called when the node reached first time.
1117 1117
    /// 
1118 1118
    /// It is Called when the node reached first time.
1119 1119
    void reach(const Node& node) {}
1120 1120
    /// \brief Called when the arc examined but target of the arc 
1121 1121
    /// already discovered.
1122 1122
    /// 
1123 1123
    /// It called when the arc examined but the target of the arc 
1124 1124
    /// already discovered.
1125 1125
    void examine(const Arc& arc) {}
1126 1126
    /// \brief Called for the source node of the bfs.
1127 1127
    /// 
1128 1128
    /// It is called for the source node of the bfs.
1129 1129
    void start(const Node& node) {}
1130 1130
    /// \brief Called when the node processed.
1131 1131
    /// 
1132 1132
    /// It is Called when the node processed.
1133 1133
    void process(const Node& node) {}
1134 1134
  };
1135 1135
#else
1136 1136
  template <typename _Digraph>
Ignore white space 192 line context
... ...
@@ -906,214 +906,214 @@
906 906
    typedef typename Digraph::OutArcIt OutArcIt;
907 907
    
908 908
    ///\brief The type of the map that stores
909 909
    ///the reached nodes
910 910
    typedef typename TR::ReachedMap ReachedMap;
911 911
    ///\brief The type of the map that stores
912 912
    ///the processed nodes
913 913
    typedef typename TR::ProcessedMap ProcessedMap;
914 914
    ///\brief The type of the map that stores the last
915 915
    ///arcs of the %DFS paths.
916 916
    typedef typename TR::PredMap PredMap;
917 917
    ///The type of the map that stores the distances of the nodes.
918 918
    typedef typename TR::DistMap DistMap;
919 919

	
920 920
  public:
921 921
    /// Constructor.
922 922
    DfsWizard() : TR() {}
923 923

	
924 924
    /// Constructor that requires parameters.
925 925

	
926 926
    /// Constructor that requires parameters.
927 927
    /// These parameters will be the default values for the traits class.
928 928
    DfsWizard(const Digraph &g, Node s=INVALID) :
929 929
      TR(g,s) {}
930 930

	
931 931
    ///Copy constructor
932 932
    DfsWizard(const TR &b) : TR(b) {}
933 933

	
934 934
    ~DfsWizard() {}
935 935

	
936 936
    ///Runs Dfs algorithm from a given node.
937 937
    
938 938
    ///Runs Dfs algorithm from a given node.
939 939
    ///The node can be given by the \ref source function.
940 940
    void run()
941 941
    {
942 942
      if(Base::_source==INVALID) throw UninitializedParameter();
943 943
      Dfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g));
944 944
      if(Base::_reached) 
945 945
        alg.reachedMap(*reinterpret_cast<ReachedMap*>(Base::_reached));
946 946
      if(Base::_processed) 
947 947
        alg.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed));
948 948
      if(Base::_pred) 
949 949
        alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred));
950 950
      if(Base::_dist) 
951 951
        alg.distMap(*reinterpret_cast<DistMap*>(Base::_dist));
952 952
      alg.run(Base::_source);
953 953
    }
954 954

	
955 955
    ///Runs Dfs algorithm from the given node.
956 956

	
957 957
    ///Runs Dfs algorithm from the given node.
958 958
    ///\param s is the given source.
959 959
    void run(Node s)
960 960
    {
961 961
      Base::_source=s;
962 962
      run();
963 963
    }
964 964

	
965 965
    template<class T>
966 966
    struct DefPredMapBase : public Base {
967 967
      typedef T PredMap;
968 968
      static PredMap *createPredMap(const Digraph &) { return 0; };
969 969
      DefPredMapBase(const TR &b) : TR(b) {}
970 970
    };
971 971
    
972 972
    ///\brief \ref named-templ-param "Named parameter"
973 973
    ///function for setting PredMap type
974 974
    ///
975 975
    /// \ref named-templ-param "Named parameter"
976 976
    ///function for setting PredMap type
977 977
    ///
978 978
    template<class T>
979 979
    DfsWizard<DefPredMapBase<T> > predMap(const T &t) 
980 980
    {
981 981
      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
982 982
      return DfsWizard<DefPredMapBase<T> >(*this);
983 983
    }
984 984
    
985 985
 
986 986
    template<class T>
987 987
    struct DefReachedMapBase : public Base {
988 988
      typedef T ReachedMap;
989 989
      static ReachedMap *createReachedMap(const Digraph &) { return 0; };
990 990
      DefReachedMapBase(const TR &b) : TR(b) {}
991 991
    };
992 992
    
993 993
    ///\brief \ref named-templ-param "Named parameter"
994 994
    ///function for setting ReachedMap
995 995
    ///
996 996
    /// \ref named-templ-param "Named parameter"
997 997
    ///function for setting ReachedMap
998 998
    ///
999 999
    template<class T>
1000 1000
    DfsWizard<DefReachedMapBase<T> > reachedMap(const T &t) 
1001 1001
    {
1002
      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
1002
      Base::_reached=reinterpret_cast<void*>(const_cast<T*>(&t));
1003 1003
      return DfsWizard<DefReachedMapBase<T> >(*this);
1004 1004
    }
1005 1005
    
1006 1006

	
1007 1007
    template<class T>
1008 1008
    struct DefProcessedMapBase : public Base {
1009 1009
      typedef T ProcessedMap;
1010 1010
      static ProcessedMap *createProcessedMap(const Digraph &) { return 0; };
1011 1011
      DefProcessedMapBase(const TR &b) : TR(b) {}
1012 1012
    };
1013 1013
    
1014 1014
    ///\brief \ref named-templ-param "Named parameter"
1015 1015
    ///function for setting ProcessedMap
1016 1016
    ///
1017 1017
    /// \ref named-templ-param "Named parameter"
1018 1018
    ///function for setting ProcessedMap
1019 1019
    ///
1020 1020
    template<class T>
1021 1021
    DfsWizard<DefProcessedMapBase<T> > processedMap(const T &t) 
1022 1022
    {
1023
      Base::_pred=reinterpret_cast<void*>(const_cast<T*>(&t));
1023
      Base::_processed=reinterpret_cast<void*>(const_cast<T*>(&t));
1024 1024
      return DfsWizard<DefProcessedMapBase<T> >(*this);
1025 1025
    }
1026 1026
    
1027 1027
    template<class T>
1028 1028
    struct DefDistMapBase : public Base {
1029 1029
      typedef T DistMap;
1030 1030
      static DistMap *createDistMap(const Digraph &) { return 0; };
1031 1031
      DefDistMapBase(const TR &b) : TR(b) {}
1032 1032
    };
1033 1033
    
1034 1034
    ///\brief \ref named-templ-param "Named parameter"
1035 1035
    ///function for setting DistMap type
1036 1036
    ///
1037 1037
    /// \ref named-templ-param "Named parameter"
1038 1038
    ///function for setting DistMap type
1039 1039
    ///
1040 1040
    template<class T>
1041 1041
    DfsWizard<DefDistMapBase<T> > distMap(const T &t) 
1042 1042
    {
1043 1043
      Base::_dist=reinterpret_cast<void*>(const_cast<T*>(&t));
1044 1044
      return DfsWizard<DefDistMapBase<T> >(*this);
1045 1045
    }
1046 1046
    
1047 1047
    /// Sets the source node, from which the Dfs algorithm runs.
1048 1048

	
1049 1049
    /// Sets the source node, from which the Dfs algorithm runs.
1050 1050
    /// \param s is the source node.
1051 1051
    DfsWizard<TR> &source(Node s) 
1052 1052
    {
1053 1053
      Base::_source=s;
1054 1054
      return *this;
1055 1055
    }
1056 1056
    
1057 1057
  };
1058 1058
  
1059 1059
  ///Function type interface for Dfs algorithm.
1060 1060

	
1061 1061
  ///\ingroup search
1062 1062
  ///Function type interface for Dfs algorithm.
1063 1063
  ///
1064 1064
  ///This function also has several
1065 1065
  ///\ref named-templ-func-param "named parameters",
1066 1066
  ///they are declared as the members of class \ref DfsWizard.
1067 1067
  ///The following
1068 1068
  ///example shows how to use these parameters.
1069 1069
  ///\code
1070 1070
  ///  dfs(g,source).predMap(preds).run();
1071 1071
  ///\endcode
1072 1072
  ///\warning Don't forget to put the \ref DfsWizard::run() "run()"
1073 1073
  ///to the end of the parameter list.
1074 1074
  ///\sa DfsWizard
1075 1075
  ///\sa Dfs
1076 1076
  template<class GR>
1077 1077
  DfsWizard<DfsWizardBase<GR> >
1078 1078
  dfs(const GR &g,typename GR::Node s=INVALID)
1079 1079
  {
1080 1080
    return DfsWizard<DfsWizardBase<GR> >(g,s);
1081 1081
  }
1082 1082

	
1083 1083
#ifdef DOXYGEN
1084 1084
  /// \brief Visitor class for dfs.
1085 1085
  ///  
1086 1086
  /// It gives a simple interface for a functional interface for dfs 
1087 1087
  /// traversal. The traversal on a linear data structure. 
1088 1088
  template <typename _Digraph>
1089 1089
  struct DfsVisitor {
1090 1090
    typedef _Digraph Digraph;
1091 1091
    typedef typename Digraph::Arc Arc;
1092 1092
    typedef typename Digraph::Node Node;
1093 1093
    /// \brief Called when the arc reach a node.
1094 1094
    /// 
1095 1095
    /// It is called when the dfs find an arc which target is not
1096 1096
    /// reached yet.
1097 1097
    void discover(const Arc& arc) {}
1098 1098
    /// \brief Called when the node reached first time.
1099 1099
    /// 
1100 1100
    /// It is Called when the node reached first time.
1101 1101
    void reach(const Node& node) {}
1102 1102
    /// \brief Called when we step back on an arc.
1103 1103
    /// 
1104 1104
    /// It is called when the dfs should step back on the arc.
1105 1105
    void backtrack(const Arc& arc) {}
1106 1106
    /// \brief Called when we step back from the node.
1107 1107
    /// 
1108 1108
    /// It is called when we step back from the node.
1109 1109
    void leave(const Node& node) {}
1110 1110
    /// \brief Called when the arc examined but target of the arc 
1111 1111
    /// already discovered.
1112 1112
    /// 
1113 1113
    /// It called when the arc examined but the target of the arc 
1114 1114
    /// already discovered.
1115 1115
    void examine(const Arc& arc) {}
1116 1116
    /// \brief Called for the source node of the dfs.
1117 1117
    /// 
1118 1118
    /// It is called for the source node of the dfs.
1119 1119
    void start(const Node& node) {}
0 comments (0 inline)