Skip to content

Commit

Permalink
upto 8 varaible kmap supported.
Browse files Browse the repository at this point in the history
  • Loading branch information
neeraj-395 committed Feb 24, 2024
1 parent 070b1a9 commit 374650a
Show file tree
Hide file tree
Showing 9 changed files with 262 additions and 388 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.vscode
**/.vscode/
src/experiment/
src/Implement.h
src/Implement.c
src/Implement.exe
Expand All @@ -10,4 +11,5 @@ src/experiment/exp.exe
src/hashtable.o
src/branching_method.o
src/tabular_method.o
src/libutils.o
src/libutils.o
style/other_feature.js
Binary file added backend/executables/main_program.out
Binary file not shown.
46 changes: 26 additions & 20 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>K-Map Solver</title>
<meta name="viewport" content="width=device-width, initial-scale=0.75" />
<meta charset="UTF-8" />
<link rel="stylesheet" href="style/index.css" />
<link rel="stylesheet" href="style/style.css" />
<link rel="icon" type="image/png" href="./style/favicon.ico" sizes="152x152">
<script>
MathJax = {
Expand All @@ -13,10 +13,11 @@
</script>
<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
<script id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<script src="style/index.js"></script>
<script src="style/inputhandler.js"></script>
<script src="style/karnaughmap.js"></script>
</head>

<body>
<body onload = "initKMAP('k-map')">

<header style="block-size: 100px;">
<a href="https://dseu.ac.in/" target="_blank" style="text-decoration: none;">
Expand Down Expand Up @@ -46,8 +47,7 @@ <h1 class="heading">Karnaugh Map Solver</h1>
target="_blank" style="text-decoration: none; color:rgb(68, 68, 249)">
<span class="para">Quine-McCluskey Algorithm</span></a>
with user-friendly interactivity to simplify boolean expression
solutions. Whether you're a student, an electronics enthusiast, our application is
designed to assist you in simplifying digital logical expressions.<br />
solutions.<br />
</p>

<p style="font-size: 22px; font-family: 'Libre Baskerville'">
Expand All @@ -57,18 +57,24 @@ <h1 class="heading">Karnaugh Map Solver</h1>
<span class="para">Logic Function Notation:</span>\[f(A,B,....)=\sum m(0,1,2,3,.....)\]
</p>
<br><br>

<button type="button" class="button" onclick="Draw('k-map','variables/ii_variables.html')">
<span class="button-name">II&nbsp;&nbsp;Variables</span>
</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button type="button" class="button" onclick="Draw('k-map','variables/iii_variables.html')">
<span class="button-name">III&nbsp;&nbsp;Variables </span>
</button>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<button type="button" class="button" onclick="Draw('k-map','variables/iv_variables.html')">
<span class="button-name">IV&nbsp;&nbsp;Variables</span>
</button><br><br><br>

<p class = "para">
Number of input variables:
<select style = "font-size: 24px;" onchange = "initKMAP('k-map');" id = nVar_id>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4" selected>4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
</select>
&nbsp;
<button type="button" class="button" onclick = "initKMAP('k-map');">Reset</button>
&nbsp;
<button type="button" class="button" onclick = "Inputs();">Submit</button>
</p>

<div id="k-map" style="display: none; user-select: none;"></div>

Expand All @@ -80,16 +86,16 @@ <h1 class="heading">Karnaugh Map Solver</h1>
<li>JavaScript for both frontend and backend.</li>
<li>Using PHP to link a C program with web technologies.</li>
<li>You can find this website source code at :
<a href="https://github.com/Neeraj395-N3rd/K-Map_Solver" target="_blank" style="text-decoration: none"><span
<a href="https://github.com/neeraj-395/K-Map_Solver" target="_blank" style="text-decoration: none"><span
class="name">GitHub</span></a></li>
</ul>
</p>
<p class="para"><b>Note: </b>
This project is intended for educational purposes and as a demonstration of integrating C programming with web technologies. It is not meant for deployment on the internet.
</p>

<p class="para">Φ Developed by:<br />
<a href="https://github.com/Neeraj395-N3rd" target="_blank" style="text-decoration: none">
<p class="para">&Psi;&nbsp;Developed by:<br />
<a href="https://github.com/neeraj-395" target="_blank" style="text-decoration: none">
<span class="mention">§ Neeraj_Singh</span>
</a><br />
<a href="https://www.instagram.com/itz_krishu_4u/" target="_blank" style="text-decoration: none">
Expand Down
139 changes: 26 additions & 113 deletions style/index.js → style/inputhandler.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
//------------K-Map Fetch Function----------------------//

function Draw(container_id, ex_filename) {
function initKMAP(container_id) {
var container = document.getElementById(container_id);
var vars = document.getElementById("nVar_id").value;

if (container.style.display == "none") {
fetch(ex_filename)
.then((response) => response.text())
.then((htmlCode) => {
container.innerHTML = "";
container.innerHTML = htmlCode;
MathJax.typeset();
})
.catch((error) => {
console.error("Error loading HTML:", error);
});
container.innerHTML = "";
if(vars == 5 || vars == 6) {
document.body.style.setProperty('--font_size', '16px');
drawKmap(vars, 60, container_id);
}
else
drawKmap(vars, 50, container_id);
MathJax.typeset();
container.style.display = "block";
} else {
container.style.display = "none";
return Draw(container_id, ex_filename);
return initKMAP(container_id, vars);
}
}

//------------Ternary-Toggle Input Function(0-->1-->X)---------------------//

function toggle(id) {
var Min = document.getElementById(id).innerHTML;
if (Min === "0") {
Expand All @@ -33,8 +29,6 @@ function toggle(id) {
}
}

// ---------------PHP Linking Functions-----------------//

function Inputs() {
let i=0;
const minIndex = document.querySelectorAll("text.minIndex");
Expand All @@ -49,6 +43,13 @@ function Inputs() {
Inputvalues[Indexs[i++]] = min.textContent;
});

if(!Inputvalues.includes('1'))
{
let min = ['(null)'];
booleanOutput(min);
return;
}

let _1sDec = "";
let XsDec = "";
let program_arguments = "";
Expand All @@ -66,10 +67,10 @@ function Inputs() {
program_arguments += (_1sDec !== "") ? _1sDec.slice(0, -1) : "\"(null)\"";
program_arguments += " dcare= "
program_arguments += (XsDec !== "") ? XsDec.slice(0, -1) : "\"(null)\"";
Output(Inputvalues, program_arguments);
Output(program_arguments);
}

function Output(Input, program_arg) {
function Output(program_arg) {
var jsonArray = JSON.stringify(program_arg);
fetch("backend/link.php", {
method: "POST",
Expand All @@ -90,8 +91,6 @@ function Output(Input, program_arg) {
.then(output => {
const dataArray = output.split(/\r?\n/);
booleanOutput(dataArray);
Minterms(Input);
Implicants_Input(dataArray);
})
.catch((error) => {
console.error("Error:", error);
Expand All @@ -104,47 +103,16 @@ function OutputTransfer(Mathjax_Output) {
MathJax.typeset();
}

//------------------LOGIC-FUNCTION-NOTATION----------------------//

function Minterms(Min) {
var i = 0,j = 0,k = 0;
var min = [], dontC = [], MinString;

Min.forEach((valueofMin) => {
if (valueofMin === "1") {
min[j] = i.toString();
j++;
} else if (valueofMin === "X") {
dontC[k] = i.toString();
k++;
}
i++;
});

if (j === 0 && k === 0) MinString = "`summ(phi)`";
else if (j && k === 0) MinString = "`summ(" + min.join(",") + ")`";
else if (j && k) MinString = "`summ(" + min.join(",") + ")` `+` `d(" + dontC.join(",") + ")`";
else MinString = "`summ(phi)+d(" + dontC.join(",") + ")`";

document.getElementById("Min").textContent = MinString;
MathJax.typeset();
}

//--------------EPI's to MathJAX Converter----------------//

function booleanOutput(minterms) {
let Mathjax_Output = [];
let sor = minterms.length;
let soc = minterms[0].length;
let index = 0;
if (soc == 1) {
Mathjax_Output = '0';
OutputTransfer(Mathjax_Output);
return;
}

if(minterms[0] === "(null)") return OutputTransfer('0');

else if (!(minterms[0].includes('1')) && !(minterms[0].includes('0'))) {
Mathjax_Output = '1';
OutputTransfer(Mathjax_Output);
OutputTransfer('1');
return;
}

Expand Down Expand Up @@ -181,59 +149,4 @@ function booleanOutput(minterms) {
index += 3;
}
OutputTransfer(Mathjax_Output);
}

//--------------------------------------------------------//


//---------------Minterms_Group_Generator-----------------//

var Groups, index;
var _weight, _1sweight;

function Implicants_Input(EPIs) {
Groups = [];
index = 0;
for (let i = 0; i < EPIs.length; i++) {
let PI = EPIs[i].match(/./g);
Groups.push([]);
GroupG(PI);
index++;
}
console.log(Groups); // you can use this Groups array for ring logic!!
}

function GroupG(Epi) {
_weight = [];
_1sweight = 0;
const _n = WeightG(Epi);
for (let i = 0, j, k; i < _n; i++) {
k = i;
j = 0;
let temp = 0;
while (k > 0) {
if (k % 2) temp += _weight[j];
j++;
k >>= 1;
}
temp += _1sweight;
Groups[index].push(temp);
}
}

function WeightG(Epi) {
const soc = Epi.length;
let n = 0;
for (let i = 0; i < soc; i++) {
switch (Epi[soc - i - 1]) {
case '_': _weight[n] = 2 ** i;
n++;
break;
case '1': _1sweight += 2 ** i;
break;
}
}
return 2 ** n;
}

//-------------------------------------------------------//
}
Loading

0 comments on commit 374650a

Please sign in to comment.