equal
deleted
inserted
replaced
46 { |
46 { |
47 ///The graph type the algorithm runs on. |
47 ///The graph type the algorithm runs on. |
48 typedef GR Graph; |
48 typedef GR Graph; |
49 ///The type of the map that stores the edge lengths. |
49 ///The type of the map that stores the edge lengths. |
50 |
50 |
|
51 ///The type of the map that stores the edge lengths. |
51 ///It must meet the \ref concept::ReadMap "ReadMap" concept. |
52 ///It must meet the \ref concept::ReadMap "ReadMap" concept. |
52 /// |
|
53 typedef LM LengthMap; |
53 typedef LM LengthMap; |
54 //The type of the length of the edges. |
54 //The type of the length of the edges. |
55 typedef typename LM::Value Value; |
55 typedef typename LM::Value Value; |
56 ///The heap type used by Dijkstra algorithm. |
56 ///The heap type used by Dijkstra algorithm. |
57 |
57 |
65 std::less<Value> > Heap; |
65 std::less<Value> > Heap; |
66 |
66 |
67 ///\brief The type of the map that stores the last |
67 ///\brief The type of the map that stores the last |
68 ///edges of the shortest paths. |
68 ///edges of the shortest paths. |
69 /// |
69 /// |
|
70 ///The type of the map that stores the last |
|
71 ///edges of the shortest paths. |
70 ///It must meet the \ref concept::WriteMap "WriteMap" concept. |
72 ///It must meet the \ref concept::WriteMap "WriteMap" concept. |
71 /// |
73 /// |
72 typedef typename Graph::template NodeMap<typename GR::Edge> PredMap; |
74 typedef typename Graph::template NodeMap<typename GR::Edge> PredMap; |
73 ///Instantiates a PredMap. |
75 ///Instantiates a PredMap. |
74 |
76 |
80 return new PredMap(G); |
82 return new PredMap(G); |
81 } |
83 } |
82 ///\brief The type of the map that stores the last but one |
84 ///\brief The type of the map that stores the last but one |
83 ///nodes of the shortest paths. |
85 ///nodes of the shortest paths. |
84 /// |
86 /// |
|
87 ///The type of the map that stores the last but one |
|
88 ///nodes of the shortest paths. |
85 ///It must meet the \ref concept::WriteMap "WriteMap" concept. |
89 ///It must meet the \ref concept::WriteMap "WriteMap" concept. |
86 /// |
90 /// |
87 typedef typename Graph::template NodeMap<typename GR::Node> PredNodeMap; |
91 typedef typename Graph::template NodeMap<typename GR::Node> PredNodeMap; |
88 ///Instantiates a PredNodeMap. |
92 ///Instantiates a PredNodeMap. |
89 |
93 |
94 return new PredNodeMap(G); |
98 return new PredNodeMap(G); |
95 } |
99 } |
96 |
100 |
97 ///The type of the map that stores whether a nodes is reached. |
101 ///The type of the map that stores whether a nodes is reached. |
98 |
102 |
|
103 ///The type of the map that stores whether a nodes is reached. |
99 ///It must meet the \ref concept::WriteMap "WriteMap" concept. |
104 ///It must meet the \ref concept::WriteMap "WriteMap" concept. |
100 ///By default it is a NullMap. |
105 ///By default it is a NullMap. |
101 ///\todo If it is set to a real map, Dijkstra::reached() should read this. |
106 ///\todo If it is set to a real map, Dijkstra::reached() should read this. |
102 ///\todo named parameter to set this type, function to read and write. |
107 ///\todo named parameter to set this type, function to read and write. |
103 typedef NullMap<typename Graph::Node,bool> ReachedMap; |
108 typedef NullMap<typename Graph::Node,bool> ReachedMap; |
109 { |
114 { |
110 return new ReachedMap(); |
115 return new ReachedMap(); |
111 } |
116 } |
112 ///The type of the map that stores the dists of the nodes. |
117 ///The type of the map that stores the dists of the nodes. |
113 |
118 |
|
119 ///The type of the map that stores the dists of the nodes. |
114 ///It must meet the \ref concept::WriteMap "WriteMap" concept. |
120 ///It must meet the \ref concept::WriteMap "WriteMap" concept. |
115 /// |
121 /// |
116 typedef typename Graph::template NodeMap<typename LM::Value> DistMap; |
122 typedef typename Graph::template NodeMap<typename LM::Value> DistMap; |
117 ///Instantiates a DistMap. |
123 ///Instantiates a DistMap. |
118 |
124 |
507 |
513 |
508 }; |
514 }; |
509 |
515 |
510 /// Default traits used by \ref DijkstraWizard |
516 /// Default traits used by \ref DijkstraWizard |
511 |
517 |
512 /// To make it easier to use Dijkstra algorithm we created a wizard class. |
518 /// To make it easier to use Dijkstra algorithm we have created a wizard class. |
513 /// This \ref DijkstraWizard class also needs default traits. |
519 /// This \ref DijkstraWizard class needs default traits, as well as the \ref Dijkstra class. |
514 /// The \ref DijkstraWizardBase is a class to be the default traits of the |
520 /// The \ref DijkstraWizardBase is a class to be the default traits of the |
515 /// \ref DijkstraWizard class. |
521 /// \ref DijkstraWizard class. |
516 template<class GR,class LM> |
522 template<class GR,class LM> |
517 class DijkstraWizardBase : public DijkstraDefaultTraits<GR,LM> |
523 class DijkstraWizardBase : public DijkstraDefaultTraits<GR,LM> |
518 { |
524 { |
562 /// It uses the functions and features of the plain \ref Dijkstra, |
568 /// It uses the functions and features of the plain \ref Dijkstra, |
563 /// but it is much more simple to use it. |
569 /// but it is much more simple to use it. |
564 /// |
570 /// |
565 /// Simplicity means that the way to change the types defined |
571 /// Simplicity means that the way to change the types defined |
566 /// in the traits class is based on functions that returns the new class |
572 /// in the traits class is based on functions that returns the new class |
567 /// and not on templatable built-in classes. When using the plain \Dijkstra |
573 /// and not on templatable built-in classes. When using the plain \ref Dijkstra |
568 /// the new class with the modified type comes from the original by using the :: |
574 /// the new class with the modified type comes from the original class by using the :: |
569 /// operator. In this case only a function have to be called and it will |
575 /// operator. In the case of \ref DijkstraWizard only a function have to be called and it will |
570 /// return the needed class. |
576 /// return the needed class. |
571 /// |
577 /// |
572 /// It does not have own \ref run method. When its \ref run method is called |
578 /// It does not have own \ref run method. When its \ref run method is called |
573 /// it initiates a plain \ref Dijkstra class, and calls the \ref Dijkstra::run |
579 /// it initiates a plain \ref Dijkstra class, and calls the \ref Dijkstra::run |
574 /// method of it. |
580 /// method of it. |
606 public: |
612 public: |
607 /// Constructor. |
613 /// Constructor. |
608 DijkstraWizard() : TR() {} |
614 DijkstraWizard() : TR() {} |
609 |
615 |
610 /// Constructor that requires parameters. |
616 /// Constructor that requires parameters. |
|
617 |
|
618 /// Constructor that requires parameters. |
611 /// These parameters will be the default values for the traits class. |
619 /// These parameters will be the default values for the traits class. |
612 DijkstraWizard(const Graph &g,const LengthMap &l, Node s=INVALID) : |
620 DijkstraWizard(const Graph &g,const LengthMap &l, Node s=INVALID) : |
613 TR(g,l,s) {} |
621 TR(g,l,s) {} |
614 |
622 |
615 ///Copy constructor |
623 ///Copy constructor |
629 if(_predNode) Dij.predNodeMap(*(PredNodeMap*)_predNode); |
637 if(_predNode) Dij.predNodeMap(*(PredNodeMap*)_predNode); |
630 if(_dist) Dij.distMap(*(DistMap*)_dist); |
638 if(_dist) Dij.distMap(*(DistMap*)_dist); |
631 Dij.run(*(Node*)_source); |
639 Dij.run(*(Node*)_source); |
632 } |
640 } |
633 |
641 |
634 ///Runs Dijkstra algorithm from a given node. |
642 ///Runs Dijkstra algorithm from the given node. |
635 |
643 |
636 ///Runs Dijkstra algorithm from a given node. |
644 ///Runs Dijkstra algorithm from the given node. |
637 ///\param s is the given source. |
645 ///\param s is the given source. |
638 void run(Node s) |
646 void run(Node s) |
639 { |
647 { |
640 _source=(void *)&s; |
648 _source=(void *)&s; |
641 run(); |
649 run(); |
649 }; |
657 }; |
650 |
658 |
651 /// \ref named-templ-param "Named parameter" function for setting PredMap type |
659 /// \ref named-templ-param "Named parameter" function for setting PredMap type |
652 |
660 |
653 /// \ref named-templ-param "Named parameter" function for setting PredMap type |
661 /// \ref named-templ-param "Named parameter" function for setting PredMap type |
|
662 /// |
654 template<class T> |
663 template<class T> |
655 DijkstraWizard<DefPredMapBase<T> > predMap(const T &t) |
664 DijkstraWizard<DefPredMapBase<T> > predMap(const T &t) |
656 { |
665 { |
657 _pred=(void *)&t; |
666 _pred=(void *)&t; |
658 return DijkstraWizard<DefPredMapBase<T> >(*this); |
667 return DijkstraWizard<DefPredMapBase<T> >(*this); |
667 }; |
676 }; |
668 |
677 |
669 /// \ref named-templ-param "Named parameter" function for setting PredNodeMap type |
678 /// \ref named-templ-param "Named parameter" function for setting PredNodeMap type |
670 |
679 |
671 /// \ref named-templ-param "Named parameter" function for setting PredNodeMap type |
680 /// \ref named-templ-param "Named parameter" function for setting PredNodeMap type |
|
681 /// |
672 template<class T> |
682 template<class T> |
673 DijkstraWizard<DefPredNodeMapBase<T> > predNodeMap(const T &t) |
683 DijkstraWizard<DefPredNodeMapBase<T> > predNodeMap(const T &t) |
674 { |
684 { |
675 _predNode=(void *)&t; |
685 _predNode=(void *)&t; |
676 return DijkstraWizard<DefPredNodeMapBase<T> >(*this); |
686 return DijkstraWizard<DefPredNodeMapBase<T> >(*this); |
684 }; |
694 }; |
685 |
695 |
686 /// \ref named-templ-param "Named parameter" function for setting DistMap type |
696 /// \ref named-templ-param "Named parameter" function for setting DistMap type |
687 |
697 |
688 /// \ref named-templ-param "Named parameter" function for setting DistMap type |
698 /// \ref named-templ-param "Named parameter" function for setting DistMap type |
|
699 /// |
689 template<class T> |
700 template<class T> |
690 DijkstraWizard<DefDistMapBase<T> > distMap(const T &t) |
701 DijkstraWizard<DefDistMapBase<T> > distMap(const T &t) |
691 { |
702 { |
692 _dist=(void *)&t; |
703 _dist=(void *)&t; |
693 return DijkstraWizard<DefDistMapBase<T> >(*this); |
704 return DijkstraWizard<DefDistMapBase<T> >(*this); |