Wertetabellen-Ausgabe hinzugefügt
This commit is contained in:
parent
bcac4dd121
commit
9d79f2dc27
3 changed files with 133 additions and 3 deletions
|
@ -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"
|
#include "stdafx.h"
|
||||||
|
@ -9,6 +9,7 @@
|
||||||
#include "PrimImplikant.h"
|
#include "PrimImplikant.h"
|
||||||
#include "PrimImplikantCollection.h"
|
#include "PrimImplikantCollection.h"
|
||||||
#include "Cell.h"
|
#include "Cell.h"
|
||||||
|
#include "Wertetabelle.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -94,10 +95,15 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Wertetabelle* wt = new Wertetabelle(&cells, variables);
|
||||||
|
wt->Print();
|
||||||
|
delete wt;
|
||||||
|
|
||||||
|
|
||||||
// find hazards
|
// find hazards
|
||||||
if (numOnes > numElements / 2) // we have more 1 than 0 --> checkerboard --> 50% of cells are checked
|
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++)
|
for (uint i = 0; i < numElements; i++)
|
||||||
{
|
{
|
||||||
uint grayI = i ^ (i/2); // transform to gray code
|
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
|
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++)
|
for (uint i = 0; i < numElements; i++)
|
||||||
{
|
{
|
||||||
if (!cells[i]->value)
|
if (!cells[i]->value)
|
||||||
|
|
87
Hazard/Hazard/Wertetabelle.cpp
Normal file
87
Hazard/Hazard/Wertetabelle.cpp
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
#include "stdafx.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#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<string>::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 << " ";
|
||||||
|
}
|
37
Hazard/Hazard/Wertetabelle.h
Normal file
37
Hazard/Hazard/Wertetabelle.h
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
#include "stdafx.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include "Cell.h"
|
||||||
|
#include "PrimImplikant.h"
|
||||||
|
#include "Cell.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
#ifndef WERTETABELLE
|
||||||
|
#define WERTETABELLE
|
||||||
|
|
||||||
|
class Wertetabelle
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void Print();
|
||||||
|
|
||||||
|
Wertetabelle(vector<Cell*>* cells, vector<string>* variables)
|
||||||
|
{
|
||||||
|
this->cells = cells;
|
||||||
|
this->variables = variables;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
string makeHeader();
|
||||||
|
void printHeader();
|
||||||
|
void printI(unsigned int i);
|
||||||
|
void printPrimImplikanten(unsigned int i);
|
||||||
|
|
||||||
|
vector<Cell*>* cells;
|
||||||
|
vector<string>* variables;
|
||||||
|
vector<float> padding;
|
||||||
|
uint width;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in a new issue