diff --git a/Hazard/Hazard/Hazard.cpp b/Hazard/Hazard/Hazard.cpp index 5d84d3d..14b8abf 100644 --- a/Hazard/Hazard/Hazard.cpp +++ b/Hazard/Hazard/Hazard.cpp @@ -1,4 +1,4 @@ -// Hazard.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung. +// Hazard.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung. // #include "stdafx.h" @@ -9,6 +9,7 @@ #include "PrimImplikant.h" #include "PrimImplikantCollection.h" #include "Cell.h" +#include "Wertetabelle.h" using namespace std; @@ -93,11 +94,16 @@ int _tmain(int argc, _TCHAR* argv[]) numOnes++; } + + Wertetabelle* wt = new Wertetabelle(&cells, variables); + wt->Print(); + delete wt; + // find hazards if (numOnes > numElements / 2) // we have more 1 than 0 --> checkerboard --> 50% of cells are checked { - cout << "\nSchachbrettmuster\n"; + cout << "\nHazard-Algorithmus: Schachbrettmuster\n"; for (uint i = 0; i < numElements; i++) { uint grayI = i ^ (i/2); // transform to gray code @@ -115,7 +121,7 @@ int _tmain(int argc, _TCHAR* argv[]) } else // less 1 than 0 --> only check every 1 --> less than 50% (numOnes/numElements) of cells are checked { - cout << "\nÃœberspringe Nullen\n"; + cout << "\nHazard-Algorithmus: Ueberspringe Nullen\n"; for (uint i = 0; i < numElements; i++) { if (!cells[i]->value) diff --git a/Hazard/Hazard/Wertetabelle.cpp b/Hazard/Hazard/Wertetabelle.cpp new file mode 100644 index 0000000..f7edf1a --- /dev/null +++ b/Hazard/Hazard/Wertetabelle.cpp @@ -0,0 +1,87 @@ +#include "stdafx.h" +#include +#include +#include +#include "Cell.h" +#include "PrimImplikant.h" +#include "Wertetabelle.h" + +using namespace std; + +extern uint dimension; +extern uint numElements; + +void Wertetabelle::Print() +{ + printHeader(); + + for (uint i = 0; i < numElements; i++) + { + cout << "|"; // => | + this->printI(i); // => 0 1 0 0 + cout << "| "; // => | + cout << (*this->cells)[i]->value; // => 1 + cout << " |"; // => | + this->printPrimImplikanten(i); // => 0 0x1 4 + cout << endl; + + if (i > 0 && i % 20 == 0 && i - numElements > 5) + cout << this->makeHeader() << endl; + } + + cout << string(this->width, '-'); +} + +string Wertetabelle::makeHeader() +{ + bool setPad = padding.size() == 0; + if (setPad) + padding.resize(dimension); + + string row2 = "|"; + for (vector::iterator v = variables->begin(); v < variables->end(); v++) + { + row2 += " " + *v; + if (setPad) + padding.push_back(((*v).size()-1) / 2.0f); + } + + row2 += " | y |"; + + this->width = row2.size(); + + row2 += " PrimImplikanten"; + + return row2; +} + +void Wertetabelle::printHeader() +{ + string row2 = this->makeHeader(); + + cout << string(this->width, '-') << endl; // repeat '-' several times => --------------------- + cout << row2 << endl; // print header row => | a bärchen c d | y | PrimtImpl. + cout << string(this->width, '-') << endl; // repeat '-' several times => --------------------- +} + +void Wertetabelle::printI(uint i) +{ + string row = " "; + for (int j = dimension - 1; j >= 0; j--) // Variablen rückwärts durchlaufen (s.u.) + { + char iAtJ = (i & 0x1) + '0'; // Maskierung (aktuelle Stelle j, die ausgegeben wird) + i >>= 1; // Schieben für nächstes Mal + // ' ' + Padding left (' ') + 1 | 0 + Padding right (' ') + row + row = string((uint)ceil(padding[j]) + 1, ' ') + iAtJ + string((uint)floor(padding[j]), ' ') + row; + } + cout << row; +} + +void Wertetabelle::printPrimImplikanten(unsigned int i) +{ + cout << ' '; + Cell* cell = cells->at(i); + + for (unsigned int pi = 0; pi < cell->primImplikanten.size(); pi++) // for every PrimImplikant in Cell + cout << cell->primImplikanten[pi]->name << " "; +} \ No newline at end of file diff --git a/Hazard/Hazard/Wertetabelle.h b/Hazard/Hazard/Wertetabelle.h new file mode 100644 index 0000000..d9feeb9 --- /dev/null +++ b/Hazard/Hazard/Wertetabelle.h @@ -0,0 +1,37 @@ +#include "stdafx.h" +#include +#include +#include +#include "Cell.h" +#include "PrimImplikant.h" +#include "Cell.h" + +using namespace std; + +#ifndef WERTETABELLE +#define WERTETABELLE + +class Wertetabelle +{ +public: + void Print(); + + Wertetabelle(vector* cells, vector* variables) + { + this->cells = cells; + this->variables = variables; + } + +private: + string makeHeader(); + void printHeader(); + void printI(unsigned int i); + void printPrimImplikanten(unsigned int i); + + vector* cells; + vector* variables; + vector padding; + uint width; +}; + +#endif \ No newline at end of file