{"id":29267156,"url":"https://github.com/rrsmart8/cnf-conversion-tool","last_synced_at":"2025-10-28T05:33:46.898Z","repository":{"id":261302530,"uuid":"883902815","full_name":"rrsmart8/CNF-Conversion-Tool","owner":"rrsmart8","description":"Generates the equivalent CNF formulas to be used in SAT solvers","archived":false,"fork":false,"pushed_at":"2025-04-01T18:13:53.000Z","size":2004,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-01T19:29:34.495Z","etag":null,"topics":["cnf","logical-gates","sat-solver"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rrsmart8.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-11-05T19:23:40.000Z","updated_at":"2025-04-01T18:13:57.000Z","dependencies_parsed_at":"2024-11-05T20:49:42.511Z","dependency_job_id":null,"html_url":"https://github.com/rrsmart8/CNF-Conversion-Tool","commit_stats":null,"previous_names":["rrsmart8/cnf-conversion-tool"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rrsmart8/CNF-Conversion-Tool","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrsmart8%2FCNF-Conversion-Tool","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrsmart8%2FCNF-Conversion-Tool/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrsmart8%2FCNF-Conversion-Tool/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrsmart8%2FCNF-Conversion-Tool/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rrsmart8","download_url":"https://codeload.github.com/rrsmart8/CNF-Conversion-Tool/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rrsmart8%2FCNF-Conversion-Tool/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263586054,"owners_count":23484498,"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":["cnf","logical-gates","sat-solver"],"created_at":"2025-07-04T17:16:53.861Z","updated_at":"2025-10-28T05:33:41.842Z","avatar_url":"https://github.com/rrsmart8.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Overview\nThis project is a **CNF Conversion Tool** that reads gate definitions from an input file and outputs a **Conjunctive Normal Form (CNF)** representation of the circuit. The tool handles **AND**, **OR**, and **NOT** gates, and generates the equivalent CNF formulas to be used in SAT solvers. The tool also includes a shell script to verify the output using **CaDiCaL**, a SAT solver.\n\n## Files\n\n- **main.c**: The main C source file that includes the implementation of reading gate inputs, generating CNF formulas, and writing them to an output file.\n- **checker/check.sh**: A shell script that compiles the source, runs the tool on several test cases, and uses **CaDiCaL** to check the correctness of the output.\n\n## Features\n\n- **Gate Handling**: The tool supports **AND**, **OR**, and **NOT** gates.\n- **CNF Conversion**: Converts logic gate definitions into CNF format for use in SAT solvers.\n- **Verification**: The checker script verifies the CNF using **CaDiCaL**.\n- **Error Handling**: Allocates and deallocates memory properly to prevent memory leaks.\n\n## How to Build and Run\n\n### Prerequisites\n\n- **GCC** or any compatible C compiler.\n- **Make** for build automation.\n- **CaDiCaL SAT Solver** (included in the `checker` directory).\n\n### Building the Project\n\nTo build the project, navigate to the `src` directory and run:\n\n```sh\nmake build\n```\n\nThis command will compile the source code and generate an executable.\n\n### Running the Tool\n\nTo run the CNF conversion tool:\n\n```sh\n./main \u003cinput_file\u003e \u003coutput_file\u003e\n```\n\n- `\u003cinput_file\u003e`: File containing gate definitions.\n- `\u003coutput_file\u003e`: File to write the CNF output.\n\n### Running Tests\n\nTo run the tests provided in the `checker` directory, execute the following command in the root of the project:\n\n```sh\n./checker/check.sh\n```\n\nThis script runs the executable on a set of predefined test cases and compares the results against reference outputs using **CaDiCaL**.\n\n## Input Format\n\nThe input file should start with two numbers:\n\n1. **Number of Inputs**: The number of input variables.\n2. **Last Gate Number**: The highest gate number defined.\n\nEach subsequent line should define a gate operation:\n\n- **N X Y**: Represents a **NOT** gate with input `X` and output `Y`.\n- **O X1 X2 ... Xn Y**: Represents an **OR** gate with inputs `X1, X2, ..., Xn` and output `Y`.\n- **A X1 X2 ... Xn Y**: Represents an **AND** gate with inputs `X1, X2, ..., Xn` and output `Y`.\n\n## Output Format\n\nThe output is written in **DIMACS** CNF format:\n\n- The first line follows the convention:\n\n  ```\n  p cnf \u003cnumber_of_variables\u003e \u003cnumber_of_clauses\u003e\n  ```\n\n- Each subsequent line contains a clause followed by `0`.\n- The last gate is written as an assertion.\n\n## Example\n\n### Input\n```\n3\n4\nN 1 4\nA 1 2 3 5\nO 4 5 6\n```\n\n### Output\n```\np cnf 6 4\n-1 -4 0\n1 4 0\n-1 -2 -3 5 0\n-4 5 0\n```\n\n## Checker Script Details\n\nThe **checker/check.sh** script is used to run automated tests to validate the output. It consists of the following steps:\n\n1. **Compilation**: Compiles the source code using `make build`.\n2. **Execution**: Runs the executable against the input files located in `checker/in/`.\n3. **Verification**: Uses **CaDiCaL** to verify if the output is satisfiable or unsatisfiable and compares it with reference outputs (`.ref` files).\n\nThe script outputs the result of each test (`PASS`, `FAIL`, `TLE` for timeout) and calculates the total score.\n\n## Memory Management\n\nThe program ensures proper **memory allocation and deallocation**:\n\n- The `gate_list` is allocated dynamically to hold gate definitions.\n- Functions like `destroy_gate_list()` and `free()` are used to release the allocated memory to prevent memory leaks.\n\n## Limitations and Future Improvements\n\n- **Gate Limitations**: The number of gates is currently limited to **100** and inputs to **60**. This could be made dynamic based on input requirements.\n- **Concurrency**: The current implementation processes gates sequentially. Future versions could introduce parallelism for more efficient handling of larger circuits.\n\n## License\n\nThis project is open source and can be freely modified and distributed.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frrsmart8%2Fcnf-conversion-tool","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frrsmart8%2Fcnf-conversion-tool","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frrsmart8%2Fcnf-conversion-tool/lists"}