Problem 7.3

Problem 7.3#

Integrated Energy Grids

Problem 7.3

[This problem has been slightly modified from the exercise sheet to alleviate solve issues.] Assume the gas transport system that is shown in Figure 2. Gas can be injected in Node 1 at a marginal price of 10 EUR/kg or at Node 5 at 15 EUR/kg. There is a demand of 400 kg/s in Node 4. Finally, Node 2-3 represents a pumping station where gas pressure can be increased by \(k_{23}\)=1.2 at a cost that is proportional to the mass flow \(m_{23}\) by a constant \(o_{23}\) =5 EUR/kg.

To calculate the speed of sound in gas \(c\), assume the universal gas constant \(R\)=8.314 J/molK, the molar mass of methane \(M\)=16 g/mol, compression factor \(Z\)=1.31, and temperature T=25\(^{\circ}\)C. Assume the diameter of the pipelines is \(D\) = 1000 mm, the length \(L_{12}\)=\(L_{34}\)=\(L_{45}\)=1000 m, and calculate the Darcy friction coefficient \(f_{D}\) assuming fully-turbulent flow and roughness \(\epsilon\)=0.001m.

(a) Write the equations of the optimization problem that minimizes the total system cost and use the Weymouth equation to represent pressure drop in the pipelines as a function of the mass flow \(m_{ij}\).

We define the pressure at differet node as \(\pi_i\) and the mass flow at different pipes as \(m_{ij}\) We have 9 variables (\(m_{12}\), \(m_{23}\), \(m_{34}\), \(m_{45}\), \(\pi_1\), \(\pi_2\), \(\pi_3\), \(\pi_4\), \(\pi_5\)).

We impose the energy balance constraint in nodes 1, 4 and 5, and the pipeline mass conservation and Weymouth equation in pipelines 12, 34 and 45.

\[\begin{alignat*}{3} \min_{x,y} \quad & o_1g_1 + o_5g_5 +o_{23}m_{23} & \\ \text{s.t.} \quad & g_{1}=m_{12} \\ \quad & -d_{4}=-m_{34}+m_{45} \\ \quad & g_{5}=-m_{45} \\ \quad & m_{12}=m_{23} \\ \quad & m_{23}=m_{34} \\ \quad & m_{34}=m_{45} \\ \quad & \pi_{3}=k_{23}\pi_{2} \\ \quad & \pi_{1}^2-\pi_{2}^2=a_{12}m_{12} |m_{12} | \\ \quad & \pi_{3}^2-\pi_{4}^2=a_{34}m_{34} |m_{34} | \\ \quad & \pi_{4}^2-\pi_{5}^2=a_{45}m_{45} |m_{34} | \\ \end{alignat*}\]

where the coefficients \(a_{ij}=\frac{Lf^Dc^2}{DA^2}\) depend on the physical properties of the pipelines and the methane gas.

(b) Use gurobipy to formulate and solve the problem. Solve the problem for two extra cases of : \(o_{23}\) =1 EUR/kg and \(o_{23}\) =10 EUR/kg and compare the results.

Hint: It is usefull to define logical boundaries for the problem to make the optimisation faster. For example, we assume the pressure at all nodes to be between [0, 100 kPa], which is an acceptable range as pressure in gas pipelines is usually in the range of 30-100 kpa.

We start by calculating the cofficients \(a_{ij}\) from the Weymouth equation

import numpy as np

The cross-sectional area \(A\), and the speed of sound in gas \(c\), can be calculated as

D = 1 # m

Z = 1.31
R = 8.314 # J/molk
M = 0.016 # Kg/mol
T = 273+25 # K

A = np.pi*(D/2)**2
c=np.sqrt(Z*R*T/M)
c
450.3900615022494

The Darcy friction coefficient can be calculated as \(\frac{1}{\sqrt f_D}=-2log_{10}(\frac{\epsilon}{3.7D})\)

epsilon = 0.001 #m

f_D=(1/(-2*np.log10(epsilon/(3.7*D))))**2
f_D
0.0196354659355267

The coefficients from the Weymouth equation can be calculated as \(a_{ij}=\frac{Lf_Dc^2}{DA^2}\)

L = 1000 #km 
L_12=L
a_12=L_12*f_D*c**2/(D*A**2)
a_34=a_12
a_45=a_12
a_12
6457122.799219107

We import gurobipy and write the problem

import gurobipy as gp
from gurobipy import GRB
k_23 = 1.2
d_4 = 400 #kg/s
o_1 = 10 #EUR/kg
o_5 = 15 #EUR/kg
o_m23 = 5 #EUR/kg   

model = gp.Model("My_quadratic_problem")
g_1 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, name="g_1")
g_5 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, name="g_5")

m_12 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, ub=d_4, name="m_12")
m_23 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, ub=d_4, name="m_23")
m_34 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, ub=d_4, name="m_34")
m_45 = model.addVar(vtype=GRB.CONTINUOUS, lb=-d_4, ub=0,  name="m_45")

abs_m_12 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, name="abs_m_12")
abs_m_34 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, name="abs_m_34")
abs_m_45 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, name="abs_m_45")

p_1 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, ub=100*1e5, name="p_1")  
p_2 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, ub=100*1e5, name="p_2")
p_3 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, ub=100*1e5, name="p_3")
p_4 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, ub=100*1e5, name="p_4")  
p_5 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, ub=100*1e5, name="p_5") 

model.setObjective(o_1*g_1 + o_5*g_5 + o_m23*m_23, GRB.MINIMIZE)

constraint_a = model.addLConstr(g_1 == m_12)
constraint_b = model.addLConstr(-g_5 == m_45)
constraint_c = model.addLConstr(-d_4 == -m_34+m_45)
constraint_d = model.addLConstr(m_12 == m_23)
constraint_e = model.addLConstr(m_12 == m_34)
constraint_f = model.addLConstr(p_3 == k_23*p_2)
#constraint_g = model.addLConstr(p_4 == p4)

# We need to define additional constraints to use absolute values
from gurobipy import abs_
model.addConstr(abs_m_12 == abs_(m_12), name='abs_m_12')
model.addConstr(abs_m_34 == abs_(m_34), name='abs_m_34')
model.addConstr(abs_m_45 == abs_(m_45), name='abs_m_45')
constraint_h  = model.addQConstr(a_12*m_12*abs_m_12 == p_1**2-p_2**2)
constraint_j  = model.addQConstr(a_34*m_34*abs_m_34 == p_3**2-p_4**2)
constraint_k  = model.addQConstr(a_45*m_45*abs_m_45 == p_4**2-p_5**2)

model.setParam("Method", 2)  # We use the barrier method, Barrier is ideal for quadratic / conic problems and numerically unstable models
model.optimize()
Set parameter TokenServer to value "sophia1.hpc.ait.dtu.dk"
Set parameter Method to value 2
Gurobi Optimizer version 11.0.2 build v11.0.2rc0 (linux64 - "CentOS Linux 7 (Core)")

CPU model: AMD EPYC 7351 16-Core Processor, instruction set [SSE2|AVX|AVX2]
Thread count: 32 physical cores, 32 logical processors, using up to 32 threads

Optimize a model with 6 rows, 14 columns and 12 nonzeros
Model fingerprint: 0xac4bb344
Model has 3 quadratic constraints
Model has 3 general constraints
Variable types: 14 continuous, 0 integer (0 binary)
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  QMatrix range    [1e+00, 6e+06]
  Objective range  [5e+00, 2e+01]
  Bounds range     [4e+02, 1e+07]
  RHS range        [4e+02, 4e+02]
Presolve removed 5 rows and 8 columns
Presolve time: 0.00s
Presolved: 22 rows, 12 columns, 41 nonzeros
Presolved model has 6 bilinear constraint(s)

Solving non-convex MIQCP

Variable types: 12 continuous, 0 integer (0 binary)
Root barrier log...

Ordering time: 0.00s

Barrier statistics:
 AA' NZ     : 6.000e+00
 Factor NZ  : 1.000e+01
 Factor Ops : 3.000e+01 (less than 1 second per iteration)
 Threads    : 1

                  Objective                Residual
Iter       Primal          Dual         Primal    Dual     Compl     Time
   0   6.00000000e+03 -6.31598434e+03  6.79e+04 0.00e+00  7.31e+03     0s
   1   6.00000000e+03 -3.40669849e+03  0.00e+00 6.94e-18  9.41e+02     0s
   2   6.00000000e+03  5.99059330e+03  0.00e+00 6.94e-18  9.41e-01     0s
   3   6.00000000e+03  5.99999059e+03  0.00e+00 0.00e+00  9.41e-04     0s
   4   6.00000000e+03  5.99999999e+03  0.00e+00 4.37e-24  9.41e-07     0s
   5   6.00000000e+03  6.00000000e+03  0.00e+00 3.04e-24  9.41e-10     0s

Barrier solved model in 5 iterations and 0.09 seconds (0.00 work units)
Optimal objective 6.00000000e+03


Root relaxation: objective 6.000000e+03, 4 iterations, 0.01 seconds (0.00 work units)

    Nodes    |    Current Node    |     Objective Bounds      |     Work
 Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

     0     0 6000.00000    0    6          - 6000.00000      -     -    0s
     0     0 6000.00000    0    6          - 6000.00000      -     -    0s
     0     2 6000.00000    0    6          - 6000.00000      -     -    0s
H  192   100                    6000.0000000 6000.00000  0.00%   1.3    0s

Explored 245 nodes (312 simplex iterations) in 0.15 seconds (0.00 work units)
Thread count was 32 (of 32 available processors)

Solution count 1: 6000 

Optimal solution found (tolerance 1.00e-04)
Best objective 6.000000000000e+03, best bound 6.000000000000e+03, gap 0.0000%
print(str(g_1.VarName) + ' ' + str(g_1.x))
print(str(g_5.VarName) + ' ' + str(g_5.x))

print(str(m_12.VarName) + ' ' + str(m_12.x))
print(str(m_23.VarName) + ' ' + str(m_23.x))
print(str(m_34.VarName) + ' ' + str(m_34.x))
print(str(m_45.VarName) + ' ' + str(m_45.x))
                                   
print(str(p_1.VarName) + ' ' + str(round(p_1.x)) + ' Pa')
print(str(p_2.VarName) + ' ' + str(round(p_2.x)) + ' Pa')
print(str(p_3.VarName) + ' ' + str(round(p_3.x)) + ' Pa')
print(str(p_4.VarName) + ' ' + str(round(p_4.x)) + ' Pa')
print(str(p_5.VarName) + ' ' + str(round(p_5.x)) + ' Pa')
g_1 200.0
g_5 200.0
m_12 200.0
m_23 200.0
m_34 200.0
m_45 -200.0
p_1 2170327 Pa
p_2 2109985 Pa
p_3 2531981 Pa
p_4 2480453 Pa
p_5 2531981 Pa

We can also solve for different compressor costs:

flows_g1=[]
flows_g5=[]

for o_m23 in [0,1,2,3,4, 5, 6 ,10, 15] : #EUR/kg   
    #model.setParam("MIPFocus", 1)
    #model.setParam("Threads", 1)
    #model.setParam("Seed", 0)  
    model = gp.Model("My_quadratic_problem")
    g_1 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, name="g_1")
    g_5 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, name="g_5")
    
    m_12 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, ub=d_4, name="m_12")
    m_23 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, ub=d_4, name="m_23")
    m_34 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, ub=d_4, name="m_34")
    m_45 = model.addVar(vtype=GRB.CONTINUOUS, lb=-d_4, ub=0,  name="m_45")
    
    abs_m_12 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, name="abs_m_12")
    abs_m_34 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, name="abs_m_34")
    abs_m_45 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, name="abs_m_45")
    
    p_1 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, ub=100*1e5, name="p_1")
    p_2 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, ub=100*1e5, name="p_2")
    p_3 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, ub=100*1e5, name="p_3")
    p_4 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, ub=100*1e5, name="p_4")  
    p_5 = model.addVar(vtype=GRB.CONTINUOUS, lb=0, ub=100*1e5, name="p_5") 
    
    model.setObjective(o_1*g_1 + o_5*g_5 + o_m23*m_23, GRB.MINIMIZE)
    
    constraint_a = model.addLConstr(g_1 == m_12)
    constraint_b = model.addLConstr(-g_5 == m_45)
    constraint_c = model.addLConstr(-d_4 == -m_34+m_45)
    constraint_d = model.addLConstr(m_12 == m_23)
    constraint_e = model.addLConstr(m_12 == m_34)
    constraint_f = model.addLConstr(p_3 == k_23*p_2)
    #constraint_g = model.addLConstr(p_4 == p4)
    
    # We need to define additional constraints to use absolute values
    from gurobipy import abs_
    model.addConstr(abs_m_12 == abs_(m_12), name='abs_m_12')
    model.addConstr(abs_m_34 == abs_(m_34), name='abs_m_34')
    model.addConstr(abs_m_45 == abs_(m_45), name='abs_m_45')
    constraint_h  = model.addQConstr(a_12*m_12*abs_m_12 == p_1**2-p_2**2)
    constraint_j  = model.addQConstr(a_34*m_34*abs_m_34 == p_3**2-p_4**2)
    constraint_k  = model.addQConstr(a_45*m_45*abs_m_45 == p_4**2-p_5**2)
    
    model.setParam("Method", 2)  # barrier
    model.optimize()
    flows_g1.append(g_1.x)
    flows_g5.append(g_5.x)
Set parameter Method to value 2
Gurobi Optimizer version 11.0.2 build v11.0.2rc0 (linux64 - "CentOS Linux 7 (Core)")

CPU model: AMD EPYC 7351 16-Core Processor, instruction set [SSE2|AVX|AVX2]
Thread count: 32 physical cores, 32 logical processors, using up to 32 threads

Optimize a model with 6 rows, 14 columns and 12 nonzeros
Model fingerprint: 0xcf560096
Model has 3 quadratic constraints
Model has 3 general constraints
Variable types: 14 continuous, 0 integer (0 binary)
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  QMatrix range    [1e+00, 6e+06]
  Objective range  [1e+01, 2e+01]
  Bounds range     [4e+02, 1e+07]
  RHS range        [4e+02, 4e+02]
Presolve removed 5 rows and 8 columns
Presolve time: 0.00s
Presolved: 22 rows, 12 columns, 41 nonzeros
Presolved model has 6 bilinear constraint(s)

Solving non-convex MIQCP

Variable types: 12 continuous, 0 integer (0 binary)
Root barrier log...

Ordering time: 0.00s

Barrier statistics:
 AA' NZ     : 6.000e+00
 Factor NZ  : 1.000e+01
 Factor Ops : 3.000e+01 (less than 1 second per iteration)
 Threads    : 1

                  Objective                Residual
Iter       Primal          Dual         Primal    Dual     Compl     Time
   0   5.35609179e+03 -8.31598434e+03  8.21e+04 0.00e+00  8.00e+03     0s
   1   4.89547077e+03 -5.52790984e+03  0.00e+00 6.94e-18  1.04e+03     0s
   2   4.71641154e+03  3.85457112e+03  0.00e+00 0.00e+00  8.62e+01     0s
   3   4.01781083e+03  3.97814377e+03  0.00e+00 1.83e-19  3.97e+00     0s
   4   4.00001744e+03  3.99997777e+03  0.00e+00 2.39e-18  3.97e-03     0s
   5   4.00000002e+03  3.99999998e+03  0.00e+00 6.61e-19  3.97e-06     0s
   6   4.00000000e+03  4.00000000e+03  0.00e+00 1.73e-18  3.97e-09     0s
   7   4.00000000e+03  4.00000000e+03  0.00e+00 0.00e+00  3.97e-12     0s

Barrier solved model in 7 iterations and 0.02 seconds (0.00 work units)
Optimal objective 4.00000000e+03

Extra simplex iterations after uncrush: 1

Root relaxation: objective 4.000000e+03, 5 iterations, 0.01 seconds (0.00 work units)

    Nodes    |    Current Node    |     Objective Bounds      |     Work
 Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

     0     0 4000.00000    0    4          - 4000.00000      -     -    0s
     0     0 4000.00000    0    4          - 4000.00000      -     -    0s
     0     2 4000.00000    0    4          - 4000.00000      -     -    0s
* 5709  4512              86    4001.2022489 4000.00000  0.03%   1.6    0s
* 8022  4512              75    4001.1937597 4000.00000  0.03%   1.6    0s
H 9520  3579                    4000.0000000 4000.00000  0.00%   1.6    0s

Explored 9520 nodes (15651 simplex iterations) in 0.29 seconds (0.01 work units)
Thread count was 32 (of 32 available processors)

Solution count 3: 4000 4001.19 4001.2 

Optimal solution found (tolerance 1.00e-04)
Warning: max constraint violation (7.8125e-03) exceeds tolerance
Best objective 4.000000000002e+03, best bound 4.000000000000e+03, gap 0.0000%
Set parameter Method to value 2
Gurobi Optimizer version 11.0.2 build v11.0.2rc0 (linux64 - "CentOS Linux 7 (Core)")

CPU model: AMD EPYC 7351 16-Core Processor, instruction set [SSE2|AVX|AVX2]
Thread count: 32 physical cores, 32 logical processors, using up to 32 threads

Optimize a model with 6 rows, 14 columns and 12 nonzeros
Model fingerprint: 0x66dccb5e
Model has 3 quadratic constraints
Model has 3 general constraints
Variable types: 14 continuous, 0 integer (0 binary)
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  QMatrix range    [1e+00, 6e+06]
  Objective range  [1e+00, 2e+01]
  Bounds range     [4e+02, 1e+07]
  RHS range        [4e+02, 4e+02]
Presolve removed 5 rows and 8 columns
Presolve time: 0.00s
Presolved: 22 rows, 12 columns, 41 nonzeros
Presolved model has 6 bilinear constraint(s)

Solving non-convex MIQCP

Variable types: 12 continuous, 0 integer (0 binary)
Root barrier log...

Ordering time: 0.00s

Barrier statistics:
 AA' NZ     : 6.000e+00
 Factor NZ  : 1.000e+01
 Factor Ops : 3.000e+01 (less than 1 second per iteration)
 Threads    : 1

                  Objective                Residual
Iter       Primal          Dual         Primal    Dual     Compl     Time
   0   5.48366463e+03 -7.91598434e+03  8.18e+04 0.00e+00  7.98e+03     0s
   1   5.12990779e+03 -5.26355510e+03  0.00e+00 1.04e-17  1.04e+03     0s
   2   5.01409384e+03  4.27185040e+03  0.00e+00 3.47e-18  7.42e+01     0s
   3   4.41859263e+03  4.37739470e+03  0.00e+00 1.73e-18  4.12e+00     0s
   4   4.40001817e+03  4.39997693e+03  0.00e+00 2.17e-19  4.12e-03     0s
   5   4.40000002e+03  4.39999998e+03  0.00e+00 4.70e-13  4.12e-06     0s
   6   4.40000000e+03  4.40000000e+03  0.00e+00 4.98e-16  4.12e-09     0s
   7   4.40000000e+03  4.40000000e+03  0.00e+00 1.08e-18  4.12e-12     0s

Barrier solved model in 7 iterations and 0.02 seconds (0.00 work units)
Optimal objective 4.40000000e+03

Extra simplex iterations after uncrush: 1

Root relaxation: objective 4.400000e+03, 5 iterations, 0.01 seconds (0.00 work units)

    Nodes    |    Current Node    |     Objective Bounds      |     Work
 Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

     0     0 4400.00000    0    4          - 4400.00000      -     -    0s
     0     0 4400.00000    0    4          - 4400.00000      -     -    0s
H    0     0                    4400.0067500 4400.00000  0.00%     -    0s

Explored 1 nodes (5 simplex iterations) in 0.03 seconds (0.00 work units)
Thread count was 32 (of 32 available processors)

Solution count 1: 4400.01 

Optimal solution found (tolerance 1.00e-04)
Best objective 4.400006749972e+03, best bound 4.400000000000e+03, gap 0.0002%
Set parameter Method to value 2
Gurobi Optimizer version 11.0.2 build v11.0.2rc0 (linux64 - "CentOS Linux 7 (Core)")

CPU model: AMD EPYC 7351 16-Core Processor, instruction set [SSE2|AVX|AVX2]
Thread count: 32 physical cores, 32 logical processors, using up to 32 threads

Optimize a model with 6 rows, 14 columns and 12 nonzeros
Model fingerprint: 0xa6aa52a3
Model has 3 quadratic constraints
Model has 3 general constraints
Variable types: 14 continuous, 0 integer (0 binary)
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  QMatrix range    [1e+00, 6e+06]
  Objective range  [2e+00, 2e+01]
  Bounds range     [4e+02, 1e+07]
  RHS range        [4e+02, 4e+02]
Presolve removed 5 rows and 8 columns
Presolve time: 0.00s
Presolved: 22 rows, 12 columns, 41 nonzeros
Presolved model has 6 bilinear constraint(s)

Solving non-convex MIQCP

Variable types: 12 continuous, 0 integer (0 binary)
Root barrier log...

Ordering time: 0.00s

Barrier statistics:
 AA' NZ     : 6.000e+00
 Factor NZ  : 1.000e+01
 Factor Ops : 3.000e+01 (less than 1 second per iteration)
 Threads    : 1

                  Objective                Residual
Iter       Primal          Dual         Primal    Dual     Compl     Time
   0   5.61130636e+03 -7.51598434e+03  8.14e+04 0.00e+00  7.95e+03     0s
   1   5.35762853e+03 -4.99243168e+03  0.00e+00 6.94e-18  1.04e+03     0s
   2   5.29184568e+03  4.69491452e+03  0.00e+00 0.00e+00  5.97e+01     0s
   3   4.81814867e+03  4.77608199e+03  0.00e+00 3.25e-19  4.21e+00     0s
   4   4.80001789e+03  4.79997550e+03  0.00e+00 1.63e-18  4.24e-03     0s
   5   4.80000002e+03  4.79999998e+03  0.00e+00 6.88e-19  4.24e-06     0s
   6   4.80000000e+03  4.80000000e+03  0.00e+00 0.00e+00  4.24e-09     0s
   7   4.80000000e+03  4.80000000e+03  0.00e+00 3.87e-19  4.24e-12     0s

Barrier solved model in 7 iterations and 0.02 seconds (0.00 work units)
Optimal objective 4.80000000e+03

Extra simplex iterations after uncrush: 1

Root relaxation: objective 4.800000e+03, 5 iterations, 0.01 seconds (0.00 work units)

    Nodes    |    Current Node    |     Objective Bounds      |     Work
 Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

     0     0 4800.00000    0    4          - 4800.00000      -     -    0s
     0     0 4800.00000    0    4          - 4800.00000      -     -    0s
     0     2 4800.00000    0    4          - 4800.00000      -     -    0s
* 8908  4732              76    4800.6758245 4800.00000  0.01%   1.6    0s

Explored 10351 nodes (16856 simplex iterations) in 0.25 seconds (0.01 work units)
Thread count was 32 (of 32 available processors)

Solution count 1: 4800.68 

Optimal solution found (tolerance 1.00e-04)
Warning: max constraint violation (2.4414e-04) exceeds tolerance
Best objective 4.800675824507e+03, best bound 4.800675824507e+03, gap 0.0000%
Set parameter Method to value 2
Gurobi Optimizer version 11.0.2 build v11.0.2rc0 (linux64 - "CentOS Linux 7 (Core)")

CPU model: AMD EPYC 7351 16-Core Processor, instruction set [SSE2|AVX|AVX2]
Thread count: 32 physical cores, 32 logical processors, using up to 32 threads

Optimize a model with 6 rows, 14 columns and 12 nonzeros
Model fingerprint: 0xf89c6754
Model has 3 quadratic constraints
Model has 3 general constraints
Variable types: 14 continuous, 0 integer (0 binary)
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  QMatrix range    [1e+00, 6e+06]
  Objective range  [3e+00, 2e+01]
  Bounds range     [4e+02, 1e+07]
  RHS range        [4e+02, 4e+02]
Presolve removed 5 rows and 8 columns
Presolve time: 0.00s
Presolved: 22 rows, 12 columns, 41 nonzeros
Presolved model has 6 bilinear constraint(s)

Solving non-convex MIQCP

Variable types: 12 continuous, 0 integer (0 binary)
Root barrier log...

Ordering time: 0.00s

Barrier statistics:
 AA' NZ     : 6.000e+00
 Factor NZ  : 1.000e+01
 Factor Ops : 3.000e+01 (less than 1 second per iteration)
 Threads    : 1

                  Objective                Residual
Iter       Primal          Dual         Primal    Dual     Compl     Time
   0   5.73910355e+03 -7.11598434e+03  8.07e+04 0.00e+00  7.90e+03     0s
   1   5.57850009e+03 -4.70322109e+03  0.00e+00 1.39e-17  1.03e+03     0s
   2   5.54896076e+03  5.12499969e+03  0.00e+00 6.94e-18  4.24e+01     0s
   3   5.21555996e+03  5.18053470e+03  0.00e+00 2.17e-19  3.50e+00     0s
   4   5.20001580e+03  5.19998001e+03  0.00e+00 2.53e-19  3.58e-03     0s
   5   5.20000002e+03  5.19999998e+03  0.00e+00 3.68e-13  3.58e-06     0s
   6   5.20000000e+03  5.20000000e+03  0.00e+00 4.58e-16  3.58e-09     0s
   7   5.20000000e+03  5.20000000e+03  0.00e+00 4.34e-19  3.58e-12     0s

Barrier solved model in 7 iterations and 0.02 seconds (0.00 work units)
Optimal objective 5.20000000e+03

Extra simplex iterations after uncrush: 1

Root relaxation: objective 5.200000e+03, 5 iterations, 0.01 seconds (0.00 work units)

    Nodes    |    Current Node    |     Objective Bounds      |     Work
 Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

     0     0 5200.00000    0    4          - 5200.00000      -     -    0s
     0     0 5200.00000    0    4          - 5200.00000      -     -    0s
     0     2 5200.00000    0    4          - 5200.00000      -     -    0s
* 4948  5005             118    5200.0000000 5200.00000  0.00%   1.6    0s

Explored 11567 nodes (18646 simplex iterations) in 0.25 seconds (0.01 work units)
Thread count was 32 (of 32 available processors)

Solution count 1: 5200 

Optimal solution found (tolerance 1.00e-04)
Warning: max constraint violation (3.8147e-04) exceeds tolerance
Best objective 5.200000000021e+03, best bound 5.200000000021e+03, gap 0.0000%
Set parameter Method to value 2
Gurobi Optimizer version 11.0.2 build v11.0.2rc0 (linux64 - "CentOS Linux 7 (Core)")

CPU model: AMD EPYC 7351 16-Core Processor, instruction set [SSE2|AVX|AVX2]
Thread count: 32 physical cores, 32 logical processors, using up to 32 threads

Optimize a model with 6 rows, 14 columns and 12 nonzeros
Model fingerprint: 0xcee932d4
Model has 3 quadratic constraints
Model has 3 general constraints
Variable types: 14 continuous, 0 integer (0 binary)
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  QMatrix range    [1e+00, 6e+06]
  Objective range  [4e+00, 2e+01]
  Bounds range     [4e+02, 1e+07]
  RHS range        [4e+02, 4e+02]
Presolve removed 5 rows and 8 columns
Presolve time: 0.00s
Presolved: 22 rows, 12 columns, 41 nonzeros
Presolved model has 6 bilinear constraint(s)

Solving non-convex MIQCP

Variable types: 12 continuous, 0 integer (0 binary)
Root barrier log...

Ordering time: 0.00s

Barrier statistics:
 AA' NZ     : 6.000e+00
 Factor NZ  : 1.000e+01
 Factor Ops : 3.000e+01 (less than 1 second per iteration)
 Threads    : 1

                  Objective                Residual
Iter       Primal          Dual         Primal    Dual     Compl     Time
   0   5.86739250e+03 -6.71598434e+03  7.89e+04 0.00e+00  7.81e+03     0s
   1   5.79243327e+03 -4.35146449e+03  0.00e+00 4.51e-17  1.01e+03     0s
   2   5.78491928e+03  5.56129062e+03  0.00e+00 6.29e-18  2.24e+01     0s
   3   5.60951100e+03  5.58885407e+03  0.00e+00 0.00e+00  2.07e+00     0s
   4   5.60001029e+03  5.59998854e+03  0.00e+00 3.25e-19  2.18e-03     0s
   5   5.60000001e+03  5.59999999e+03  0.00e+00 6.27e-13  2.18e-06     0s
   6   5.60000000e+03  5.60000000e+03  0.00e+00 7.72e-16  2.18e-09     0s
   7   5.60000000e+03  5.60000000e+03  0.00e+00 8.67e-19  2.18e-12     0s

Barrier solved model in 7 iterations and 0.02 seconds (0.00 work units)
Optimal objective 5.60000000e+03

Extra simplex iterations after uncrush: 1

Root relaxation: objective 5.600000e+03, 5 iterations, 0.01 seconds (0.00 work units)

    Nodes    |    Current Node    |     Objective Bounds      |     Work
 Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

     0     0 5600.00000    0    4          - 5600.00000      -     -    0s
     0     0 5600.00000    0    4          - 5600.00000      -     -    0s
     0     2 5600.00000    0    4          - 5600.00000      -     -    0s
H 4467  1927                    5600.0006928 5600.00000  0.00%   1.6    0s

Explored 4467 nodes (7189 simplex iterations) in 0.19 seconds (0.01 work units)
Thread count was 32 (of 32 available processors)

Solution count 1: 5600 

Optimal solution found (tolerance 1.00e-04)
Warning: max constraint violation (3.9062e-03) exceeds tolerance
Best objective 5.600000692807e+03, best bound 5.600000000000e+03, gap 0.0000%
Set parameter Method to value 2
Gurobi Optimizer version 11.0.2 build v11.0.2rc0 (linux64 - "CentOS Linux 7 (Core)")

CPU model: AMD EPYC 7351 16-Core Processor, instruction set [SSE2|AVX|AVX2]
Thread count: 32 physical cores, 32 logical processors, using up to 32 threads

Optimize a model with 6 rows, 14 columns and 12 nonzeros
Model fingerprint: 0xac4bb344
Model has 3 quadratic constraints
Model has 3 general constraints
Variable types: 14 continuous, 0 integer (0 binary)
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  QMatrix range    [1e+00, 6e+06]
  Objective range  [5e+00, 2e+01]
  Bounds range     [4e+02, 1e+07]
  RHS range        [4e+02, 4e+02]
Presolve removed 5 rows and 8 columns
Presolve time: 0.00s
Presolved: 22 rows, 12 columns, 41 nonzeros
Presolved model has 6 bilinear constraint(s)

Solving non-convex MIQCP

Variable types: 12 continuous, 0 integer (0 binary)
Root barrier log...

Ordering time: 0.00s

Barrier statistics:
 AA' NZ     : 6.000e+00
 Factor NZ  : 1.000e+01
 Factor Ops : 3.000e+01 (less than 1 second per iteration)
 Threads    : 1

                  Objective                Residual
Iter       Primal          Dual         Primal    Dual     Compl     Time
   0   6.00000000e+03 -6.31598434e+03  6.79e+04 0.00e+00  7.31e+03     0s
   1   6.00000000e+03 -3.40669849e+03  0.00e+00 6.94e-18  9.41e+02     0s
   2   6.00000000e+03  5.99059330e+03  0.00e+00 6.94e-18  9.41e-01     0s
   3   6.00000000e+03  5.99999059e+03  0.00e+00 0.00e+00  9.41e-04     0s
   4   6.00000000e+03  5.99999999e+03  0.00e+00 4.37e-24  9.41e-07     0s
   5   6.00000000e+03  6.00000000e+03  0.00e+00 3.04e-24  9.41e-10     0s

Barrier solved model in 5 iterations and 0.01 seconds (0.00 work units)
Optimal objective 6.00000000e+03


Root relaxation: objective 6.000000e+03, 4 iterations, 0.01 seconds (0.00 work units)

    Nodes    |    Current Node    |     Objective Bounds      |     Work
 Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

     0     0 6000.00000    0    6          - 6000.00000      -     -    0s
     0     0 6000.00000    0    6          - 6000.00000      -     -    0s
     0     2 6000.00000    0    6          - 6000.00000      -     -    0s
H  192   100                    6000.0000000 6000.00000  0.00%   1.3    0s

Explored 245 nodes (312 simplex iterations) in 0.05 seconds (0.00 work units)
Thread count was 32 (of 32 available processors)

Solution count 1: 6000 

Optimal solution found (tolerance 1.00e-04)
Best objective 6.000000000000e+03, best bound 6.000000000000e+03, gap 0.0000%
Set parameter Method to value 2
Gurobi Optimizer version 11.0.2 build v11.0.2rc0 (linux64 - "CentOS Linux 7 (Core)")

CPU model: AMD EPYC 7351 16-Core Processor, instruction set [SSE2|AVX|AVX2]
Thread count: 32 physical cores, 32 logical processors, using up to 32 threads

Optimize a model with 6 rows, 14 columns and 12 nonzeros
Model fingerprint: 0x1c94ba1b
Model has 3 quadratic constraints
Model has 3 general constraints
Variable types: 14 continuous, 0 integer (0 binary)
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  QMatrix range    [1e+00, 6e+06]
  Objective range  [6e+00, 2e+01]
  Bounds range     [4e+02, 1e+07]
  RHS range        [4e+02, 4e+02]
Presolve removed 5 rows and 8 columns
Presolve time: 0.00s
Presolved: 22 rows, 12 columns, 41 nonzeros
Presolved model has 6 bilinear constraint(s)

Solving non-convex MIQCP

Variable types: 12 continuous, 0 integer (0 binary)
Root barrier log...

Ordering time: 0.00s

Barrier statistics:
 AA' NZ     : 6.000e+00
 Factor NZ  : 1.000e+01
 Factor Ops : 3.000e+01 (less than 1 second per iteration)
 Threads    : 1

                  Objective                Residual
Iter       Primal          Dual         Primal    Dual     Compl     Time
   0   6.14782407e+03 -5.91598434e+03  6.65e+04 1.95e-03  7.23e+03     0s
   1   6.20341015e+03 -3.06879754e+03  0.00e+00 1.04e-17  9.27e+02     0s
   2   6.19527275e+03  5.95560926e+03  0.00e+00 0.00e+00  2.40e+01     0s
   3   6.02018308e+03  5.97508089e+03  0.00e+00 0.00e+00  4.51e+00     0s
   4   6.00021295e+03  5.99996873e+03  0.00e+00 2.68e-19  2.44e-02     0s
   5   6.00000021e+03  5.99999999e+03  0.00e+00 8.91e-11  2.44e-05     0s
   6   6.00000000e+03  6.00000000e+03  0.00e+00 9.59e-14  2.44e-08     0s
   7   6.00000000e+03  6.00000000e+03  0.00e+00 9.58e-17  2.44e-11     0s

Barrier solved model in 7 iterations and 0.02 seconds (0.00 work units)
Optimal objective 6.00000000e+03

Extra simplex iterations after uncrush: 1

Root relaxation: objective 6.000000e+03, 5 iterations, 0.01 seconds (0.00 work units)

    Nodes    |    Current Node    |     Objective Bounds      |     Work
 Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

     0     0 6000.00000    0    4          - 6000.00000      -     -    0s
     0     0 6000.00000    0    4          - 6000.00000      -     -    0s
H    0     0                    6000.0067499 6000.00000  0.00%     -    0s

Explored 1 nodes (5 simplex iterations) in 0.03 seconds (0.00 work units)
Thread count was 32 (of 32 available processors)

Solution count 1: 6000.01 

Optimal solution found (tolerance 1.00e-04)
Warning: max constraint violation (3.9062e-03) exceeds tolerance
Best objective 6.000006749886e+03, best bound 6.000000000000e+03, gap 0.0001%
Set parameter Method to value 2
Gurobi Optimizer version 11.0.2 build v11.0.2rc0 (linux64 - "CentOS Linux 7 (Core)")

CPU model: AMD EPYC 7351 16-Core Processor, instruction set [SSE2|AVX|AVX2]
Thread count: 32 physical cores, 32 logical processors, using up to 32 threads

Optimize a model with 6 rows, 14 columns and 12 nonzeros
Model fingerprint: 0xb4494f8e
Model has 3 quadratic constraints
Model has 3 general constraints
Variable types: 14 continuous, 0 integer (0 binary)
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  QMatrix range    [1e+00, 6e+06]
  Objective range  [1e+01, 2e+01]
  Bounds range     [4e+02, 1e+07]
  RHS range        [4e+02, 4e+02]
Presolve removed 5 rows and 8 columns
Presolve time: 0.00s
Presolved: 22 rows, 12 columns, 41 nonzeros
Presolved model has 6 bilinear constraint(s)

Solving non-convex MIQCP

Variable types: 12 continuous, 0 integer (0 binary)
Root barrier log...

Ordering time: 0.00s

Barrier statistics:
 AA' NZ     : 6.000e+00
 Factor NZ  : 1.000e+01
 Factor Ops : 3.000e+01 (less than 1 second per iteration)
 Threads    : 1

                  Objective                Residual
Iter       Primal          Dual         Primal    Dual     Compl     Time
   0   6.73912034e+03 -4.31598434e+03  6.65e+04 9.77e-03  7.19e+03     0s
   1   6.94437023e+03 -2.13574332e+03  0.00e+00 6.94e-18  9.08e+02     0s
   2   6.74363195e+03  5.93954897e+03  0.00e+00 9.54e-18  8.04e+01     0s
   3   6.00795756e+03  5.96047329e+03  0.00e+00 8.67e-19  4.75e+00     0s
   4   6.00000812e+03  5.99996016e+03  0.00e+00 1.67e-18  4.80e-03     0s
   5   6.00000001e+03  5.99999996e+03  0.00e+00 4.34e-19  4.80e-06     0s
   6   6.00000000e+03  6.00000000e+03  0.00e+00 0.00e+00  4.80e-09     0s

Barrier solved model in 6 iterations and 0.02 seconds (0.00 work units)
Optimal objective 6.00000000e+03

Extra simplex iterations after uncrush: 1

Root relaxation: objective 6.000000e+03, 5 iterations, 0.01 seconds (0.00 work units)

    Nodes    |    Current Node    |     Objective Bounds      |     Work
 Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

     0     0 6000.00000    0    4          - 6000.00000      -     -    0s
     0     0 6000.00000    0    4          - 6000.00000      -     -    0s
H    0     0                    6000.0000000 6000.00000  0.00%     -    0s
     0     0 6000.00000    0    4 6000.00000 6000.00000  0.00%     -    0s

Explored 1 nodes (5 simplex iterations) in 0.03 seconds (0.00 work units)
Thread count was 32 (of 32 available processors)

Solution count 1: 6000 

Optimal solution found (tolerance 1.00e-04)
Best objective 6.000000000002e+03, best bound 6.000000000002e+03, gap 0.0000%
Set parameter Method to value 2
Gurobi Optimizer version 11.0.2 build v11.0.2rc0 (linux64 - "CentOS Linux 7 (Core)")

CPU model: AMD EPYC 7351 16-Core Processor, instruction set [SSE2|AVX|AVX2]
Thread count: 32 physical cores, 32 logical processors, using up to 32 threads

Optimize a model with 6 rows, 14 columns and 12 nonzeros
Model fingerprint: 0xacefb630
Model has 3 quadratic constraints
Model has 3 general constraints
Variable types: 14 continuous, 0 integer (0 binary)
Coefficient statistics:
  Matrix range     [1e+00, 1e+00]
  QMatrix range    [1e+00, 6e+06]
  Objective range  [1e+01, 2e+01]
  Bounds range     [4e+02, 1e+07]
  RHS range        [4e+02, 4e+02]
Presolve removed 5 rows and 8 columns
Presolve time: 0.00s
Presolved: 22 rows, 12 columns, 41 nonzeros
Presolved model has 6 bilinear constraint(s)

Solving non-convex MIQCP

Variable types: 12 continuous, 0 integer (0 binary)
Root barrier log...

Ordering time: 0.00s

Barrier statistics:
 AA' NZ     : 6.000e+00
 Factor NZ  : 1.000e+01
 Factor Ops : 3.000e+01 (less than 1 second per iteration)
 Threads    : 1

                  Objective                Residual
Iter       Primal          Dual         Primal    Dual     Compl     Time
   0   7.47824067e+03 -2.31598434e+03  6.65e+04 1.95e-02  7.14e+03     0s
   1   7.69605683e+03 -1.01943136e+03  0.00e+00 1.73e-17  8.72e+02     0s
   2   6.96692162e+03  5.95616533e+03  0.00e+00 6.94e-18  1.01e+02     0s
   3   6.00230082e+03  5.99002797e+03  0.00e+00 8.67e-19  1.23e+00     0s
   4   6.00000228e+03  5.99999001e+03  0.00e+00 6.98e-19  1.23e-03     0s
   5   6.00000000e+03  5.99999999e+03  0.00e+00 0.00e+00  1.23e-06     0s
   6   6.00000000e+03  6.00000000e+03  0.00e+00 0.00e+00  1.23e-09     0s

Barrier solved model in 6 iterations and 0.02 seconds (0.00 work units)
Optimal objective 6.00000000e+03

Extra simplex iterations after uncrush: 1

Root relaxation: objective 6.000000e+03, 5 iterations, 0.01 seconds (0.00 work units)

    Nodes    |    Current Node    |     Objective Bounds      |     Work
 Expl Unexpl |  Obj  Depth IntInf | Incumbent    BestBd   Gap | It/Node Time

     0     0 6000.00000    0    4          - 6000.00000      -     -    0s
     0     0 6000.00000    0    4          - 6000.00000      -     -    0s
     0     2 6000.00000    0    4          - 6000.00000      -     -    0s
* 3830  3154              88    6000.3514970 6000.00000  0.01%   1.5    0s

Explored 6989 nodes (10653 simplex iterations) in 0.15 seconds (0.00 work units)
Thread count was 32 (of 32 available processors)

Solution count 1: 6000.35 

Optimal solution found (tolerance 1.00e-04)
Warning: max constraint violation (3.0518e-05) exceeds tolerance
Best objective 6.000351497047e+03, best bound 6.000000000000e+03, gap 0.0059%
import matplotlib.pyplot as plt

plt.plot([0,1,2,3,4,5,6, 10, 15],flows_g1, color='red', label='g1 (w compressor)')
plt.plot([0,1,2,3,4,5,6, 10, 15],flows_g5, color='green', label='g5')

plt.xticks([0,1,5, 10, 15, 20])
plt.xlabel('compressor price')

plt.legend()
<matplotlib.legend.Legend at 0x7ffea7d285c0>
../_images/f82ac6639b5e177b8bd0729f0d822a83e49d59e69e1398cceeeaf29c7410191d.png