| ... | ... |
@@ -1047,75 +1047,77 @@ |
| 1047 | 1047 |
} |
| 1048 | 1048 |
}; |
| 1049 | 1049 |
|
| 1050 | 1050 |
/// Default traits class used by \ref DijkstraWizard |
| 1051 | 1051 |
|
| 1052 | 1052 |
/// To make it easier to use Dijkstra algorithm |
| 1053 | 1053 |
/// we have created a wizard class. |
| 1054 | 1054 |
/// This \ref DijkstraWizard class needs default traits, |
| 1055 | 1055 |
/// as well as the \ref Dijkstra class. |
| 1056 | 1056 |
/// The \ref DijkstraWizardBase is a class to be the default traits of the |
| 1057 | 1057 |
/// \ref DijkstraWizard class. |
| 1058 | 1058 |
/// \todo More named parameters are required... |
| 1059 | 1059 |
template<class GR,class LM> |
| 1060 | 1060 |
class DijkstraWizardBase : public DijkstraWizardDefaultTraits<GR,LM> |
| 1061 | 1061 |
{
|
| 1062 | 1062 |
typedef DijkstraWizardDefaultTraits<GR,LM> Base; |
| 1063 | 1063 |
protected: |
| 1064 | 1064 |
//The type of the nodes in the digraph. |
| 1065 | 1065 |
typedef typename Base::Digraph::Node Node; |
| 1066 | 1066 |
|
| 1067 | 1067 |
//Pointer to the digraph the algorithm runs on. |
| 1068 | 1068 |
void *_g; |
| 1069 | 1069 |
//Pointer to the length map |
| 1070 | 1070 |
void *_length; |
| 1071 |
//Pointer to the map of processed nodes. |
|
| 1072 |
void *_processed; |
|
| 1071 | 1073 |
//Pointer to the map of predecessors arcs. |
| 1072 | 1074 |
void *_pred; |
| 1073 | 1075 |
//Pointer to the map of distances. |
| 1074 | 1076 |
void *_dist; |
| 1075 | 1077 |
//Pointer to the source node. |
| 1076 | 1078 |
Node _source; |
| 1077 | 1079 |
|
| 1078 | 1080 |
public: |
| 1079 | 1081 |
/// Constructor. |
| 1080 | 1082 |
|
| 1081 | 1083 |
/// This constructor does not require parameters, therefore it initiates |
| 1082 | 1084 |
/// all of the attributes to default values (0, INVALID). |
| 1083 |
DijkstraWizardBase() : _g(0), _length(0), _pred(0), |
|
| 1085 |
DijkstraWizardBase() : _g(0), _length(0), _processed(0), _pred(0), |
|
| 1084 | 1086 |
_dist(0), _source(INVALID) {}
|
| 1085 | 1087 |
|
| 1086 | 1088 |
/// Constructor. |
| 1087 | 1089 |
|
| 1088 | 1090 |
/// This constructor requires some parameters, |
| 1089 | 1091 |
/// listed in the parameters list. |
| 1090 | 1092 |
/// Others are initiated to 0. |
| 1091 | 1093 |
/// \param g The digraph the algorithm runs on. |
| 1092 | 1094 |
/// \param l The length map. |
| 1093 | 1095 |
/// \param s The source node. |
| 1094 | 1096 |
DijkstraWizardBase(const GR &g,const LM &l, Node s=INVALID) : |
| 1095 | 1097 |
_g(reinterpret_cast<void*>(const_cast<GR*>(&g))), |
| 1096 | 1098 |
_length(reinterpret_cast<void*>(const_cast<LM*>(&l))), |
| 1097 |
_pred(0), _dist(0), _source(s) {}
|
|
| 1099 |
_processed(0), _pred(0), _dist(0), _source(s) {}
|
|
| 1098 | 1100 |
|
| 1099 | 1101 |
}; |
| 1100 | 1102 |
|
| 1101 | 1103 |
/// Auxiliary class for the function type interface of Dijkstra algorithm. |
| 1102 | 1104 |
|
| 1103 | 1105 |
/// This auxiliary class is created to implement the function type |
| 1104 | 1106 |
/// interface of \ref Dijkstra algorithm. It uses the functions and features |
| 1105 | 1107 |
/// of the plain \ref Dijkstra, but it is much simpler to use it. |
| 1106 | 1108 |
/// It should only be used through the \ref dijkstra() function, which makes |
| 1107 | 1109 |
/// it easier to use the algorithm. |
| 1108 | 1110 |
/// |
| 1109 | 1111 |
/// Simplicity means that the way to change the types defined |
| 1110 | 1112 |
/// in the traits class is based on functions that returns the new class |
| 1111 | 1113 |
/// and not on templatable built-in classes. |
| 1112 | 1114 |
/// When using the plain \ref Dijkstra |
| 1113 | 1115 |
/// the new class with the modified type comes from |
| 1114 | 1116 |
/// the original class by using the :: |
| 1115 | 1117 |
/// operator. In the case of \ref DijkstraWizard only |
| 1116 | 1118 |
/// a function have to be called, and it will |
| 1117 | 1119 |
/// return the needed class. |
| 1118 | 1120 |
/// |
| 1119 | 1121 |
/// It does not have own \ref run() method. When its \ref run() method |
| 1120 | 1122 |
/// is called, it initiates a plain \ref Dijkstra object, and calls the |
| 1121 | 1123 |
/// \ref Dijkstra::run() method of it. |
| ... | ... |
@@ -1152,50 +1154,54 @@ |
| 1152 | 1154 |
DijkstraWizard() : TR() {}
|
| 1153 | 1155 |
|
| 1154 | 1156 |
/// Constructor that requires parameters. |
| 1155 | 1157 |
|
| 1156 | 1158 |
/// Constructor that requires parameters. |
| 1157 | 1159 |
/// These parameters will be the default values for the traits class. |
| 1158 | 1160 |
DijkstraWizard(const Digraph &g,const LengthMap &l, Node s=INVALID) : |
| 1159 | 1161 |
TR(g,l,s) {}
|
| 1160 | 1162 |
|
| 1161 | 1163 |
///Copy constructor |
| 1162 | 1164 |
DijkstraWizard(const TR &b) : TR(b) {}
|
| 1163 | 1165 |
|
| 1164 | 1166 |
~DijkstraWizard() {}
|
| 1165 | 1167 |
|
| 1166 | 1168 |
///Runs Dijkstra algorithm from a source node. |
| 1167 | 1169 |
|
| 1168 | 1170 |
///Runs Dijkstra algorithm from a source node. |
| 1169 | 1171 |
///The node can be given with the \ref source() function. |
| 1170 | 1172 |
void run() |
| 1171 | 1173 |
{
|
| 1172 | 1174 |
if(Base::_source==INVALID) throw UninitializedParameter(); |
| 1173 | 1175 |
Dijkstra<Digraph,LengthMap,TR> |
| 1174 | 1176 |
dij(*reinterpret_cast<const Digraph*>(Base::_g), |
| 1175 | 1177 |
*reinterpret_cast<const LengthMap*>(Base::_length)); |
| 1176 |
if(Base::_pred) dij.predMap(*reinterpret_cast<PredMap*>(Base::_pred)); |
|
| 1177 |
if(Base::_dist) dij.distMap(*reinterpret_cast<DistMap*>(Base::_dist)); |
|
| 1178 |
if(Base::_processed) |
|
| 1179 |
dij.processedMap(*reinterpret_cast<ProcessedMap*>(Base::_processed)); |
|
| 1180 |
if(Base::_pred) |
|
| 1181 |
dij.predMap(*reinterpret_cast<PredMap*>(Base::_pred)); |
|
| 1182 |
if(Base::_dist) |
|
| 1183 |
dij.distMap(*reinterpret_cast<DistMap*>(Base::_dist)); |
|
| 1178 | 1184 |
dij.run(Base::_source); |
| 1179 | 1185 |
} |
| 1180 | 1186 |
|
| 1181 | 1187 |
///Runs Dijkstra algorithm from the given node. |
| 1182 | 1188 |
|
| 1183 | 1189 |
///Runs Dijkstra algorithm from the given node. |
| 1184 | 1190 |
///\param s is the given source. |
| 1185 | 1191 |
void run(Node s) |
| 1186 | 1192 |
{
|
| 1187 | 1193 |
Base::_source=s; |
| 1188 | 1194 |
run(); |
| 1189 | 1195 |
} |
| 1190 | 1196 |
|
| 1191 | 1197 |
/// Sets the source node, from which the Dijkstra algorithm runs. |
| 1192 | 1198 |
|
| 1193 | 1199 |
/// Sets the source node, from which the Dijkstra algorithm runs. |
| 1194 | 1200 |
/// \param s is the source node. |
| 1195 | 1201 |
DijkstraWizard<TR> &source(Node s) |
| 1196 | 1202 |
{
|
| 1197 | 1203 |
Base::_source=s; |
| 1198 | 1204 |
return *this; |
| 1199 | 1205 |
} |
| 1200 | 1206 |
|
| 1201 | 1207 |
template<class T> |
0 comments (0 inline)