PrimImplikant mit KV_PiEleLocs
Der PrimImplikant verfügt nun über eine Methode, die die enthaltenen Elemente nach Gray aufsteigend sortiert. Außerdem kann für jedes Element eine KV_PiEleLoc erstellt und in einem Vector abgelegt werden.
This commit is contained in:
		
							parent
							
								
									17f4b32239
								
							
						
					
					
						commit
						1f55b1bfc3
					
				
					 2 changed files with 54 additions and 14 deletions
				
			
		| 
						 | 
				
			
			@ -1,5 +1,6 @@
 | 
			
		|||
#include "stdafx.h"
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <algorithm>
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include "PrimImplikant.h"
 | 
			
		||||
#include "Implikant_localisation.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -7,7 +8,7 @@
 | 
			
		|||
using namespace std;
 | 
			
		||||
 | 
			
		||||
bool PrimImplikant::valueAt(uint pos) {
 | 
			
		||||
	for (vector<uint>::iterator i = implikanten.begin(); i < implikanten.end(); ++i)
 | 
			
		||||
	for (vector<uint>::iterator i = elements.begin(); i < elements.end(); ++i)
 | 
			
		||||
		if (*i == pos)
 | 
			
		||||
			return true;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -40,6 +41,31 @@ void PrimImplikant::parser(string input) {  // Analyser
 | 
			
		|||
		implikant += (uint)c - (uint)'0';
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	implikanten.push_back(implikant);
 | 
			
		||||
	elements.push_back(implikant);
 | 
			
		||||
	I_Vector.push_back(new Implikant_localisation(implikant));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void PrimImplikant::sort()
 | 
			
		||||
{
 | 
			
		||||
	sort(this->elements.begin(), this->elements.end(), PrimImplikant::compareGray);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool PrimImplikant::compareGray(uint &a, uint &b)
 | 
			
		||||
{
 | 
			
		||||
	return (a ^ (a/2)) < (b ^ (b/2));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void PrimImplikant::makeLocations()
 | 
			
		||||
{
 | 
			
		||||
	this->sort();
 | 
			
		||||
	this->locations = new vector<KV_PiEleLoc*>();
 | 
			
		||||
	for (uint i = 0; i < this->elements.size(); i++)
 | 
			
		||||
		this->locations.push_back(new KV_PiEleLoc(this->elements[i]));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
vector<KV_PiEleLoc*>* locations()
 | 
			
		||||
{
 | 
			
		||||
	if (this->locations == NULL)
 | 
			
		||||
		this->makeLocations();
 | 
			
		||||
	return this->locations;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,5 +1,4 @@
 | 
			
		|||
#ifndef PRIMIMPLIKANT
 | 
			
		||||
#define PRIMIMPLIKANT
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <string>
 | 
			
		||||
#include <vector>
 | 
			
		||||
| 
						 | 
				
			
			@ -9,9 +8,16 @@ using namespace std;
 | 
			
		|||
 | 
			
		||||
class PrimImplikant
 | 
			
		||||
{
 | 
			
		||||
private:
 | 
			
		||||
	bool compareGray(uint &a, uint &b);
 | 
			
		||||
	void makeLocations();
 | 
			
		||||
 | 
			
		||||
	vector<KV_PiEleLoc*>* locations = NULL;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
	string name;
 | 
			
		||||
	uint id;
 | 
			
		||||
	vector<uint> elements;
 | 
			
		||||
 | 
			
		||||
	PrimImplikant(string input)
 | 
			
		||||
	{
 | 
			
		||||
| 
						 | 
				
			
			@ -42,14 +48,22 @@ public:
 | 
			
		|||
		I_Vector.push_back(new Implikant_localisation(input2));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	bool PrimImplikant::valueAt(uint position);
 | 
			
		||||
	void PrimImplikant::parser(string input);
 | 
			
		||||
	bool valueAt(uint position);
 | 
			
		||||
	void parser(string input);
 | 
			
		||||
	void sort();
 | 
			
		||||
	vector<KV_PiEleLoc*>* locations();
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	vector<uint> implikanten;
 | 
			
		||||
	vector<Implikant_localisation*> I_Vector;
 | 
			
		||||
	vector<vector<Implikant_localisation*>*> PI_groupCollection;
 | 
			
		||||
	~PrimImplikant()
 | 
			
		||||
	{
 | 
			
		||||
		if (this->locations)
 | 
			
		||||
		{
 | 
			
		||||
			for (uint i = 0; i < this->locations.size(); i++)
 | 
			
		||||
			{
 | 
			
		||||
				delete this->locations[i];
 | 
			
		||||
				this->locations[i] = NULL;
 | 
			
		||||
			}
 | 
			
		||||
			delete this->locations;
 | 
			
		||||
			this->locations = NULL;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
		Loading…
	
		Reference in a new issue