2323#===============================================================================
2424
2525import networkx as nx
26- from pyomo .environ import *
26+ import pyomo .environ as pyomo
2727
2828#===============================================================================
2929
@@ -38,7 +38,7 @@ def __init__(self, edges, edge_lines, node_edge_order):
3838 self .__graph .edges [edge ]['lines' ] = set ()
3939 for edge , lines in edge_lines .items ():
4040 self .__graph .edges [edge ]['lines' ].update (lines )
41- self .__model = ConcreteModel ()
41+ self .__model = pyomo . ConcreteModel ()
4242 node_ordering = { key : tuple (node for node in ordered_nodes if node in self .__graph )
4343 for key , ordered_nodes in node_edge_order .items () }
4444
@@ -55,7 +55,7 @@ def n_n1_l_le_p_set():
5555
5656 def n_n1_l_le_p_constraint (model , n , n1 , l , p ):
5757 if p == len (self .__graph .edges [n , n1 ]['lines' ]):
58- return Constraint .Skip
58+ return pyomo . Constraint .Skip
5959 return model .n_n1_l_le_p [n , n1 , l , p ] <= model .n_n1_l_le_p [n , n1 , l , p + 1 ]
6060
6161 def edge_position_set ():
@@ -77,10 +77,10 @@ def edge_line_mirror_constraint(model, n, n1, l):
7777 return (sum (model .n_n1_l_le_p [n , n1 , l , p ]
7878 + model .n_n1_l_le_p [n1 , n , l , p ] for p in range (1 , len (lines )+ 1 ))) == (len (lines ) + 1 )
7979
80- self .__model .n_n1_l_le_p = Var (n_n1_l_le_p_set (), domain = Binary )
81- self .__model .n_n1_l_p_constraint = Constraint (n_n1_l_le_p_set (), rule = n_n1_l_le_p_constraint )
82- self .__model .edge_position_unique_constraint = Constraint (edge_position_set (), rule = edge_position_unique_constraint )
83- self .__model .edge_line_mirror_constraint = Constraint (edge_line_set (), rule = edge_line_mirror_constraint )
80+ self .__model .n_n1_l_le_p = pyomo . Var (n_n1_l_le_p_set (), domain = pyomo . Binary )
81+ self .__model .n_n1_l_p_constraint = pyomo . Constraint (n_n1_l_le_p_set (), rule = n_n1_l_le_p_constraint )
82+ self .__model .edge_position_unique_constraint = pyomo . Constraint (edge_position_set (), rule = edge_position_unique_constraint )
83+ self .__model .edge_line_mirror_constraint = pyomo . Constraint (edge_line_set (), rule = edge_line_mirror_constraint )
8484
8585 #======================================================================
8686
@@ -107,10 +107,10 @@ def n_n1_A_lt_B_constraint_2(model, n, n1, A, B):
107107 def n_n1_A_lt_B_constraint_3 (model , n , n1 , A , B ):
108108 return model .n_n1_A_lt_B [n , n1 , A , B ] + model .n_n1_A_lt_B [n1 , n , A , B ] == 1
109109
110- self .__model .n_n1_A_lt_B = Var (set (n_n1_A_lt_B_set ()), domain = Binary )
111- self .__model .n_n1_A_lt_B_constraint_1 = Constraint (set (n_n1_A_lt_B_set ()), rule = n_n1_A_lt_B_constraint_1 )
112- self .__model .n_n1_A_lt_B_constraint_2 = Constraint (set (n_n1_A_lt_B_set ()), rule = n_n1_A_lt_B_constraint_2 )
113- self .__model .n_n1_A_lt_B_constraint_3 = Constraint (set (n_n1_A_lt_B_set ()), rule = n_n1_A_lt_B_constraint_3 )
110+ self .__model .n_n1_A_lt_B = pyomo . Var (set (n_n1_A_lt_B_set ()), domain = pyomo . Binary )
111+ self .__model .n_n1_A_lt_B_constraint_1 = pyomo . Constraint (set (n_n1_A_lt_B_set ()), rule = n_n1_A_lt_B_constraint_1 )
112+ self .__model .n_n1_A_lt_B_constraint_2 = pyomo . Constraint (set (n_n1_A_lt_B_set ()), rule = n_n1_A_lt_B_constraint_2 )
113+ self .__model .n_n1_A_lt_B_constraint_3 = pyomo . Constraint (set (n_n1_A_lt_B_set ()), rule = n_n1_A_lt_B_constraint_3 )
114114
115115 #======================================================================
116116
@@ -136,9 +136,9 @@ def n_n1_n2_A_B_constraint_2(model, node, n1, n2, A, B):
136136 - model .n_n1_A_lt_B [node , n1 , A , B ]
137137 - model .n_n1_n2_A_B [node , n1 , n2 , A , B ]) <= 0
138138
139- self .__model .n_n1_n2_A_B = Var (n_n1_n2_A_B_set (), domain = Binary )
140- self .__model .n_n1_n2_A_B_constraint_1 = Constraint (n_n1_n2_A_B_set (), rule = n_n1_n2_A_B_constraint_1 )
141- self .__model .n_n1_n2_A_B_constraint_2 = Constraint (n_n1_n2_A_B_set (), rule = n_n1_n2_A_B_constraint_2 )
139+ self .__model .n_n1_n2_A_B = pyomo . Var (n_n1_n2_A_B_set (), domain = pyomo . Binary )
140+ self .__model .n_n1_n2_A_B_constraint_1 = pyomo . Constraint (n_n1_n2_A_B_set (), rule = n_n1_n2_A_B_constraint_1 )
141+ self .__model .n_n1_n2_A_B_constraint_2 = pyomo . Constraint (n_n1_n2_A_B_set (), rule = n_n1_n2_A_B_constraint_2 )
142142
143143 #======================================================================
144144
@@ -174,8 +174,8 @@ def n_n1_n2_n3_A_B_constraint(model, node, n1, n2, n3, A, B):
174174 else :
175175 return 1 - model .n_n1_A_lt_B [node , n1 , B , A ] - model .n_n1_n2_n3_A_B [node , n1 , n2 , n3 , A , B ] <= 0
176176
177- self .__model .n_n1_n2_n3_A_B = Var (n_n1_n2_n3_A_B_set (), domain = Binary )
178- self .__model .n_n1_n2_n3_A_B_constraint = Constraint (n_n1_n2_n3_A_B_set (), rule = n_n1_n2_n3_A_B_constraint )
177+ self .__model .n_n1_n2_n3_A_B = pyomo . Var (n_n1_n2_n3_A_B_set (), domain = pyomo . Binary )
178+ self .__model .n_n1_n2_n3_A_B_constraint = pyomo . Constraint (n_n1_n2_n3_A_B_set (), rule = n_n1_n2_n3_A_B_constraint )
179179
180180 #======================================================================
181181
@@ -186,7 +186,7 @@ def total_crossings(model):
186186 + sum (model .n_n1_n2_n3_A_B [node , n1 , n2 , n3 , A , B ]
187187 for (node , n1 , n2 , n3 , A , B ) in model .n_n1_n2_n3_A_B ))
188188
189- self .__model .total_crossings = Objective (rule = total_crossings )
189+ self .__model .total_crossings = pyomo . Objective (rule = total_crossings )
190190
191191 #======================================================================
192192
@@ -197,7 +197,7 @@ def solve(self, tee=False):
197197 #==========================
198198 # Solve the model using CBC
199199 options = {'sec' : 600 , 'threads' : 10 , 'ratio' : 0.02 }
200- SolverFactory ('cbc' ).solve (self .__model , options = options , tee = tee )
200+ pyomo . SolverFactory ('cbc' ).solve (self .__model , options = options , tee = tee )
201201
202202 def results (self ):
203203 #=================
0 commit comments