amanyasin
Technical User
- Feb 7, 2003
- 28
Bonjour,
Dear all
I am facing general programming related logical error. I want to access bolean variable of the class by using get method. but it is not giving the right result. When i read the counter and boolean variable by getcount() and isPathExist() methods. Each time it returns "0" for counter and false for boolean.
My code is below
#include "AlgoPC.h"
#include <boost/graph/depth_first_search.hpp>
//=============================Depth First Search===========================
class DFSVisitor: public default_dfs_visitor
{
protected:
slBayesianNetwork *pBN;
int nodeA, nodeC;
bool exist;
int counter;
public:
DFSVisitor(slBayesianNetwork *pBN, int nodeA, int nodeC);
~DFSVisitor();
void discover_vertex(slNode u, const slGraph &g);
void resetCounter();
bool isPathExist();
int getCounter();
};
//--------------------------------------------------------------------------
DFSVisitor:FSVisitor(slBayesianNetwork *pBN, int nodeA, int nodeC)
{
this->pBN = pBN;
this->nodeA = nodeA;
this->nodeC = nodeC;
this->exist = false;
this->resetCounter();
}
//--------------------------------------------------------------------------
DFSVisitor::~DFSVisitor() { }
//--------------------------------------------------------------------------
void DFSVisitor::resetCounter()
{
this->counter = 0;
}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
void DFSVisitor::discover_vertex(slNode u, const slGraph &g)
{
this->counter++;
unsigned int varIdx = this->pBN->getVariableIndex(u);
if ((varIdx == this->nodeC ) && ((this->counter) > 2))
{
this->exist = true;
cout<<"\n "<<counter<<" node = "<< varIdx+1;
}
}
//--------------------------------------------------------------------------
int DFSVisitor::getCounter()
{
return this->counter;
}
//--------------------------------------------------------------------------
bool DFSVisitor::isPathExist()
{
return this->exist;
}
====================== main program =======================
cout<< "\n a = "<<a<<" c = "<<c;
DFSVisitor vis(this->pBN, a , c);
depth_first_search((slGraph&)this->pBN->get_graph(),visitor(vis).root_vertex(vertex(a, this->pBN->get_graph())));
cout<<"\n counter is = "<<vis.getCounter()<<" Path exist = "<< vis.isPathExist();
======================== out put =========================
counter is = 0 path exist = 0 (false)
-------------------------------------------------------
I will be thankful to you for guiding me.
Best Regards
Dear all
I am facing general programming related logical error. I want to access bolean variable of the class by using get method. but it is not giving the right result. When i read the counter and boolean variable by getcount() and isPathExist() methods. Each time it returns "0" for counter and false for boolean.
My code is below
#include "AlgoPC.h"
#include <boost/graph/depth_first_search.hpp>
//=============================Depth First Search===========================
class DFSVisitor: public default_dfs_visitor
{
protected:
slBayesianNetwork *pBN;
int nodeA, nodeC;
bool exist;
int counter;
public:
DFSVisitor(slBayesianNetwork *pBN, int nodeA, int nodeC);
~DFSVisitor();
void discover_vertex(slNode u, const slGraph &g);
void resetCounter();
bool isPathExist();
int getCounter();
};
//--------------------------------------------------------------------------
DFSVisitor:FSVisitor(slBayesianNetwork *pBN, int nodeA, int nodeC)
{
this->pBN = pBN;
this->nodeA = nodeA;
this->nodeC = nodeC;
this->exist = false;
this->resetCounter();
}
//--------------------------------------------------------------------------
DFSVisitor::~DFSVisitor() { }
//--------------------------------------------------------------------------
void DFSVisitor::resetCounter()
{
this->counter = 0;
}
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
void DFSVisitor::discover_vertex(slNode u, const slGraph &g)
{
this->counter++;
unsigned int varIdx = this->pBN->getVariableIndex(u);
if ((varIdx == this->nodeC ) && ((this->counter) > 2))
{
this->exist = true;
cout<<"\n "<<counter<<" node = "<< varIdx+1;
}
}
//--------------------------------------------------------------------------
int DFSVisitor::getCounter()
{
return this->counter;
}
//--------------------------------------------------------------------------
bool DFSVisitor::isPathExist()
{
return this->exist;
}
====================== main program =======================
cout<< "\n a = "<<a<<" c = "<<c;
DFSVisitor vis(this->pBN, a , c);
depth_first_search((slGraph&)this->pBN->get_graph(),visitor(vis).root_vertex(vertex(a, this->pBN->get_graph())));
cout<<"\n counter is = "<<vis.getCounter()<<" Path exist = "<< vis.isPathExist();
======================== out put =========================
counter is = 0 path exist = 0 (false)
-------------------------------------------------------
I will be thankful to you for guiding me.
Best Regards