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 "stdafx.h"
 | 
				
			||||||
#include <string>
 | 
					#include <string>
 | 
				
			||||||
 | 
					#include <algorithm>
 | 
				
			||||||
#include <vector>
 | 
					#include <vector>
 | 
				
			||||||
#include "PrimImplikant.h"
 | 
					#include "PrimImplikant.h"
 | 
				
			||||||
#include "Implikant_localisation.h"
 | 
					#include "Implikant_localisation.h"
 | 
				
			||||||
| 
						 | 
					@ -7,7 +8,7 @@
 | 
				
			||||||
using namespace std;
 | 
					using namespace std;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
bool PrimImplikant::valueAt(uint pos) {
 | 
					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)
 | 
							if (*i == pos)
 | 
				
			||||||
			return true;
 | 
								return true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -40,6 +41,31 @@ void PrimImplikant::parser(string input) {  // Analyser
 | 
				
			||||||
		implikant += (uint)c - (uint)'0';
 | 
							implikant += (uint)c - (uint)'0';
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	implikanten.push_back(implikant);
 | 
						elements.push_back(implikant);
 | 
				
			||||||
	I_Vector.push_back(new Implikant_localisation(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
 | 
					#pragma once
 | 
				
			||||||
#define PRIMIMPLIKANT
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include <string>
 | 
					#include <string>
 | 
				
			||||||
#include <vector>
 | 
					#include <vector>
 | 
				
			||||||
| 
						 | 
					@ -9,9 +8,16 @@ using namespace std;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PrimImplikant
 | 
					class PrimImplikant
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					private:
 | 
				
			||||||
 | 
						bool compareGray(uint &a, uint &b);
 | 
				
			||||||
 | 
						void makeLocations();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						vector<KV_PiEleLoc*>* locations = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
	string name;
 | 
						string name;
 | 
				
			||||||
	uint id;
 | 
						uint id;
 | 
				
			||||||
 | 
						vector<uint> elements;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	PrimImplikant(string input)
 | 
						PrimImplikant(string input)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
| 
						 | 
					@ -42,14 +48,22 @@ public:
 | 
				
			||||||
		I_Vector.push_back(new Implikant_localisation(input2));
 | 
							I_Vector.push_back(new Implikant_localisation(input2));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	bool PrimImplikant::valueAt(uint position);
 | 
						bool valueAt(uint position);
 | 
				
			||||||
	void PrimImplikant::parser(string input);
 | 
						void parser(string input);
 | 
				
			||||||
 | 
						void sort();
 | 
				
			||||||
 | 
						vector<KV_PiEleLoc*>* locations();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						~PrimImplikant()
 | 
				
			||||||
	
 | 
						{
 | 
				
			||||||
 | 
							if (this->locations)
 | 
				
			||||||
	vector<uint> implikanten;
 | 
							{
 | 
				
			||||||
	vector<Implikant_localisation*> I_Vector;
 | 
								for (uint i = 0; i < this->locations.size(); i++)
 | 
				
			||||||
	vector<vector<Implikant_localisation*>*> PI_groupCollection;
 | 
								{
 | 
				
			||||||
 | 
									delete this->locations[i];
 | 
				
			||||||
 | 
									this->locations[i] = NULL;
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								delete this->locations;
 | 
				
			||||||
 | 
								this->locations = NULL;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
#endif
 | 
					 | 
				
			||||||
		Loading…
	
		Reference in a new issue