I am performing several max-flow computations on extremely similar networks and I seek to improve their execution time based on information from previous computations (As there is a lot of repetitive computation). The code below is from the following repository + some additional details that I've added: https://github.com/Pyomo/PyomoGallery/blob/master/maxflow/maxflow.py
I am interested in the solutions for computations which are equal to a
predefined_sum parameter. In addition I've added the
additional_rule which aims to apply a constraint that the maximum flow in the sink node should be equal to
However, this seems to slow down the computation and does not improve the running time. Does someone have information about why this happens? Additionally, please let me know if you know some additional way to speed up the computation. I was also advised that the CPLEX API offers more functionality for such improvements so if someone knows some specific resources that can be used would be very helpful.
from pyomo.environ import * model = AbstractModel() #Specified flow model.predefined_sum = pyo.Param(within=NonNegativeReals) # Nodes in the network model.N = Set() # Network arcs model.A = Set(within=model.N*model.N) # Source node model.s = Param(within=model.N) # Sink node model.t = Param(within=model.N) # Flow capacity limits model.c = Param(model.A) # The flow over each arc model.f = Var(model.A, within=NonNegativeReals) # Maximize the flow into the sink nodes def total_rule(model): return sum(model.f[i,j] for (i, j) in model.A if j == value(model.t)) model.total = Objective(rule=total_rule, sense=maximize) # Enforce an upper limit on the flow across each arc def limit_rule(model, i, j): return model.f[i,j] <= model.c[i, j] model.limit = Constraint(model.A, rule=limit_rule) # Enforce flow through each node def flow_rule(model, k): if k == value(model.s) or k == value(model.t): return Constraint.Skip inFlow = sum(model.f[i,j] for (i,j) in model.A if j == k) outFlow = sum(model.f[i,j] for (i,j) in model.A if i == k) return inFlow == outFlow model.flow = Constraint(model.N, rule=flow_rule) def additional_rule(model): return sum(model.f[i,j] for (i, j) in model.A if j == value(model.t)) == model.predefined_sum model.additional_rule = pyo.Constraint(rule=additional_rule) ```