fix scheduling examples by adding the default key index ordering in Scheduler.
parent
00f109e88f
commit
a5f1d68099
|
|
@ -94,7 +94,8 @@ Potentials::ADT DiscreteConditional::choose(const Values& parentsValues) const {
|
||||||
pFS = pFS.choose(j, value);
|
pFS = pFS.choose(j, value);
|
||||||
} catch (exception&) {
|
} catch (exception&) {
|
||||||
cout << "Key: " << j << " Value: " << value << endl;
|
cout << "Key: " << j << " Value: " << value << endl;
|
||||||
pFS.print("pFS: ");
|
parentsValues.print("parentsValues: ");
|
||||||
|
// pFS.print("pFS: ");
|
||||||
throw runtime_error("DiscreteConditional::choose: parent value missing");
|
throw runtime_error("DiscreteConditional::choose: parent value missing");
|
||||||
};
|
};
|
||||||
return pFS;
|
return pFS;
|
||||||
|
|
|
||||||
|
|
@ -257,7 +257,12 @@ namespace gtsam {
|
||||||
/** Eliminate, return a Bayes net */
|
/** Eliminate, return a Bayes net */
|
||||||
DiscreteBayesNet::shared_ptr Scheduler::eliminate() const {
|
DiscreteBayesNet::shared_ptr Scheduler::eliminate() const {
|
||||||
gttic(my_eliminate);
|
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);
|
gttoc(my_eliminate);
|
||||||
return chordal;
|
return chordal;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,17 @@ void addStudent(Scheduler& s, size_t i) {
|
||||||
}
|
}
|
||||||
/* ************************************************************************* */
|
/* ************************************************************************* */
|
||||||
Scheduler largeExample(size_t nrStudents = 7) {
|
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/");
|
string path("../../../gtsam_unstable/discrete/examples/");
|
||||||
Scheduler s(nrStudents, path + "Doodle.csv");
|
Scheduler s(nrStudents, path + "Doodle.csv");
|
||||||
|
|
||||||
|
|
@ -156,7 +167,9 @@ void solveStaged(size_t addMutex = 2) {
|
||||||
gttoc_(eliminate);
|
gttoc_(eliminate);
|
||||||
|
|
||||||
// find root node
|
// 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)
|
if (debug)
|
||||||
root->print(""/*scheduler.studentName(s)*/);
|
root->print(""/*scheduler.studentName(s)*/);
|
||||||
|
|
||||||
|
|
@ -309,7 +322,7 @@ void accomodateStudent() {
|
||||||
DiscreteBayesNet::shared_ptr chordal = scheduler.eliminate();
|
DiscreteBayesNet::shared_ptr chordal = scheduler.eliminate();
|
||||||
|
|
||||||
// find root node
|
// find root node
|
||||||
DiscreteConditional::shared_ptr root = *(chordal->end()-1);
|
DiscreteConditional::shared_ptr root = chordal->back();
|
||||||
if (debug)
|
if (debug)
|
||||||
root->print(""/*scheduler.studentName(s)*/);
|
root->print(""/*scheduler.studentName(s)*/);
|
||||||
// GTSAM_PRINT(*chordal);
|
// GTSAM_PRINT(*chordal);
|
||||||
|
|
@ -321,6 +334,8 @@ void accomodateStudent() {
|
||||||
// get corresponding count
|
// get corresponding count
|
||||||
DiscreteKey dkey = scheduler.studentKey(0);
|
DiscreteKey dkey = scheduler.studentKey(0);
|
||||||
values[dkey.first] = bestSlot;
|
values[dkey.first] = bestSlot;
|
||||||
|
values.print("Values: ");
|
||||||
|
root->print("Root: ");
|
||||||
size_t count = (*root)(values);
|
size_t count = (*root)(values);
|
||||||
cout << boost::format("%s = %d (%d), count = %d") % scheduler.studentName(0)
|
cout << boost::format("%s = %d (%d), count = %d") % scheduler.studentName(0)
|
||||||
% scheduler.slotName(bestSlot) % bestSlot % count << endl;
|
% scheduler.slotName(bestSlot) % bestSlot % count << endl;
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,10 @@ void solveStaged(size_t addMutex = 2) {
|
||||||
gttoc_(eliminate);
|
gttoc_(eliminate);
|
||||||
|
|
||||||
// find root node
|
// 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)
|
if (debug)
|
||||||
root->print(""/*scheduler.studentName(s)*/);
|
root->print(""/*scheduler.studentName(s)*/);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -208,7 +208,7 @@ void solveStaged(size_t addMutex = 2) {
|
||||||
gttoc_(eliminate);
|
gttoc_(eliminate);
|
||||||
|
|
||||||
// find root node
|
// find root node
|
||||||
DiscreteConditional::shared_ptr root = *(chordal->end()-1);
|
DiscreteConditional::shared_ptr root = chordal->back();
|
||||||
if (debug)
|
if (debug)
|
||||||
root->print(""/*scheduler.studentName(s)*/);
|
root->print(""/*scheduler.studentName(s)*/);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue