A Python-based interactive visualizer for NP-complete problem reductions. This tool provides dynamic visualizations of problem instances and their corresponding reductions, such as 3SAT → Independent Set and 3SAT → 3-Coloring. For detailed documentation, see Documentation.pdf in the repository.
- Python 3
numpypygame
git clone git@github.com:wuwendyy/NP-reduction-visualization.git
cd NP-reduction-visualizationconda create -n npvis python=3.12
conda activate npvispip install -e .Run:
python -m tests.reduction_test.test_3sat_to_isA window will open showing:
- Left: 3SAT problem
- Right: Independent Set problem
Clicking an element in either panel highlights corresponding elements in the other. Press S to toggle solution visualization using color groups.
Run:
python -m tests.reduction_test.test_3sat_to_3colorThis visualizer allows multiple elements in the 3Color panel to correspond to one 3SAT clause. The more elements you select, the brighter the clause's highlight.
| 3 Elements Selected | 6 Elements Selected |
|---|---|
![]() |
![]() |
Element: Abstract class with methodsparse(),display(), andhandle_event().SubElement: Abstract class used for core visual components such as nodes, edges, variables, and clauses.
Basic Node for a graph
Connects two nodes with highlighting behavior.
variable.py and clause.py
Used in SAT formulas, supporting logical evaluation and color-based visualization.
Encapsulates visual representation of nodes and edges. Supports grouped node layouts and collision avoidance.
Input Format (TXT):
X1
X2
...
(X1, X2)
...
[X1, X2, X4]
| Random Graph | Grouped Graph |
|---|---|
![]() |
![]() |
Represents a 3SAT-style Boolean formula with text parsing and rendering.
Input Format:
- Literal expressions like
X1 OR NOT X2 OR X3in specific syntax.
| Basic | Colored |
|---|---|
![]() |
![]() |
Given a graph, verify if selected nodes form a valid independent set (no two connected). Supports evaluation and visual feedback.
| Default | With Solution |
|---|---|
![]() |
![]() |
for usage example:
Evaluates whether a Boolean formula with 3-literal clauses can be satisfied.
- Core visual logic powered by Pygame
- Modular architecture with reusable
Elementtypes - Input files and visual styling defined clearly for extensibility











