Commit 9a78e7cb authored by ehebrard's avatar ehebrard
Browse files

reversible graph

parent 0b6b0943
......@@ -7,7 +7,7 @@
#include "Global.hpp"
#include "SparseSet.hpp"
#define DEBUG_BELLMANFORD
// #define DEBUG_BELLMANFORD
using namespace std;
......@@ -56,6 +56,8 @@ public:
private:
SparseSet<> changed;
// long unsigned max_num_step{0};
};
template <typename T> BellmanFord<T>::BellmanFord() {}
......@@ -79,6 +81,8 @@ template <typename T>
template<class G>
void BellmanFord<T>::allShortestPaths(const int s, const G& neighbors, vector<T>& shortest_path) {
// long unsigned steps{0};
shortest_path[s] = 0;
changed.add(s);
......@@ -89,6 +93,11 @@ void BellmanFord<T>::allShortestPaths(const int s, const G& neighbors, vector<T>
auto u{changed.front()};
changed.pop_front();
// ++steps;
// if (steps > max_num_step) {
// max_num_step = steps;
// cout << max_num_step << endl;
// }
// cout << u << ":";
for (auto e : neighbors[u]) {
......@@ -101,6 +110,7 @@ void BellmanFord<T>::allShortestPaths(const int s, const G& neighbors, vector<T>
if (v == s) {
negative_cycle = true;
changed.clear();
return;
}
......@@ -130,6 +140,8 @@ void BellmanFord<T>::allShorterPaths(const int x, const int y, const T wxy,
#endif
) {
// long unsigned steps{0};
assert(changed.empty());
#ifdef DEBUG_BELLMANFORD
if (debug_flag)
......@@ -160,6 +172,12 @@ void BellmanFord<T>::allShorterPaths(const int x, const int y, const T wxy,
changed.pop_front();
// ++steps;
// if (steps > max_num_step) {
// max_num_step = steps;
// cout << max_num_step << endl;
// }
for (auto e : neighbors[u]) {
auto v{e.neighbor()};
auto w{e.length()};
......
......@@ -14,7 +14,7 @@
// #include "SparseDistanceGraph.hpp"
// #define DEBUG_UPDATES
#define ONLY_MINIMAL
// #define ONLY_MINIMAL
// #define DEBUG_FLOYDWARSHALL true
// #define DEBUG_CONSTRAINT
......@@ -729,7 +729,7 @@ template <class T> ChoicePoint Schedule<T>::selectChoicePoint() {
}
template <class T> ostream &Schedule<T>::displayStats(ostream &os) const {
os << "new lb = [" << left << setw(5) << setfill('.') << lb;
os << "new bounds = [" << left << setw(5) << setfill('.') << lb;
if (ub < INFTY)
os << right << setw(6) << setfill('.') << ub;
else
......@@ -737,7 +737,13 @@ template <class T> ostream &Schedule<T>::displayStats(ostream &os) const {
os << setfill(' ') << "] fails=" << setw(8) << left << num_fails
<< " updates=" << setw(10) << left << num_updates
<< " literals=" << setw(12) << left << num_literals
<< " prunings=" << setw(8) << left << num_prunings
<< " prunings=" << setw(8) << left << num_prunings << " graph=" << setw(8)
<< left <<
#ifdef ONLY_MINIMAL
minimal_graph.arcCount()
#else
full_graph.arcCount()
#endif
<< " cpu=" << (cpu_time() - start_time) << "\n";
return os;
}
......@@ -766,6 +772,11 @@ template <class T> void Schedule<T>::search() {
init_level = ReversibleObject::env->level();
while (lb < ub) {
// if ((num_propagations % 100) == 0) {
// displayStats(cout);
// }
try {
propagate();
......
......@@ -140,6 +140,10 @@ template <typename T> SparseGraph<T>::SparseGraph() : ReversibleObject() {}
template <typename T> void SparseGraph<T>::addArc(DistanceVariable<T> *v) {
ReversibleObject::save();
trail.push_back(v->from);
trail.push_back(v->to);
auto pto{static_cast<int>(neighbor[PREDECESSOR][v->to].size())};
auto pfrom{static_cast<int>(neighbor[SUCCESSOR][v->from].size())};
......@@ -421,7 +425,29 @@ template <typename T> void SparseGraph<T>::undo() {
auto y{trail.back()};
trail.pop_back();
split(y);
if (vertices.has(y)) {
// cout << "undo arc\n";
// undo an addArc(x,y)
auto x{trail.back()};
trail.pop_back();
assert(neighbor[SUCCESSOR][x].back().neighbor() == y);
assert(neighbor[PREDECESSOR][y].back().neighbor() == x);
neighbor[SUCCESSOR][x].pop_back();
neighbor[PREDECESSOR][y].pop_back();
--numArc;
} else {
// cout << "undo merge\n";
// undo a merge
split(y);
}
}
template <typename T> void SparseGraph<T>::split(const int y) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment