Commit ecf4a076 authored by ehebrard's avatar ehebrard
Browse files

some progress

parent 8fc49c33
......@@ -28,12 +28,12 @@ void Graph::add(Arc a) {
// cout << "add (" << a[0] << "," << a[1] << ")\n";
for (auto l{SUCCESSOR}; l <= PREDECESSOR; ++l) {
neighbor_rank[l][a[l]].push_back(
static_cast<int>(neighbor[1 - l][a[1 - l]].size()));
for (auto l{OUT}; l <= IN; ++l) {
neighbor_rank[l][a[l]].push_back(
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]);
// ++numArc;
}
......@@ -50,7 +50,7 @@ void Graph::removeVertex(const int u) {
ReversibleObject::save();
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;) {
removeIthNeighbor(u, l, i);
--numArc;
......@@ -98,23 +98,23 @@ void Graph::addIthNeighbor(const int u, const int l, const int ith) {
auto v{neighbor[l][u][ith]};
// k = 0;
// for (auto z : neighbor[SUCCESSOR][v]) {
// cout << " " << z << "@" << neighbor_rank[SUCCESSOR][v][k++];
// for (auto z : neighbor[OUT][v]) {
// cout << " " << z << "@" << neighbor_rank[OUT][v][k++];
// }
// cout << " /";
// k = 0;
// for (auto z : neighbor[PREDECESSOR][v]) {
// cout << " " << z << "@" << neighbor_rank[PREDECESSOR][v][k++];
// for (auto z : neighbor[IN][v]) {
// cout << " " << z << "@" << neighbor_rank[IN][v][k++];
// }
// cout << endl;
// k = 0;
// for (auto z : neighbor[SUCCESSOR][5]) {
// cout << " " << z << "@" << neighbor_rank[SUCCESSOR][5][k++];
// for (auto z : neighbor[OUT][5]) {
// cout << " " << z << "@" << neighbor_rank[OUT][5][k++];
// }
// cout << " /";
// k = 0;
// for (auto z : neighbor[PREDECESSOR][5]) {
// cout << " " << z << "@" << neighbor_rank[PREDECESSOR][5][k++];
// for (auto z : neighbor[IN][5]) {
// cout << " " << z << "@" << neighbor_rank[IN][5][k++];
// }
// cout << endl;
......@@ -153,29 +153,29 @@ void Graph::addIthNeighbor(const int u, const int l, const int ith) {
// cout << " (in place of " << w << ")\n";
//
// k = 0;
// for (auto z : neighbor[SUCCESSOR][v]) {
// cout << " " << z << "@" << neighbor_rank[SUCCESSOR][v][k++];
// for (auto z : neighbor[OUT][v]) {
// cout << " " << z << "@" << neighbor_rank[OUT][v][k++];
// }
// cout << " /";
// k = 0;
// for (auto z : neighbor[PREDECESSOR][v]) {
// cout << " " << z << "@" << neighbor_rank[PREDECESSOR][v][k++];
// for (auto z : neighbor[IN][v]) {
// cout << " " << z << "@" << neighbor_rank[IN][v][k++];
// }
// cout << endl;
// k = 0;
// for (auto z : neighbor[SUCCESSOR][5]) {
// cout << " " << z << "@" << neighbor_rank[SUCCESSOR][5][k++];
// for (auto z : neighbor[OUT][5]) {
// cout << " " << z << "@" << neighbor_rank[OUT][5][k++];
// }
// cout << " /";
// k = 0;
// for (auto z : neighbor[PREDECESSOR][5]) {
// cout << " " << z << "@" << neighbor_rank[PREDECESSOR][5][k++];
// for (auto z : neighbor[IN][5]) {
// cout << " " << z << "@" << neighbor_rank[IN][5][k++];
// }
// cout << endl;
}
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";
......@@ -216,10 +216,10 @@ void Graph::undo(Arc a) {
// cout << "undo (" << a[0] << "," << a[1] << ")\n" ; //<< *this << endl;
for (auto l{SUCCESSOR}; l <= PREDECESSOR; ++l) {
assert(neighbor[l][a[l]].back() == a[1 - l]);
neighbor[l][a[l]].pop_back();
neighbor_rank[l][a[l]].pop_back();
for (auto l{OUT}; l <= IN; ++l) {
assert(neighbor[l][a[l]].back() == a[1 - l]);
neighbor[l][a[l]].pop_back();
neighbor_rank[l][a[l]].pop_back();
}
// edges.remove(a);
......@@ -233,18 +233,18 @@ void Graph::resize(const int n) {
buffer.resize(n, 0);
neighbor[PREDECESSOR].resize(n);
neighbor[SUCCESSOR].resize(n);
neighbor_rank[PREDECESSOR].resize(n);
neighbor_rank[SUCCESSOR].resize(n);
neighbor[IN].resize(n);
neighbor[OUT].resize(n);
neighbor_rank[IN].resize(n);
neighbor_rank[OUT].resize(n);
vertices.reserve(n);
vertices.fill_back();
// cout << "before resize " << edges << endl;
// edges.resize(this->vertices, this->neighbor[SUCCESSOR]);
// cout << "after resize " << edges << endl;
// edges.resize(this->vertices, this->neighbor[OUT]);
// cout << "after resize " << edges << endl;
}
#ifdef DEBUG_SG
......@@ -259,6 +259,10 @@ size_t Graph::vertexCount() const { return vertices.count(); }
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) {
......@@ -270,7 +274,7 @@ void Graph::merge(const int u, const int v) {
// 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 " <<
//
......@@ -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.set(u);
for (auto w : neighbor[SUCCESSOR][u]) {
for (auto w : neighbor[OUT][u]) {
assert(w >= 0);
assert(w < buffer.size());
buffer.set(w);
}
for (auto w : neighbor[SUCCESSOR][v]) {
for (auto w : neighbor[OUT][v]) {
if (not buffer[w]) {
// cout << " -" << w << endl;
......@@ -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.set(u);
for (auto w : neighbor[PREDECESSOR][u]) {
for (auto w : neighbor[IN][u]) {
assert(w >= 0);
assert(w < buffer.size());
buffer.set(w);
}
for (auto w : neighbor[PREDECESSOR][v]) {
for (auto w : neighbor[IN][v]) {
if (not buffer[w]) {
// cout << " -" << w << endl;
......@@ -373,10 +377,10 @@ ostream &Graph::display(ostream &os) const {
// } else {
int k{0};
for (auto v : neighbor[SUCCESSOR][i]) {
for (auto v : neighbor[OUT][i]) {
os << " " << v
#ifdef DEBUG_SG
<< "@" << neighbor_rank[SUCCESSOR][i][k++]
<< "@" << neighbor_rank[OUT][i][k++]
#endif
;
......@@ -384,10 +388,10 @@ ostream &Graph::display(ostream &os) const {
}
os << " /";
k = 0;
for (auto v : neighbor[PREDECESSOR][i]) {
for (auto v : neighbor[IN][i]) {
os << " " << v
#ifdef DEBUG_SG
<< "@" << neighbor_rank[PREDECESSOR][i][k++]
<< "@" << neighbor_rank[IN][i][k++]
#endif
;
// assert(edges.has(v,i));
......@@ -408,7 +412,7 @@ ostream &Graph::display(ostream &os) const {
void Graph::verify(const char *msg) {
// cout << msg << endl ;
for (auto l{SUCCESSOR}; l <= PREDECESSOR; ++l) {
for (auto l{OUT}; l <= IN; ++l) {
int count = 0;
for (auto x : vertices) {
int rank = 0;
......@@ -418,19 +422,19 @@ void Graph::verify(const char *msg) {
cout << msg << ": error, there is a loop on " << x << endl;
exit(1);
}
if(l==SUCCESSOR)
// if(not edges.has(x,y)) {
// cout << msg << ": error, edge (" << x << "," << y << ") is not in edge set"
// << endl << *this << endl;
//
// cout << edges << endl;
//
// exit(1);
// }
auto jth{neighbor_rank[l][x][ith]};
if (l == OUT)
// if(not edges.has(x,y)) {
// cout << msg << ": error, edge (" << x << "," << y << ")
// is not in edge set"
// << endl << *this << endl;
//
// cout << edges << endl;
//
// exit(1);
// }
auto jth{neighbor_rank[l][x][ith]};
if (neighbor_rank[1 - l][y][jth] != ith or
neighbor[1 - l][y][jth] != x) {
......@@ -485,6 +489,10 @@ void Graph::verify(const char *msg) {
bool EdgeSet::newArc(const int x, const int y) {
if (x != y) {
auto e{x * size_ + y};
assert(e < edgeset.size());
assert(e >= 0);
if (not edgeset[e]) {
edgeset.set(e);
return true;
......@@ -494,13 +502,24 @@ bool EdgeSet::newArc(const int x, const int y) {
}
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) {
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 {
......@@ -521,6 +540,11 @@ size_t EdgeSet::count() const { return edgeset.count(); }
bool ReversibleEdgeSet::newArc(const int x, const int y) {
if (x != y) {
auto e{x * size_ + y};
assert(e < edgeset.size());
assert(e >= 0);
if (not edgeset[e]) {
ReversibleObject::save();
trail.push_back(x);
......@@ -533,13 +557,26 @@ bool ReversibleEdgeSet::newArc(const int x, const int y) {
}
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) {
assert(edgeset[a[0] * size_ + a[1]]);
edgeset.reset(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]]);
//
//
// assert(edgeset[a[0] * size_ + a[1]]);
//
// edgeset.reset(a[0] * size_ + a[1]);
}
ostream& ReversibleEdgeSet::display(ostream& os) const {
......
......@@ -42,9 +42,8 @@ public:
size_t size() const;
size_t numVar() 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) {
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, int N>
// 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 <typename T>
ostream &operator<<(ostream &os, const ConstraintGraph<T> &x) {
return x.display(os);
}
//
// template <class T> ostream &operator<<(ostream &os, const ResourceConstraint<T> &x) {
// return x.display(os);
......
......@@ -79,11 +79,11 @@ void ConstraintQueue<T, N>::triggers(const int var_id, const int cons_id) {
if (not active[p].has(cons_id)) {
active[p].add(cons_id);
#ifdef TRACE
if (scheduler.debug_flag and (TRACE & PROPAGATION)) {
cout << " triggers " << *cons << endl;
}
#endif
// #ifdef TRACE
// if (QUEUE_FLAG and (TRACE & PROPAGATION)) {
// cout << " triggers " << *cons << endl;
// }
// #endif
}
}
......
......@@ -124,6 +124,8 @@ public:
size_t numLiterals() const;
size_t arcCount() const; // { return core.arcCount(); }
bool closed() const;
// correct with merge
......@@ -131,6 +133,9 @@ public:
// be careful, does not work with merges
T get(const event ei, const event ej) const;
T getMaximumMakespan() const;
T getMinimumMakespan() const;
lit getLiteral(const event ei, const event ej) const;
// handles the case where 'from' and/or 'to' are merged events and calls
......@@ -160,80 +165,80 @@ public:
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;
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;
// vector<event> representant;
void getLiteralInfo(const lit l, event &x, event &y, T &d) const;
// merge stuff
vector<event> rmap;
vector<event> umap;
SparseSet<> merged;
// vector<size_t> numMerged;
event getRepresentant(const event i) const;
// tail[i] == last vertex mapped to i
vector<event> tail;
// next[i] == next vertex mapped to the same event as i (i, if there is
// none)
vector<event> next;
// prev[i] == prev vertex mapped to the same event as i (i, if there is
// none)
vector<event> prev;
// access to "active events"
vector<int>::const_iterator firstActive() const;
vector<int>::const_iterator lastActive() const;
bool isActive(const event i) const;
// update stuff
Reversible<lit> first_edge;
BellmanFord<T> algo;
vector<T> shortest_path_from_x;
vector<T> shortest_path_to_y;
SparseSet<> candidates[2];
void reserve(const size_t n);
event getRepresentant(const event i, T &d) const;
// merge event ej to event ei
void merge(const event ei, const event ej);
void doMerge();
void undoMerge();
// just add a new literal on the stack, does not change the distance
// until the
// next update
// TODO: explanations
void push(const event from, const event to, const T d,
const Explanation e = Constant::NoReason);
private:
Graph core;
ReversibleEdgeSet core_edges;
vector<T> distance;
vector<event> from;
vector<event> to;
vector<Explanation> reason;
vector<vector<lit>> current_edge;
vector<lit> prev_edge;
// merge stuff
vector<event> rmap;
vector<event> umap;
SparseSet<> merged;
// vector<size_t> numMerged;
// TODO: are those really useful now that we merge the triggers ?
// tail[i] == last vertex mapped to i
vector<event> tail;
// next[i] == next vertex mapped to the same event as i (i, if there is
// none)
vector<event> next;
// prev[i] == prev vertex mapped to the same event as i (i, if there is
// none)
vector<event> prev;
// update stuff
Reversible<lit> first_edge;
BellmanFord<T> algo;
vector<T> shortest_path_from_x;
vector<T> shortest_path_to_y;
SparseSet<> candidates[2];
void reserve(const size_t n);
event getRepresentant(const event i, T &d) const;
// merge event ej to event ei
void merge(const event ei, const event ej);
void doMerge();
void undoMerge();
// just add a new literal on the stack, does not change the distance
// until the
// next update
// TODO: explanations
void push(const event from, const event to, const T d,
const Explanation e = Constant::NoReason);
// actually applies the change corresponding to literal l
void commit(const lit l);
// actually applies the change corresponding to literal l
void commit(const lit l);
// actually applies the change corresponding to literal l as well as the
// transitive closure
void transitive_commit(const lit l);
// actually applies the change corresponding to literal l as well as the
// transitive closure
void transitive_commit(const lit l);
// push and commit
void set(const event from, const event to, const T d,
const Explanation e = Constant::NoReason);
// push and commit
void set(const event from, const event to, const T d,
const Explanation e = Constant::NoReason);
// bool inCore(const event x, const event y) const;
// bool inCore(const event x, const event y) const;
// void addToCore(const event x, const event y);
// void addToCore(const event x, const event y);
};
// template <class T> const T &DistanceConstraint<T>::operator()() const {
......@@ -357,12 +362,12 @@ template <class T> DistanceMatrix<T>::DistanceMatrix() : first_edge(0) {
// ORIGIN is the first event, HORIZON is the last event
current_edge[HORIZON][ORIGIN] = IdLit;
// if()
core.addArc(HORIZON, ORIGIN);
auto ver{core_edges.newArc(HORIZON, ORIGIN)};
assert(ver);
// core_edges.newArc(HORIZON, ORIGIN);
// if()
core.addArc(HORIZON, ORIGIN);
auto ver{core_edges.newArc(HORIZON, ORIGIN)};
assert(ver);
// core_edges.newArc(HORIZON, ORIGIN);
first_edge = 2;
// resize(2);
......@@ -389,11 +394,11 @@ template <class T> void DistanceMatrix<T>::resize(const size_t n) {
core.addArc(i, ORIGIN);
core.addArc(HORIZON, i);
auto ver{core_edges.newArc(i, ORIGIN)};
assert(ver);