Commit ecf4a076 authored by ehebrard's avatar ehebrard
Browse files

some progress

parent 8fc49c33
...@@ -28,12 +28,12 @@ void Graph::add(Arc a) { ...@@ -28,12 +28,12 @@ void Graph::add(Arc a) {
// cout << "add (" << a[0] << "," << a[1] << ")\n"; // cout << "add (" << a[0] << "," << a[1] << ")\n";
for (auto l{SUCCESSOR}; l <= PREDECESSOR; ++l) { for (auto l{OUT}; l <= IN; ++l) {
neighbor_rank[l][a[l]].push_back( neighbor_rank[l][a[l]].push_back(
static_cast<int>(neighbor[1 - l][a[1 - l]].size())); static_cast<int>(neighbor[1 - l][a[1 - l]].size()));
} }
for (auto l{SUCCESSOR}; l <= PREDECESSOR; ++l) { for (auto l{OUT}; l <= IN; ++l) {
neighbor[l][a[l]].push_back(a[1 - l]); neighbor[l][a[l]].push_back(a[1 - l]);
// ++numArc; // ++numArc;
} }
...@@ -50,7 +50,7 @@ void Graph::removeVertex(const int u) { ...@@ -50,7 +50,7 @@ void Graph::removeVertex(const int u) {
ReversibleObject::save(); ReversibleObject::save();
trail.push_back(u); trail.push_back(u);
for (auto l{SUCCESSOR}; l <= PREDECESSOR; ++l) { for (auto l{OUT}; l <= IN; ++l) {
for (auto i{neighbor[l][u].size()}; i-- > 0;) { for (auto i{neighbor[l][u].size()}; i-- > 0;) {
removeIthNeighbor(u, l, i); removeIthNeighbor(u, l, i);
--numArc; --numArc;
...@@ -98,23 +98,23 @@ void Graph::addIthNeighbor(const int u, const int l, const int ith) { ...@@ -98,23 +98,23 @@ void Graph::addIthNeighbor(const int u, const int l, const int ith) {
auto v{neighbor[l][u][ith]}; auto v{neighbor[l][u][ith]};
// k = 0; // k = 0;
// for (auto z : neighbor[SUCCESSOR][v]) { // for (auto z : neighbor[OUT][v]) {
// cout << " " << z << "@" << neighbor_rank[SUCCESSOR][v][k++]; // cout << " " << z << "@" << neighbor_rank[OUT][v][k++];
// } // }
// cout << " /"; // cout << " /";
// k = 0; // k = 0;
// for (auto z : neighbor[PREDECESSOR][v]) { // for (auto z : neighbor[IN][v]) {
// cout << " " << z << "@" << neighbor_rank[PREDECESSOR][v][k++]; // cout << " " << z << "@" << neighbor_rank[IN][v][k++];
// } // }
// cout << endl; // cout << endl;
// k = 0; // k = 0;
// for (auto z : neighbor[SUCCESSOR][5]) { // for (auto z : neighbor[OUT][5]) {
// cout << " " << z << "@" << neighbor_rank[SUCCESSOR][5][k++]; // cout << " " << z << "@" << neighbor_rank[OUT][5][k++];
// } // }
// cout << " /"; // cout << " /";
// k = 0; // k = 0;
// for (auto z : neighbor[PREDECESSOR][5]) { // for (auto z : neighbor[IN][5]) {
// cout << " " << z << "@" << neighbor_rank[PREDECESSOR][5][k++]; // cout << " " << z << "@" << neighbor_rank[IN][5][k++];
// } // }
// cout << endl; // cout << endl;
...@@ -153,29 +153,29 @@ void Graph::addIthNeighbor(const int u, const int l, const int ith) { ...@@ -153,29 +153,29 @@ void Graph::addIthNeighbor(const int u, const int l, const int ith) {
// cout << " (in place of " << w << ")\n"; // cout << " (in place of " << w << ")\n";
// //
// k = 0; // k = 0;
// for (auto z : neighbor[SUCCESSOR][v]) { // for (auto z : neighbor[OUT][v]) {
// cout << " " << z << "@" << neighbor_rank[SUCCESSOR][v][k++]; // cout << " " << z << "@" << neighbor_rank[OUT][v][k++];
// } // }
// cout << " /"; // cout << " /";
// k = 0; // k = 0;
// for (auto z : neighbor[PREDECESSOR][v]) { // for (auto z : neighbor[IN][v]) {
// cout << " " << z << "@" << neighbor_rank[PREDECESSOR][v][k++]; // cout << " " << z << "@" << neighbor_rank[IN][v][k++];
// } // }
// cout << endl; // cout << endl;
// k = 0; // k = 0;
// for (auto z : neighbor[SUCCESSOR][5]) { // for (auto z : neighbor[OUT][5]) {
// cout << " " << z << "@" << neighbor_rank[SUCCESSOR][5][k++]; // cout << " " << z << "@" << neighbor_rank[OUT][5][k++];
// } // }
// cout << " /"; // cout << " /";
// k = 0; // k = 0;
// for (auto z : neighbor[PREDECESSOR][5]) { // for (auto z : neighbor[IN][5]) {
// cout << " " << z << "@" << neighbor_rank[PREDECESSOR][5][k++]; // cout << " " << z << "@" << neighbor_rank[IN][5][k++];
// } // }
// cout << endl; // cout << endl;
} }
void Graph::recall(const int u) { void Graph::recall(const int u) {
for (auto l{PREDECESSOR}; l >= SUCCESSOR; --l) { for (auto l{IN}; l >= OUT; --l) {
// cout << (l ? "prede" : "suc") << "cessors\n"; // cout << (l ? "prede" : "suc") << "cessors\n";
...@@ -216,10 +216,10 @@ void Graph::undo(Arc a) { ...@@ -216,10 +216,10 @@ void Graph::undo(Arc a) {
// cout << "undo (" << a[0] << "," << a[1] << ")\n" ; //<< *this << endl; // cout << "undo (" << a[0] << "," << a[1] << ")\n" ; //<< *this << endl;
for (auto l{SUCCESSOR}; l <= PREDECESSOR; ++l) { for (auto l{OUT}; l <= IN; ++l) {
assert(neighbor[l][a[l]].back() == a[1 - l]); assert(neighbor[l][a[l]].back() == a[1 - l]);
neighbor[l][a[l]].pop_back(); neighbor[l][a[l]].pop_back();
neighbor_rank[l][a[l]].pop_back(); neighbor_rank[l][a[l]].pop_back();
} }
// edges.remove(a); // edges.remove(a);
...@@ -233,18 +233,18 @@ void Graph::resize(const int n) { ...@@ -233,18 +233,18 @@ void Graph::resize(const int n) {
buffer.resize(n, 0); buffer.resize(n, 0);
neighbor[PREDECESSOR].resize(n); neighbor[IN].resize(n);
neighbor[SUCCESSOR].resize(n); neighbor[OUT].resize(n);
neighbor_rank[PREDECESSOR].resize(n); neighbor_rank[IN].resize(n);
neighbor_rank[SUCCESSOR].resize(n); neighbor_rank[OUT].resize(n);
vertices.reserve(n); vertices.reserve(n);
vertices.fill_back(); vertices.fill_back();
// cout << "before resize " << edges << endl; // cout << "before resize " << edges << endl;
// edges.resize(this->vertices, this->neighbor[SUCCESSOR]); // edges.resize(this->vertices, this->neighbor[OUT]);
// cout << "after resize " << edges << endl; // cout << "after resize " << edges << endl;
} }
#ifdef DEBUG_SG #ifdef DEBUG_SG
...@@ -259,6 +259,10 @@ size_t Graph::vertexCount() const { return vertices.count(); } ...@@ -259,6 +259,10 @@ size_t Graph::vertexCount() const { return vertices.count(); }
size_t Graph::size() const { return vertices.capacity(); } size_t Graph::size() const { return vertices.capacity(); }
size_t Graph::outdegree(const int u) const { return neighbor[OUT][u].size(); }
size_t Graph::indegree(const int u) const { return neighbor[IN][u].size(); }
// //
void Graph::merge(const int u, const int v) { void Graph::merge(const int u, const int v) {
...@@ -270,7 +274,7 @@ void Graph::merge(const int u, const int v) { ...@@ -270,7 +274,7 @@ void Graph::merge(const int u, const int v) {
// cout << "1/ REMOVE " << v << ":\n" << *this << endl; // cout << "1/ REMOVE " << v << ":\n" << *this << endl;
// for (auto l{SUCCESSOR}; l <= PREDECESSOR; ++l) { // for (auto l{OUT}; l <= IN; ++l) {
// //
// // cout << (l+2) << "/ COMPLETE " << // // cout << (l+2) << "/ COMPLETE " <<
// //
...@@ -290,17 +294,17 @@ void Graph::merge(const int u, const int v) { ...@@ -290,17 +294,17 @@ void Graph::merge(const int u, const int v) {
// } // }
// } // }
// cout << "2/ FILL " << u << "'s successors:\n"; // cout << "2/ FILL " << u << "'s OUTs:\n";
buffer.reset(); buffer.reset();
buffer.set(u); buffer.set(u);
for (auto w : neighbor[SUCCESSOR][u]) { for (auto w : neighbor[OUT][u]) {
assert(w >= 0); assert(w >= 0);
assert(w < buffer.size()); assert(w < buffer.size());
buffer.set(w); buffer.set(w);
} }
for (auto w : neighbor[SUCCESSOR][v]) { for (auto w : neighbor[OUT][v]) {
if (not buffer[w]) { if (not buffer[w]) {
// cout << " -" << w << endl; // cout << " -" << w << endl;
...@@ -309,17 +313,17 @@ void Graph::merge(const int u, const int v) { ...@@ -309,17 +313,17 @@ void Graph::merge(const int u, const int v) {
} }
} }
// cout << *this << "\n2/ FILL " << u << "'s predecessors:\n"; // cout << *this << "\n2/ FILL " << u << "'s INs:\n";
buffer.reset(); buffer.reset();
buffer.set(u); buffer.set(u);
for (auto w : neighbor[PREDECESSOR][u]) { for (auto w : neighbor[IN][u]) {
assert(w >= 0); assert(w >= 0);
assert(w < buffer.size()); assert(w < buffer.size());
buffer.set(w); buffer.set(w);
} }
for (auto w : neighbor[PREDECESSOR][v]) { for (auto w : neighbor[IN][v]) {
if (not buffer[w]) { if (not buffer[w]) {
// cout << " -" << w << endl; // cout << " -" << w << endl;
...@@ -373,10 +377,10 @@ ostream &Graph::display(ostream &os) const { ...@@ -373,10 +377,10 @@ ostream &Graph::display(ostream &os) const {
// } else { // } else {
int k{0}; int k{0};
for (auto v : neighbor[SUCCESSOR][i]) { for (auto v : neighbor[OUT][i]) {
os << " " << v os << " " << v
#ifdef DEBUG_SG #ifdef DEBUG_SG
<< "@" << neighbor_rank[SUCCESSOR][i][k++] << "@" << neighbor_rank[OUT][i][k++]
#endif #endif
; ;
...@@ -384,10 +388,10 @@ ostream &Graph::display(ostream &os) const { ...@@ -384,10 +388,10 @@ ostream &Graph::display(ostream &os) const {
} }
os << " /"; os << " /";
k = 0; k = 0;
for (auto v : neighbor[PREDECESSOR][i]) { for (auto v : neighbor[IN][i]) {
os << " " << v os << " " << v
#ifdef DEBUG_SG #ifdef DEBUG_SG
<< "@" << neighbor_rank[PREDECESSOR][i][k++] << "@" << neighbor_rank[IN][i][k++]
#endif #endif
; ;
// assert(edges.has(v,i)); // assert(edges.has(v,i));
...@@ -408,7 +412,7 @@ ostream &Graph::display(ostream &os) const { ...@@ -408,7 +412,7 @@ ostream &Graph::display(ostream &os) const {
void Graph::verify(const char *msg) { void Graph::verify(const char *msg) {
// cout << msg << endl ; // cout << msg << endl ;
for (auto l{SUCCESSOR}; l <= PREDECESSOR; ++l) { for (auto l{OUT}; l <= IN; ++l) {
int count = 0; int count = 0;
for (auto x : vertices) { for (auto x : vertices) {
int rank = 0; int rank = 0;
...@@ -418,19 +422,19 @@ void Graph::verify(const char *msg) { ...@@ -418,19 +422,19 @@ void Graph::verify(const char *msg) {
cout << msg << ": error, there is a loop on " << x << endl; cout << msg << ": error, there is a loop on " << x << endl;
exit(1); exit(1);
} }
if(l==SUCCESSOR) if (l == OUT)
// if(not edges.has(x,y)) { // if(not edges.has(x,y)) {
// cout << msg << ": error, edge (" << x << "," << y << ") is not in edge set" // cout << msg << ": error, edge (" << x << "," << y << ")
// << endl << *this << endl; // is not in edge set"
// // << endl << *this << endl;
// cout << edges << endl; //
// // cout << edges << endl;
// exit(1); //
// } // exit(1);
// }
auto jth{neighbor_rank[l][x][ith]}; auto jth{neighbor_rank[l][x][ith]};
if (neighbor_rank[1 - l][y][jth] != ith or if (neighbor_rank[1 - l][y][jth] != ith or
neighbor[1 - l][y][jth] != x) { neighbor[1 - l][y][jth] != x) {
...@@ -485,6 +489,10 @@ void Graph::verify(const char *msg) { ...@@ -485,6 +489,10 @@ void Graph::verify(const char *msg) {
bool EdgeSet::newArc(const int x, const int y) { bool EdgeSet::newArc(const int x, const int y) {
if (x != y) { if (x != y) {
auto e{x * size_ + y}; auto e{x * size_ + y};
assert(e < edgeset.size());
assert(e >= 0);
if (not edgeset[e]) { if (not edgeset[e]) {
edgeset.set(e); edgeset.set(e);
return true; return true;
...@@ -494,13 +502,24 @@ bool EdgeSet::newArc(const int x, const int y) { ...@@ -494,13 +502,24 @@ bool EdgeSet::newArc(const int x, const int y) {
} }
bool EdgeSet::has(const int x, const int y) const { bool EdgeSet::has(const int x, const int y) const {
return edgeset[x * size_ + y];
auto e{x * size_ + y};
assert(e < edgeset.size());
assert(e >= 0);
return edgeset[e];
} }
void EdgeSet::remove(const Arc a) { void EdgeSet::remove(const Arc a) {
assert(edgeset[a[0] * size_ + a[1]]);
auto e{a[0] * size_ + a[1]};
assert(e < edgeset.size());
assert(e >= 0);
assert(edgeset[a[0] * size_ + a[1]]);
edgeset.reset(a[0] * size_ + a[1]); edgeset.reset(e);
} }
ostream& EdgeSet::display(ostream& os) const { ostream& EdgeSet::display(ostream& os) const {
...@@ -521,6 +540,11 @@ size_t EdgeSet::count() const { return edgeset.count(); } ...@@ -521,6 +540,11 @@ size_t EdgeSet::count() const { return edgeset.count(); }
bool ReversibleEdgeSet::newArc(const int x, const int y) { bool ReversibleEdgeSet::newArc(const int x, const int y) {
if (x != y) { if (x != y) {
auto e{x * size_ + y}; auto e{x * size_ + y};
assert(e < edgeset.size());
assert(e >= 0);
if (not edgeset[e]) { if (not edgeset[e]) {
ReversibleObject::save(); ReversibleObject::save();
trail.push_back(x); trail.push_back(x);
...@@ -533,13 +557,26 @@ bool ReversibleEdgeSet::newArc(const int x, const int y) { ...@@ -533,13 +557,26 @@ bool ReversibleEdgeSet::newArc(const int x, const int y) {
} }
bool ReversibleEdgeSet::has(const int x, const int y) const { bool ReversibleEdgeSet::has(const int x, const int y) const {
return edgeset[x * size_ + y]; auto e{x * size_ + y};
assert(e < edgeset.size());
assert(e >= 0);
return edgeset[e];
// return edgeset[x * size_ + y];
} }
void ReversibleEdgeSet::remove(const Arc a) { void ReversibleEdgeSet::remove(const Arc a) {
assert(edgeset[a[0] * size_ + a[1]]); auto e{a[0] * size_ + a[1]};
assert(e < edgeset.size());
edgeset.reset(a[0] * size_ + a[1]); assert(e >= 0);
assert(edgeset[a[0] * size_ + a[1]]);
//
//
// assert(edgeset[a[0] * size_ + a[1]]);
//
// edgeset.reset(a[0] * size_ + a[1]);
} }
ostream& ReversibleEdgeSet::display(ostream& os) const { ostream& ReversibleEdgeSet::display(ostream& os) const {
......
...@@ -42,9 +42,8 @@ public: ...@@ -42,9 +42,8 @@ public:
size_t size() const; size_t size() const;
size_t numVar() const; size_t numVar() const;
size_t numCon() const; size_t numCon() const;
// ostream &display(ostream &os) const; ostream &display(ostream &os) const;
}; };
...@@ -95,38 +94,29 @@ void ConstraintGraph<T>::createTrigger(const var v, const int c) { ...@@ -95,38 +94,29 @@ void ConstraintGraph<T>::createTrigger(const var v, const int c) {
network.addArc(v + numCon(), c); network.addArc(v + numCon(), c);
} }
template <typename T> void ConstraintGraph<T>::merge(const int x, const int y) {
network.merge(x, y);
}
template <typename T> ostream &ConstraintGraph<T>::display(ostream &os) const {
auto s{numCon()};
for (auto x{s}; x < s + numVar(); ++x) {
if (network.has(x) and network.outdegree(x) > 0) {
cout << x << ":";
for (auto c : network[x]) {
cout << " " << *(constraints[c]);
}
cout << endl;
}
}
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const ConstraintGraph<T> &x) {
// template <typename T, int N> return x.display(os);
// ostream &ConstraintQueue<T, N>::display(ostream &os) const { }
//
// for (auto x{0}; x < size(); ++x) {
// if(constraints[x] == NULL) {
// for (auto y{0}; y < size(); ++y) {
// if(constraints[y] != NULL) {
//
//
// auto varxy{scheduler.getVariable(x, y)};
// if (varxy != NoVar) {
// os << "watch " << scheduler.label(x) << "->" << scheduler.label(y)
// << ":";
// for (auto t : triggers[varxy])
// os << " " << *(constraints[t.constraint_id]);
// os << endl;
// }
// }
// }
// }
// }
// return os;
// }
//
// template <typename T, int N>
// ostream &operator<<(ostream &os, const ConstraintQueue<T, N> &x) {
// return x.display(os);
// }
// //
// template <class T> ostream &operator<<(ostream &os, const ResourceConstraint<T> &x) { // template <class T> ostream &operator<<(ostream &os, const ResourceConstraint<T> &x) {
// return x.display(os); // return x.display(os);
......
...@@ -79,11 +79,11 @@ void ConstraintQueue<T, N>::triggers(const int var_id, const int cons_id) { ...@@ -79,11 +79,11 @@ void ConstraintQueue<T, N>::triggers(const int var_id, const int cons_id) {
if (not active[p].has(cons_id)) { if (not active[p].has(cons_id)) {
active[p].add(cons_id); active[p].add(cons_id);
#ifdef TRACE // #ifdef TRACE
if (scheduler.debug_flag and (TRACE & PROPAGATION)) { // if (QUEUE_FLAG and (TRACE & PROPAGATION)) {
cout << " triggers " << *cons << endl; // cout << " triggers " << *cons << endl;
} // }
#endif // #endif
} }
} }
......
...@@ -124,6 +124,8 @@ public: ...@@ -124,6 +124,8 @@ public:
size_t numLiterals() const; size_t numLiterals() const;
size_t arcCount() const; // { return core.arcCount(); }
bool closed() const; bool closed() const;
// correct with merge // correct with merge
...@@ -131,6 +133,9 @@ public: ...@@ -131,6 +133,9 @@ public:
// be careful, does not work with merges // be careful, does not work with merges
T get(const event ei, const event ej) const; T get(const event ei, const event ej) const;
T getMaximumMakespan() const;
T getMinimumMakespan() const;
lit getLiteral(const event ei, const event ej) const; lit getLiteral(const event ei, const event ej) const;
// handles the case where 'from' and/or 'to' are merged events and calls // handles the case where 'from' and/or 'to' are merged events and calls
...@@ -160,80 +165,80 @@ public: ...@@ -160,80 +165,80 @@ public:
ostream &print_reason(ostream &os, const hint h) const override; ostream &print_reason(ostream &os, const hint h) const override;
size_t arcCount() { return core.arcCount(); } void getLiteralInfo(const lit l, event &x, event &y, T &d) const;
void getLiteralInfo(const lit l, event &x, event &y, T &d) const;
event getRepresentant(const event i) const;
private:
Graph core;
ReversibleEdgeSet core_edges;
// boost::dynamic_bitset<> core_edges;
// vector<size_t> core_list;
vector<T> distance;
vector<event> from;
vector<event> to;
vector<Explanation> reason;
vector<vector<lit>> current_edge;
vector<lit> prev_edge;