Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gsoc'24): typescript integration in quinMcCluskey file #339

Merged
merged 3 commits into from
Jul 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
// Algorithm used for Combinational Analysis

type BooleanMinimizeType = {
minTerms: number[]
dontCares: number[]
numVars: number
result: string[]
}

export default function BooleanMinimize(
numVarsArg,
minTermsArg,
dontCaresArg = []
numVarsArg: number,
minTermsArg: number[],
dontCaresArg: number[] = []
) {
var __result
var __result: string[]

Object.defineProperties(this, {
minTerms: {
Expand Down Expand Up @@ -47,7 +54,7 @@ export default function BooleanMinimize(
}

BooleanMinimize.prototype.solve = function () {
function dec_to_binary_string(n) {
const dec_to_binary_string = (n: number) => {
var str = n.toString(2)

while (str.length != this.numVars) {
Expand All @@ -57,14 +64,14 @@ BooleanMinimize.prototype.solve = function () {
return str
}

function num_set_bits(s) {
const num_set_bits = (s: string) => {
var ans = 0
for (let i = 0; i < s.length; ++i) if (s[i] === '1') ans++
return ans
}

function get_prime_implicants(allTerms) {
var table = []
const get_prime_implicants = (allTerms: string[]) => {
var table: Set<string>[] = []
var primeImplicants = new Set()
var reduced

Expand Down Expand Up @@ -115,11 +122,11 @@ BooleanMinimize.prototype.solve = function () {
return primeImplicants
}

function get_essential_prime_implicants(primeImplicants, minTerms) {
const get_essential_prime_implicants = (primeImplicants: string[], minTerms: string[]) => {
var table = [],
column

function check_if_similar(minTerm, primeImplicant) {
const check_if_similar = (minTerm: string, primeImplicant: string) => {
for (let i = 0; i < primeImplicant.length; ++i) {
if (
primeImplicant[i] !== '-' &&
Expand All @@ -131,7 +138,7 @@ BooleanMinimize.prototype.solve = function () {
return true
}

function get_complexity(terms) {
const get_complexity = (terms: string[]) => {
var complexity = terms.length

for (let t of terms) {
Expand All @@ -146,7 +153,7 @@ BooleanMinimize.prototype.solve = function () {
return complexity
}

function isSubset(sub, sup) {
const isSubset = (sub: Set<number>, sup: Set<number>) => {
for (let i of sub) {
if (!sup.has(i)) return false
}
Expand All @@ -166,8 +173,8 @@ BooleanMinimize.prototype.solve = function () {
table.push(column)
}

var possibleSets = [],
tempSets
let possibleSets: Set<number>[] = [],
tempSets: Set<number>[]

for (let i of table[0]) {
possibleSets.push(new Set([i]))
Expand Down Expand Up @@ -216,12 +223,12 @@ BooleanMinimize.prototype.solve = function () {
return essentialImplicants
}

var minTerms = this.minTerms.map(dec_to_binary_string.bind(this))
var dontCares = this.dontCares.map(dec_to_binary_string.bind(this))
var minTerms: string[] = this.minTerms.map(dec_to_binary_string.bind(this))
var dontCares: string[] = this.dontCares.map(dec_to_binary_string.bind(this))

return get_essential_prime_implicants.call(
this,
Array.from(get_prime_implicants.call(this, minTerms.concat(dontCares))),
Array.from(get_prime_implicants.call(this, minTerms.concat(dontCares))) as string[],
minTerms
)
}
Loading