Commit a2f208f9 authored by ehebrard's avatar ehebrard
Browse files

ok

parent 67f141ae
......@@ -96,8 +96,6 @@ template <typename T> struct Bound {
T value;
const Explanation<T> reason;
// const Explainer<T> *reason;
// const int hint;
};
......@@ -108,6 +106,7 @@ template <typename T> class DistanceVariable : public ReversibleObject {
public:
Schedule<T> &sched;
int id;
T offset{0};
event from;
event to;
......@@ -123,27 +122,45 @@ public:
intialise(x, y, INFTY);
}
DistanceVariable(DistanceVariable<T> *d, const event x, const event y,
const int i, const T o)
: sched(d->sched), id(i), from(x), to(y) {
// intialise(x, y, INFTY);
literals = d->literals;
offset = o;
}
~DistanceVariable() { delete literals; }
void intialise(const event x, const event y, const T d) {
from = x;
to = y;
// from = x;
// to = y;
// literals.push_back({d, Constant<T>::NoReason, NoHint});
literals.push_back({d, Constant<T>::NoReason});
literals = new vector<Bound<T>>();
literals->push_back({d, Constant<T>::NoReason});
// literals.push_back({d, Constant<T>::NoReason});
// trail.push_back(d);
// reason.push_back(Constant<T>::NoReason);
}
DistanceLiteral<T> current() {
return {this, static_cast<int>(literals.size()) - 1};
// return {this, static_cast<int>(literals.size()) - 1};
return {this, static_cast<int>(literals->size()) - 1};
}
// get the current distance
T get() const { return literals.back().value; }
operator T() const { return literals.back().value; }
// T get() const { return literals.back().value + offset; }
// operator T() const { return literals.back().value + offset; }
T get() const { return literals->back().value + offset; }
operator T() const { return literals->back().value + offset; }
const Bound<T> &back() const { return literals.back(); }
// const Bound<T> &back() const { return literals.back(); }
const Bound<T> &back() const { return literals->back(); }
const Bound<T> &get(const int l) const { return literals[l]; }
// const Bound<T> &get(const int l) const { return literals[l]; }
const Bound<T> &get(const int l) const { return (*literals)[l]; }
// set the new distance to 'd'
// void set(const T d, const Explanation<T> *e) {
......@@ -165,12 +182,14 @@ public:
void set(const T d,
const Explanation<T> e){
// const Explainer<T> *e, const int h) {
if (get() > d) {
ReversibleObject::save();
literals.push_back({d, e});
// trail.push_back(d);
// reason.push_back(e);
auto l{d - offset};
if (get() > l) {
ReversibleObject::save();
// literals.push_back({l, e});
literals->push_back({l, e});
// trail.push_back(d);
// reason.push_back(e);
}
}
......@@ -190,7 +209,8 @@ public:
void undo() override {
// trail.pop_back();
// reason.pop_back();
literals.pop_back();
// literals.pop_back();
literals->pop_back();
}
void clear() { from = -1; }
......@@ -241,7 +261,7 @@ public:
// stores the successive values, the explainer, and a hint used to index the
// literals on the explainer's side, or directly encode a hint to allow to
// reconstruct the reason
vector<Bound<T>> literals;
vector<Bound<T>> *literals;
// vector<T> trail;
//
......
This diff is collapsed.
......@@ -586,6 +586,8 @@ template <typename T> ostream &SparseGraph<T>::display(ostream &os) const {
for (auto ej : neighbor[SUCCESSOR][i]) {
if (ej.length() != INFTY)
os << " " << ej.neighbor() << ":" << ej.length();
else
os << " " << ej.neighbor();
}
os << endl;
}
......
......@@ -6,8 +6,6 @@
using namespace std;
// #define DEBUG_CONSTRAINT
// #define PB_DOMERGE
namespace schedcl {
......@@ -34,6 +32,8 @@ private:
vector<DistanceLiteral<T>> cur_explanation;
bool disjunctive{true};
int id(const int x, const int y) { return (x << (4 * sizeof(int))) + y; }
void get_id(const int h, int &x, int &y) {
......@@ -85,8 +85,6 @@ CumulativeTimeTabling<T, C>::CumulativeTimeTabling(Schedule<T> &schedule,
// ++c;
}
// assert(c == end_consumption);
vector<int> order(m_task_consumption.size(), 0);
for (auto i{0}; i < order.size(); ++i) {
order[i] = i;
......@@ -108,6 +106,15 @@ CumulativeTimeTabling<T, C>::CumulativeTimeTabling(Schedule<T> &schedule,
}
cout << endl;
auto s{m_tasks.size()};
if (s > 1) {
if (m_task_consumption[order[s - 1]] + m_task_consumption[order[s - 2]] <=
resource_capacity) {
disjunctive = false;
}
}
// disjunctive = false;
distance.resize(2 * m_tasks.size() + 2);
// explanation.resize(2 * m_tasks.size() + 2);
for (auto &v : distance) {
......@@ -130,24 +137,33 @@ CumulativeTimeTabling<T, C>::CumulativeTimeTabling(Schedule<T> &schedule,
distance[ORIGIN][START(i)] =
m_schedule.addMaximumLag(ORIGIN, START(m_tasks[i]), INFTY);
// // ORIGIN <= END(i)
// distance[END(i)][ORIGIN] =
// m_schedule.addPrecedence(ORIGIN, END(m_tasks[i]), -INFTY);
// ORIGIN <= END(i)
distance[END(i)][ORIGIN] =
m_schedule.addPrecedence(ORIGIN, END(m_tasks[i]), -INFTY);
m_schedule.addMaximumLag(END(m_tasks[i]), ORIGIN, INFTY);
// END(i) <= ORIGIN + oo
distance[ORIGIN][END(i)] =
m_schedule.addMaximumLag(ORIGIN, END(m_tasks[i]), INFTY);
// // END(i) <= HORIZON
// distance[HORIZON][END(i)] =
// m_schedule.addPrecedence(END(m_tasks[i]), HORIZON, -INFTY);
// END(i) <= HORIZON
distance[HORIZON][END(i)] =
m_schedule.addPrecedence(END(m_tasks[i]), HORIZON, -INFTY);
m_schedule.addMaximumLag(HORIZON, END(m_tasks[i]), INFTY);
// HORIZON <= END(i) + oo
distance[END(i)][HORIZON] =
m_schedule.addMaximumLag(END(m_tasks[i]), HORIZON, INFTY);
// // START(i) <= HORIZON
// distance[HORIZON][START(i)] =
// m_schedule.addPrecedence(START(m_tasks[i]), HORIZON, -INFTY);
// START(i) <= HORIZON
distance[HORIZON][START(i)] =
m_schedule.addPrecedence(START(m_tasks[i]), HORIZON, -INFTY);
// HORIZON <= START(i) + oo
m_schedule.addMaximumLag(HORIZON, START(m_tasks[i]), INFTY);
// HORIZON <= STARTaddMaximumLag + oo
distance[START(i)][HORIZON] =
m_schedule.addMaximumLag(START(m_tasks[i]), HORIZON, INFTY);
......@@ -197,9 +213,6 @@ CumulativeTimeTabling<T, C>::CumulativeTimeTabling(Schedule<T> &schedule,
distance[END(j)][START(i)] =
m_schedule.addMaximumLag(END(m_tasks[j]), START(m_tasks[i]), INFTY);
m_schedule.addChoicePoint(m_schedule.numVar() - 2,
m_schedule.numVar() - 1);
// END(i) <= START(j) + oo
distance[START(j)][END(i)] =
m_schedule.addMaximumLag(START(m_tasks[j]), END(m_tasks[i]), INFTY);
......@@ -207,8 +220,17 @@ CumulativeTimeTabling<T, C>::CumulativeTimeTabling(Schedule<T> &schedule,
distance[END(i)][START(j)] =
m_schedule.addMaximumLag(END(m_tasks[i]), START(m_tasks[j]), INFTY);
m_schedule.addChoicePoint(m_schedule.numVar() - 2,
m_schedule.numVar() - 1);
if (disjunctive) {
m_schedule.addChoicePoint(distance[START(i)][END(j)]->id,
distance[START(j)][END(i)]->id);
} else {
assert(false);
m_schedule.addChoicePoint(distance[START(i)][END(j)]->id,
distance[END(j)][START(i)]->id);
m_schedule.addChoicePoint(distance[START(j)][END(i)]->id,
distance[END(i)][START(j)]->id);
}
}
// cout << m_schedule << endl;
......@@ -239,31 +261,14 @@ void CumulativeTimeTabling<T, C>::post(const int idx) {
m_schedule.wake_me_on(distance[j][i], idx, j*distance.size()+i);
}
}
// m_schedule.wake_me_on(m_tasks.begin(), m_tasks.end(), idx);
// for(int i{0}; i<distance.size(); ++i) {
// for(int j{0}; j<distance.size(); ++j) if(i!=j) {
// if(distance[i][j] == NULL) {
// cout << m_schedule.label(i) << "/" <<
// m_schedule.label(j)
// <<
// endl;
// exit(1);
// }
// }
// }
//
// for(auto task : m_task) {
// variable[id][0] = m_schedule.addPrecedence(ORIGIN, START(i));
// variable[1][id+1] = m_schedule.addPrecedence(END(i), HORIZON);
// id += 2;
// }
// m_schedule.post(this, m_tasks.begin(), m_tasks.end());
//
// m_schedule.wake_me_on(ORIGIN, idx, 0);
// m_schedule.wake_me_on(CMAX, idx, 1);
// int h{2};
// for (auto j : m_tasks) {
// m_schedule.wake_me_on(START(j), idx, h++);
// m_schedule.wake_me_on(END(j), idx, h++);
// }
}
template <class T, class C>
......
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