Update app.py
Browse files
app.py
CHANGED
|
@@ -31,11 +31,10 @@ def draw_graph(G, pos=None, title="Graph Visualization"):
|
|
| 31 |
nx.draw(G, pos=pos, with_labels=True, node_color='lightblue', node_size=500, font_size=10, font_weight='bold')
|
| 32 |
st.pyplot(plt)
|
| 33 |
|
|
|
|
| 34 |
def circuit_to_formula(circuit):
|
| 35 |
-
# Convert the circuit to an equivalent formula.
|
| 36 |
formula = nx.dag_to_branching(circuit)
|
| 37 |
-
# Transfer the operator or variable labels for each node from the
|
| 38 |
-
# circuit to the formula.
|
| 39 |
for v in formula:
|
| 40 |
source = formula.nodes[v]["source"]
|
| 41 |
formula.nodes[v]["label"] = circuit.nodes[source]["label"]
|
|
@@ -45,6 +44,7 @@ def circuit_to_formula(circuit):
|
|
| 45 |
def formula_to_circuit(formula):
|
| 46 |
circuit = nx.DiGraph()
|
| 47 |
node_id = 0
|
|
|
|
| 48 |
def add_formula_node(expr):
|
| 49 |
nonlocal node_id
|
| 50 |
# Create a unique node for each part of the formula
|
|
@@ -93,6 +93,7 @@ def formula_to_string(formula):
|
|
| 93 |
root = next(v for v, d in formula.in_degree() if d == 0)
|
| 94 |
return _to_string(formula, root)
|
| 95 |
|
|
|
|
| 96 |
def algorithms_circuits():
|
| 97 |
st.title("Algorithms: Circuits")
|
| 98 |
|
|
|
|
| 31 |
nx.draw(G, pos=pos, with_labels=True, node_color='lightblue', node_size=500, font_size=10, font_weight='bold')
|
| 32 |
st.pyplot(plt)
|
| 33 |
|
| 34 |
+
# Function to convert the circuit to an equivalent formula.
|
| 35 |
def circuit_to_formula(circuit):
|
|
|
|
| 36 |
formula = nx.dag_to_branching(circuit)
|
| 37 |
+
# Transfer the operator or variable labels for each node from the circuit to the formula.
|
|
|
|
| 38 |
for v in formula:
|
| 39 |
source = formula.nodes[v]["source"]
|
| 40 |
formula.nodes[v]["label"] = circuit.nodes[source]["label"]
|
|
|
|
| 44 |
def formula_to_circuit(formula):
|
| 45 |
circuit = nx.DiGraph()
|
| 46 |
node_id = 0
|
| 47 |
+
|
| 48 |
def add_formula_node(expr):
|
| 49 |
nonlocal node_id
|
| 50 |
# Create a unique node for each part of the formula
|
|
|
|
| 93 |
root = next(v for v, d in formula.in_degree() if d == 0)
|
| 94 |
return _to_string(formula, root)
|
| 95 |
|
| 96 |
+
# Main Streamlit application
|
| 97 |
def algorithms_circuits():
|
| 98 |
st.title("Algorithms: Circuits")
|
| 99 |
|