Revision a6f5ec85 src/sim/cheuristic.cc

View differences:

src/sim/cheuristic.cc
85 85
		double lowerBound;
86 86
		double upperBound;
87 87
		typedef std::list<cNode*> nodeSet_t;
88
		nodeSet_t leaves;
88
		nodeSet_t bfsVisitList;
89 89

  
90 90
	public:
91 91
		/**
......
98 98
			upperBound=1;
99 99
		}
100 100

  
101
		bool leafSetContainsParent(cNode* parent)
101
		bool leafSetContainsParent(cNode* parent) const
102 102
		{
103
			bool res=*leaves.begin()==parent;
103
			bool res=*bfsVisitList.begin()==parent;
104 104
#ifdef DEBUG
105 105
			std::cout << "Is parent really always at beginning of list?" << std::endl;
106 106
			bool checkedRes=false;
107
			for(nodeSet_t::iterator it=leaves.begin();it!=leaves.end();it++)
107
			for(nodeSet_t::iterator it=bfsVisitList.begin();it!=bfsVisitList.end();it++)
108 108
			{
109 109
				if(*it==parent) checkedRes=true;
110 110
			}
......
130 130
			const double dangerProb=newNode->getProbability();
131 131
			upperBound=1-(1-upperBound)*(1-dangerProb);
132 132
			if(isConflicting) lowerBound=1-(1-lowerBound)*(1-dangerProb);
133
			if(parent && leafSetContainsParent(parent))
134
			{
135
				upperBound=1-(1-upperBound)/(1-parent->getProbability());
136
				leaves.remove(parent);
137
			}
138
			leaves.push_back(newNode);
133
			bfsVisitList.push_back(newNode);
139 134
		}
140 135

  
141 136
		// Performing BFS and spanning the tree:
142 137
		bool bfs(double threshold, int moduleId)
143 138
		{
144
			for(nodeSet_t::iterator leaf=leaves.begin();leaf!=leaves.end();++leaf)
139
			nodeSet_t::iterator it;
140
			while((it=bfsVisitList.begin()) != bfsVisitList.end())
145 141
			{
146
				if((*leaf)->isConflicting())
142
				std::cout << "bfsVisitList.size()=" << bfsVisitList.size() << std::endl;
143
				cNode* node=*it;
144
				bfsVisitList.erase(it);
145
				if(node->isConflicting())
147 146
				{
148 147
					continue;
149 148
				}
150
				succList_t succs=(*leaf)->getSuccessors();
149
				else
150
				{
151
					upperBound=1-(1-upperBound)/(1-node->getProbability());
152
				}
153
				succList_t succs=node->getSuccessors();
151 154
				for(succList_t::iterator succ=succs.begin();succ!=succs.end();++succ)
152 155
				{
153 156
					// We need to convolve the PDF of the (previous) leaf node with the PDF of its successors:
154
					//pdf_t convolvedPdf=leaf->getProbabilityDistribution()+succ->getProbabilityDistribution();
157
					//pdf_t convolvedPdf=node->getProbabilityDistribution()+succ->getProbabilityDistribution();
155 158
					pdf_t convolvedPdf=succ->getProbabilityDistributionCopy();
156
					convolvedPdf+=(*leaf)->getProbabilityDistribution();
159
					convolvedPdf+=node->getProbabilityDistribution();
157 160
					evType_t* succEvType=succ->getEvType();
158 161
					int succModId=succ->getEvType()->getModId();
159 162
					bool isConflicting=moduleId==succModId;
160 163
					// We add the new node as a child of the leaf into the tree:
161
					addNode(*leaf,succEvType,convolvedPdf,isConflicting);
164
					addNode(node,succEvType,convolvedPdf,isConflicting);
162 165
					// If both bounds for the probability are below (above) the threshold,
163 166
					// the probability itself is also below (above) the threshold,
164 167
					// i.e. we can yield the decision without further inspecting the BFS tree.
......
167 170
				}
168 171
				node->releaseSuccListLock();
169 172
			}
173
			if(lowerBound<=threshold && upperBound<=threshold) return true;
174
			return false; // be pessimistic
170 175
		}
171 176
};
172 177

  

Also available in: Unified diff