From f575d32cc91a3433de1ae65638195ef0f0ca0b75 Mon Sep 17 00:00:00 2001 From: kilian Date: Thu, 3 Sep 2026 15:31:55 +0200 Subject: [PATCH] Dateien nach "ILP/butadien" hochladen --- ILP/butadien/butadiensynthesis.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ILP/butadien/butadiensynthesis.py b/ILP/butadien/butadiensynthesis.py index 1363847..f1440eb 100644 --- a/ILP/butadien/butadiensynthesis.py +++ b/ILP/butadien/butadiensynthesis.py @@ -134,6 +134,7 @@ def build_model(name, hyperedges, vertices, nmrlikelihoodsmax, nmrlikelihoods1, #Assigns the edges a likelihood based on the products for e, (tails, heads) in hyperedges.items(): + ''' en1[e] = math.prod(n1[head] for head in heads) en2[e] = math.prod(n2[head] for head in heads) en3[e] = math.prod(n3[head] for head in heads) @@ -149,15 +150,15 @@ def build_model(name, hyperedges, vertices, nmrlikelihoodsmax, nmrlikelihoods1, en1[e] = 0.0 en2[e] = 0.0 en3[e] = 0.0 - ''' + #print(enmax[123]) #print(enmax[42]) vertices = set(v for tails, heads in hyperedges.values() for v in tails + heads) for v in vertices: - inflow = quicksum(x[e_id] * heads.count(v) for e_id, (_, heads) in hyperedges.items() if v in heads) - outflow = quicksum(x[e_id] * tails.count(v) for e_id, (tails, _) in hyperedges.items() if v in tails) + inflow = quicksum(x[e_id] * heads.count(v) for e_id, (_, heads) in hyperedges.items()) + outflow = quicksum(x[e_id] * tails.count(v) for e_id, (tails, _) in hyperedges.items()) model.addConstr(inflow == outflow, name = f"flow_conservation_{v}") for e_id, value in FIXED_FLOWS.items(): @@ -199,17 +200,17 @@ def build_model(name, hyperedges, vertices, nmrlikelihoodsmax, nmrlikelihoods1, #2 Butadien create first different molecule and it has to be created first: model.addConstr(b[4] + b[7] == 1) model.addConstr(b[213] == 1) - #model.addConstr(b[41] == 1) + model.addConstr(b[41] == 1) #Every item created has to be consumed: + ''' for mol in vertices: for edge, (heads, tails) in hyperedges.items(): count[mol] += x[edge] * (heads.count(mol) - tails.count(mol)) - #model.addConstr(count[mol] == 0) - + model.addConstr(count[mol] == 0) + ''' #No cyclic reaction pairs: - for e_id1, (heads1, tails1) in hyperedges.items(): for e_id2, (heads2, tails2) in hyperedges.items(): if (heads1, tails1) == (tails2, heads2):