The main recursion function.
332 if (
DG1__->isTerminalNode(currentSituation.DG1Node())
333 &&
DG2__->isTerminalNode(currentSituation.DG2Node())) {
337 GUM_SCALAR tempVal =
combine__(
DG1__->nodeValue(currentSituation.DG1Node()),
338 DG2__->nodeValue(currentSituation.DG2Node()));
342 return rd__->manager()->addTerminalNode(newVal);
350 short int* dg1NeededVar
354 Idx dg1CurrentVarPos =
DG1__->isTerminalNode(currentSituation.DG1Node())
356 :
rd__->variablesSequence().pos(
357 DG1__->node(currentSituation.DG1Node())->nodeVar());
358 short int* dg2NeededVar
362 Idx dg2CurrentVarPos =
DG2__->isTerminalNode(currentSituation.DG2Node())
364 :
rd__->variablesSequence().pos(
365 DG2__->node(currentSituation.DG2Node())->nodeVar());
367 short int* instNeeded
371 instNeeded[i] = dg1NeededVar[i] + dg2NeededVar[i];
374 double curSitKey = currentSituation.key(instNeeded);
377 DEALLOCATE(instNeeded,
sizeof(
short int) * nbVar__);
384 NodeId origDG1 = currentSituation.DG1Node(),
385 origDG2 = currentSituation.DG2Node();
387 const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy >* leaddg
390 Idx leadVarPos =
rd__->variablesSequence().size();
391 typedef void (O4DGContext::*SetNodeFunction)(
const NodeId&);
392 SetNodeFunction leadFunction =
nullptr;
394 bool sameVar =
false;
396 if (!
DG1__->isTerminalNode(currentSituation.DG1Node())) {
397 if (currentSituation.varModality(dg1CurrentVarPos) != 0) {
400 currentSituation.setDG1Node(
401 DG1__->node(currentSituation.DG1Node())
402 ->son(currentSituation.varModality(dg1CurrentVarPos) - 1));
404 newNode =
compute__(currentSituation, lastInstVarPos);
406 currentSituation.setDG1Node(origDG1);
407 currentSituation.setDG2Node(origDG2);
409 DEALLOCATE(instNeeded,
sizeof(
short int) * nbVar__);
415 leadNodeId = currentSituation.DG1Node();
416 leadVarPos = dg1CurrentVarPos;
420 if (!
DG2__->isTerminalNode(currentSituation.DG2Node())) {
421 if (currentSituation.varModality(dg2CurrentVarPos) != 0) {
424 currentSituation.setDG2Node(
425 DG2__->node(currentSituation.DG2Node())
426 ->son(currentSituation.varModality(dg2CurrentVarPos) - 1));
428 newNode =
compute__(currentSituation, lastInstVarPos);
430 currentSituation.setDG1Node(origDG1);
431 currentSituation.setDG2Node(origDG2);
433 DEALLOCATE(instNeeded,
sizeof(
short int) * nbVar__);
438 if (leadVarPos == dg2CurrentVarPos) { sameVar =
true; }
440 if (leadVarPos > dg2CurrentVarPos) {
442 leadNodeId = currentSituation.DG2Node();
443 leadVarPos = dg2CurrentVarPos;
453 for (
Idx varPos = lastInstVarPos + 1; varPos < leadVarPos; ++varPos) {
454 if (instNeeded[varPos]) {
455 const DiscreteVariable* curVar =
rd__->variablesSequence().atPos(varPos);
459 for (
Idx modality = 0; modality < curVar->domainSize(); modality++) {
460 currentSituation.chgVarModality(varPos, modality + 1);
462 sonsIds[modality] =
compute__(currentSituation, varPos);
465 newNode =
rd__->manager()->addInternalNode(curVar, sonsIds);
468 currentSituation.chgVarModality(varPos, 0);
469 currentSituation.setDG1Node(origDG1);
470 currentSituation.setDG2Node(origDG2);
472 DEALLOCATE(instNeeded,
sizeof(
short int) * nbVar__);
487 DG2__->nodeValue(
DG2__->node(origDG2)->son(targetModa))));
488 newNode =
rd__->manager()->addTerminalNode(newVal);
490 DEALLOCATE(instNeeded,
sizeof(
short int) * nbVar__);
493 if (
DG1__->isTerminalNode(origDG1)) {
501 DG2__->nodeValue(
DG2__->node(origDG2)->son(targetModa))));
502 newNode =
rd__->manager()->addTerminalNode(newVal);
504 DEALLOCATE(instNeeded,
sizeof(
short int) * nbVar__);
509 &&
DG2__->isTerminalNode(origDG2)) {
516 DG2__->nodeValue(origDG2)));
517 newNode =
rd__->manager()->addTerminalNode(newVal);
519 DEALLOCATE(instNeeded,
sizeof(
short int) * nbVar__);
532 const InternalNode* dg1Node =
DG1__->node(origDG1);
533 const InternalNode* dg2Node =
DG2__->node(origDG2);
535 const DiscreteVariable* curVar = dg1Node->nodeVar();
536 Idx varPos =
rd__->variablesSequence().pos(curVar);
540 for (
Idx modality = 0; modality < curVar->domainSize(); modality++) {
541 currentSituation.chgVarModality(varPos, modality + 1);
542 currentSituation.setDG1Node(dg1Node->son(modality));
543 currentSituation.setDG2Node(dg2Node->son(modality));
545 sonsIds[modality] =
compute__(currentSituation, varPos);
548 newNode =
rd__->manager()->addInternalNode(curVar, sonsIds);
551 currentSituation.chgVarModality(varPos, 0);
552 currentSituation.setDG1Node(origDG1);
553 currentSituation.setDG2Node(origDG2);
555 DEALLOCATE(instNeeded,
sizeof(
short int) * nbVar__);
561 const InternalNode* leaddgNode = leaddg->node(leadNodeId);
563 const DiscreteVariable* curVar = leaddgNode->nodeVar();
567 for (
Idx modality = 0; modality < curVar->domainSize(); modality++) {
568 currentSituation.chgVarModality(leadVarPos, modality + 1);
569 (currentSituation.*leadFunction)(leaddgNode->son(modality));
571 sonsIds[modality] =
compute__(currentSituation, leadVarPos);
574 newNode =
rd__->manager()->addInternalNode(curVar, sonsIds);
577 currentSituation.chgVarModality(leadVarPos, 0);
578 currentSituation.setDG1Node(origDG1);
579 currentSituation.setDG2Node(origDG2);
581 DEALLOCATE(instNeeded,
sizeof(
short int) * nbVar__);
Idx nbVar__
The total number of variable implied in the operation.
MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * rd__
The resulting function graph.
NodeId compute__(O4DGContext ¤tSituation, Idx lastInstVarPos)
The main recursion function.
HashTable< NodeId, short int *> DG2InstantiationNeeded__
bool exists(const Key &key) const
Checks whether there exists an element with a given key in the hashtable.
HashTable< double, NodeId > explorationTable__
The hashtable used to know if two pair of nodes have already been visited.
virtual Size domainSize() const =0
const DiscreteVariable * targetVar__
The variable we work on to eleminate.
void setDG1Node(const NodeId &)
Set DG1 diagram current explored Node.
const PROJECTOPERATOR< GUM_SCALAR > project__
const GUM_SCALAR neutral__
The function to be performed on the leaves.
const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * DG1__
One of the two function graphs used for the operation.
void setDG2Node(const NodeId &)
Set DG2 diagram current explored Node.
short int * default__
Just a computationnal trick.
const MultiDimFunctionGraph< GUM_SCALAR, TerminalNodePolicy > * DG2__
The other one.
HashTable< NodeId, short int *> DG1InstantiationNeeded__
Table uses to know if a given node of given function graph has retrograde variables.
value_type & insert(const Key &key, const Val &val)
Adds a new element (actually a copy of this element) into the hash table.
const COMBINEOPERATOR< GUM_SCALAR > combine__
The functions to be performed on the leaves.
Size NodeId
Type for node ids.