fix scheduling examples by adding the default key index ordering in Scheduler.

release/4.3a0
Duy-Nguyen Ta 2013-10-11 21:55:31 +00:00
parent 00f109e88f
commit a5f1d68099
5 changed files with 30 additions and 6 deletions

View File

@ -94,7 +94,8 @@ Potentials::ADT DiscreteConditional::choose(const Values& parentsValues) const {
pFS = pFS.choose(j, value);
} catch (exception&) {
cout << "Key: " << j << " Value: " << value << endl;
pFS.print("pFS: ");
parentsValues.print("parentsValues: ");
// pFS.print("pFS: ");
throw runtime_error("DiscreteConditional::choose: parent value missing");
};
return pFS;

View File

@ -257,7 +257,12 @@ namespace gtsam {
/** Eliminate, return a Bayes net */
DiscreteBayesNet::shared_ptr Scheduler::eliminate() const {
gttic(my_eliminate);
DiscreteBayesNet::shared_ptr chordal = this->eliminateSequential();
// TODO: fix this!!
size_t maxKey = keys().size();
Ordering defaultKeyOrdering;
for (size_t i = 0; i<maxKey; ++i)
defaultKeyOrdering += Key(i);
DiscreteBayesNet::shared_ptr chordal = this->eliminateSequential(defaultKeyOrdering);
gttoc(my_eliminate);
return chordal;
}

View File

@ -53,6 +53,17 @@ void addStudent(Scheduler& s, size_t i) {
}
/* ************************************************************************* */
Scheduler largeExample(size_t nrStudents = 7) {
char cCurrentPath[FILENAME_MAX];
if (!getcwd(cCurrentPath, sizeof(cCurrentPath)))
{
return errno;
}
cCurrentPath[sizeof(cCurrentPath) - 1] = '\0'; /* not really required */
printf ("The current working directory is %s", cCurrentPath);
string path("../../../gtsam_unstable/discrete/examples/");
Scheduler s(nrStudents, path + "Doodle.csv");
@ -156,7 +167,9 @@ void solveStaged(size_t addMutex = 2) {
gttoc_(eliminate);
// find root node
DiscreteConditional::shared_ptr root = *(chordal->end()-1);
chordal->back()->print("back: ");
chordal->front()->print("front: ");
DiscreteConditional::shared_ptr root = chordal->back();
if (debug)
root->print(""/*scheduler.studentName(s)*/);
@ -309,7 +322,7 @@ void accomodateStudent() {
DiscreteBayesNet::shared_ptr chordal = scheduler.eliminate();
// find root node
DiscreteConditional::shared_ptr root = *(chordal->end()-1);
DiscreteConditional::shared_ptr root = chordal->back();
if (debug)
root->print(""/*scheduler.studentName(s)*/);
// GTSAM_PRINT(*chordal);
@ -321,6 +334,8 @@ void accomodateStudent() {
// get corresponding count
DiscreteKey dkey = scheduler.studentKey(0);
values[dkey.first] = bestSlot;
values.print("Values: ");
root->print("Root: ");
size_t count = (*root)(values);
cout << boost::format("%s = %d (%d), count = %d") % scheduler.studentName(0)
% scheduler.slotName(bestSlot) % bestSlot % count << endl;

View File

@ -183,7 +183,10 @@ void solveStaged(size_t addMutex = 2) {
gttoc_(eliminate);
// find root node
DiscreteConditional::shared_ptr root = *(chordal->end()-1);
// chordal->back()->print("back: ");
// chordal->front()->print("front: ");
// exit(0);
DiscreteConditional::shared_ptr root = chordal->back();
if (debug)
root->print(""/*scheduler.studentName(s)*/);

View File

@ -208,7 +208,7 @@ void solveStaged(size_t addMutex = 2) {
gttoc_(eliminate);
// find root node
DiscreteConditional::shared_ptr root = *(chordal->end()-1);
DiscreteConditional::shared_ptr root = chordal->back();
if (debug)
root->print(""/*scheduler.studentName(s)*/);