Dateien nach "ILP/butadien" hochladen

This commit is contained in:
2026-09-03 15:31:55 +02:00
parent 764fb24e5f
commit f575d32cc9
+8 -7
View File
@@ -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):