Commit 67f141ae authored by ehebrard's avatar ehebrard
Browse files

test

parent 9a78e7cb
......@@ -14,7 +14,7 @@
// #include "SparseDistanceGraph.hpp"
// #define DEBUG_UPDATES
// #define ONLY_MINIMAL
#define ONLY_MINIMAL
// #define DEBUG_FLOYDWARSHALL true
// #define DEBUG_CONSTRAINT
......@@ -198,9 +198,10 @@ public:
#ifdef ONLY_MINIMAL
vector<vector<DistanceVariable<T> *>> matrix;
#else
SparseGraph<T> full_graph;
#endif
// #else
SparseGraph<T> full_graph;
// #endif
SparseGraph<T> minimal_graph;
......@@ -309,12 +310,13 @@ template <class T> void Schedule<T>::initialise() {
// full_graph.initialise(*this, true);
// minimal_graph.initialise(*this, false);
#ifndef ONLY_MINIMAL
full_graph.initialise(this->numEvent());
for (auto v : variables) {
full_graph.addArc(v);
}
#ifndef ONLY_MINIMAL
shortest_path_from_x.resize(numEvent(), INFTY);
shortest_path_to_y.resize(numEvent(), INFTY);
......@@ -1245,17 +1247,12 @@ void Schedule<T>::set(DistanceVariable<T> *v, const T bound, const Explanation<T
}
}
#else
// cout << fCandidates << endl;
//
// cout << bCandidates << endl;
// vertices whose distance from x has been reduced
for (auto b : fCandidates) {
// cout << "update SP from vertices whose path to " << label(b) << " has
// been shortened by " << label(x) << "->" << label(y) << endl;
#ifdef TRACE
if (debug_flag and (TRACE & UPDATES)) {
cout << " the shortest path from " << label(x) << " to " << label(b)
......@@ -1263,47 +1260,24 @@ void Schedule<T>::set(DistanceVariable<T> *v, const T bound, const Explanation<T
}
#endif
for (auto a{0}; a < numEvent(); ++a) {
if (matrix[a][b] != NULL) {
assert(shortest_path_to_y_min[a] != -INFTY);
assert(shortest_path_from_x_min[b] != -INFTY);
if (shortest_path_to_y_min[a] != INFTY and
shortest_path_from_x_min[b] != INFTY) {
// // cout << " " << label(a) << "?\n";
//
// cout << shortest_path_to_y_min[a] << " - " << bound << " +"
// << shortest_path_from_x_min[b] << endl;
auto nd{shortest_path_to_y_min[a] - bound +
shortest_path_from_x_min[b]};
if (nd < *matrix[a][b]) {
// cout << " yes!\n";
assert(nd != -INFTY);
if (makeCycle(matrix[a][b], nd)) {
fail({this, v->id});
}
for (auto e : full_graph.neighbor[PREDECESSOR][b]) {
auto a{e.neighbor()};
if (shortest_path_to_y_min[a] != INFTY and shortest_path_from_x_min[b] != INFTY) {
auto nd{shortest_path_to_y_min[a] - bound + shortest_path_from_x_min[b]};
if (nd < e.length()) {
assert(nd != -INFTY);
if (makeCycle(e.var, nd))
fail({this, opposite(e.var)->id});
#ifdef TRACE
if (debug_flag and (TRACE & UPDATES)) {
cout << " -> reduction of " << label(a) << " to " << label(b)
<< " (" << (T)(*matrix[a][b]) << ": " << nd << ")\n";
}
if (debug_flag and (TRACE & UPDATES)) {
cout << " -> reduction of " << label(a) << " to " << label(b)
<< " (" << *(e.var) << ": " << nd << ")\n";
}
#endif
// cout << label(a) << "->" << label(b) << ": " <<
// (T)(*matrix[a][b]) << " => " << nd << endl;
matrix[a][b]->set(nd, {this, v->id});
// cout << " verif: " << (T)(*matrix[a][b]) << endl;
queue.notifyChange(matrix[a][b]->id);
}
e.var->set(nd, {this, v->id});
queue.notifyChange(e.var->id);
}
}
}
......@@ -1311,9 +1285,6 @@ void Schedule<T>::set(DistanceVariable<T> *v, const T bound, const Explanation<T
for (auto a : bCandidates) {
// cout << "update SP to vertices whose path from " << label(a) << " has
// been shortened by " << label(x) << "->" << label(y) << endl;
#ifdef TRACE
if (debug_flag and (TRACE & UPDATES)) {
cout << " the shortest path from " << label(a) << " to " << label(y)
......@@ -1321,38 +1292,136 @@ void Schedule<T>::set(DistanceVariable<T> *v, const T bound, const Explanation<T
}
#endif
for (auto b{0}; b < numEvent(); ++b) {
if (matrix[a][b] != NULL) {
if (shortest_path_to_y_min[a] != INFTY and
shortest_path_from_x_min[b] != INFTY) {
// cout << " " << label(b) << "?\n";
auto nd{shortest_path_to_y_min[a] - bound +
shortest_path_from_x_min[b]};
if (nd < *matrix[a][b]) {
// cout << " yes!\n";
for (auto e : full_graph.neighbor[SUCCESSOR][a]) {
auto b{e.neighbor()};
if (shortest_path_to_y_min[a] != INFTY and shortest_path_from_x_min[b] != INFTY) {
auto nd{shortest_path_to_y_min[a] - bound + shortest_path_from_x_min[b]};
if (nd < e.length()) {
assert(nd != -INFTY);
if (makeCycle(e.var, nd))
fail({this, opposite(e.var)->id});
#ifdef TRACE
if (debug_flag and (TRACE & UPDATES)) {
cout << " -> reduction of " << label(a) << " to " << label(b)
<< " (" << (T)(*matrix[a][b]) << ": " << nd << ")\n";
}
if (debug_flag and (TRACE & UPDATES)) {
cout << " -> reduction of " << label(a) << " to " << label(b)
<< " (" << *(e.var) << ": " << nd << ")\n";
}
#endif
assert(nd != -INFTY);
if (makeCycle(matrix[a][b], nd)) {
fail({this, v->id});
}
matrix[a][b]->set(nd, {this, v->id});
queue.notifyChange(matrix[a][b]->id);
}
e.var->set(nd, {this, v->id});
queue.notifyChange(e.var->id);
}
}
}
}
// // cout << fCandidates << endl;
// //
// // cout << bCandidates << endl;
//
// // vertices whose distance from x has been reduced
// for (auto b : fCandidates) {
//
// // cout << "update SP from vertices whose path to " << label(b) << " has
// // been shortened by " << label(x) << "->" << label(y) << endl;
//
// #ifdef TRACE
// if (debug_flag and (TRACE & UPDATES)) {
// cout << " the shortest path from " << label(x) << " to " << label(b)
// << " has decreased\n";
// }
// #endif
//
// for (auto a{0}; a < numEvent(); ++a) {
// if (matrix[a][b] != NULL) {
//
// assert(shortest_path_to_y_min[a] != -INFTY);
// assert(shortest_path_from_x_min[b] != -INFTY);
//
// if (shortest_path_to_y_min[a] != INFTY and
// shortest_path_from_x_min[b] != INFTY) {
//
// // // cout << " " << label(a) << "?\n";
// //
// // cout << shortest_path_to_y_min[a] << " - " << bound << " +"
// // << shortest_path_from_x_min[b] << endl;
//
// auto nd{shortest_path_to_y_min[a] - bound +
// shortest_path_from_x_min[b]};
// if (nd < *matrix[a][b]) {
//
// // cout << " yes!\n";
//
// assert(nd != -INFTY);
// if (makeCycle(matrix[a][b], nd)) {
// fail({this, v->id});
// }
//
// #ifdef TRACE
// if (debug_flag and (TRACE & UPDATES)) {
// cout << " -> reduction of " << label(a) << " to " << label(b)
// << " (" << (T)(*matrix[a][b]) << ": " << nd << ")\n";
// }
// #endif
//
// // cout << label(a) << "->" << label(b) << ": " <<
// // (T)(*matrix[a][b]) << " => " << nd << endl;
//
// matrix[a][b]->set(nd, {this, v->id});
//
// // cout << " verif: " << (T)(*matrix[a][b]) << endl;
//
// queue.notifyChange(matrix[a][b]->id);
// }
// }
// }
// }
// }
//
// for (auto a : bCandidates) {
//
// // cout << "update SP to vertices whose path from " << label(a) << " has
// // been shortened by " << label(x) << "->" << label(y) << endl;
//
// #ifdef TRACE
// if (debug_flag and (TRACE & UPDATES)) {
// cout << " the shortest path from " << label(a) << " to " << label(y)
// << " has decreased\n";
// }
// #endif
//
// for (auto b{0}; b < numEvent(); ++b) {
// if (matrix[a][b] != NULL) {
// if (shortest_path_to_y_min[a] != INFTY and
// shortest_path_from_x_min[b] != INFTY) {
//
// // cout << " " << label(b) << "?\n";
//
// auto nd{shortest_path_to_y_min[a] - bound +
// shortest_path_from_x_min[b]};
// if (nd < *matrix[a][b]) {
//
// // cout << " yes!\n";
//
// #ifdef TRACE
// if (debug_flag and (TRACE & UPDATES)) {
// cout << " -> reduction of " << label(a) << " to " << label(b)
// << " (" << (T)(*matrix[a][b]) << ": " << nd << ")\n";
// }
// #endif
//
// assert(nd != -INFTY);
// if (makeCycle(matrix[a][b], nd)) {
// fail({this, v->id});
// }
//
// matrix[a][b]->set(nd, {this, v->id});
// queue.notifyChange(matrix[a][b]->id);
// }
// }
// }
// }
// }
#endif
// // vertices whose distance from x has been reduced
......
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