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) {
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,7 +216,7 @@ void Graph::undo(Arc a) {
// 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]);
neighbor[l][a[l]].pop_back();
neighbor_rank[l][a[l]].pop_back();
......@@ -233,17 +233,17 @@ 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]);
// edges.resize(this->vertices, this->neighbor[OUT]);
// cout << "after resize " << edges << endl;
}
......@@ -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;
......@@ -419,9 +423,10 @@ void Graph::verify(const char *msg) {
exit(1);
}
if(l==SUCCESSOR)
if (l == OUT)
// if(not edges.has(x,y)) {
// cout << msg << ": error, edge (" << x << "," << y << ") is not in edge set"
// cout << msg << ": error, edge (" << x << "," << y << ")
// is not in edge set"
// << endl << *this << endl;
//
// cout << edges << endl;
......@@ -429,7 +434,6 @@ void Graph::verify(const char *msg) {
// exit(1);
// }
auto jth{neighbor_rank[l][x][ith]};
if (neighbor_rank[1 - l][y][jth] != ith or
......@@ -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) {
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]]);
auto e{a[0] * size_ + a[1]};
assert(e < edgeset.size());
assert(e >= 0);
edgeset.reset(a[0] * size_ + a[1]);
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 {
......
......@@ -43,8 +43,7 @@ public:
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,17 +165,18 @@ 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:
// access to "active events"
vector<int>::const_iterator firstActive() const;
vector<int>::const_iterator lastActive() const;
bool isActive(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;
......@@ -180,14 +186,13 @@ public:
vector<vector<lit>> current_edge;
vector<lit> prev_edge;
// vector<event> representant;
// 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
......@@ -497,6 +502,10 @@ template <class T> size_t DistanceMatrix<T>::numLiterals() const {
return distance.size();
}
template <class T> size_t DistanceMatrix<T>::arcCount() const {
return core.arcCount();
}
template <class T> bool DistanceMatrix<T>::closed() const {
return numLiterals() == first_edge;
}
......@@ -508,6 +517,20 @@ template <class T> bool DistanceMatrix<T>::closed() const {
// return DistanceFunction(distance, current_edge[e]);
// }
template <class T>
vector<int>::const_iterator DistanceMatrix<T>::firstActive() const {
return core.begin();
}
template <class T>
vector<int>::const_iterator DistanceMatrix<T>::lastActive() const {
return core.end();
}
template <class T> bool DistanceMatrix<T>::isActive(const event i) const {
return core.has(i);
}
template <class T>
event DistanceMatrix<T>::getRepresentant(const event i, T &d) const {
auto p{i};
......@@ -531,6 +554,14 @@ T DistanceMatrix<T>::get(const event ei, const event ej) const {
return distance[current_edge[ei][ej]];
}
template <class T> T DistanceMatrix<T>::getMaximumMakespan() const {
return get(ORIGIN, HORIZON);
}
template <class T> T DistanceMatrix<T>::getMinimumMakespan() const {
return -get(HORIZON, ORIGIN);
}
template <class T>
T DistanceMatrix<T>::operator()(const event ei, const event ej) const {
T di{0};
......@@ -554,12 +585,12 @@ template <class T> void DistanceMatrix<T>::transitive_commit(const lit l) {
// event a[2] = {rom[l], to[l]};
// for(auto e : events)
// assert(core.vertices.has(e));
//
//
// for(auto e : core.vertices)
// assert(events.has(e));
// for(auto e : events)
// assert(core.vertices.has(e));
//
//
// for(auto e : core.vertices)
// assert(events.has(e));
assert(core.has(x) and core.has(y));
......@@ -569,31 +600,31 @@ template <class T> void DistanceMatrix<T>::transitive_commit(const lit l) {
shortest_path_from_x[z] = get(x, z);
shortest_path_to_y[z] = get(z, x);
}
candidates[SUCCESSOR].clear();
candidates[PREDECESSOR].clear();
candidates[OUT].clear();
candidates[IN].clear();
algo.initialise(size());
current_edge[x][y] = l;
algo.allShorterPaths(x, y, bound, core.forward(), *this,
shortest_path_from_x, candidates[SUCCESSOR]);
shortest_path_from_x, candidates[OUT]);
algo.allShorterPaths(y, x, bound, core.backward(), backward(),
shortest_path_to_y, candidates[PREDECESSOR]);
shortest_path_to_y, candidates[IN]);
// cout << *this << endl;
//
// cout << "from " << x << ":";
// for (auto z : events)
// cout << " " << shortest_path_from_x[z]
// << (candidates[SUCCESSOR].has(z) ? "*" : "");
// << (candidates[OUT].has(z) ? "*" : "");
// cout << endl;
//
// cout << "to " << y << ":";
// for (auto z : events)
// cout << " " << shortest_path_to_y[z]
// << (candidates[PREDECESSOR].has(z) ? "*" : "");
// << (candidates[IN].has(z) ? "*" : "");
// cout << endl;
for (auto a : core) {
......@@ -601,7 +632,7 @@ template <class T> void DistanceMatrix<T>::transitive_commit(const lit l) {
if (dax == INFTY)
continue;
for (auto b : candidates[SUCCESSOR]) {
for (auto b : candidates[OUT]) {
auto dxb = shortest_path_from_x[b]; // get(x,b);
auto dab = get(a, b);
if (dax + dxb < dab) {
......@@ -619,7 +650,7 @@ template <class T> void DistanceMatrix<T>::transitive_commit(const lit l) {
if (dyb == INFTY)
continue;
for (auto a : candidates[PREDECESSOR]) {
for (auto a : candidates[IN]) {
auto day = shortest_path_to_y[a]; // get(x,b);
auto dab = get(a, b);
if (day + dyb < dab) {
......@@ -649,12 +680,8 @@ void DistanceMatrix<T>::push(const event x, const event y, const T d,
if (cycle_length != INFTY) {
cycle_length += d;
if (cycle_length < 0) {
cout << "FAILURE\n";
exit(0);
throw Failure();
} else if (cycle_length == 0) {
// cout << "mark " << x << " " << y << " as merged\n";
merge(x, y);
}
}
......@@ -695,7 +722,7 @@ void DistanceMatrix<T>::add(const event ei, const event ej, const T d,
// }
// addToCore(rei, rej);
if(core_edges.newArc(rei, rej))
if (core_edges.newArc(rei, rej))
core.addArc(rei, rej);
// core_edges.newArc(rei, rej);
......@@ -703,12 +730,13 @@ void DistanceMatrix<T>::add(const event ei, const event ej, const T d,
//
// cout << *this << endl;
//
// cout << rei << "/" << rej << " " << (*this)(rei, rej) << "=" << get(rei, rej)
// cout << rei << "/" << rej << " " << (*this)(rei, rej) << "=" << get(rei,
// rej)
// << " > " << d << " - " << di << " + " << dj << endl;
//
// assert(get(rei, rej) > d - di + dj);
if(get(rei, rej) > d - di + dj)
if (get(rei, rej) > d - di + dj)
push(rei, rej, d - di + dj, e);
}
......@@ -770,11 +798,8 @@ template <class T> void DistanceMatrix<T>::undoMerge() {
// for(auto e : core.vertices)
// assert(events.has(e));
int x{0};