One Objective with high weight, Prints for edges and compounds used in example for presentation

This commit is contained in:
2026-09-11 12:28:40 +02:00
parent 90153c7f7e
commit 0a1bec0062
+31 -15
View File
@@ -141,6 +141,7 @@ def build_model(name, hyperedges, elmax, el1, el2, el3, excluded_support=None):
#Multiply edgelikelihood with the edge use boolean
#Adapt to have
'''
model.setObjectiveN(
quicksum(elmax[e_id] * b[e_id] for e_id in hyperedges),
index = 0,
@@ -154,7 +155,9 @@ def build_model(name, hyperedges, elmax, el1, el2, el3, excluded_support=None):
priority= 1,
name="minimize_used_hyperedges",
)
'''
model.setObjective(quicksum(1000 * elmax[e_id] * b[e_id] - x[e_id] for e_id in hyperedges),GRB.MAXIMIZE)
#Excluding creation and destruction only three reactions for three nmr
model.addConstr(quicksum(b[e_id] for e_id, (tails, heads) in hyperedges.items() if tails != [] and heads != []) == 3)
#Restrict number of used edges to prevent using all available
@@ -162,8 +165,9 @@ def build_model(name, hyperedges, elmax, el1, el2, el3, excluded_support=None):
#2 Butadien create first different molecule and it has to be created first:
startmolecule = ["Butadien"]
#model.addConstr(quicksum(b[e_id] for e_id, (tails, _) in hyperedges.items() if list(set(tails)) == startmolecule) == 1)
#Including it or not changes first and second solution (sometimes flipped)
model.addConstr(quicksum(b[e_id] for e_id, (tails, _) in hyperedges.items() if list(set(tails)) == startmolecule) == 1)
#model.addConstr(b[4] + b[7] == 1)
model.addConstr(quicksum(b[e_id] for e_id, (tails, heads) in hyperedges.items() if tails == [] and heads == startmolecule)== 1)
@@ -215,19 +219,18 @@ def main():
#Chosable parameters
modes = ["Product", "Average"]
mode = modes[1]
normalize = True
mode = modes[0]
normalize = False
if normalize:
print("test")
NMR1 = [round(l/sum(NMR1), 2) for l in NMR1]
NMR2 = [round(l/sum(NMR2), 2) for l in NMR2]
NMR3 = [round(l/sum(NMR3), 2) for l in NMR3]
print(NMR1)
print(NMR2)
print(NMR3)
#print(NMR1)
#print(NMR2)
#print(NMR3)
return
#Kombiniert Molekül it Wahrscheinlichkeit für NMR1:
VERTICE1 = {}
for vertice, likelihood in zip(VERTICES, NMR1):
@@ -269,11 +272,24 @@ def main():
EDGEMAX[edge] = max([EDGE1[edge], EDGE2[edge], EDGE3[edge]])
#print(EDGEMAX[edge], HYPERGRAPH[edge])
#print(EDGEMAX[4])
#print(EDGEMAX[23])
#print(EDGEMAX[42])
'''
#Vertices from example:
verticelist = [0,1,2,3,4,5,11,12]
print([VERTICES[a] for a in verticelist])
print([NMR1[a] for a in verticelist])
print([NMR2[a] for a in verticelist])
print([NMR3[a] for a in verticelist])
#Edges from example
print(EDGEMAX[4], HYPERGRAPH[4])
print(EDGEMAX[7], HYPERGRAPH[7])
print(EDGEMAX[13], HYPERGRAPH[13])
print(EDGEMAX[23], HYPERGRAPH[23])
print(EDGEMAX[37], HYPERGRAPH[37])
print(EDGEMAX[42], HYPERGRAPH[42])
print(EDGEMAX[67], HYPERGRAPH[67])
'''
model, x, b = build_model("HypergraphFlow", HYPERGRAPH, EDGEMAX, EDGE1, EDGE2, EDGE3)
model.optimize()
if model.status != GRB.Status.OPTIMAL: