Commit 7e452765 authored by ehebrard's avatar ehebrard
Browse files

hmmm

parent 47873d28
......@@ -42,10 +42,13 @@ public:
size_t size() const;
size_t numVar() const;
size_t numCon() const;
//
// int var(const int i) const;
ostream &display(ostream &os) const;
bool has(const int u) const;
//
// int var(const int i) const;
ostream &display(ostream &os) const;
};
......@@ -62,10 +65,9 @@ const vector<int> &ConstraintGraph<T>::operator[](const int var_id) const {
// return network[PREDECESSOR][cons_id];
// }
// template<typename T>
// int ConstraintGraph<T>::var(const int i) const {
// return i + numCon();
// }
template <typename T> bool ConstraintGraph<T>::has(const int u) const {
return network.has(u);
}
template<typename T>
size_t ConstraintGraph<T>::size() const {
......@@ -98,7 +100,7 @@ void ConstraintGraph<T>::add(ResourceConstraint<T> *cons) {
template <typename T>
void ConstraintGraph<T>::createTrigger(const var v, const int c) {
network.addArc(v + numCon(), c);
network.addArc(v, c);
}
template <typename T> void ConstraintGraph<T>::merge(const int x, const int y) {
......
......@@ -167,7 +167,10 @@ private:
int init_level{0};
ConstraintGraph<T> network;
vector<ResourceConstraint<T> *> constraints;
// ConstraintGraph<T> network;
Graph constraint_network;
ConstraintQueue<T, 1> queue;
void updateNetwork(vector<event>::const_iterator first);
......@@ -233,11 +236,11 @@ template <typename T> int Scheduler<T>::getUB() const {
}
template <typename T> size_t Scheduler<T>::numVar() const {
return network.numVar();
return constraint_network.size() - numCon();
}
template <typename T> size_t Scheduler<T>::numCon() const {
return network.numCon();
return constraints.size();
}
template <typename T> size_t Scheduler<T>::numTask() const {
......@@ -254,33 +257,35 @@ template <typename T> var Scheduler<T>::getVariable(event x, event y) const {
template <typename T> void Scheduler<T>::declareVariable(event x, event y) {
if (getVariable(x, y) == NoVar) {
varmap[x][y] = network.addVar();
varmap[x][y] = constraint_network.size();
constraint_network.resize(constraint_network.size() + 1);
}
}
template <typename T> void Scheduler<T>::post(ResourceConstraint<T> *c) {
#ifdef DEBUG_CONSTRAINT
c->id = network.numCon();
c->id = numCon();
c->debug_flag = true;
#endif
network.add(c);
// network.add(c);
constraints.push_back(c);
}
template <typename T>
void Scheduler<T>::wake_me_on(const event x, const event y, const int c,
const bool choicepoint) {
cout << "wake " << c << " on "<< x << "/" << y << " (" << choicepoint <<
")" << endl;
// cout << "wake " << c << " on "<< x << "/" << y << " (" << choicepoint <<
// ")" << endl;
auto rx{distance.getRepresentant(x)};
auto ry{distance.getRepresentant(y)};
if (getVariable(rx, ry) == NoVar) {
cout << "declare var " << rx << "/" << ry << " (" << choicepoint <<
")" << endl;
// cout << "declare var " << rx << "/" << ry << " (" << choicepoint <<
// ")" << endl;
declareVariable(rx, ry);
// this is a variable that a constraint wants in its watch list
......@@ -291,11 +296,15 @@ void Scheduler<T>::wake_me_on(const event x, const event y, const int c,
choicepoints.push_back({rx, ry, 0});
}
}
cout << "create triggers" << endl ;
if (network[varmap[rx][ry]].empty() or network[varmap[rx][ry]].back() != c)
network.createTrigger(varmap[rx][ry], c);
// cout << "create triggers" << endl ;
// if (network[varmap[rx][ry]].empty() or network[varmap[rx][ry]].back() != c)
// network.createTrigger(varmap[rx][ry], c);
if (constraint_network[varmap[rx][ry]].empty() or
constraint_network[varmap[rx][ry]].back() != c)
constraint_network.addArc(varmap[rx][ry], c);
}
template <typename T>
......@@ -543,20 +552,21 @@ template <typename T> void Scheduler<T>::initialize() {
// cout << "varmap: " << varmap.size() << "\n";
for (auto i{0}; i < network.numCon(); ++i) {
constraint_network.resize(numCon());
cout << "post " << *(network.constraints[i]) << endl;
for (auto i{0}; i < numCon(); ++i) {
network.constraints[i]->post(i);
// cout << "post " << *(constraints[i]) << endl;
constraints[i]->post(i);
}
cout << network.numVar() << " variables, " << network.numCon()
<< " constraints\n";
cout << numVar() << " variables, " << numCon() << " constraints\n";
queue.initialize(&network.constraints);
queue.initialize(&constraints);
for (auto v{0}; v < network.numVar(); ++v) {
for (auto c : network[v]) {
for (auto v{0}; v < numVar(); ++v) {
for (auto c : constraint_network[v + numCon()]) {
queue.triggers(v, c);
}
}
......@@ -566,12 +576,6 @@ template <typename T> void Scheduler<T>::initialize() {
// initialisation
sequence.reserve(choicepoints.size());
sequence.fill();
cout << endl << "INIT:\n";
displayNetwork(cout);
cout << endl;
}
template <typename T> void Scheduler<T>::search() {
......@@ -745,13 +749,13 @@ template <typename T> void Scheduler<T>::backtrack() {
template <typename T>
void Scheduler<T>::updateNetwork(vector<event>::const_iterator first) {
if(first != distance.firstActive()) {
cout << endl;
displayNetwork(cout);
cout << endl;
}
// if(first != distance.firstActive()) {
// cout << endl;
// displayNetwork(cout);
// cout << endl;
// }
for (auto merged{first}; merged != distance.firstActive(); ++merged) {
auto merged_event{*merged};
auto rep_event{distance.getRepresentant(merged_event)};
......@@ -769,27 +773,19 @@ void Scheduler<T>::updateNetwork(vector<event>::const_iterator first) {
auto rep_other{distance.getRepresentant(other_event)};
auto the_rep{getVariable(rep_event, rep_other)};
#ifdef DEBUG_MERGE
if (rep_event != rep_other) {
#ifdef DEBUG_MERGE
cout << " -> merge (" << label(merged_event) << ","
<< label(other_event) << ") to (" << label(rep_event) << ","
<< label(rep_other) << ")";
#endif
if (the_rep == NoVar) {
cout << " NOT A VAR!";
assert(false);
declareVariable(rep_event, rep_other);
}
}
#endif
if (rep_event != rep_other) {
cout << endl;
displayNetwork(cout);
cout << endl;
network.merge(the_rep, to_merge);
cout << " -->" << endl;
displayNetwork(cout);
cout << endl;
}
constraint_network.merge(the_rep, to_merge);
}
}
to_merge = getVariable(other_event, merged_event);
......@@ -798,28 +794,18 @@ void Scheduler<T>::updateNetwork(vector<event>::const_iterator first) {
auto rep_other{distance.getRepresentant(other_event)};
auto the_rep{getVariable(rep_other, rep_event)};
#ifdef DEBUG_MERGE
if (rep_event != rep_other) {
cout << " -> merge (" << label(other_event) << ","
<< label(merged_event) << ") to (" << label(rep_other) << ","
<< label(rep_event) << ")";
if (the_rep == NoVar) {
cout << " NOT A VAR!";
assert(false);
declareVariable(rep_other, rep_event);
}
}
#endif
if (rep_event != rep_other) {
cout << endl;
displayNetwork(cout);
cout << endl;
network.merge(the_rep, to_merge);
cout << " -->" << endl;
displayNetwork(cout);
cout << endl;
}
constraint_network.merge(the_rep, to_merge);
}
}
}
#ifdef DEBUG_MERGE
......@@ -871,13 +857,12 @@ template <typename T> void Scheduler<T>::propagate() {
auto varxy{varmap[x][y]};
if (varxy != NoVar)
for (auto cons_id : network[varxy]) {
for (auto cons_id : constraint_network[varxy]) {
#ifdef TRACE
if (DEBUG_FLAG and (TRACE & PROPAGATION)) {
if (not queue.has(cons_id))
cout << " - triggers " << *(network.constraints[cons_id])
<< endl;
cout << " - triggers " << *(constraints[cons_id]) << endl;
}
#endif
......@@ -1437,16 +1422,23 @@ Scheduler<T>::displayChoicePoint(ostream &os,
template <typename T> ostream &Scheduler<T>::displayNetwork(ostream &os) const {
// cout << "varmap[0][2]: " << varmap[0][2] << endl;
// cout << distance.isActive(2) << endl;
// if(network.size() > 10)
// cout << network.has(10) << endl;
for (auto i{0}; i < numEvent(); ++i) {
if (distance.isActive(i)) {
for (auto j{0}; j < numEvent(); ++j) {
if (distance.isActive(j)) {
auto xij{varmap[i][j]};
if (xij != NoVar) {
os << xij << " ("<< label(i) << "," << label(j) << "):";
for (auto c : network[xij])
os << " " << *(network.constraints[c]);
// os << " c" << c;
assert(constraint_network.has(xij));
os << xij << " (" << label(i) << "," << label(j) << "):";
for (auto c : constraint_network[xij])
os << " " << *(constraints[c]);
// os << " c" << c;
os << endl;
}
}
......@@ -1454,7 +1446,7 @@ template <typename T> ostream &Scheduler<T>::displayNetwork(ostream &os) const {
}
}
return os;
return os;
}
template <typename T> ostream &Scheduler<T>::display(ostream &os) const {
......
......@@ -152,24 +152,14 @@ void CumulativeTimeTabling<T, C>::post(const int idx) {
cout << "post " << *this << endl;
}
#endif
cout << "post " << *this << endl;
// int k{0};
// to be called when the ub changes
m_schedule.wake_me_on(ORIGIN, HORIZON, idx);
for (int i{0}; i < m_tasks.size(); ++i) {
cout << i << endl;
cout << m_tasks[i] << endl;
cout << START(m_tasks[i]) << endl;
m_schedule.wake_me_on(START(m_tasks[i]), ORIGIN, idx);
cout << 11 << endl;
m_schedule.wake_me_on(ORIGIN, START(m_tasks[i]), idx);
cout << 22 << endl;
m_schedule.wake_me_on(END(m_tasks[i]), ORIGIN, idx);
m_schedule.wake_me_on(ORIGIN, END(m_tasks[i]), idx);
......
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