Commit 35012861 authored by ehebrard's avatar ehebrard
Browse files

ok

parent 9c902e0d
......@@ -34,7 +34,8 @@ int main(int argc, char *argv[]) {
vector<int> duration;
vector<vector<int>> resource;
osp::read_instance("j3-per0-1.txt", duration, resource);
osp::read_instance((argc > 1 ? argv[1] : "j3-per0-1.txt"), duration,
resource);
cout << duration.size() << " tasks:";
for (auto d : duration) {
......@@ -77,51 +78,51 @@ int main(int argc, char *argv[]) {
// S2.addEdge(END(x), END(y));
// }
// }
con->debug_flag = true;
// #ifdef DEBUG_CONSTRAINT
// con->debug_flag = true;
// #endif
}
auto ub{osp::getUb(duration, resource)};
// S.setUpperBound(ub);
S.setUpperBound(1250);
// S.setUpperBound(1126);
// vector<task> scope;
// vector<int> demand;
// for (auto &job : resource) {
// demand.resize(job.size(), 1);
// for (auto j : job)
// scope.push_back(j);
// vector<task> scope;
// vector<int> demand;
// for (auto &job : resource) {
// demand.resize(job.size(), 1);
// for (auto j : job)
// scope.push_back(j);
// SparseDistanceGraph<int> SG(S);
// SparseDistanceGraph<int> SG(S);
// cout << SG << endl;
// cout << SG << endl;
// DistanceGraph<int> G(S2);
// DistanceGraph<int> G(S2);
// cout << G << endl;
// cout << G << endl;
// G.FloydWarshall();
// G.FloydWarshall();
// cout << G << endl;
// cout << G << endl;
// BellmanFord<int> BF(SG.size());
// BellmanFord<int> BF(SG.size());
// vector<int> shortest_path(S.numEvent(), numeric_limits<int>::max());
//
// BF.allShortestPaths(ORIGIN, SG.successor, shortest_path);
// vector<int> shortest_path(S.numEvent(), numeric_limits<int>::max());
//
// BF.allShortestPaths(ORIGIN, SG.successor, shortest_path);
// for(auto v{0}; v<S.numEvent(); ++v)
// cout << S.label(v) << ": " << shortest_path[v] << endl;
// for(auto v{0}; v<S.numEvent(); ++v)
// cout << S.label(v) << ": " << shortest_path[v] << endl;
S.initialise();
S.initialise();
cout << S << endl;
// S.updateDistances();
//
// cout << S << endl;
S.search();
cout << S << endl;
// S.updateDistances();
//
// cout << S << endl;
S.search();
}
......@@ -6,27 +6,41 @@ using namespace schedcl;
BacktrackEnvironment* ReversibleObject::env = new BacktrackEnvironment();
BacktrackEnvironment::BacktrackEnvironment() {}
BacktrackEnvironment::BacktrackEnvironment() { stamps.push_back(0); }
BacktrackEnvironment::~BacktrackEnvironment() {}
int BacktrackEnvironment::level() const {
return static_cast<int>(stamps.size());
return static_cast<int>(stamps.size()) - 1;
}
void BacktrackEnvironment::save(ReversibleObject *o) { trail.push_back(o); }
void BacktrackEnvironment::save() { stamps.push_back(trail.size()); }
void BacktrackEnvironment::override() { *(stamps.rbegin()) = trail.size(); }
void BacktrackEnvironment::save() {
// assert(stamps.size() > 0);
*(stamps.rbegin()) = trail.size();
stamps.push_back(trail.size());
// cout << "save\n";
// print();
}
// void BacktrackEnvironment::override() { *(stamps.rbegin()) = trail.size(); }
void BacktrackEnvironment::restore(const int lvl) {
assert(level() >= lvl);
size_t stamp = (lvl == 0 ? 0 : stamps[lvl - 1]);
// print();
// cout << "restore to "<< lvl << "\n";
// assert(level() >= lvl);
// assert(lvl >= 0);
cout << "stamp: " << stamp << " size: " << trail.size() << endl;
// size_t stamp = (lvl == 0 ? 0 : stamps[lvl - 1]);
size_t stamp = stamps[lvl];
// cout << "stamp: " << stamp << " size: " << trail.size() << endl;
while (trail.size() > stamp) {
trail.back()->undo();
trail.pop_back();
}
stamps.resize(lvl);
stamps.resize(lvl + 1);
// while(level() > lvl) {
// size_t stamp = stamps.back();
......@@ -36,6 +50,19 @@ void BacktrackEnvironment::restore(const int lvl) {
// trail.pop_back();
// }
// }
// print();
}
void BacktrackEnvironment::print() const {
cout << "levels:";
for (auto i{0}; i < level(); ++i)
cout << setw(5) << i;
cout << " cur" << endl;
cout << "stamps:";
for (auto s : stamps)
cout << setw(5) << s;
cout << " | " << trail.size() << endl;
}
ReversibleObject::ReversibleObject() {}
......
......@@ -3,14 +3,15 @@
#include "DistanceGraph.hpp"
#define DEBUG_CONSTRAINT
namespace schedcl {
class Constraint {
public:
#ifdef DEBUG_CONSTRAINT
bool debug_flag{false};
#endif
virtual void propagate() = 0;
// virtual bool trigger(const edge_idx newedge) { return true; }
......@@ -22,6 +23,7 @@ public:
os << "a scheduling constraint";
return os;
}
};
} // namespace
......
......@@ -18,6 +18,11 @@ class Failure: public std::exception
}
};
class SearchExhausted : public std::exception {
virtual const char *what() const throw() {
return "Complete search tree exhausted";
}
};
}
#endif // __FAILURE_HPP
......@@ -28,11 +28,16 @@ public:
void override();
void restore(const int lvl);
void restore();
void print() const;
protected:
vector< ReversibleObject* > trail;
vector< size_t > stamps;
// list of ptrs to reversible objects to call their "undo()"
vector<ReversibleObject *> trail;
// stamps[l] is the size of the trail at level l, that is, after l calls to
// "save()"
vector<size_t> stamps;
};
......
This diff is collapsed.
#include <map>
#include <vector>
#include "Constraint.hpp"
// #include "Constraint.hpp"
#include "Schedule.hpp"
using namespace std;
#define DEBUG_CONSTRAINT
//#define PB_DOMERGE
// #define DEBUG_CONSTRAINT
// #define PB_DOMERGE
namespace schedcl {
......@@ -59,10 +59,6 @@ public:
void post(const int idx) override;
void propagate() override;
#ifdef DEBUG_CONSTRAINT
bool debug_flag{false};
#endif
ostream &display(ostream &os) const override;
};
......@@ -228,7 +224,7 @@ template <class T, class C>
void CumulativeTimeTabling<T, C>::post(const int idx) {
#ifdef DEBUG_CONSTRAINT
if (this->debug_flag) {
if (this->ResourceConstraint<T>::debug_flag) {
cout << endl << "post timetabling(";
for (auto t : m_tasks) {
cout << " " << m_schedule.taskLabel(t) << " " << m_schedule.domain(t);
......@@ -275,7 +271,7 @@ template <class T, class C>
void CumulativeTimeTabling<T, C>::propagate() {
#ifdef DEBUG_CONSTRAINT
if (this->debug_flag) {
if (this->ResourceConstraint<T>::debug_flag) {
cout << endl << "propagate timetabling(";
for (auto t : m_tasks) {
cout << " " << m_schedule.taskLabel(t) << " " << m_schedule.domain(t);
......@@ -326,7 +322,7 @@ void CumulativeTimeTabling<T, C>::propagate() {
cur_explanation.clear();
#ifdef DEBUG_CONSTRAINT
if (this->debug_flag) {
if (this->ResourceConstraint<T>::debug_flag) {
cout << endl
<< "check event " << m_schedule.label(get_event(e)) << " "
<< offset_before_event << ".." << offset_after_event << endl;
......@@ -343,7 +339,7 @@ void CumulativeTimeTabling<T, C>::propagate() {
height += m_task_consumption[i];
#ifdef DEBUG_CONSTRAINT
if (this->debug_flag) {
if (this->ResourceConstraint<T>::debug_flag) {
cout << " - happens during " << m_schedule.taskLabel(m_tasks[i])
<< " (" << height << ")" << endl;
}
......@@ -355,7 +351,7 @@ void CumulativeTimeTabling<T, C>::propagate() {
min(offset_before_event, -get_distance(e, START(i)));
#ifdef DEBUG_CONSTRAINT
if (this->debug_flag) {
if (this->ResourceConstraint<T>::debug_flag) {
cout << " - happens during " << m_schedule.taskLabel(m_tasks[i])
<< " (" << height << "): " << offset_before_event << ".."
<< offset_after_event << endl;
......@@ -371,7 +367,7 @@ void CumulativeTimeTabling<T, C>::propagate() {
distance[END(i)][e]->current()); // could use a tighter literal
if (height > m_resource_capacity) {
#ifdef DEBUG_CONSTRAINT
if (this->debug_flag) {
if (this->ResourceConstraint<T>::debug_flag) {
std::cout << "Time tabling: failure" << std::endl << " Tasks: ";
for (auto ex : cur_explanation)
cout << " " << ex;
......@@ -385,7 +381,7 @@ void CumulativeTimeTabling<T, C>::propagate() {
}
} else {
#ifdef DEBUG_CONSTRAINT
if (this->debug_flag) {
if (this->ResourceConstraint<T>::debug_flag) {
cout << " - cannot be before " << m_schedule.taskLabel(m_tasks[i])
<< endl;
}
......@@ -397,7 +393,7 @@ void CumulativeTimeTabling<T, C>::propagate() {
tasks_that_end_after.push_back(i);
#ifdef DEBUG_CONSTRAINT
if (this->debug_flag) {
if (this->ResourceConstraint<T>::debug_flag) {
cout << " - cannot be after " << m_schedule.taskLabel(m_tasks[i])
<< endl;
}
......@@ -405,7 +401,7 @@ void CumulativeTimeTabling<T, C>::propagate() {
}
// #ifdef DEBUG_CONSTRAINT
// if (this->debug_flag) {
// if (this->ResourceConstraint<T>::debug_flag) {
// cout << "base explanation*:";
// for (auto ex : cur_explanation) {
// cout << " " << ex;
......@@ -422,7 +418,7 @@ void CumulativeTimeTabling<T, C>::propagate() {
if (m_task_consumption[i] + height > m_resource_capacity) {
#ifdef DEBUG_CONSTRAINT
if (this->debug_flag) {
if (this->ResourceConstraint<T>::debug_flag) {
std::cout << "Time tabling: " << m_schedule.taskLabel(m_tasks[i])
<< " starts before event " << m_schedule.label(e)
<< " with offet " << offset << " and will be filtered "
......@@ -440,7 +436,7 @@ void CumulativeTimeTabling<T, C>::propagate() {
// m_schedule.getGraph()->addEdgeAndExplain(pru, explanation);
#ifdef DEBUG_CONSTRAINT
if (this->debug_flag) {
if (this->ResourceConstraint<T>::debug_flag) {
cout << " update edge " << *distance[e][END(i)] << " -> "
<< -offset_before_event << endl;
cout << " explanation";
......@@ -459,7 +455,7 @@ void CumulativeTimeTabling<T, C>::propagate() {
if (m_task_consumption[i] + height > m_resource_capacity) {
#ifdef DEBUG_CONSTRAINT
if (this->debug_flag) {
if (this->ResourceConstraint<T>::debug_flag) {
std::cout << "Time tabling: " << m_schedule.taskLabel(m_tasks[i])
<< " ends after event " << m_schedule.label(e)
<< " with offset " << offset << " and will be filtered "
......@@ -482,7 +478,7 @@ void CumulativeTimeTabling<T, C>::propagate() {
// m_schedule.getGraph()->addEdgeAndExplain(pru, explanation);
#ifdef DEBUG_CONSTRAINT
if (this->debug_flag) {
if (this->ResourceConstraint<T>::debug_flag) {
cout << " update edge " << *distance[START(i)][e] << " -> "
<< -offset_after_event << endl;
cout << " explanation";
......@@ -522,7 +518,11 @@ void CumulativeTimeTabling<T, C>::propagate() {
template <class T, class C>
ostream &CumulativeTimeTabling<T, C>::display(ostream &os) const {
os << "TimeTabling";
os << "TimeTabling(";
for (auto t : m_tasks) {
cout << " " << m_schedule.taskLabel(t) ;
}
cout << " )\n";
return os;
}
......
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