{"id":14483696,"url":"https://github.com/pubkey/binary-decision-diagram","last_synced_at":"2025-04-06T16:14:27.539Z","repository":{"id":37065842,"uuid":"240919941","full_name":"pubkey/binary-decision-diagram","owner":"pubkey","description":"A library to create, minimize and optimize binary decision diagrams https://github.com/pubkey/binary-decision-diagram","archived":false,"fork":false,"pushed_at":"2024-10-29T22:46:35.000Z","size":300,"stargazers_count":31,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-10-29T22:52:13.143Z","etag":null,"topics":["bdd","binary-decision-diagram","binary-decision-diagrams","binary-decision-tree","mtbdd","robdd","truth-table"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pubkey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-16T15:57:51.000Z","updated_at":"2024-10-29T22:46:23.000Z","dependencies_parsed_at":"2023-09-26T03:12:15.391Z","dependency_job_id":"ff1d8f1c-5ec7-4251-aba0-b10aae142348","html_url":"https://github.com/pubkey/binary-decision-diagram","commit_stats":{"total_commits":443,"total_committers":4,"mean_commits":110.75,"dds":"0.41986455981941306","last_synced_commit":"4628ca9cfc25d3c83860538c4adc1fa30e6f5811"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pubkey%2Fbinary-decision-diagram","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pubkey%2Fbinary-decision-diagram/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pubkey%2Fbinary-decision-diagram/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pubkey%2Fbinary-decision-diagram/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pubkey","download_url":"https://codeload.github.com/pubkey/binary-decision-diagram/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247509237,"owners_count":20950232,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bdd","binary-decision-diagram","binary-decision-diagrams","binary-decision-tree","mtbdd","robdd","truth-table"],"created_at":"2024-09-03T00:02:00.096Z","updated_at":"2025-04-06T16:14:27.516Z","avatar_url":"https://github.com/pubkey.png","language":"TypeScript","readme":"# binary decision diagram\n\nA library to **create**, **minimize** and **optimize** binary decision diagrams in JavaScript.\n\n\n\nA binary decision diagram is a data structure that represents a set of boolean function in an efficient way. To learn more about it, follow these links:\n\n- [Introduction on BDDs](https://web.archive.org/web/20110304135553/http://configit.com/fileadmin/Configit/Documents/bdd-eap.pdf)\n- [Presentation on BDDs](https://de.slideshare.net/RajeshYadav49/reduced-ordered-binary-decision-diagram-devi)\n- [Implementation of ROBDD](https://pdfs.semanticscholar.org/788d/ed39ca36300753bcb20c43762972b00f9b80.pdf)\n\n\n### Installation\n\n```bash\nnpm install binary-decision-diagram --save\n```\n\n### createBddFromTruthTable()\n\nCreates a BDD from a truth table.\nThe Truth-Table is a `Map\u003cstring, number\u003e` where the string is a truth-set like `1101` and the number is the value.\n\n```typescript\nconst truthTable = new Map();\ntruthTable.add('00', 1);\ntruthTable.add('01', 3);\ntruthTable.add('10', 2);\ntruthTable.add('11', 1);\n\nconst bdd = createBddFromTruthTable(\n    truthTable\n);\n```\n\n### minimize()\n\nReduces the nodes of a BDD by applying the reduction- and elimination rules.\n\n```typescript\nbdd.minimize(\n    false // if true, logs stuff (optional)\n);\n```\n\n### countNodes()\n\nReturns the amount of nodes of the BDD.\n\n```typescript\nbdd.countNodes(); // returns a number\n```\n\n### removeIrrelevantLeafNodes()\n\nRemoves all irrelevant leaf-nodes with the given value.\n\n```typescript\n// this will remove all leaf-nodes with the value of 5\nbdd.removeIrrelevantLeafNodes(5);\n```\n\n\n### resolve()\n\nResolves a state by calling the boolean functions through the nodes.\n\nThe resolve-functions is an object with the truth-table-value as key and a boolean function as value.\n\n```typescript\nconst resolvers: ResolverFunctions = {\n    1: (i) =\u003e true,\n    2: (i) =\u003e true,\n    3: (i) =\u003e false\n};\n```\n\n```typescript\nconst bddValue = bdd.resolve(\n    resolvers, \n    i // input that is passed to the resolvers\n); // returns a value from the truth table\n```\n\n### bddToMinimalString()\n\nReturns a string-representation of the BDD which can be used in the client side to have a small javascript-bundle.\nBDDs can be very big so an effective storage format was needed.\n\n```typescript\nconst minimalString = bddToMinimalString(bdd)\n```\n\n### minimalStringToSimpleBdd()\n\nParses the minimal string into an `SimpleBdd`. The `SimpleBdd` very small and only can resolve stuff.\n\n```typescript\nconst simpleBdd = minimalStringToSimpleBdd(str);\n```\n\n### resolveWithMinimalBdd()\n\nResolves a value with the `SimpleBdd` and the `ResolverFunctions`.\n\n```typescript\nresolveWithSimpleBdd(\n    simpleBdd,\n    resolvers,\n    key\n);\n```\n\n### optimizeBruteForce()\n\nOptimizes the sorting of the boolean functions to get an optimal BDD. Returns a promise with the best found BDD.\n\n```typescript\nconst optimizedResult = await optimizeBruteForce({\n    truthTable,\n    iterations: 10000,\n    // hook that runs whenever a bdd is created (optional)\n    afterBddCreation: (bdd: RootNode) =\u003e {\n        bdd.removeIrrelevantLeafNodes(unknownValueActionId);\n    },\n    // hook that is triggered whenever a better bdd was found (optional)\n    onBetterBdd: (res: OptimisationResult) =\u003e {\n        const bddMinimalString = bddToMinimalString(res.bdd);\n        console.log('new string: ' + bddMinimalString);\n        console.log('value mapping:');\n        console.dir(res.mapping);\n    },\n    // (optional) start with this BDD to optimize. If not set, will create an own one.\n    initialBdd: myBdd\n});\n```\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpubkey%2Fbinary-decision-diagram","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpubkey%2Fbinary-decision-diagram","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpubkey%2Fbinary-decision-diagram/lists"}