Implemented Cell
getNeighbors() & getHazards()
This commit is contained in:
		
							parent
							
								
									049e6a4a95
								
							
						
					
					
						commit
						b360e34a4a
					
				
					 5 changed files with 62 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -4,14 +4,50 @@
 | 
			
		|||
#include "PrimImplikantCollection.h"
 | 
			
		||||
#include "Cell.h"
 | 
			
		||||
 | 
			
		||||
vector<Cell*> Cell::GetNeighbors()
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
extern uint dimension;
 | 
			
		||||
 | 
			
		||||
void Cell::refresh(PrimImplikantCollection* &globalPIC)
 | 
			
		||||
{
 | 
			
		||||
	vector<Cell*> neighbors;
 | 
			
		||||
	this->primImplikanten = globalPIC->primImplikantenAt(index);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
vector<Cell*>* Cell::getNeighbors(vector<Cell*> &allCells)
 | 
			
		||||
{
 | 
			
		||||
	vector<Cell*>* neighbors = new vector<Cell*>();
 | 
			
		||||
 | 
			
		||||
	uint j = 1;
 | 
			
		||||
	for (unsigned char i = 0; i < dimension; i++)
 | 
			
		||||
	{
 | 
			
		||||
		neighbors->push_back(allCells[this->index ^ j]);
 | 
			
		||||
		j <<= 1;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	return neighbors;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
vector<Cell*> Cell::GetHazards()
 | 
			
		||||
vector<Cell*>* Cell::getHazards(vector<Cell*> &allCells)
 | 
			
		||||
{
 | 
			
		||||
	vector<Cell*> neighbors;
 | 
			
		||||
	return neighbors;
 | 
			
		||||
	vector<Cell*>* hazardous = new vector<Cell*>();
 | 
			
		||||
	vector<Cell*>* neighbors = this->getNeighbors(allCells);
 | 
			
		||||
 | 
			
		||||
	for (vector<Cell*>::iterator neighbor = neighbors->begin(); neighbor < neighbors->end(); neighbor++)
 | 
			
		||||
	{
 | 
			
		||||
		if ((*neighbor)->value == false)
 | 
			
		||||
			continue;
 | 
			
		||||
		if ((*neighbor)->hasOneOfThose(this->primImplikanten) == false)
 | 
			
		||||
			hazardous->push_back(*neighbor);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	delete neighbors;
 | 
			
		||||
	return hazardous;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool Cell::hasOneOfThose(PrimImplikantCollection &foreignPic)
 | 
			
		||||
{
 | 
			
		||||
	for (uint i = 0; i < foreignPic.size(); i++)
 | 
			
		||||
		if (this->primImplikanten.contains(foreignPic[i]))
 | 
			
		||||
			return true;
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -12,13 +12,15 @@ public:
 | 
			
		|||
	bool value;
 | 
			
		||||
	unsigned int index;
 | 
			
		||||
 | 
			
		||||
	vector<Cell*> GetNeighbors();			// returns numElements Cells
 | 
			
		||||
	vector<Cell*> GetHazards();				// returns the neighbor Cells which are hazardous
 | 
			
		||||
	vector<Cell*>* getNeighbors(vector<Cell*> &allCells);			// returns numElements Cells
 | 
			
		||||
	vector<Cell*>* getHazards(vector<Cell*> &allCells);				// returns the neighbor Cells which are hazardous
 | 
			
		||||
	bool hasOneOfThose(PrimImplikantCollection &foreignPIC);
 | 
			
		||||
	void refresh(PrimImplikantCollection* &globalPIC);				// refreshes the local primImplikantCollection
 | 
			
		||||
 | 
			
		||||
	Cell(unsigned int index, PrimImplikantCollection* &globalPIC)
 | 
			
		||||
	{
 | 
			
		||||
		this->index = index;
 | 
			
		||||
		this->primImplikanten = globalPIC->primImplikantenAt(index);
 | 
			
		||||
		this->refresh(globalPIC);
 | 
			
		||||
		this->value = this->primImplikanten.size() > 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -10,6 +10,7 @@ class PrimImplikant
 | 
			
		|||
{
 | 
			
		||||
public:
 | 
			
		||||
	string name;
 | 
			
		||||
	uint id;
 | 
			
		||||
 | 
			
		||||
	PrimImplikant(string input)
 | 
			
		||||
	{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,17 +13,20 @@ void PrimImplikantCollection::add(PrimImplikant* &PI)
 | 
			
		|||
void PrimImplikantCollection::add(string input)
 | 
			
		||||
{
 | 
			
		||||
	PrimImplikant* PI = new PrimImplikant(input);
 | 
			
		||||
	PIVector.push_back(PI);
 | 
			
		||||
	PI->id = this->size();
 | 
			
		||||
	this->add(PI);
 | 
			
		||||
}
 | 
			
		||||
void PrimImplikantCollection::add(uint input)
 | 
			
		||||
{
 | 
			
		||||
	PrimImplikant* PI = new PrimImplikant(input);
 | 
			
		||||
	PIVector.push_back(PI);
 | 
			
		||||
	PI->id = this->size();
 | 
			
		||||
	this->add(PI);
 | 
			
		||||
}
 | 
			
		||||
void PrimImplikantCollection::add(uint input1, uint input2)
 | 
			
		||||
{
 | 
			
		||||
	PrimImplikant* PI = new PrimImplikant(input1, input2);
 | 
			
		||||
	PIVector.push_back(PI);
 | 
			
		||||
	PI->id = this->size();
 | 
			
		||||
	this->add(PI);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool PrimImplikantCollection::valueAt(uint position)
 | 
			
		||||
| 
						 | 
				
			
			@ -43,6 +46,14 @@ PrimImplikantCollection PrimImplikantCollection::primImplikantenAt(uint position
 | 
			
		|||
	return pic;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool PrimImplikantCollection::contains(PrimImplikant* foreign)
 | 
			
		||||
{
 | 
			
		||||
	for (vector<PrimImplikant*>::iterator i = PIVector.begin(); i < PIVector.end(); i++)
 | 
			
		||||
		if ((*i)->id == foreign->id)
 | 
			
		||||
			return true;
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint PrimImplikantCollection::size()
 | 
			
		||||
{
 | 
			
		||||
	return this->PIVector.size();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,6 +17,7 @@ public:
 | 
			
		|||
 | 
			
		||||
	bool valueAt(uint position);
 | 
			
		||||
	PrimImplikantCollection primImplikantenAt(uint position);
 | 
			
		||||
	bool contains(PrimImplikant* foreign);
 | 
			
		||||
 | 
			
		||||
	void Dispose();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue