Skip to content

Commit

Permalink
Now Can Compute Upto 21 Variable!! "slower"
Browse files Browse the repository at this point in the history
  • Loading branch information
neeraj-395 committed Feb 2, 2024
1 parent 8dd1a41 commit 070b1a9
Show file tree
Hide file tree
Showing 14 changed files with 641 additions and 501 deletions.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ src/Implement.c
src/Implement.exe
src/main.exe
src/troubleshoot.h
src/exp.c
src/exp.exe
src/experiment/exp.c
src/experiment/exp.exe
src/hashtable.o
src/branching_method.o
src/tabular_method.o
src/libutils.o
Binary file modified backend/executables/main_program.exe
Binary file not shown.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ <h1 class="heading">Karnaugh Map Solver</h1>
</a>
</p>
</body>
</html>
</html>
15 changes: 15 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CC = gcc
CFLAGS = -Wall -Wextra
OBJS = branching_method.o tabular_method.o libutils.o hashtable.o
TARGET = main

all: $(TARGET)

$(TARGET): $(OBJS) main.c
$(CC) $(CFLAGS) $(OBJS) main.c -o $(TARGET)

%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@

clean:
rm $(OBJS) $(TARGET)
162 changes: 162 additions & 0 deletions src/branching_method.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#include "branching_method.h"

size_t uncovered_terms(char *track, size_t size, size_t *posi)
{
size_t n = 0;
for (size_t i = 0, w = 0; i < size; i++)
{
if (track[i] == UNCOVERED)
{
if (posi)
posi[w++] = i;
n++;
}
}
return n;
}

void draw_pitable(pit_set *epi, char **piBin, ULL_INT *minDec, size_t var)
{
for (size_t i = 0; i < epi->nom; i++)
{
for (size_t j = 0; j < epi->nopi; j++)
{
ULL_INT min_dec = minDec[i];
bool check = true;
for (int k = (var - 1); k >= 0; k--)
{
if ((piBin[j][k] - '0') == (int)(min_dec % 2)
|| piBin[j][k] == '_')
min_dec >>= 1;
else{
check = false;
break;
}
}
epi->table[i][j] = (check) ? '1' : '0';
}
}
}

void covered_minterms_eliminator(pit_set *epi, ctt_set *track)
{
size_t Adomi, Bdomi;
size_t opm[epi->nom], opnom;
size_t oppi[epi->nopi], opnopi;

opnopi = uncovered_terms(track->epi, epi->nopi, oppi);
opnom = uncovered_terms(track->min, epi->nom, opm);

for (size_t A = 0; A < opnom; A++)
{
for (size_t B = (A + 1); B < opnom; B++)
{
Adomi = 0, Bdomi = 0;
for (size_t k = 0; k < opnopi; k++)
{
if (epi->table[opm[A]][oppi[k]] == '1')
Adomi += (epi->table[opm[B]][oppi[k]] == '0') ? 1 : 0; // mismatch count
else if (epi->table[opm[B]][oppi[k]] == '1')
Bdomi += (epi->table[opm[A]][oppi[k]] == '0') ? 1 : 0; // mismatch count
}

if (Adomi == 0 && Bdomi > 0)
track->min[opm[B]] = COVERED;
else if (Bdomi == 0 && Adomi > 0)
track->min[opm[A]] = COVERED;
else if (Adomi == 0 && Bdomi == 0)
track->min[opm[B]] = COVERED;
}
}
}

void non_essential_primes_eliminator(pit_set *epi, ctt_set *track)
{
size_t Adomi, Bdomi;
size_t opm[epi->nom], opnom;
size_t oppi[epi->nopi], opnopi;

opnom = uncovered_terms(track->min, epi->nom, opm);
opnopi = uncovered_terms(track->epi, epi->nopi, oppi);

for (size_t A = 0; A < opnopi; A++)
{
for (size_t B = (A + 1); B < opnopi; B++)
{
Adomi = 0, Bdomi = 0;
for (size_t k = 0; k < opnom; k++)
{
if (epi->table[opm[k]][oppi[A]] == '1')
Adomi += (epi->table[opm[k]][oppi[B]] == '0') ? 1 : 0; // mismatch
else if (epi->table[opm[k]][oppi[B]] == '1')
Bdomi += (epi->table[opm[k]][oppi[A]] == '0') ? 1 : 0; // mismatch
}
if (Adomi == 0 && Bdomi > 0)
track->epi[oppi[A]] = NON_ESSENTIAL;
else if (Bdomi == 0 && Adomi > 0)
track->epi[oppi[B]] = NON_ESSENTIAL;
else if (Adomi == 0 && Bdomi == 0)
track->epi[oppi[A]] = NON_ESSENTIAL;
}
}
}

void collect_essential_primes(pit_set *epi, ctt_set *track)
{
size_t posi = epi->nopi;
size_t opm[epi->nom], opnom;
size_t oppi[epi->nopi], opnopi; // no. of minterms after elimination

opnom = uncovered_terms(track->min, epi->nom, opm);
opnopi = uncovered_terms(track->epi, epi->nopi, oppi);

for (size_t i = 0; i < opnom; i++)
{
for (size_t j = 0, count = 0; j < opnopi; j++)
{
if (count > 1)
break;
if (epi->table[opm[i]][oppi[j]] == '1')
posi = ((++count) == 1) ? oppi[j] : epi->nopi;
}
if (posi != epi->nopi)
{
for (size_t k = 0; k < opnom; k++)
if (epi->table[opm[k]][posi] == '1')
track->min[opm[k]] = COVERED;
track->epi[posi] = ESSENTIAL;
}
}
}

void cyclic_function_method(pit_set *epi, ctt_set *track)
{
size_t posi[2];
for (size_t i = 0, count; i < epi->nopi; i++)
{
if (track->epi[i] == UNCOVERED)
{
count = 0;
for (size_t j = 0; j < epi->nom; j++)
{
if (count > 2)
break;
if (epi->table[j][i] == '1' && track->min[j] == UNCOVERED)
{
count++;
if (count == 1)
posi[0] = j;
else if (count == 2)
posi[1] = j;
}
}
if (count == 2)
{
track->min[posi[0]] = COVERED;
track->min[posi[1]] = COVERED;
track->epi[i] = ESSENTIAL;
return;
}
}
}
}
Loading

0 comments on commit 070b1a9

Please sign in to comment.